def test_passive_and_hidden(self): self.c = ReplicaSetConnection(self.seed, replicaSet=self.name, use_greenlets=use_greenlets) db = self.c.pymongo_test w = len(self.c.secondaries) + 1 db.test.remove({}, safe=True, w=w) db.test.insert({'foo': 'bar'}, safe=True, w=w) passives = ha_tools.get_passives() passives = [_partition_node(member) for member in passives] hidden = ha_tools.get_hidden_members() hidden = [_partition_node(member) for member in hidden] self.assertEqual(self.c.secondaries, set(passives)) for mode in (ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED): db.read_preference = mode for _ in xrange(10): cursor = db.test.find() cursor.next() self.assertTrue(cursor._Cursor__connection_id in passives) self.assertTrue(cursor._Cursor__connection_id not in hidden) ha_tools.kill_members(ha_tools.get_passives(), 2) sleep(2 * MONITOR_INTERVAL) db.read_preference = ReadPreference.SECONDARY_PREFERRED for _ in xrange(10): cursor = db.test.find() cursor.next() self.assertEqual(cursor._Cursor__connection_id, self.c.primary)
def test_passive_and_hidden(self): self.c = ReplicaSetConnection( self.seed, replicaSet=self.name, use_greenlets=use_greenlets) db = self.c.pymongo_test w = len(self.c.secondaries) + 1 db.test.remove({}, safe=True, w=w) db.test.insert({'foo': 'bar'}, safe=True, w=w) passives = ha_tools.get_passives() passives = [_partition_node(member) for member in passives] hidden = ha_tools.get_hidden_members() hidden = [_partition_node(member) for member in hidden] self.assertEqual(self.c.secondaries, set(passives)) for mode in ( ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED ): db.read_preference = mode for _ in xrange(10): cursor = db.test.find() cursor.next() self.assertTrue(cursor._Cursor__connection_id in passives) self.assertTrue(cursor._Cursor__connection_id not in hidden) ha_tools.kill_members(ha_tools.get_passives(), 2) sleep(2 * MONITOR_INTERVAL) db.read_preference = ReadPreference.SECONDARY_PREFERRED for _ in xrange(10): cursor = db.test.find() cursor.next() self.assertEqual(cursor._Cursor__connection_id, self.c.primary)
def test_passive_and_hidden(self): self.c = MongoReplicaSetClient( self.seed, replicaSet=self.name, use_greenlets=use_greenlets) passives = ha_tools.get_passives() passives = partition_nodes(passives) self.assertEqual(self.c.secondaries, set(passives)) for mode in SECONDARY, SECONDARY_PREFERRED: utils.assertReadFromAll(self, self.c, passives, mode) ha_tools.kill_members(ha_tools.get_passives(), 2) sleep(2 * MONITOR_INTERVAL) utils.assertReadFrom(self, self.c, self.c.primary, SECONDARY_PREFERRED)
def test_passive_and_hidden(self): self.c = motor.MotorReplicaSetClient(self.seed, replicaSet=self.name) yield self.c.open() passives = ha_tools.get_passives() passives = [_partition_node(member) for member in passives] self.assertEqual(self.c.secondaries, set(passives)) for mode in SECONDARY, SECONDARY_PREFERRED: yield assert_read_from_all(self, self.c, passives, mode) ha_tools.kill_members(ha_tools.get_passives(), 2) yield self.pause(2 * MONITOR_INTERVAL) yield assert_read_from( self, self.c, self.c.primary, SECONDARY_PREFERRED)
def test_passive_and_hidden(self): self.c = motor.MotorReplicaSetClient(self.seed, replicaSet=self.name) yield self.c.open() passives = ha_tools.get_passives() passives = [_partition_node(member) for member in passives] self.assertEqual(self.c.secondaries, set(passives)) for mode in SECONDARY, SECONDARY_PREFERRED: yield assert_read_from_all(self, self.c, passives, mode) ha_tools.kill_members(ha_tools.get_passives(), 2) yield self.pause(2 * MONITOR_INTERVAL) yield assert_read_from(self, self.c, self.c.primary, SECONDARY_PREFERRED)
def test_passive_and_hidden(self): self.c = MongoClient( self.seed, replicaSet=self.name, serverSelectionTimeoutMS=self.server_selection_timeout) passives = ha_tools.get_passives() passives = partition_nodes(passives) self.assertEqual(self.c.secondaries, set(passives)) for mode in SECONDARY, SECONDARY_PREFERRED: utils.assertReadFromAll(self, self.c, passives, mode) ha_tools.kill_members(ha_tools.get_passives(), 2) time.sleep(2 * self.heartbeat_frequency) utils.assertReadFrom(self, self.c, self.c.primary, SECONDARY_PREFERRED)
def test_passive_and_hidden(self): loop = IOLoop.instance() self.c = motor.MotorReplicaSetClient(self.seed, replicaSet=self.name) self.c passives = ha_tools.get_passives() passives = [_partition_node(member) for member in passives] self.assertEqual(self.c.secondaries, set(passives)) for mode in SECONDARY, SECONDARY_PREFERRED: yield motor.Op(assertReadFromAll, self, self.c, passives, mode) ha_tools.kill_members(ha_tools.get_passives(), 2) yield gen.Task(loop.add_timeout, time.time() + 2 * MONITOR_INTERVAL) yield motor.Op(assertReadFrom, self, self.c, self.c.primary, SECONDARY_PREFERRED)