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


Python metadata.NetworkTopologyStrategy类代码示例

本文整理汇总了Python中cassandra.metadata.NetworkTopologyStrategy的典型用法代码示例。如果您正苦于以下问题:Python NetworkTopologyStrategy类的具体用法?Python NetworkTopologyStrategy怎么用?Python NetworkTopologyStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NetworkTopologyStrategy类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_nts_make_token_replica_map_multi_rack

    def test_nts_make_token_replica_map_multi_rack(self):
        token_to_host_owner = {}

        # (A) not enough distinct racks, first skipped is used
        dc1_1 = Host("dc1.1", SimpleConvictionPolicy)
        dc1_2 = Host("dc1.2", SimpleConvictionPolicy)
        dc1_3 = Host("dc1.3", SimpleConvictionPolicy)
        dc1_4 = Host("dc1.4", SimpleConvictionPolicy)
        dc1_1.set_location_info("dc1", "rack1")
        dc1_2.set_location_info("dc1", "rack1")
        dc1_3.set_location_info("dc1", "rack2")
        dc1_4.set_location_info("dc1", "rack2")
        token_to_host_owner[MD5Token(0)] = dc1_1
        token_to_host_owner[MD5Token(100)] = dc1_2
        token_to_host_owner[MD5Token(200)] = dc1_3
        token_to_host_owner[MD5Token(300)] = dc1_4

        # (B) distinct racks, but not contiguous
        dc2_1 = Host("dc2.1", SimpleConvictionPolicy)
        dc2_2 = Host("dc2.2", SimpleConvictionPolicy)
        dc2_3 = Host("dc2.3", SimpleConvictionPolicy)
        dc2_1.set_location_info("dc2", "rack1")
        dc2_2.set_location_info("dc2", "rack1")
        dc2_3.set_location_info("dc2", "rack2")
        token_to_host_owner[MD5Token(1)] = dc2_1
        token_to_host_owner[MD5Token(101)] = dc2_2
        token_to_host_owner[MD5Token(201)] = dc2_3

        ring = [MD5Token(0), MD5Token(1), MD5Token(100), MD5Token(101), MD5Token(200), MD5Token(201), MD5Token(300)]

        nts = NetworkTopologyStrategy({"dc1": 3, "dc2": 2})
        replica_map = nts.make_token_replica_map(token_to_host_owner, ring)

        token_replicas = replica_map[MD5Token(0)]
        self.assertItemsEqual(token_replicas, (dc1_1, dc1_2, dc1_3, dc2_1, dc2_3))
开发者ID:pentve,项目名称:python-driver,代码行数:35,代码来源:test_metadata.py

示例2: test_nts_token_performance

    def test_nts_token_performance(self):
        """
        Tests to ensure that when rf exceeds the number of nodes available, that we dont'
        needlessly iterate trying to construct tokens for nodes that don't exist.

        @since 3.7
        @jira_ticket PYTHON-379
        @expected_result timing with 1500 rf should be same/similar to 3rf if we have 3 nodes

        @test_category metadata
        """

        token_to_host_owner = {}
        ring = []
        dc1hostnum = 3
        current_token = 0
        vnodes_per_host = 500
        for i in range(dc1hostnum):

            host = Host('dc1.{0}'.format(i), SimpleConvictionPolicy)
            host.set_location_info('dc1', "rack1")
            for vnode_num in range(vnodes_per_host):
                md5_token = MD5Token(current_token+vnode_num)
                token_to_host_owner[md5_token] = host
                ring.append(md5_token)
            current_token += 1000

        nts = NetworkTopologyStrategy({'dc1': 3})
        start_time = timeit.default_timer()
        nts.make_token_replica_map(token_to_host_owner, ring)
        elapsed_base = timeit.default_timer() - start_time

        nts = NetworkTopologyStrategy({'dc1': 1500})
        start_time = timeit.default_timer()
        nts.make_token_replica_map(token_to_host_owner, ring)
        elapsed_bad = timeit.default_timer() - start_time
        difference = elapsed_bad - elapsed_base
        self.assertTrue(difference < 1 and difference > -1)
开发者ID:mambocab,项目名称:python-driver,代码行数:38,代码来源:test_metadata.py

示例3: test_nts_export_for_schema

 def test_nts_export_for_schema(self):
     strategy = NetworkTopologyStrategy({'dc1': '1', 'dc2': '2'})
     self.assertEqual("{'class': 'NetworkTopologyStrategy', 'dc1': '1', 'dc2': '2'}",
                      strategy.export_for_schema())
开发者ID:mambocab,项目名称:python-driver,代码行数:4,代码来源:test_metadata.py


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