Skip to content

Commit 4ef23f3

Browse files
committed
Added test for WhiteListRoundRobinPolicyTests
1 parent 1cc6b63 commit 4ef23f3

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

tests/integration/standard/test_policies.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
except ImportError:
2020
import unittest # noqa
2121

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
2524
from cassandra.pool import Host
2625

27-
from tests.integration import PROTOCOL_VERSION
28-
26+
from tests.integration import PROTOCOL_VERSION, local
2927

3028
from concurrent.futures import wait as wait_futures
3129

30+
3231
def setup_module():
3332
use_singledc()
3433

34+
3535
class HostFilterPolicyTests(unittest.TestCase):
3636

3737
def test_predicate_changes(self):
@@ -74,3 +74,20 @@ def test_predicate_changes(self):
7474
response = session.execute("SELECT * from system.local")
7575
queried_hosts.update(response.response_future.attempted_hosts)
7676
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)

tests/unit/test_policies.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,22 +1232,6 @@ def test_hosts_with_hostname(self):
12321232

12331233
self.assertEqual(policy.distance(host), HostDistance.LOCAL)
12341234

1235-
def test_deprecated(self):
1236-
import warnings
1237-
1238-
warnings.resetwarnings() # in case we've instantiated one before
1239-
1240-
# set up warning filters to allow all, set up restore when this test is done
1241-
filters_backup, warnings.filters = warnings.filters, []
1242-
self.addCleanup(setattr, warnings, 'filters', filters_backup)
1243-
1244-
with warnings.catch_warnings(record=True) as caught_warnings:
1245-
WhiteListRoundRobinPolicy([])
1246-
self.assertEqual(len(caught_warnings), 1)
1247-
warning_message = caught_warnings[-1]
1248-
self.assertEqual(warning_message.category, DeprecationWarning)
1249-
self.assertIn('4.0', warning_message.message.args[0])
1250-
12511235

12521236
class AddressTranslatorTest(unittest.TestCase):
12531237

0 commit comments

Comments
 (0)