本文整理汇总了Python中pymongo.mongo_replica_set_client._partition_node函数的典型用法代码示例。如果您正苦于以下问题:Python _partition_node函数的具体用法?Python _partition_node怎么用?Python _partition_node使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_partition_node函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stepdown_triggers_refresh
def test_stepdown_triggers_refresh(self):
c_find_one = yield motor.MotorReplicaSetClient(
self.seed, replicaSet=self.name).open()
# We've started the primary and one secondary
primary = ha_tools.get_primary()
secondary = ha_tools.get_secondaries()[0]
self.assertEqual(
one(c_find_one.secondaries), _partition_node(secondary))
ha_tools.stepdown_primary()
# Make sure the stepdown completes
yield self.pause(1)
# Trigger a refresh
with assert_raises(AutoReconnect):
yield c_find_one.test.test.find_one()
# Wait for the immediate refresh to complete - we're not waiting for
# the periodic refresh, which has been disabled
yield self.pause(1)
# We've detected the stepdown
self.assertTrue(
not c_find_one.primary
or primary != _partition_node(c_find_one.primary))
示例2: test_stepdown_triggers_refresh
def test_stepdown_triggers_refresh(self, done):
c_find_one = motor.MotorReplicaSetClient(
self.seed, replicaSet=self.name).open_sync()
# We've started the primary and one secondary
primary = ha_tools.get_primary()
secondary = ha_tools.get_secondaries()[0]
self.assertEqual(
one(c_find_one.secondaries), _partition_node(secondary))
ha_tools.stepdown_primary()
# Make sure the stepdown completes
yield gen.Task(IOLoop.instance().add_timeout, time.time() + 1)
# Trigger a refresh
yield AssertRaises(AutoReconnect, c_find_one.test.test.find_one)
# Wait for the immediate refresh to complete - we're not waiting for
# the periodic refresh, which has been disabled
yield gen.Task(IOLoop.instance().add_timeout, time.time() + 1)
# We've detected the stepdown
self.assertTrue(
not c_find_one.primary
or primary != _partition_node(c_find_one.primary))
done()
示例3: test_recovering_member_triggers_refresh
def test_recovering_member_triggers_refresh(self):
# To test that find_one() and count() trigger immediate refreshes,
# we'll create a separate client for each
self.c_find_one, self.c_count = yield [
motor.MotorReplicaSetClient(
self.seed, replicaSet=self.name, read_preference=SECONDARY
).open() for _ in xrange(2)]
# We've started the primary and one secondary
primary = ha_tools.get_primary()
secondary = ha_tools.get_secondaries()[0]
# Pre-condition: just make sure they all connected OK
for c in self.c_find_one, self.c_count:
self.assertEqual(one(c.secondaries), _partition_node(secondary))
ha_tools.set_maintenance(secondary, True)
# Trigger a refresh in various ways
with assert_raises(AutoReconnect):
yield self.c_find_one.test.test.find_one()
with assert_raises(AutoReconnect):
yield self.c_count.test.test.count()
# Wait for the immediate refresh to complete - we're not waiting for
# the periodic refresh, which has been disabled
yield self.pause(1)
for c in self.c_find_one, self.c_count:
self.assertFalse(c.secondaries)
self.assertEqual(_partition_node(primary), c.primary)
示例4: setUp
def setUp(self):
client = MongoClient(pair)
response = client.admin.command('ismaster')
if 'setName' in response:
self.name = str(response['setName'])
self.w = len(response['hosts'])
self.hosts = set([_partition_node(h)
for h in response["hosts"]])
self.arbiters = set([_partition_node(h)
for h in response.get("arbiters", [])])
repl_set_status = client.admin.command('replSetGetStatus')
primary_info = [
m for m in repl_set_status['members']
if m['stateStr'] == 'PRIMARY'
][0]
self.primary = _partition_node(primary_info['name'])
self.secondaries = [
_partition_node(m['name']) for m in repl_set_status['members']
if m['stateStr'] == 'SECONDARY'
]
else:
raise SkipTest("Not connected to a replica set")
super(TestReplicaSetClientBase, self).setUp()
示例5: setUp
def setUp(self):
super(MotorTestReadPreference, self).setUp()
members = [
# primary
{'tags': {'dc': 'ny', 'name': 'primary'}},
# secondary
{'tags': {'dc': 'la', 'name': 'secondary'}, 'priority': 0},
# other_secondary
{'tags': {'dc': 'ny', 'name': 'other_secondary'}, 'priority': 0},
]
res = ha_tools.start_replica_set(members)
self.seed, self.name = res
primary = ha_tools.get_primary()
self.primary = _partition_node(primary)
self.primary_tags = ha_tools.get_tags(primary)
# Make sure priority worked
self.assertEqual('primary', self.primary_tags['name'])
self.primary_dc = {'dc': self.primary_tags['dc']}
secondaries = ha_tools.get_secondaries()
(secondary, ) = [
s for s in secondaries
if ha_tools.get_tags(s)['name'] == 'secondary']
self.secondary = _partition_node(secondary)
self.secondary_tags = ha_tools.get_tags(secondary)
self.secondary_dc = {'dc': self.secondary_tags['dc']}
(other_secondary, ) = [
s for s in secondaries
if ha_tools.get_tags(s)['name'] == 'other_secondary']
self.other_secondary = _partition_node(other_secondary)
self.other_secondary_tags = ha_tools.get_tags(other_secondary)
self.other_secondary_dc = {'dc': self.other_secondary_tags['dc']}
# Synchronous PyMongo interfaces for convenience
self.c = pymongo.mongo_replica_set_client.MongoReplicaSetClient(
self.seed, replicaSet=self.name)
self.db = self.c.motor_test
self.w = len(self.c.secondaries) + 1
self.db.test.remove({}, w=self.w)
self.db.test.insert(
[{'foo': i} for i in xrange(10)], w=self.w)
self.clear_ping_times()
示例6: setUp
def setUp(self):
client = MongoClient(pair)
response = client.admin.command("ismaster")
if "setName" in response:
self.name = str(response["setName"])
self.w = len(response["hosts"])
self.hosts = set([_partition_node(h) for h in response["hosts"]])
self.arbiters = set([_partition_node(h) for h in response.get("arbiters", [])])
repl_set_status = client.admin.command("replSetGetStatus")
primary_info = [m for m in repl_set_status["members"] if m["stateStr"] == "PRIMARY"][0]
self.primary = _partition_node(primary_info["name"])
self.secondaries = [
_partition_node(m["name"]) for m in repl_set_status["members"] if m["stateStr"] == "SECONDARY"
]
else:
raise SkipTest("Not connected to a replica set")
示例7: test_monitor_removes_recovering_member
def test_monitor_removes_recovering_member(self):
self.c = motor.MotorReplicaSetClient(self.seed, replicaSet=self.name)
yield self.c.open()
secondaries = ha_tools.get_secondaries()
for mode in SECONDARY, SECONDARY_PREFERRED:
partitioned_secondaries = [_partition_node(s) for s in secondaries]
yield assert_read_from_all(
self, self.c, partitioned_secondaries, mode)
secondary, recovering_secondary = secondaries
ha_tools.set_maintenance(recovering_secondary, True)
yield self.pause(2 * MONITOR_INTERVAL)
for mode in SECONDARY, SECONDARY_PREFERRED:
# Don't read from recovering member
yield assert_read_from(
self, self.c, _partition_node(secondary), mode)
示例8: test_passive_and_hidden
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)