jyothsnakonisa commented on code in PR #317: URL: https://github.com/apache/cassandra-sidecar/pull/317#discussion_r2819139527
########## integration-tests/src/integrationTest/org/apache/cassandra/sidecar/testing/SharedClusterCdcSidecarIntegrationTestBase.java: ########## @@ -0,0 +1,197 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.testing; + +import java.util.Map; +import java.util.function.Function; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import io.vertx.core.Vertx; +import org.apache.cassandra.cdc.api.SchemaSupplier; +import org.apache.cassandra.cdc.msg.CdcEvent; +import org.apache.cassandra.cdc.sidecar.CdcSidecarInstancesProvider; +import org.apache.cassandra.cdc.sidecar.ClusterConfigProvider; +import org.apache.cassandra.cdc.sidecar.SidecarCdcClient; +import org.apache.cassandra.cdc.stats.ICdcStats; +import org.apache.cassandra.distributed.api.ICluster; +import org.apache.cassandra.distributed.api.IInstance; +import org.apache.cassandra.sidecar.cdc.CdcConfig; +import org.apache.cassandra.sidecar.cdc.CdcPublisher; +import org.apache.cassandra.sidecar.cdc.SidecarCdcStats; +import org.apache.cassandra.sidecar.concurrent.ExecutorPools; +import org.apache.cassandra.sidecar.config.SidecarClientConfiguration; +import org.apache.cassandra.sidecar.config.SidecarConfiguration; +import org.apache.cassandra.sidecar.config.ServiceConfiguration; +import org.apache.cassandra.sidecar.config.yaml.ServiceConfigurationImpl; +import org.apache.cassandra.sidecar.config.yaml.SidecarConfigurationImpl; +import org.apache.cassandra.sidecar.coordination.ContentionFreeRangeManager; +import org.apache.cassandra.sidecar.coordination.TokenRingProvider; +import org.apache.cassandra.sidecar.db.CdcDatabaseAccessor; +import org.apache.cassandra.sidecar.db.VirtualTablesDatabaseAccessor; +import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher; +import org.apache.cassandra.sidecar.utils.SimpleCassandraVersion; +import org.apache.cassandra.testing.ClusterBuilderConfiguration; +import org.apache.kafka.common.serialization.Serializer; +import org.junit.jupiter.api.AfterEach; + +import static org.assertj.core.api.Assumptions.assumeThat; + +/** + * Base class for CDC integration tests. Extends SharedClusterIntegrationTestBase with + * CDC-specific configuration and setup, including: + * - CDC-enabled Cassandra cluster configuration + * - TestCdcPublisher with TestCdcEventConsumer + * - Cassandra 4.1 version requirement + * - Helper methods to access CDC components + */ +public abstract class SharedClusterCdcSidecarIntegrationTestBase extends SharedClusterIntegrationTestBase +{ + @AfterEach + void cleanupCdcConsumerAfterEachTest() + { + TestCdcPublisher testCdcPublisher = (TestCdcPublisher) serverWrapper.injector.getInstance(CdcPublisher.class); + if (testCdcPublisher != null) + { + TestCdcEventConsumer consumer = testCdcPublisher.getTestEventConsumer(); + if (consumer != null) + { + consumer.clear(); + } + } + } + + @Override + protected void beforeClusterProvisioning() + { + // CDC integration test is only compatible with Cassandra 4.1 due to cassandra-analytics library version + SimpleCassandraVersion version = SimpleCassandraVersion.create(testVersion.version()); + assumeThat(version.major) + .as("CDC test requires Cassandra 4.x") + .isEqualTo(4); + assumeThat(version.minor) + .as("CDC test requires Cassandra 4.1") + .isEqualTo(1); + } + + @Override + protected ClusterBuilderConfiguration testClusterConfiguration() + { + return super.testClusterConfiguration() + .dcCount(1) + .nodesPerDc(1) + .additionalInstanceConfig(Map.of("cdc_enabled", true)); + } + + @Override + protected Function<SidecarConfigurationImpl.Builder, SidecarConfigurationImpl.Builder> configurationOverrides() + { + return builder -> { + // Override service configuration to use specific port for CDC tests + ServiceConfiguration existingConfig = builder.build().serviceConfiguration(); + ServiceConfiguration cdcServiceConfig = ServiceConfigurationImpl.builder() + .host(existingConfig.host()) + .port(9043) // TODO: Make this port dynamically allocated Review Comment: In cassandra-analytics, we are using port number that is passed in `SidecarCdcClient.ClientConfig` instead of using the port number from `CdcDynamicSidecarInstancesProvider` and hence test is not able to use correct port number in sidecar client when dynamic ports are being used for sidecar. This needs a fix in cassandra-analytics, which I made a note of and this fix will go in next release. Until then, it is good to have an integration test(even with fixed port) to validate several cdc related changes that we are making. We can do a followup JIRA for the test to use dynamic port later. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

