|
19 | 19 | except ImportError: |
20 | 20 | import unittest # noqa |
21 | 21 |
|
22 | | -from cassandra.cluster import Cluster |
23 | | -from cassandra.policies import HostFilterPolicy, RoundRobinPolicy, \ |
24 | | - SimpleConvictionPolicy |
| 22 | +from cassandra.cluster import Cluster, ExecutionProfile |
| 23 | +from cassandra.policies import HostFilterPolicy, RoundRobinPolicy, SimpleConvictionPolicy, WhiteListRoundRobinPolicy |
25 | 24 | from cassandra.pool import Host |
26 | 25 |
|
27 | | -from tests.integration import PROTOCOL_VERSION |
28 | | - |
| 26 | +from tests.integration import PROTOCOL_VERSION, local |
29 | 27 |
|
30 | 28 | from concurrent.futures import wait as wait_futures |
31 | 29 |
|
| 30 | + |
32 | 31 | def setup_module(): |
33 | 32 | use_singledc() |
34 | 33 |
|
| 34 | + |
35 | 35 | class HostFilterPolicyTests(unittest.TestCase): |
36 | 36 |
|
37 | 37 | def test_predicate_changes(self): |
@@ -74,3 +74,20 @@ def test_predicate_changes(self): |
74 | 74 | response = session.execute("SELECT * from system.local") |
75 | 75 | queried_hosts.update(response.response_future.attempted_hosts) |
76 | 76 | self.assertEqual(queried_hosts, all_hosts) |
| 77 | + |
| 78 | + |
| 79 | +class WhiteListRoundRobinPolicyTests(unittest.TestCase): |
| 80 | + |
| 81 | + @local |
| 82 | + def test_only_connects_to_subset(self): |
| 83 | + only_connect_hosts = {"127.0.0.1", "127.0.0.2"} |
| 84 | + white_list = ExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy(only_connect_hosts)) |
| 85 | + cluster = Cluster(execution_profiles={"white_list": white_list}) |
| 86 | + #cluster = Cluster(load_balancing_policy=WhiteListRoundRobinPolicy(only_connect_hosts)) |
| 87 | + session = cluster.connect(wait_for_all_pools=True) |
| 88 | + queried_hosts = set() |
| 89 | + for _ in range(10): |
| 90 | + response = session.execute('SELECT * from system.local', execution_profile="white_list") |
| 91 | + queried_hosts.update(response.response_future.attempted_hosts) |
| 92 | + queried_hosts = set(host.address for host in queried_hosts) |
| 93 | + self.assertEqual(queried_hosts, only_connect_hosts) |
0 commit comments