Skip to content

Conversation

@yifan-c
Copy link
Contributor

@yifan-c yifan-c commented Feb 6, 2025

Patch by Yifan Cai; Reviewed by TBD for CASSSIDECAR-204

@yifan-c yifan-c force-pushed the CASSSIDECAR-204/trunk branch from b1a32c6 to 41a6fa9 Compare February 6, 2025 21:50
Patch by Yifan Cai; Reviewed by TBD for CASSSIDECAR-204
@yifan-c yifan-c force-pushed the CASSSIDECAR-204/trunk branch from 41a6fa9 to d8782aa Compare February 6, 2025 21:50
Comment on lines +354 to +356
Vertx vertx = sidecarServerInjector.getInstance(Vertx.class);
vertx.eventBus()
.localConsumer(SidecarServerEvents.ON_SIDECAR_SCHEMA_INITIALIZED.address(), msg -> sidecarSchemaReadyLatch.countDown());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

register the event consumer at the earliest. The original setup misses the event occasionally.

import static org.apache.cassandra.testing.utils.AssertionUtils.getBlocking;
import static org.assertj.core.api.Assertions.assertThat;

class SchemaHandlerIntegrationTest extends SharedClusterSidecarIntegrationTestBase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrated, to speed up and to avoid flakiness.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what a difference! This will help with CI, we should find more opportunities to migrate

Before:

$ ./gradlew --stacktrace :server:integrationTestLightWeight --tests org.apache.cassandra.sidecar.routes.SchemaHandlerIntegrationTest

> Task :server:integrationTestLightWeight

