def test_mongos_ha(self): coll = self.client[self.dbname].test self.assertTrue(coll.insert({'foo': 'bar'})) first = '%s:%d' % (self.client.host, self.client.port) ha_tools.kill_mongos(first) # Fail first attempt self.assertRaises(AutoReconnect, coll.count) # Find new mongos self.assertEqual(1, coll.count()) second = '%s:%d' % (self.client.host, self.client.port) self.assertNotEqual(first, second) ha_tools.kill_mongos(second) # Fail first attempt self.assertRaises(AutoReconnect, coll.count) # Find new mongos self.assertEqual(1, coll.count()) third = '%s:%d' % (self.client.host, self.client.port) self.assertNotEqual(second, third) ha_tools.kill_mongos(third) # Fail first attempt self.assertRaises(AutoReconnect, coll.count) # We've killed all three, restart one. ha_tools.restart_mongos(first) # Find new mongos self.assertEqual(1, coll.count())
def test_mongos_ha(self): coll = self.conn[self.dbname].test self.assertTrue(coll.insert({'foo': 'bar'}, safe=True)) first = '%s:%d' % (self.conn.host, self.conn.port) ha_tools.kill_mongos(first) # Fail first attempt self.assertRaises(AutoReconnect, coll.count) # Find new mongos self.assertEqual(1, coll.count()) second = '%s:%d' % (self.conn.host, self.conn.port) self.assertNotEqual(first, second) ha_tools.kill_mongos(second) # Fail first attempt self.assertRaises(AutoReconnect, coll.count) # Find new mongos self.assertEqual(1, coll.count()) third = '%s:%d' % (self.conn.host, self.conn.port) self.assertNotEqual(second, third) ha_tools.kill_mongos(third) # Fail first attempt self.assertRaises(AutoReconnect, coll.count) # We've killed all three, restart one. ha_tools.restart_mongos(first) # Find new mongos self.assertEqual(1, coll.count())
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()
def test_mongos_load_balancing(self): wait_until(lambda: len(ha_tools.routers) == len(self.client.nodes), 'discover all mongoses') # Can't access "address" when load balancing. with self.assertRaises(InvalidOperation): self.client.address coll = self.client[self.dbname].test coll.insert_one({'foo': 'bar'}) live_routers = list(ha_tools.routers) ha_tools.kill_mongos(live_routers.pop()) while live_routers: try: self.assertEqual(1, coll.count()) except ConnectionFailure: # If first attempt happened to select the dead mongos. self.assertEqual(1, coll.count()) wait_until(lambda: len(live_routers) == len(self.client.nodes), 'remove dead mongos', timeout=30) ha_tools.kill_mongos(live_routers.pop()) # Make sure the last one's really dead. time.sleep(1) # I'm alone. self.assertRaises(ConnectionFailure, coll.count) wait_until(lambda: 0 == len(self.client.nodes), 'remove dead mongos', timeout=30) ha_tools.restart_mongos(one(ha_tools.routers)) # Find new mongos self.assertEqual(1, coll.count())
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()))