本文整理汇总了Python中cassandra.policies.RoundRobinPolicy.populate方法的典型用法代码示例。如果您正苦于以下问题:Python RoundRobinPolicy.populate方法的具体用法?Python RoundRobinPolicy.populate怎么用?Python RoundRobinPolicy.populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.policies.RoundRobinPolicy
的用法示例。
在下文中一共展示了RoundRobinPolicy.populate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiple_query_plans
# 需要导入模块: from cassandra.policies import RoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.RoundRobinPolicy import populate [as 别名]
def test_multiple_query_plans(self):
hosts = [0, 1, 2, 3]
policy = RoundRobinPolicy()
policy.populate(None, hosts)
for i in xrange(20):
qplan = list(policy.make_query_plan())
self.assertEqual(sorted(qplan), hosts)
示例2: test_status_updates
# 需要导入模块: from cassandra.policies import RoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.RoundRobinPolicy import populate [as 别名]
def test_status_updates(self):
hosts = [0, 1, 2, 3]
policy = RoundRobinPolicy()
policy.populate(None, hosts)
policy.on_down(0)
policy.on_remove(1)
policy.on_up(4)
policy.on_add(5)
qplan = list(policy.make_query_plan())
self.assertEqual(sorted(qplan), [2, 3, 4, 5])
示例3: test_no_live_nodes
# 需要导入模块: from cassandra.policies import RoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.RoundRobinPolicy import populate [as 别名]
def test_no_live_nodes(self):
hosts = [0, 1, 2, 3]
policy = RoundRobinPolicy()
policy.populate(None, hosts)
for i in range(4):
policy.on_down(i)
query_plan = list(policy.make_query_plan())
self.assertEqual(query_plan, [])
示例4: test_thread_safety
# 需要导入模块: from cassandra.policies import RoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.RoundRobinPolicy import populate [as 别名]
def test_thread_safety(self):
hosts = range(100)
policy = RoundRobinPolicy()
policy.populate(None, hosts)
def check_query_plan():
for i in range(100):
qplan = list(policy.make_query_plan())
self.assertEqual(sorted(qplan), hosts)
threads = [Thread(target=check_query_plan) for i in range(4)]
map(lambda t: t.start(), threads)
map(lambda t: t.join(), threads)
示例5: test_no_live_nodes
# 需要导入模块: from cassandra.policies import RoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.RoundRobinPolicy import populate [as 别名]
def test_no_live_nodes(self):
"""
Ensure query plan for a downed cluster will execute without errors
"""
hosts = [0, 1, 2, 3]
policy = RoundRobinPolicy()
policy.populate(None, hosts)
for i in range(4):
policy.on_down(i)
qplan = list(policy.make_query_plan())
self.assertEqual(qplan, [])
示例6: test_thread_safety_during_modification
# 需要导入模块: from cassandra.policies import RoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.RoundRobinPolicy import populate [as 别名]
def test_thread_safety_during_modification(self):
hosts = range(100)
policy = RoundRobinPolicy()
policy.populate(None, hosts)
errors = []
def check_query_plan():
try:
for i in xrange(100):
list(policy.make_query_plan())
except Exception as exc:
errors.append(exc)
def host_up():
for i in xrange(1000):
policy.on_up(randint(0, 99))
def host_down():
for i in xrange(1000):
policy.on_down(randint(0, 99))
threads = []
for i in range(5):
threads.append(Thread(target=check_query_plan))
threads.append(Thread(target=host_up))
threads.append(Thread(target=host_down))
# make the GIL switch after every instruction, maximizing
# the chance of race conditions
check = six.PY2 or '__pypy__' in sys.builtin_module_names
if check:
original_interval = sys.getcheckinterval()
else:
original_interval = sys.getswitchinterval()
try:
if check:
sys.setcheckinterval(0)
else:
sys.setswitchinterval(0.0001)
map(lambda t: t.start(), threads)
map(lambda t: t.join(), threads)
finally:
if check:
sys.setcheckinterval(original_interval)
else:
sys.setswitchinterval(original_interval)
if errors:
self.fail("Saw errors: %s" % (errors,))
示例7: test_single_host
# 需要导入模块: from cassandra.policies import RoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.RoundRobinPolicy import populate [as 别名]
def test_single_host(self):
policy = RoundRobinPolicy()
policy.populate(None, [0])
qplan = list(policy.make_query_plan())
self.assertEqual(qplan, [0])
示例8: test_basic
# 需要导入模块: from cassandra.policies import RoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.RoundRobinPolicy import populate [as 别名]
def test_basic(self):
hosts = [0, 1, 2, 3]
policy = RoundRobinPolicy()
policy.populate(None, hosts)
qplan = list(policy.make_query_plan())
self.assertEqual(sorted(qplan), hosts)