@@ -19,9 +19,9 @@ public class ZeroTokenNodesIT {
19
19
@ DataProvider (name = "loadBalancingPolicies" )
20
20
public static Object [][] loadBalancingPolicies () {
21
21
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 }
25
25
};
26
26
}
27
27
@@ -76,7 +76,7 @@ public void should_not_discover_zero_token_DC_when_option_is_disabled() {
76
76
CCMBridge ccmBridge = null ;
77
77
try {
78
78
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 ();
80
80
ccmBridge .start ();
81
81
ccmBridge .add (2 , 3 );
82
82
ccmBridge .updateNodeConfig (3 , "join_ring" , false );
@@ -102,7 +102,7 @@ public void should_not_discover_zero_token_DC_when_option_is_disabled() {
102
102
// Queries should not land on any of the zero-token DC nodes
103
103
session .execute ("DROP KEYSPACE IF EXISTS ZeroTokenNodesIT" );
104
104
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 };" );
106
106
session .execute ("CREATE TABLE ZeroTokenNodesIT.tab (id INT PRIMARY KEY)" );
107
107
for (int i = 0 ; i < 30 ; i ++) {
108
108
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() {
128
128
minEnterprise = "2024.2.2" ,
129
129
description = "Zero-token nodes introduced in scylladb/scylladb#19684" )
130
130
public void should_discover_zero_token_DC_when_option_is_enabled (
131
- LoadBalancingPolicy loadBalancingPolicy ) {
131
+ LoadBalancingPolicy loadBalancingPolicy , boolean isDcAware ) {
132
132
// Makes sure that with QueryOptions.setConsiderZeroTokenNodesValidPeers(true)
133
133
// the zero-token peers will be discovered and added to metadata
134
134
Cluster cluster = null ;
135
135
Session session = null ;
136
136
CCMBridge ccmBridge = null ;
137
137
try {
138
138
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 ();
140
140
ccmBridge .start ();
141
141
ccmBridge .add (2 , 3 );
142
142
ccmBridge .updateNodeConfig (3 , "join_ring" , false );
@@ -164,19 +164,26 @@ public void should_discover_zero_token_DC_when_option_is_enabled(
164
164
// Later on we may want to adjust the LBP behavior to be more sophisticated.
165
165
session .execute ("DROP KEYSPACE IF EXISTS ZeroTokenNodesIT" );
166
166
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 };" );
168
168
session .execute ("CREATE TABLE ZeroTokenNodesIT.tab (id INT PRIMARY KEY)" );
169
+ PreparedStatement ps = session .prepare ("INSERT INTO ZeroTokenNodesIT.tab (id) VALUES (?)" );
169
170
Set <InetSocketAddress > queriedNodes = new HashSet <>();
170
171
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 ) );
172
173
queriedNodes .add (rs .getExecutionInfo ().getQueriedHost ().getEndPoint ().resolve ());
173
174
}
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
+ }
180
187
181
188
Set <Host > hosts = cluster .getMetadata ().getAllHosts ();
182
189
Set <String > toStrings = hosts .stream ().map (Host ::toString ).collect (Collectors .toSet ());
@@ -248,7 +255,7 @@ public void should_connect_to_zero_token_DC() {
248
255
249
256
try {
250
257
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 ();
252
259
ccmBridge .start ();
253
260
ccmBridge .add (2 , 3 );
254
261
ccmBridge .updateNodeConfig (3 , "join_ring" , false );
0 commit comments