Skip to content

Commit dea647c

Browse files
committed
fix: replace SimpleStrategy with NetworkTopologyStrategy in 3.x tests
SimpleStrategy throws InvalidConfigurationInQueryException when tablets are globally enabled (the default on recent Scylla), causing cascading test failures from keyspace creation. Replace with NetworkTopologyStrategy (datacenter1) across all 3.x integration tests: - TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT constant (fixes all callers including CCMTestsSupport and AbstractPoliciesTest) - AsyncQueryTest, ControlConnectionTest, MetadataTest, PreparedStatementInvalidationTest, ShardAwarenessTest, StatementPagesTest, TokenIntegrationTest, TupleTest, UnresolvedUserTypeTest, UserTypesTest — inline CQL statements - TokenAwarePolicyTest — disable tablets for composite-key routing test; with NTS + tablets enabled the 3.x driver routes via the tablet map and breaks the hardcoded expectation that token 4881097376275569167 for composite key (1,2) maps to node 1
1 parent 4c22d90 commit dea647c

13 files changed

Lines changed: 70 additions & 20 deletions

driver-core/src/test/java/com/datastax/driver/core/AsyncQueryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void onTestContextInitialized() {
6464
String keyspace = (String) objects[0];
6565
execute(
6666
String.format(
67-
"create keyspace %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}",
67+
"create keyspace %s WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': 1}",
6868
keyspace),
6969
String.format("create table %s.foo(k int, v int, primary key (k, v))", keyspace));
7070
for (int v = 1; v <= 100; v++)

driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void should_parse_UDT_definitions_when_using_default_protocol_version() {
119119
Cluster cluster = register(createClusterBuilder().build());
120120
Session session = cluster.connect();
121121
session.execute(
122-
"create keyspace ControlConnectionTest_ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
122+
"create keyspace ControlConnectionTest_ks WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': 1}");
123123
session.execute("create type ControlConnectionTest_ks.foo (i int)");
124124
cluster.close();
125125

driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void should_update_metadata_on_topology_change() {
6363
session.execute(
6464
"CREATE KEYSPACE "
6565
+ keyspace
66-
+ " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
66+
+ " WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': 1}");
6767
Metadata metadata = cluster.getMetadata();
6868

6969
// Capture all Token data.

driver-core/src/test/java/com/datastax/driver/core/PreparedStatementInvalidationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ private Session sessionWithSkipCQL4MetadataResolveMethod(
482482
.init();
483483
Session session = cluster.connect();
484484
session.execute(
485-
"CREATE KEYSPACE IF NOT EXISTS cql4_loopholes_test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': '1' }");
485+
"CREATE KEYSPACE IF NOT EXISTS cql4_loopholes_test WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1': '1' }");
486486
session.execute("USE cql4_loopholes_test");
487487
return session;
488488
}

driver-core/src/test/java/com/datastax/driver/core/ShardAwarenessTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void correctShardInTracingTest() {
9595
session().execute("DROP KEYSPACE IF EXISTS shardawaretest");
9696
session()
9797
.execute(
98-
"CREATE KEYSPACE shardawaretest WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'}");
98+
"CREATE KEYSPACE shardawaretest WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': '3'}");
9999
session()
100100
.execute("CREATE TABLE shardawaretest.t (pk text, ck text, v text, PRIMARY KEY (pk, ck))");
101101

driver-core/src/test/java/com/datastax/driver/core/SingleTokenIntegrationTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424
import static com.datastax.driver.core.Assertions.assertThat;
2525

2626
import com.datastax.driver.core.utils.Bytes;
27+
import com.google.common.base.Throwables;
2728
import java.nio.ByteBuffer;
2829
import java.util.List;
30+
import java.util.Objects;
2931
import java.util.Set;
32+
import org.slf4j.Logger;
33+
import org.slf4j.LoggerFactory;
3034
import org.testng.annotations.Test;
3135

3236
@CCMConfig(
@@ -36,6 +40,36 @@
3640
clusterProvider = "createClusterBuilderNoDebouncing")
3741
public class SingleTokenIntegrationTest extends CCMTestsSupport {
3842

43+
private static final Logger LOGGER = LoggerFactory.getLogger(SingleTokenIntegrationTest.class);
44+
45+
/**
46+
* Override to create the keyspace with tablets disabled when running against Scylla. This test
47+
* exercises token-range and token-map based replica lookup (getReplicasList with table == null).
48+
* With tablets enabled (the default on modern Scylla), replica placement is controlled by the
49+
* tablet map and getReplicasList returns an empty list when the table is unknown, breaking the
50+
* test assertions. Cassandra does not support the tablets property.
51+
*/
52+
@Override
53+
protected void initTestKeyspace() {
54+
try {
55+
keyspace = TestUtils.generateIdentifier("ks_");
56+
LOGGER.debug("Using keyspace " + keyspace);
57+
boolean isScylla = Objects.nonNull(ccm().getScyllaVersion());
58+
session()
59+
.execute(
60+
String.format(
61+
"CREATE KEYSPACE %s WITH replication = {'class': 'NetworkTopologyStrategy',"
62+
+ " 'datacenter1': 1}"
63+
+ (isScylla ? " AND tablets = {'enabled': false}" : ""),
64+
keyspace));
65+
useKeyspace(keyspace);
66+
} catch (Exception e) {
67+
errorOut();
68+
LOGGER.error("Could not create test keyspace", e);
69+
Throwables.propagate(e);
70+
}
71+
}
72+
3973
/** JAVA-684: Empty TokenRange returned in a one token cluster */
4074
@Test(groups = "short")
4175
public void should_return_single_non_empty_range_when_cluster_has_one_single_token() {

driver-core/src/test/java/com/datastax/driver/core/StatementPagesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class StatementPagesTest extends CCMTestsSupport {
88
@Override
99
public void onTestContextInitialized() {
1010
execute(
11-
"CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1}");
11+
"CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'datacenter1': 1}");
1212
execute("CREATE TABLE IF NOT EXISTS ks.t (pk int, ck int, v int, PRIMARY KEY(pk, ck))");
1313

1414
for (int i = 0; i < 50; i++) {

driver-core/src/test/java/com/datastax/driver/core/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public abstract class TestUtils {
8686
private static final Logger logger = LoggerFactory.getLogger(TestUtils.class);
8787

8888
public static final String CREATE_KEYSPACE_SIMPLE_FORMAT =
89-
"CREATE KEYSPACE %s WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : %d }";
89+
"CREATE KEYSPACE %s WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : %d }";
9090
public static final String CREATE_KEYSPACE_GENERIC_FORMAT =
9191
"CREATE KEYSPACE %s WITH replication = { 'class' : '%s', %s }";
9292

driver-core/src/test/java/com/datastax/driver/core/TokenIntegrationTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Collections;
3636
import java.util.HashSet;
3737
import java.util.List;
38+
import java.util.Objects;
3839
import java.util.Set;
3940
import org.testng.annotations.Test;
4041

@@ -75,12 +76,19 @@ public Cluster.Builder createClusterBuilder() {
7576
public void onTestContextInitialized() {
7677
ks1 = TestUtils.generateIdentifier("ks_");
7778
ks2 = TestUtils.generateIdentifier("ks_");
79+
// Disable tablets on ks1 when running against Scylla. With tablets enabled (the default on
80+
// modern Scylla), replica placement is controlled by the tablet map rather than the token map,
81+
// so getReplicasList(ks, null, null, key) returns an empty list and the assertions fail.
82+
// Cassandra does not support the tablets property, so the clause is omitted there.
83+
boolean isScylla = Objects.nonNull(ccm().getScyllaVersion());
7884
execute(
7985
String.format(
80-
"CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}",
86+
"CREATE KEYSPACE %s WITH replication = {'class': 'NetworkTopologyStrategy',"
87+
+ " 'datacenter1': 1}"
88+
+ (isScylla ? " AND tablets = {'enabled': false}" : ""),
8189
ks1),
8290
String.format(
83-
"CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}",
91+
"CREATE KEYSPACE %s WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': 2}",
8492
ks2),
8593
String.format("USE %s", ks1),
8694
"CREATE TABLE foo(i int primary key)",

driver-core/src/test/java/com/datastax/driver/core/TupleTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void tupleTypeTest() throws Exception {
100100
session()
101101
.execute(
102102
"CREATE KEYSPACE test_tuple_type "
103-
+ "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
103+
+ "WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1': '1'}");
104104
session().execute("USE test_tuple_type");
105105
session()
106106
.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<tuple<ascii, int, boolean>>)");
@@ -169,7 +169,7 @@ public void tupleTestTypeVaryingLengths() throws Exception {
169169
session()
170170
.execute(
171171
"CREATE KEYSPACE test_tuple_type_varying_lengths "
172-
+ "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
172+
+ "WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1': '1'}");
173173
session().execute("USE test_tuple_type_varying_lengths");
174174

175175
// programmatically create the table with tuples of said sizes
@@ -226,7 +226,7 @@ public void tupleSubtypesTest() throws Exception {
226226
session()
227227
.execute(
228228
"CREATE KEYSPACE test_tuple_subtypes "
229-
+ "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
229+
+ "WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1': '1'}");
230230
session().execute("USE test_tuple_subtypes");
231231

232232
// programmatically create the table with a tuple of all datatypes
@@ -294,7 +294,7 @@ public void tupleNonPrimitiveSubTypesTest() throws Exception {
294294
session()
295295
.execute(
296296
"CREATE KEYSPACE test_tuple_non_primitive_subtypes "
297-
+ "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
297+
+ "WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1': '1'}");
298298
session().execute("USE test_tuple_non_primitive_subtypes");
299299

300300
ArrayList<String> values = new ArrayList<String>();
@@ -471,7 +471,7 @@ public void nestedTuplesTest() throws Exception {
471471
session()
472472
.execute(
473473
"CREATE KEYSPACE test_nested_tuples "
474-
+ "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
474+
+ "WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1': '1'}");
475475
session().execute("USE test_nested_tuples");
476476

477477
// create a table with multiple sizes of nested tuples
@@ -519,7 +519,7 @@ public void testTuplesWithNulls() throws Exception {
519519
session()
520520
.execute(
521521
"CREATE KEYSPACE testTuplesWithNulls "
522-
+ "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
522+
+ "WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1': '1'}");
523523
session().execute("USE testTuplesWithNulls");
524524

525525
// create UDT

0 commit comments

Comments
 (0)