本文整理汇总了Python中pymongo.mongo_replica_set_client.MongoReplicaSetClient.in_request方法的典型用法代码示例。如果您正苦于以下问题:Python MongoReplicaSetClient.in_request方法的具体用法?Python MongoReplicaSetClient.in_request怎么用?Python MongoReplicaSetClient.in_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.mongo_replica_set_client.MongoReplicaSetClient
的用法示例。
在下文中一共展示了MongoReplicaSetClient.in_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestReplicaSetRequest
# 需要导入模块: from pymongo.mongo_replica_set_client import MongoReplicaSetClient [as 别名]
# 或者: from pymongo.mongo_replica_set_client.MongoReplicaSetClient import in_request [as 别名]
class TestReplicaSetRequest(HATestCase):
def setUp(self):
members = [{}, {}, {'arbiterOnly': True}]
res = ha_tools.start_replica_set(members)
self.c = MongoReplicaSetClient(res[0], replicaSet=res[1],
use_greenlets=use_greenlets,
auto_start_request=True)
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())
rs_state = self.c._MongoReplicaSetClient__rs_state
primary_pool = rs_state.get(primary).pool
secondary_pool = rs_state.get(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()
sleep(5)
patience_seconds = 60
for _ in range(patience_seconds):
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
sleep(1)
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()
super(TestReplicaSetRequest, self).tearDown()