Ejemplo n.º 1
0
    def test_mongos_ha(self, done):
        dbname = 'pymongo_mongos_ha'
        c = motor.MotorClient(self.seed_list).open_sync()
        yield motor.Op(c.drop_database, dbname)
        coll = c[dbname].test
        yield motor.Op(coll.insert, {'foo': 'bar'})

        first = '%s:%d' % (c.host, c.port)
        ha_tools.kill_mongos(first)
        # Fail first attempt
        yield AssertRaises(AutoReconnect, coll.count)
        # Find new mongos
        yield AssertEqual(1, coll.count)

        second = '%s:%d' % (c.host, c.port)
        self.assertNotEqual(first, second)
        ha_tools.kill_mongos(second)
        # Fail first attempt
        yield AssertRaises(AutoReconnect, coll.count)
        # Find new mongos
        yield AssertEqual(1, coll.count)

        third = '%s:%d' % (c.host, c.port)
        self.assertNotEqual(second, third)
        ha_tools.kill_mongos(third)
        # Fail first attempt
        yield AssertRaises(AutoReconnect, coll.count)

        # We've killed all three, restart one.
        ha_tools.restart_mongos(first)

        # Find new mongos
        yield AssertEqual(1, coll.count)
        done()
Ejemplo n.º 2
0
    def test_mongos_ha(self):
        dbname = 'pymongo_mongos_ha'
        c = yield motor.MotorClient(self.seed_list).open()
        yield c.drop_database(dbname)
        coll = c[dbname].test
        yield coll.insert({'foo': 'bar'})

        first = '%s:%d' % (c.host, c.port)
        ha_tools.kill_mongos(first)
        yield self.pause(1)
        # Fail first attempt
        with assert_raises(AutoReconnect):
            yield coll.count()
        # Find new mongos
        self.assertEqual(1, (yield coll.count()))

        second = '%s:%d' % (c.host, c.port)
        self.assertNotEqual(first, second)
        ha_tools.kill_mongos(second)
        yield self.pause(1)
        # Fail first attempt
        with assert_raises(AutoReconnect):
            yield coll.count()
        # Find new mongos
        self.assertEqual(1, (yield coll.count()))

        third = '%s:%d' % (c.host, c.port)
        self.assertNotEqual(second, third)
        ha_tools.kill_mongos(third)
        yield self.pause(1)
        # Fail first attempt
        with assert_raises(AutoReconnect):
            yield coll.count()

        # We've killed all three, restart one.
        ha_tools.restart_mongos(first)
        yield self.pause(1)

        # Find new mongos
        self.assertEqual(1, (yield coll.count()))
Ejemplo n.º 3
0
    def test_mongos_ha(self):
        dbname = 'pymongo_mongos_ha'
        c = yield motor.MotorClient(self.seed_list).open()
        yield c.drop_database(dbname)
        coll = c[dbname].test
        yield coll.insert({'foo': 'bar'})

        first = '%s:%d' % (c.host, c.port)
        ha_tools.kill_mongos(first)
        yield self.pause(1)
        # Fail first attempt
        with self.assertRaises(AutoReconnect):
            yield coll.count()
        # Find new mongos
        self.assertEqual(1, (yield coll.count()))

        second = '%s:%d' % (c.host, c.port)
        self.assertNotEqual(first, second)
        ha_tools.kill_mongos(second)
        yield self.pause(1)
        # Fail first attempt
        with self.assertRaises(AutoReconnect):
            yield coll.count()
        # Find new mongos
        self.assertEqual(1, (yield coll.count()))

        third = '%s:%d' % (c.host, c.port)
        self.assertNotEqual(second, third)
        ha_tools.kill_mongos(third)
        yield self.pause(1)
        # Fail first attempt
        with self.assertRaises(AutoReconnect):
            yield coll.count()

        # We've killed all three, restart one.
        ha_tools.restart_mongos(first)
        yield self.pause(1)

        # Find new mongos
        self.assertEqual(1, (yield coll.count()))