本文整理汇总了Python中cassandra.policies.DCAwareRoundRobinPolicy.used_hosts_per_remote_dc方法的典型用法代码示例。如果您正苦于以下问题:Python DCAwareRoundRobinPolicy.used_hosts_per_remote_dc方法的具体用法?Python DCAwareRoundRobinPolicy.used_hosts_per_remote_dc怎么用?Python DCAwareRoundRobinPolicy.used_hosts_per_remote_dc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.policies.DCAwareRoundRobinPolicy
的用法示例。
在下文中一共展示了DCAwareRoundRobinPolicy.used_hosts_per_remote_dc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_distance
# 需要导入模块: from cassandra.policies import DCAwareRoundRobinPolicy [as 别名]
# 或者: from cassandra.policies.DCAwareRoundRobinPolicy import used_hosts_per_remote_dc [as 别名]
def test_get_distance(self):
policy = DCAwareRoundRobinPolicy("dc1", used_hosts_per_remote_dc=0)
host = Host("ip1", SimpleConvictionPolicy)
host.set_location_info("dc1", "rack1")
policy.populate(Mock(), [host])
self.assertEqual(policy.distance(host), HostDistance.LOCAL)
# used_hosts_per_remote_dc is set to 0, so ignore it
remote_host = Host("ip2", SimpleConvictionPolicy)
remote_host.set_location_info("dc2", "rack1")
self.assertEqual(policy.distance(remote_host), HostDistance.IGNORED)
# dc2 isn't registered in the policy's live_hosts dict
policy.used_hosts_per_remote_dc = 1
self.assertEqual(policy.distance(remote_host), HostDistance.IGNORED)
# make sure the policy has both dcs registered
policy.populate(Mock(), [host, remote_host])
self.assertEqual(policy.distance(remote_host), HostDistance.REMOTE)
# since used_hosts_per_remote_dc is set to 1, only the first
# remote host in dc2 will be REMOTE, the rest are IGNORED
second_remote_host = Host("ip3", SimpleConvictionPolicy)
second_remote_host.set_location_info("dc2", "rack1")
policy.populate(Mock(), [host, remote_host, second_remote_host])
distances = set([policy.distance(remote_host), policy.distance(second_remote_host)])
self.assertEqual(distances, set([HostDistance.REMOTE, HostDistance.IGNORED]))