当前位置: 首页>>代码示例>>Python>>正文


Python RoundRobinPolicy.populate方法代码示例

本文整理汇总了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)
开发者ID:Adirio,项目名称:python-driver,代码行数:9,代码来源:test_policies.py

示例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])
开发者ID:Adirio,项目名称:python-driver,代码行数:12,代码来源:test_policies.py

示例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, [])
开发者ID:datastax,项目名称:python-driver-dse,代码行数:12,代码来源:test_policies.py

示例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)
开发者ID:Adirio,项目名称:python-driver,代码行数:15,代码来源:test_policies.py

示例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, [])
开发者ID:Adirio,项目名称:python-driver,代码行数:15,代码来源:test_policies.py

示例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,))
开发者ID:Adirio,项目名称:python-driver,代码行数:53,代码来源:test_policies.py

示例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])
开发者ID:Adirio,项目名称:python-driver,代码行数:7,代码来源:test_policies.py

示例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)
开发者ID:Adirio,项目名称:python-driver,代码行数:8,代码来源:test_policies.py


注:本文中的cassandra.policies.RoundRobinPolicy.populate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。