SchemaHandlerIntegrationTest > schemaHandlerWithReservedKeywordKeyspace(VertxTestContext) > schemaHandlerWithReservedKeywordKeyspace(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerWithReservedKeywordKeyspace(VertxTestContext) > schemaHandlerWithReservedKeywordKeyspace(VertxTestContext): 5.1 PASSED

SchemaHandlerIntegrationTest > schemaHandlerNoKeyspace(VertxTestContext) > schemaHandlerNoKeyspace(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerNoKeyspace(VertxTestContext) > schemaHandlerNoKeyspace(VertxTestContext): 5.1 PASSED

SchemaHandlerIntegrationTest > schemaHandlerWithCaseSensitiveKeyspace(VertxTestContext) > schemaHandlerWithCaseSensitiveKeyspace(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerWithCaseSensitiveKeyspace(VertxTestContext) > schemaHandlerWithCaseSensitiveKeyspace(VertxTestContext): 5.1 PASSED

SchemaHandlerIntegrationTest > schemaHandlerKeyspaceDoesNotExist(VertxTestContext) > schemaHandlerKeyspaceDoesNotExist(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerKeyspaceDoesNotExist(VertxTestContext) > schemaHandlerKeyspaceDoesNotExist(VertxTestContext): 5.1 PASSED

SchemaHandlerIntegrationTest > schemaHandlerWithKeyspace(VertxTestContext) > schemaHandlerWithKeyspace(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerWithKeyspace(VertxTestContext) > schemaHandlerWithKeyspace(VertxTestContext): 5.1 PASSED

BUILD SUCCESSFUL in 1m 16s
28 actionable tasks: 1 executed, 27 up-to-date

After:

$ ./gradlew --stacktrace :integration-tests:integrationTestLightWeight --tests org.apache.cassandra.sidecar.routes.SchemaHandlerIntegrationTest

> Task :integration-tests:integrationTestLightWeight

SchemaHandlerIntegrationTest > testSchemaHandlerWithReservedKeywordKeyspace() STARTED
SchemaHandlerIntegrationTest > testSchemaHandlerWithReservedKeywordKeyspace() PASSED

SchemaHandlerIntegrationTest > testSchemaHandlerWithCaseSensitiveKeyspace() STARTED
SchemaHandlerIntegrationTest > testSchemaHandlerWithCaseSensitiveKeyspace() PASSED

SchemaHandlerIntegrationTest > testListKeyspaces() STARTED
SchemaHandlerIntegrationTest > testListKeyspaces() PASSED

SchemaHandlerIntegrationTest > testSchemaHandlerWithKeyspace() STARTED
SchemaHandlerIntegrationTest > testSchemaHandlerWithKeyspace() PASSED

SchemaHandlerIntegrationTest > testSchemaHandlerKeyspaceDoesNotExist() STARTED
SchemaHandlerIntegrationTest > testSchemaHandlerKeyspaceDoesNotExist() PASSED

BUILD SUCCESSFUL in 19s
21 actionable tasks: 10 executed, 11 up-to-date

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you.

@Override
protected void beforeServerStart()
{
vertx.eventBus().localConsumer(ON_ALL_CASSANDRA_CQL_READY.address(), allCassandraCqlReadyMessage::set);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register the event consumer at the earliest to avoid missing events

else if (upInstanceCount == 3)
{
assertThat(jmxConnectedInstances).containsExactly(1, 2, 3);
context.verify(() -> assertThat(jmxConnectedInstances).containsExactly(1, 2, 3));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must wrap in the verify block to correctly fail the test if assertion fails. Otherwise, context/flag are not closed, and test gets stuck until timeout.

CountDownLatch testStart = new CountDownLatch(1);
IUpgradeableInstance node = cluster.get(1);
AtomicReference<Throwable> nodetoolError = new AtomicReference<>();
startAsync("Repairing node" + node.config().num(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the stream trigger from decommission to repair. The test also does not need bytebuddy to intercept, hence removing it.
We should avoid bytebuddy at the best, to avoid dependency on Cassandra's implementation details.

* Note: Some related test classes are broken down to have a single test case to parallelize test execution and
* therefore limit the instance size required to run the tests from CircleCI as the in-jvm-dtests tests are memory bound
*/
@Tag("heavy")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is actually quite heavy.

Comment on lines +77 to +78
// array of nodeNums that are 1-based
private int[] instancesToManage = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes the Cassandra instances flexible. Now, one can choose to manage, instance 1 and 3.

Comment on lines +385 to +394
private Path serverKeystorePath(CertificateBundle ca, Path path, int totalNodes) throws Exception
{
CertificateBundle keystore = new CertificateBuilder()
.subject("CN=Apache Cassandra, OU=ssl_test, O=Unknown, L=Unknown, ST=Unknown, C=Unknown")
.addSanDnsName("localhost")
.addSanIpAddress("127.0.0.1")
.buildIssuedBy(ca);
CertificateBuilder builder = new CertificateBuilder();
builder.subject("CN=Apache Cassandra, OU=ssl_test, O=Unknown, L=Unknown, ST=Unknown, C=Unknown")
.addSanDnsName("localhost");
for (int i = 1; i <= totalNodes; i++)
{
builder.addSanIpAddress("127.0.0." + i);
}
CertificateBundle keystore = builder.buildIssuedBy(ca);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow contacting other hosts rather than 127.0.0.1 only.

Comment on lines -166 to -170
public ClusterLease clusterLease()
{
return new ClusterLease(ClusterLease.Ownership.CLAIMED);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the fake lease. It now runs the actual lease competition in every integration test.

Copy link
Contributor

@frankgh frankgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Looks good to me. Left a minor comment

import static org.apache.cassandra.testing.utils.AssertionUtils.getBlocking;
import static org.assertj.core.api.Assertions.assertThat;

class SchemaHandlerIntegrationTest extends SharedClusterSidecarIntegrationTestBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what a difference! This will help with CI, we should find more opportunities to migrate

Before:

$ ./gradlew --stacktrace :server:integrationTestLightWeight --tests org.apache.cassandra.sidecar.routes.SchemaHandlerIntegrationTest

> Task :server:integrationTestLightWeight

SchemaHandlerIntegrationTest > schemaHandlerWithReservedKeywordKeyspace(VertxTestContext) > schemaHandlerWithReservedKeywordKeyspace(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerWithReservedKeywordKeyspace(VertxTestContext) > schemaHandlerWithReservedKeywordKeyspace(VertxTestContext): 5.1 PASSED

SchemaHandlerIntegrationTest > schemaHandlerNoKeyspace(VertxTestContext) > schemaHandlerNoKeyspace(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerNoKeyspace(VertxTestContext) > schemaHandlerNoKeyspace(VertxTestContext): 5.1 PASSED

SchemaHandlerIntegrationTest > schemaHandlerWithCaseSensitiveKeyspace(VertxTestContext) > schemaHandlerWithCaseSensitiveKeyspace(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerWithCaseSensitiveKeyspace(VertxTestContext) > schemaHandlerWithCaseSensitiveKeyspace(VertxTestContext): 5.1 PASSED

SchemaHandlerIntegrationTest > schemaHandlerKeyspaceDoesNotExist(VertxTestContext) > schemaHandlerKeyspaceDoesNotExist(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerKeyspaceDoesNotExist(VertxTestContext) > schemaHandlerKeyspaceDoesNotExist(VertxTestContext): 5.1 PASSED

SchemaHandlerIntegrationTest > schemaHandlerWithKeyspace(VertxTestContext) > schemaHandlerWithKeyspace(VertxTestContext): 5.1 STARTED
SchemaHandlerIntegrationTest > schemaHandlerWithKeyspace(VertxTestContext) > schemaHandlerWithKeyspace(VertxTestContext): 5.1 PASSED

BUILD SUCCESSFUL in 1m 16s
28 actionable tasks: 1 executed, 27 up-to-date

After:

$ ./gradlew --stacktrace :integration-tests:integrationTestLightWeight --tests org.apache.cassandra.sidecar.routes.SchemaHandlerIntegrationTest

> Task :integration-tests:integrationTestLightWeight

SchemaHandlerIntegrationTest > testSchemaHandlerWithReservedKeywordKeyspace() STARTED
SchemaHandlerIntegrationTest > testSchemaHandlerWithReservedKeywordKeyspace() PASSED

SchemaHandlerIntegrationTest > testSchemaHandlerWithCaseSensitiveKeyspace() STARTED
SchemaHandlerIntegrationTest > testSchemaHandlerWithCaseSensitiveKeyspace() PASSED

SchemaHandlerIntegrationTest > testListKeyspaces() STARTED
SchemaHandlerIntegrationTest > testListKeyspaces() PASSED

SchemaHandlerIntegrationTest > testSchemaHandlerWithKeyspace() STARTED
SchemaHandlerIntegrationTest > testSchemaHandlerWithKeyspace() PASSED

SchemaHandlerIntegrationTest > testSchemaHandlerKeyspaceDoesNotExist() STARTED
SchemaHandlerIntegrationTest > testSchemaHandlerKeyspaceDoesNotExist() PASSED

BUILD SUCCESSFUL in 19s
21 actionable tasks: 10 executed, 11 up-to-date


session.execute("CREATE KEYSPACE " + IF_NOT_EXISTS + " " + TEST_KEYSPACE
+ " WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', " + generateRfString(rf) + " };");
ResultSet rs = session.execute("CREATE KEYSPACE " + IF_NOT_EXISTS + " " + keyspaceName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests should try to use cluster.schemaChange instead, but I think we should make an effort to migrate integration tests.

@yifan-c yifan-c merged commit 72e38ea into apache:trunk Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants