本文整理汇总了Python中pymongo.ReplicaSetConnection.in_request方法的典型用法代码示例。如果您正苦于以下问题:Python ReplicaSetConnection.in_request方法的具体用法?Python ReplicaSetConnection.in_request怎么用?Python ReplicaSetConnection.in_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.ReplicaSetConnection
的用法示例。
在下文中一共展示了ReplicaSetConnection.in_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestReplicaSetRequest
# 需要导入模块: from pymongo import ReplicaSetConnection [as 别名]
# 或者: from pymongo.ReplicaSetConnection import in_request [as 别名]
class TestReplicaSetRequest(unittest.TestCase):
def setUp(self):
members = [{}, {}, {'arbiterOnly': True}]
res = ha_tools.start_replica_set(members)
self.c = ReplicaSetConnection(res[0], replicaSet=res[1],
use_greenlets=use_greenlets)
def test_request_during_failover(self):
primary = _partition_node(ha_tools.get_primary())
secondary = _partition_node(ha_tools.get_random_secondary())
self.assertTrue(self.c.auto_start_request)
self.assertTrue(self.c.in_request())
primary_pool = self.c._MongoReplicaSetClient__members[primary].pool
secondary_pool = self.c._MongoReplicaSetClient__members[secondary].pool
# Trigger start_request on primary pool
utils.assertReadFrom(self, self.c, primary, PRIMARY)
self.assertTrue(primary_pool.in_request())
# Fail over
ha_tools.kill_primary()
patience_seconds = 60
for _ in range(patience_seconds):
sleep(1)
try:
if ha_tools.ha_tools_debug:
print 'Waiting for failover'
if ha_tools.get_primary():
# We have a new primary
break
except ConnectionFailure:
pass
else:
self.fail("Problem with test: No new primary after %s seconds"
% patience_seconds)
try:
# Trigger start_request on secondary_pool, which is becoming new
# primary
self.c.test.test.find_one()
except AutoReconnect:
# We've noticed the failover now
pass
# The old secondary is now primary
utils.assertReadFrom(self, self.c, secondary, PRIMARY)
self.assertTrue(self.c.in_request())
self.assertTrue(secondary_pool.in_request())
def tearDown(self):
self.c.close()
ha_tools.kill_all_members()