本文整理汇总了Python中pymongo.ReplicaSetConnection.alive方法的典型用法代码示例。如果您正苦于以下问题:Python ReplicaSetConnection.alive方法的具体用法?Python ReplicaSetConnection.alive怎么用?Python ReplicaSetConnection.alive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.ReplicaSetConnection
的用法示例。
在下文中一共展示了ReplicaSetConnection.alive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alive
# 需要导入模块: from pymongo import ReplicaSetConnection [as 别名]
# 或者: from pymongo.ReplicaSetConnection import alive [as 别名]
def test_alive(self):
primary = ha_tools.get_primary()
secondary = ha_tools.get_random_secondary()
primary_cx = Connection(primary, use_greenlets=use_greenlets)
secondary_cx = Connection(secondary, use_greenlets=use_greenlets)
rsc = ReplicaSetConnection(
self.seed, replicaSet=self.name, use_greenlets=use_greenlets)
try:
self.assertTrue(primary_cx.alive())
self.assertTrue(secondary_cx.alive())
self.assertTrue(rsc.alive())
ha_tools.kill_primary()
time.sleep(0.5)
self.assertFalse(primary_cx.alive())
self.assertTrue(secondary_cx.alive())
self.assertFalse(rsc.alive())
ha_tools.kill_members([secondary], 2)
time.sleep(0.5)
self.assertFalse(primary_cx.alive())
self.assertFalse(secondary_cx.alive())
self.assertFalse(rsc.alive())
finally:
rsc.close()