本文整理汇总了Python中mongo_orchestration.replica_sets.ReplicaSet.wait_while_reachable方法的典型用法代码示例。如果您正苦于以下问题:Python ReplicaSet.wait_while_reachable方法的具体用法?Python ReplicaSet.wait_while_reachable怎么用?Python ReplicaSet.wait_while_reachable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo_orchestration.replica_sets.ReplicaSet
的用法示例。
在下文中一共展示了ReplicaSet.wait_while_reachable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReplicaSetTestCase
# 需要导入模块: from mongo_orchestration.replica_sets import ReplicaSet [as 别名]
# 或者: from mongo_orchestration.replica_sets.ReplicaSet import wait_while_reachable [as 别名]
#.........这里部分代码省略.........
def test_get_members_in_state(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
primaries = self.repl.get_members_in_state(1)
self.assertEqual(len(primaries), 1)
self.assertEqual(primaries[0], self.repl.primary())
def test_connection(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
_id = 1
hostname = self.repl.member_id_to_host(_id)
self.assertTrue(self.repl.connection(timeout=5))
self.assertTrue(self.repl.connection(hostname=hostname, timeout=5))
self.repl.member_command(_id, 'stop')
self.assertRaises(pymongo.errors.AutoReconnect, lambda: self.repl.connection(hostname=hostname, timeout=5))
def test_secondaries(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
secondaries = [item['host'] for item in self.repl.secondaries()]
self.assertEqual(secondaries, self.repl.get_members_in_state(2))
def test_arbiters(self):
self.repl = ReplicaSet(self.repl_cfg)
arbiters = [item['host'] for item in self.repl.arbiters()]
self.assertEqual(arbiters, self.repl.get_members_in_state(7))
def test_hidden(self):
self.repl = ReplicaSet(self.repl_cfg)
for _ in self.repl.hidden():
self.assertTrue(self.repl.run_command('serverStatus', arg=None, is_eval=False, member_id=2)['repl']['hidden'])
def test_passives(self):
self.repl = ReplicaSet(self.repl_cfg)
self.repl.repl_member_add({"rsParams": {"priority": 0}})
for member in self.repl.passives():
self.assertTrue(member['host'] in self.repl.run_command('isMaster', is_eval=False).get('passives'))
def test_servers(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
self.repl.repl_member_add({"rsParams": {"priority": 0}})
for member in self.repl.servers():
self.assertTrue(member['host'] in self.repl.run_command('isMaster', is_eval=False).get('hosts'))
def test_compare_servers_passives(self):
self.repl = ReplicaSet(self.repl_cfg)
self.repl.repl_member_add({"rsParams": {"priority": 0}})
self.repl.repl_member_add({})
servers = self.repl.servers()
passives = self.repl.passives()
for item in servers:
self.assertTrue(item not in passives)
for item in passives:
self.assertTrue(item not in servers)
def test_wait_while_reachable(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
servers = [member['host'] for member in self.repl.members()]
self.assertTrue(self.repl.wait_while_reachable(servers, timeout=10))
self.repl.member_command(1, 'stop')
self.assertFalse(self.repl.wait_while_reachable(servers, timeout=10))
def test_reset(self):
self.repl_cfg = {'members': [{}, {}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
server_ids = [m['server_id'] for m in self.repl.members()]
all_hosts = [Servers().hostname(server_id) for server_id in server_ids]
# Shut down all members of the ReplicaSet.
for server_id in server_ids:
Servers().command(server_id, 'stop')
# Reset the ReplicaSet. --- We should be able to connect to all members.
self.repl.reset()
for host in all_hosts:
# No ConnectionFailure/AutoReconnect.
connected(pymongo.MongoClient(host))
def test_rs_settings(self):
if SERVER_VERSION < (2, 4):
raise SkipTest(
"Need at least MongoDB >= 2.4 to test replica set settings.")
self.repl_cfg = {
'rsSettings': {'heartbeatTimeoutSecs': 20},
'members': [{}]
}
self.repl = ReplicaSet(self.repl_cfg)
conn = self.repl.connection()
if SERVER_VERSION >= (2, 8):
config = conn.admin.command('replSetGetConfig')['config']
else:
config = conn.local.system.replset.find_one()
self.assertEqual(config['settings']['heartbeatTimeoutSecs'], 20)