@@ -19,9 +19,9 @@ public class ZeroTokenNodesIT {
1919 @ DataProvider (name = "loadBalancingPolicies" )
2020 public static Object [][] loadBalancingPolicies () {
2121 return new Object [][] {
22- {DCAwareRoundRobinPolicy .builder ().build ()},
23- {new TokenAwarePolicy (DCAwareRoundRobinPolicy .builder ().build ())},
24- {new TokenAwarePolicy (new RoundRobinPolicy ())}
22+ {DCAwareRoundRobinPolicy .builder ().build (), true },
23+ {new TokenAwarePolicy (DCAwareRoundRobinPolicy .builder ().build ()), true },
24+ {new TokenAwarePolicy (new RoundRobinPolicy ()), false }
2525 };
2626 }
2727
@@ -76,7 +76,7 @@ public void should_not_discover_zero_token_DC_when_option_is_disabled() {
7676 CCMBridge ccmBridge = null ;
7777 try {
7878 ccmBridge =
79- CCMBridge .builder ().withNodes (2 ).withIpPrefix ("127.0.1." ).withBinaryPort (9042 ).build ();
79+ CCMBridge .builder ().withNodes (2 , 0 ).withIpPrefix ("127.0.1." ).withBinaryPort (9042 ).build ();
8080 ccmBridge .start ();
8181 ccmBridge .add (2 , 3 );
8282 ccmBridge .updateNodeConfig (3 , "join_ring" , false );
@@ -102,7 +102,7 @@ public void should_not_discover_zero_token_DC_when_option_is_disabled() {
102102 // Queries should not land on any of the zero-token DC nodes
103103 session .execute ("DROP KEYSPACE IF EXISTS ZeroTokenNodesIT" );
104104 session .execute (
105- "CREATE KEYSPACE ZeroTokenNodesIT WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor ': 2};" );
105+ "CREATE KEYSPACE ZeroTokenNodesIT WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1 ': 2, 'dc2': 0 };" );
106106 session .execute ("CREATE TABLE ZeroTokenNodesIT.tab (id INT PRIMARY KEY)" );
107107 for (int i = 0 ; i < 30 ; i ++) {
108108 ResultSet rs = session .execute ("INSERT INTO ZeroTokenNodesIT.tab (id) VALUES (" + i + ")" );
@@ -128,15 +128,15 @@ public void should_not_discover_zero_token_DC_when_option_is_disabled() {
128128 minEnterprise = "2024.2.2" ,
129129 description = "Zero-token nodes introduced in scylladb/scylladb#19684" )
130130 public void should_discover_zero_token_DC_when_option_is_enabled (
131- LoadBalancingPolicy loadBalancingPolicy ) {
131+ LoadBalancingPolicy loadBalancingPolicy , boolean isDcAware ) {
132132 // Makes sure that with QueryOptions.setConsiderZeroTokenNodesValidPeers(true)
133133 // the zero-token peers will be discovered and added to metadata
134134 Cluster cluster = null ;
135135 Session session = null ;
136136 CCMBridge ccmBridge = null ;
137137 try {
138138 ccmBridge =
139- CCMBridge .builder ().withNodes (2 ).withIpPrefix ("127.0.1." ).withBinaryPort (9042 ).build ();
139+ CCMBridge .builder ().withNodes (2 , 0 ).withIpPrefix ("127.0.1." ).withBinaryPort (9042 ).build ();
140140 ccmBridge .start ();
141141 ccmBridge .add (2 , 3 );
142142 ccmBridge .updateNodeConfig (3 , "join_ring" , false );
@@ -164,19 +164,26 @@ public void should_discover_zero_token_DC_when_option_is_enabled(
164164 // Later on we may want to adjust the LBP behavior to be more sophisticated.
165165 session .execute ("DROP KEYSPACE IF EXISTS ZeroTokenNodesIT" );
166166 session .execute (
167- "CREATE KEYSPACE ZeroTokenNodesIT WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor ': 2};" );
167+ "CREATE KEYSPACE ZeroTokenNodesIT WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1 ': 2, 'dc2': 0 };" );
168168 session .execute ("CREATE TABLE ZeroTokenNodesIT.tab (id INT PRIMARY KEY)" );
169+ PreparedStatement ps = session .prepare ("INSERT INTO ZeroTokenNodesIT.tab (id) VALUES (?)" );
169170 Set <InetSocketAddress > queriedNodes = new HashSet <>();
170171 for (int i = 0 ; i < 30 ; i ++) {
171- ResultSet rs = session .execute ("INSERT INTO ZeroTokenNodesIT.tab (id) VALUES (" + i + ")" );
172+ ResultSet rs = session .execute (ps . bind ( i ). setConsistencyLevel ( ConsistencyLevel . TWO ) );
172173 queriedNodes .add (rs .getExecutionInfo ().getQueriedHost ().getEndPoint ().resolve ());
173174 }
174- assertThat (queriedNodes )
175- .containsExactly (
176- ccmBridge .addressOfNode (1 ),
177- ccmBridge .addressOfNode (2 ),
178- ccmBridge .addressOfNode (3 ),
179- ccmBridge .addressOfNode (4 ));
175+
176+ if (isDcAware ) {
177+ assertThat (queriedNodes )
178+ .containsExactly (ccmBridge .addressOfNode (1 ), ccmBridge .addressOfNode (2 ));
179+ } else {
180+ assertThat (queriedNodes )
181+ .containsExactly (
182+ ccmBridge .addressOfNode (1 ),
183+ ccmBridge .addressOfNode (2 ),
184+ ccmBridge .addressOfNode (3 ),
185+ ccmBridge .addressOfNode (4 ));
186+ }
180187
181188 Set <Host > hosts = cluster .getMetadata ().getAllHosts ();
182189 Set <String > toStrings = hosts .stream ().map (Host ::toString ).collect (Collectors .toSet ());
@@ -248,7 +255,7 @@ public void should_connect_to_zero_token_DC() {
248255
249256 try {
250257 ccmBridge =
251- CCMBridge .builder ().withNodes (2 ).withIpPrefix ("127.0.1." ).withBinaryPort (9042 ).build ();
258+ CCMBridge .builder ().withNodes (2 , 0 ).withIpPrefix ("127.0.1." ).withBinaryPort (9042 ).build ();
252259 ccmBridge .start ();
253260 ccmBridge .add (2 , 3 );
254261 ccmBridge .updateNodeConfig (3 , "join_ring" , false );
0 commit comments