2929from cassandra .concurrent import execute_concurrent
3030from cassandra .policies import (RoundRobinPolicy , ExponentialReconnectionPolicy ,
3131 RetryPolicy , SimpleConvictionPolicy , HostDistance ,
32- WhiteListRoundRobinPolicy , AddressTranslator )
32+ AddressTranslator , HostFilterPolicy )
3333from cassandra .pool import Host
3434from cassandra .query import SimpleStatement , TraceUnavailable , tuple_factory
3535
@@ -477,7 +477,10 @@ def test_refresh_schema_type(self):
477477 def test_refresh_schema_no_wait (self ):
478478 contact_points = [CASSANDRA_IP ]
479479 cluster = Cluster (protocol_version = PROTOCOL_VERSION , max_schema_agreement_wait = 10 ,
480- contact_points = contact_points , load_balancing_policy = WhiteListRoundRobinPolicy (contact_points ))
480+ contact_points = contact_points ,
481+ load_balancing_policy = HostFilterPolicy (
482+ RoundRobinPolicy (), lambda host : host .address == CASSANDRA_IP
483+ ))
481484 session = cluster .connect ()
482485
483486 schema_ver = session .execute ("SELECT schema_version FROM system.local WHERE key='local'" )[0 ][0 ]
@@ -618,7 +621,7 @@ def test_trace_unavailable(self):
618621 try :
619622 result = future .get_query_trace (- 1.0 )
620623 # In case the result has time to come back before this timeout due to a race condition
621- check_trace (result )
624+ self . check_trace (result )
622625 except TraceUnavailable :
623626 break
624627 else :
@@ -630,7 +633,7 @@ def test_trace_unavailable(self):
630633 try :
631634 result = future .get_query_trace (max_wait = 120 )
632635 # In case the result has been set check the trace
633- check_trace (result )
636+ self . check_trace (result )
634637 except TraceUnavailable :
635638 break
636639 else :
@@ -774,7 +777,11 @@ def test_profile_load_balancing(self):
774777 @test_category config_profiles
775778 """
776779 query = "select release_version from system.local"
777- node1 = ExecutionProfile (load_balancing_policy = WhiteListRoundRobinPolicy ([CASSANDRA_IP ]))
780+ node1 = ExecutionProfile (
781+ load_balancing_policy = HostFilterPolicy (
782+ RoundRobinPolicy (), lambda host : host .address == CASSANDRA_IP
783+ )
784+ )
778785 with Cluster (execution_profiles = {'node1' : node1 }) as cluster :
779786 session = cluster .connect (wait_for_all_pools = True )
780787
@@ -925,8 +932,16 @@ def test_profile_pool_management(self):
925932 @test_category config_profiles
926933 """
927934
928- node1 = ExecutionProfile (load_balancing_policy = WhiteListRoundRobinPolicy (['127.0.0.1' ]))
929- node2 = ExecutionProfile (load_balancing_policy = WhiteListRoundRobinPolicy (['127.0.0.2' ]))
935+ node1 = ExecutionProfile (
936+ load_balancing_policy = HostFilterPolicy (
937+ RoundRobinPolicy (), lambda host : host .address == "127.0.0.1"
938+ )
939+ )
940+ node2 = ExecutionProfile (
941+ load_balancing_policy = HostFilterPolicy (
942+ RoundRobinPolicy (), lambda host : host .address == "127.0.0.2"
943+ )
944+ )
930945 with Cluster (execution_profiles = {EXEC_PROFILE_DEFAULT : node1 , 'node2' : node2 }) as cluster :
931946 session = cluster .connect (wait_for_all_pools = True )
932947 pools = session .get_pool_state ()
@@ -935,7 +950,11 @@ def test_profile_pool_management(self):
935950 self .assertEqual (set (h .address for h in pools ), set (('127.0.0.1' , '127.0.0.2' )))
936951
937952 # dynamically update pools on add
938- node3 = ExecutionProfile (load_balancing_policy = WhiteListRoundRobinPolicy (['127.0.0.3' ]))
953+ node3 = ExecutionProfile (
954+ load_balancing_policy = HostFilterPolicy (
955+ RoundRobinPolicy (), lambda host : host .address == "127.0.0.3"
956+ )
957+ )
939958 cluster .add_execution_profile ('node3' , node3 )
940959 pools = session .get_pool_state ()
941960 self .assertEqual (set (h .address for h in pools ), set (('127.0.0.1' , '127.0.0.2' , '127.0.0.3' )))
@@ -953,14 +972,22 @@ def test_add_profile_timeout(self):
953972 """
954973 max_retry_count = 10
955974 for i in range (max_retry_count ):
956- node1 = ExecutionProfile (load_balancing_policy = WhiteListRoundRobinPolicy (['127.0.0.1' ]))
975+ node1 = ExecutionProfile (
976+ load_balancing_policy = HostFilterPolicy (
977+ RoundRobinPolicy (), lambda host : host .address == "127.0.0.1"
978+ )
979+ )
957980 with Cluster (execution_profiles = {EXEC_PROFILE_DEFAULT : node1 }) as cluster :
958981 session = cluster .connect (wait_for_all_pools = True )
959982 pools = session .get_pool_state ()
960983 self .assertGreater (len (cluster .metadata .all_hosts ()), 2 )
961984 self .assertEqual (set (h .address for h in pools ), set (('127.0.0.1' ,)))
962985
963- node2 = ExecutionProfile (load_balancing_policy = WhiteListRoundRobinPolicy (['127.0.0.2' , '127.0.0.3' ]))
986+ node2 = ExecutionProfile (
987+ load_balancing_policy = HostFilterPolicy (
988+ RoundRobinPolicy (), lambda host : host .address in ["127.0.0.2" , "127.0.0.3" ]
989+ )
990+ )
964991
965992 start = time .time ()
966993 try :
@@ -1030,7 +1057,9 @@ def test_address_translator_with_mixed_nodes(self):
10301057
10311058@local
10321059class ContextManagementTest (unittest .TestCase ):
1033- load_balancing_policy = WhiteListRoundRobinPolicy ([CASSANDRA_IP ])
1060+ load_balancing_policy = HostFilterPolicy (
1061+ RoundRobinPolicy (), lambda host : host .address == CASSANDRA_IP
1062+ )
10341063 cluster_kwargs = {'execution_profiles' : {EXEC_PROFILE_DEFAULT : ExecutionProfile (load_balancing_policy =
10351064 load_balancing_policy )},
10361065 'schema_metadata_enabled' : False ,
@@ -1150,7 +1179,6 @@ def test_down_event_with_active_connection(self):
11501179
11511180@local
11521181class DontPrepareOnIgnoredHostsTest (unittest .TestCase ):
1153-
11541182 ignored_addresses = ['127.0.0.3' ]
11551183 ignore_node_3_policy = IgnoredHostPolicy (ignored_addresses )
11561184
@@ -1189,7 +1217,8 @@ def test_prepare_on_ignored_hosts(self):
11891217@local
11901218class DuplicateRpcTest (unittest .TestCase ):
11911219
1192- load_balancing_policy = WhiteListRoundRobinPolicy (['127.0.0.1' ])
1220+ load_balancing_policy = HostFilterPolicy (RoundRobinPolicy (),
1221+ lambda host : host .address == "127.0.0.1" )
11931222
11941223 def setUp (self ):
11951224 self .cluster = Cluster (protocol_version = PROTOCOL_VERSION , load_balancing_policy = self .load_balancing_policy )
0 commit comments