Skip to content

CASSANDRA-19635 - Run integration tests with C* 5.x #1934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@
<threadCountClasses>8</threadCountClasses>
<summaryFile>${project.build.directory}/failsafe-reports/failsafe-summary-parallelized.xml</summaryFile>
<skipITs>${skipParallelizableITs}</skipITs>
<argLine>${blockhound.argline}</argLine>
<jvm>${testing.jvm}/bin/java</jvm>
</configuration>
</execution>
<execution>
Expand All @@ -253,6 +255,7 @@
<excludedGroups>com.datastax.oss.driver.categories.ParallelizableTests, com.datastax.oss.driver.categories.IsolatedTests</excludedGroups>
<summaryFile>${project.build.directory}/failsafe-reports/failsafe-summary-serial.xml</summaryFile>
<skipITs>${skipSerialITs}</skipITs>
<argLine>${blockhound.argline}</argLine>
<jvm>${testing.jvm}/bin/java</jvm>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.servererrors.UnauthorizedException;
import com.datastax.oss.driver.api.testinfra.ccm.SchemaChangeSynchronizer;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
Expand Down Expand Up @@ -57,33 +58,38 @@ public static void addUsers() {
@Before
public void setupRoles() {

try (CqlSession session = ads.newKeyTabSession()) {
session.execute(
"CREATE ROLE IF NOT EXISTS alice WITH PASSWORD = 'fakePasswordForAlice' AND LOGIN = FALSE");
session.execute(
"CREATE ROLE IF NOT EXISTS ben WITH PASSWORD = 'fakePasswordForBen' AND LOGIN = TRUE");
session.execute("CREATE ROLE IF NOT EXISTS 'bob@DATASTAX.COM' WITH LOGIN = TRUE");
session.execute(
"CREATE ROLE IF NOT EXISTS 'charlie@DATASTAX.COM' WITH PASSWORD = 'fakePasswordForCharlie' AND LOGIN = TRUE");
session.execute(
"CREATE ROLE IF NOT EXISTS steve WITH PASSWORD = 'fakePasswordForSteve' AND LOGIN = TRUE");
session.execute(
"CREATE KEYSPACE IF NOT EXISTS aliceks WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':'1'}");
session.execute(
"CREATE TABLE IF NOT EXISTS aliceks.alicetable (key text PRIMARY KEY, value text)");
session.execute("INSERT INTO aliceks.alicetable (key, value) VALUES ('hello', 'world')");
session.execute("GRANT ALL ON KEYSPACE aliceks TO alice");
session.execute("GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'ben'");
session.execute("GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'bob@DATASTAX.COM'");
session.execute("GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'steve'");
session.execute("GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'charlie@DATASTAX.COM'");
session.execute("GRANT PROXY.LOGIN ON ROLE 'alice' TO 'ben'");
session.execute("GRANT PROXY.LOGIN ON ROLE 'alice' TO 'bob@DATASTAX.COM'");
session.execute("GRANT PROXY.EXECUTE ON ROLE 'alice' TO 'steve'");
session.execute("GRANT PROXY.EXECUTE ON ROLE 'alice' TO 'charlie@DATASTAX.COM'");
// ben and bob are allowed to login as alice, but not execute as alice.
// charlie and steve are allowed to execute as alice, but not login as alice.
}
SchemaChangeSynchronizer.withLock(
() -> {
try (CqlSession session = ads.newKeyTabSession()) {
session.execute(
"CREATE ROLE IF NOT EXISTS alice WITH PASSWORD = 'fakePasswordForAlice' AND LOGIN = FALSE");
session.execute(
"CREATE ROLE IF NOT EXISTS ben WITH PASSWORD = 'fakePasswordForBen' AND LOGIN = TRUE");
session.execute("CREATE ROLE IF NOT EXISTS 'bob@DATASTAX.COM' WITH LOGIN = TRUE");
session.execute(
"CREATE ROLE IF NOT EXISTS 'charlie@DATASTAX.COM' WITH PASSWORD = 'fakePasswordForCharlie' AND LOGIN = TRUE");
session.execute(
"CREATE ROLE IF NOT EXISTS steve WITH PASSWORD = 'fakePasswordForSteve' AND LOGIN = TRUE");
session.execute(
"CREATE KEYSPACE IF NOT EXISTS aliceks WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':'1'}");
session.execute(
"CREATE TABLE IF NOT EXISTS aliceks.alicetable (key text PRIMARY KEY, value text)");
session.execute(
"INSERT INTO aliceks.alicetable (key, value) VALUES ('hello', 'world')");
session.execute("GRANT ALL ON KEYSPACE aliceks TO alice");
session.execute("GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'ben'");
session.execute("GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'bob@DATASTAX.COM'");
session.execute("GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'steve'");
session.execute(
"GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'charlie@DATASTAX.COM'");
session.execute("GRANT PROXY.LOGIN ON ROLE 'alice' TO 'ben'");
session.execute("GRANT PROXY.LOGIN ON ROLE 'alice' TO 'bob@DATASTAX.COM'");
session.execute("GRANT PROXY.EXECUTE ON ROLE 'alice' TO 'steve'");
session.execute("GRANT PROXY.EXECUTE ON ROLE 'alice' TO 'charlie@DATASTAX.COM'");
// ben and bob are allowed to login as alice, but not execute as alice.
// charlie and steve are allowed to execute as alice, but not login as alice.
}
});
}
/**
* Validates that a connection may be successfully made as user 'alice' using the credentials of a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.ccm.SchemaChangeSynchronizer;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.categories.ParallelizableTests;
Expand Down Expand Up @@ -67,13 +68,16 @@ public class AsyncResultSetIT {
@BeforeClass
public static void setupSchema() {
// create table and load data across two partitions so we can test paging across tokens.
SESSION_RULE
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS test (k0 text, k1 int, v int, PRIMARY KEY(k0, k1))")
.setExecutionProfile(SESSION_RULE.slowProfile())
.build());
SchemaChangeSynchronizer.withLock(
() -> {
SESSION_RULE
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS test (k0 text, k1 int, v int, PRIMARY KEY(k0, k1))")
.setExecutionProfile(SESSION_RULE.slowProfile())
.build());
});

PreparedStatement prepared =
SESSION_RULE.session().prepare("INSERT INTO test (k0, k1, v) VALUES (?, ?, ?)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.datastax.oss.driver.api.core.cql.Statement;
import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.ccm.SchemaChangeSynchronizer;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
Expand Down Expand Up @@ -72,13 +73,16 @@ public void createTable() {
"CREATE TABLE counter3 (k0 text PRIMARY KEY, c counter)",
};

for (String schemaStatement : schemaStatements) {
sessionRule
.session()
.execute(
SimpleStatement.newInstance(schemaStatement)
.setExecutionProfile(sessionRule.slowProfile()));
}
SchemaChangeSynchronizer.withLock(
() -> {
for (String schemaStatement : schemaStatements) {
sessionRule
.session()
.execute(
SimpleStatement.newInstance(schemaStatement)
.setExecutionProfile(sessionRule.slowProfile()));
}
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.datastax.oss.driver.api.core.metadata.token.Token;
import com.datastax.oss.driver.api.core.type.codec.TypeCodecs;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.ccm.SchemaChangeSynchronizer;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
Expand Down Expand Up @@ -94,40 +95,44 @@ public class BoundStatementCcmIT {
@Before
public void setupSchema() {
// table where every column forms the primary key.
sessionRule
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS test (k text, v int, PRIMARY KEY(k, v))")
.setExecutionProfile(sessionRule.slowProfile())
.build());
for (int i = 0; i < 100; i++) {
sessionRule
.session()
.execute(
SimpleStatement.builder("INSERT INTO test (k, v) VALUES (?, ?)")
.addPositionalValues(KEY, i)
.build());
}

// table with simple primary key, single cell.
sessionRule
.session()
.execute(
SimpleStatement.builder("CREATE TABLE IF NOT EXISTS test2 (k text primary key, v0 int)")
.setExecutionProfile(sessionRule.slowProfile())
.build());

// table with composite partition key
sessionRule
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS test3 "
+ "(pk1 int, pk2 int, v int, "
+ "PRIMARY KEY ((pk1, pk2)))")
.setExecutionProfile(sessionRule.slowProfile())
.build());
SchemaChangeSynchronizer.withLock(
() -> {
sessionRule
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS test (k text, v int, PRIMARY KEY(k, v))")
.setExecutionProfile(sessionRule.slowProfile())
.build());
for (int i = 0; i < 100; i++) {
sessionRule
.session()
.execute(
SimpleStatement.builder("INSERT INTO test (k, v) VALUES (?, ?)")
.addPositionalValues(KEY, i)
.build());
}

// table with simple primary key, single cell.
sessionRule
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS test2 (k text primary key, v0 int)")
.setExecutionProfile(sessionRule.slowProfile())
.build());

// table with composite partition key
sessionRule
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS test3 "
+ "(pk1 int, pk2 int, v int, "
+ "PRIMARY KEY ((pk1, pk2)))")
.setExecutionProfile(sessionRule.slowProfile())
.build());
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.cql.Statement;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.ccm.SchemaChangeSynchronizer;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
Expand Down Expand Up @@ -88,12 +89,16 @@ public class ExecutionInfoWarningsIT {
@Before
public void createSchema() {
// table with simple primary key, single cell.
sessionRule
.session()
.execute(
SimpleStatement.builder("CREATE TABLE IF NOT EXISTS test (k int primary key, v text)")
.setExecutionProfile(sessionRule.slowProfile())
.build());
SchemaChangeSynchronizer.withLock(
() -> {
sessionRule
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS test (k int primary key, v text)")
.setExecutionProfile(sessionRule.slowProfile())
.build());
});
for (int i = 0; i < 100; i++) {
sessionRule
.session()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.datastax.oss.driver.api.core.type.codec.MappingCodec;
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.ccm.SchemaChangeSynchronizer;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.categories.ParallelizableTests;
Expand All @@ -55,11 +56,14 @@ public class PagingStateIT {
@Before
public void setupSchema() {
CqlSession session = SESSION_RULE.session();
session.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS foo (k int, cc int, v int, PRIMARY KEY(k, cc))")
.setExecutionProfile(SESSION_RULE.slowProfile())
.build());
SchemaChangeSynchronizer.withLock(
() -> {
session.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS foo (k int, cc int, v int, PRIMARY KEY(k, cc))")
.setExecutionProfile(SESSION_RULE.slowProfile())
.build());
});
for (int i = 0; i < 20; i++) {
session.execute(
SimpleStatement.newInstance("INSERT INTO foo (k, cc, v) VALUES (1, ?, ?)", i, i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.cql.Statement;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.ccm.SchemaChangeSynchronizer;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
Expand Down Expand Up @@ -67,13 +68,16 @@ public class PerRequestKeyspaceIT {

@Before
public void setupSchema() {
sessionRule
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS foo (k text, cc int, v int, PRIMARY KEY(k, cc))")
.setExecutionProfile(sessionRule.slowProfile())
.build());
SchemaChangeSynchronizer.withLock(
() -> {
sessionRule
.session()
.execute(
SimpleStatement.builder(
"CREATE TABLE IF NOT EXISTS foo (k text, cc int, v int, PRIMARY KEY(k, cc))")
.setExecutionProfile(sessionRule.slowProfile())
.build());
});
}

@Test
Expand Down Expand Up @@ -220,27 +224,31 @@ public void should_prepare_statement_with_keyspace() {
@BackendRequirement(type = BackendType.CASSANDRA, minInclusive = "4.0")
public void should_reprepare_statement_with_keyspace_on_the_fly() {
// Create a separate session because we don't want it to have a default keyspace
try (CqlSession session = SessionUtils.newSession(ccmRule)) {
executeDdl(
session,
String.format(
"CREATE TABLE IF NOT EXISTS %s.bar (k int primary key)", sessionRule.keyspace()));
PreparedStatement pst =
session.prepare(
SimpleStatement.newInstance("SELECT * FROM bar WHERE k=?")
.setKeyspace(sessionRule.keyspace()));
SchemaChangeSynchronizer.withLock(
() -> {
try (CqlSession session = SessionUtils.newSession(ccmRule)) {
executeDdl(
session,
String.format(
"CREATE TABLE IF NOT EXISTS %s.bar (k int primary key)",
sessionRule.keyspace()));
PreparedStatement pst =
session.prepare(
SimpleStatement.newInstance("SELECT * FROM bar WHERE k=?")
.setKeyspace(sessionRule.keyspace()));

// Drop and re-create the table to invalidate the prepared statement server side
executeDdl(session, String.format("DROP TABLE %s.bar", sessionRule.keyspace()));
executeDdl(
session,
String.format("CREATE TABLE %s.bar (k int primary key)", sessionRule.keyspace()));
assertThat(preparedStatementExistsOnServer(session, pst.getId())).isFalse();
// Drop and re-create the table to invalidate the prepared statement server side
executeDdl(session, String.format("DROP TABLE %s.bar", sessionRule.keyspace()));
executeDdl(
session,
String.format("CREATE TABLE %s.bar (k int primary key)", sessionRule.keyspace()));
assertThat(preparedStatementExistsOnServer(session, pst.getId())).isFalse();

// This will re-prepare on the fly
session.execute(pst.bind(0));
assertThat(preparedStatementExistsOnServer(session, pst.getId())).isTrue();
}
// This will re-prepare on the fly
session.execute(pst.bind(0));
assertThat(preparedStatementExistsOnServer(session, pst.getId())).isTrue();
}
});
}

private void executeDdl(CqlSession session, String query) {
Expand Down
Loading