本文整理汇总了Python中lib.rs.ReplicaSet类的典型用法代码示例。如果您正苦于以下问题:Python ReplicaSet类的具体用法?Python ReplicaSet怎么用?Python ReplicaSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReplicaSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_member_del_no_reconfig
def test_member_del_no_reconfig(self):
self.repl_cfg = {'members': [{}, {}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
m_count = len(self.repl.config['members'])
self.assertTrue(self.repl.member_del(2, reconfig=False))
self.assertEqual(len(self.repl.config['members']), m_count)
self.repl.host_map.pop(2)
示例2: test_member_update
def test_member_update(self):
self.repl = ReplicaSet(self.repl_cfg)
member = [item for item in self.repl.config['members'] if item['_id'] == 2][0]
self.assertTrue(member.get('hidden', False))
self.assertTrue(self.repl.member_update(2, {"rsParams": {"priority": 1, "hidden": False}}))
member = [item for item in self.repl.config['members'] if item['_id'] == 2][0]
self.assertFalse(member.get('hidden', False))
示例3: test_len
def test_len(self):
self.repl = ReplicaSet(self.repl_cfg)
self.assertTrue(len(self.repl) == len(self.repl_cfg['members']))
self.repl.member_del(3)
self.assertTrue(len(self.repl) == len(self.repl_cfg['members']) - 1)
self.repl.repl_member_add({'rsParams': {'arbiterOnly': True}})
self.assertTrue(len(self.repl) == len(self.repl_cfg['members']))
示例4: test_repl_member_add
def test_repl_member_add(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
member_id = self.repl.repl_member_add({"rsParams": {"priority": 0, "hidden": True}})
self.assertTrue(member_id >= 0)
member = [item for item in self.repl.config['members'] if item['_id'] == member_id][0]
self.assertTrue(member['hidden'])
示例5: test_wait_while_reachable
def test_wait_while_reachable(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
hosts = [member['host'] for member in self.repl.members()]
self.assertTrue(self.repl.wait_while_reachable(hosts, timeout=10))
self.repl.member_command(1, 'stop')
self.assertFalse(self.repl.wait_while_reachable(hosts, timeout=10))
示例6: test_repl_update
def test_repl_update(self):
self.repl_cfg = {'members': [{}, {}, {'rsParams': {'priority': 0, 'hidden': True}}]}
self.repl = ReplicaSet(self.repl_cfg)
config = self.repl.config
config['members'][1]['priority'] = 0
config['members'][1]['hidden'] = True
self.assertTrue(self.repl.repl_update(config))
self.assertTrue(self.repl.config['members'][1]['hidden'])
示例7: test_member_info
def test_member_info(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
member = [item for item in self.repl.config['members'] if item['_id'] == 1][0]
result = self.repl.member_info(1)
self.assertTrue(result['procInfo']['alive'])
self.assertEqual(member['host'], result['uri'])
self.assertTrue(len(result['rsInfo']) > 0)
示例8: test_run_command
def test_run_command(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
self.assertEqual(self.repl.run_command("rs.status()", is_eval=True)['ok'], 1)
result = self.repl.run_command('serverStatus', arg=None, is_eval=False, member_id=0)['repl']
for key in ('me', 'ismaster', 'setName', 'primary', 'hosts'):
self.assertTrue(key in result)
self.assertEqual(self.repl.run_command(command="replSetGetStatus", is_eval=False)['ok'], 1)
示例9: test_member_freeze
def test_member_freeze(self):
self.repl_cfg = {"members": [{"rsParams": {"priority": 19}}, {"rsParams": {"priority": 7}}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
primary_next = self.repl.member_info(2)['uri']
self.assertTrue(self.repl.member_freeze(1, 30))
self.repl.member_command(0, 'stop')
self.assertEqual(self.repl.primary(), primary_next)
time.sleep(40)
self.assertEqual(self.repl.primary(), self.repl.member_info(1)['uri'])
示例10: test_connection
def test_connection(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
_id = 1
hostname = self.repl.id2host(_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))
示例11: test_members
def test_members(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
members1 = sorted(self.repl.config['members'], key=lambda item: item['_id'])
members2 = sorted(self.repl.members(), key=lambda item: item['_id'])
self.assertEqual(len(members1), len(members2))
for i in xrange(len(members1)):
self.assertEqual(members1[i]['host'], members2[i]['host'])
self.assertEqual(members1[i]['_id'], members2[i]['_id'])
示例12: test_member_create
def test_member_create(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
result = self.repl.member_create({}, 13)
self.assertTrue('host' in result)
self.assertTrue('_id' in result)
h_id = Hosts().id_by_hostname(result['host'])
h_info = Hosts().info(h_id)
self.assertEqual(result['host'], h_info['uri'])
self.assertTrue(h_info['procInfo']['alive'])
Hosts().remove(h_id)
示例13: test_member_command
def test_member_command(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
_id = 1
self.assertTrue(self.repl.member_info(_id)['procInfo']['alive'])
self.repl.member_command(_id, 'stop')
self.assertFalse(self.repl.member_info(_id)['procInfo']['alive'])
self.repl.member_command(_id, 'start')
self.assertTrue(self.repl.member_info(_id)['procInfo']['alive'])
self.repl.member_command(_id, 'restart')
self.assertTrue(self.repl.member_info(_id)['procInfo']['alive'])
示例14: test_compare_hosts_passives
def test_compare_hosts_passives(self):
self.repl = ReplicaSet(self.repl_cfg)
self.repl.repl_member_add({"rsParams": {"priority": 0}})
self.repl.repl_member_add({})
hosts = self.repl.hosts()
passives = self.repl.passives()
for item in hosts:
self.assertTrue(item not in passives)
for item in passives:
self.assertTrue(item not in hosts)
示例15: test_info
def test_info(self):
self.repl_cfg = {'members': [{}, {}]}
self.repl = ReplicaSet(self.repl_cfg)
cfg = self.repl.config
info = self.repl.info()
self.assertEqual(info['auth_key'], self.repl.auth_key)
self.assertEqual(info['id'], self.repl.repl_id)
self.assertEqual(len(info['members']), len(cfg['members']))
members1 = sorted(cfg['members'], key=lambda item: item['_id'])
members2 = sorted(info['members'], key=lambda item: item['_id'])
for i in range(len(members1)):
self.assertEqual(members1[i]['_id'], members2[i]['_id'])
self.assertEqual(members1[i]['host'], members2[i]['host'])