Class SharedClusterIntegrationTestBase
- java.lang.Object
-
- org.apache.cassandra.sidecar.testing.SharedClusterIntegrationTestBase
-
@TestInstance(PER_CLASS) @ExtendWith(io.vertx.junit5.VertxExtension.class) public abstract class SharedClusterIntegrationTestBase extends java.lang.ObjectThis class provides an opinionated way to run integration tests. Thesetup()method runs once at the beginning of all the tests in the implementation, as well as thetearDown()method. The tests will share the same cluster throughout the lifetime of the tests, which means that implementers must be aware that any cluster alteration will have an impact on subsequent test runs, so it is recommended that tests run in isolated keyspaces/tables when required. Additionally, the state of the cluster should ideally remain the same for all tests, so ideally tests should not alter the state of the cluster in a way that would affect other tests.The setup will run the following steps:
- Find the first version from the
TestVersionSupplier.testVersions() - (Optional) Before cluster provisioning (implementer can supply)
- Provision a cluster for the test using the version from the previous step (implementer must supply)
- (Optional) After cluster provisioned (implementer can supply)
- Initialize schemas required for the test (implementer must supply)
- Start sidecar that talks to the provisioned cluster
- (Optional) Run the before test start method (implementer can supply)
The above order guarantees that the cluster and Sidecar are both ready by the time the test setup completes. Removing the need to wait for schema propagation from the cluster to Sidecar, and removing the need to poll for schema changes to propagate. This helps in improving test time.
For the teardown of the test the steps are the following:
- (Optional) Before sidecar stops (implementer can supply)
- Stop sidecar
- (Optional) Before cluster shutdowns (implementer can supply)
- Close cluster
- (Optional) Before tear down ends (implementer can supply)
- Find the first version from the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSharedClusterIntegrationTestBase.IntegrationTestModule
-
Field Summary
Fields Modifier and Type Field Description protected IClusterExtension<? extends org.apache.cassandra.distributed.api.IInstance>clusterprotected org.apache.cassandra.sidecar.common.server.dns.DnsResolverdnsResolverprotected org.slf4j.Loggerloggerprotected MtlsTestHelpermtlsTestHelperprotected org.apache.cassandra.sidecar.server.Serverserverprotected TestVersiontestVersion
-
Constructor Summary
Constructors Constructor Description SharedClusterIntegrationTestBase()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidafterClusterProvisioned()Override to perform an action after the cluster has been successfully provisionedprotected voidafterClusterShutdown()Override to perform an action after the cluster has shutdownprotected voidbeforeClusterProvisioning()Override to perform an action before the cluster provisioningprotected voidbeforeClusterShutdown()Override to perform an action before the cluster stopsprotected voidbeforeSidecarStop()Override to perform an action before Sidecar stopsprotected voidbeforeTestStart()Override to perform an action before the tests startprotected voidcloseCluster()Closes the cluster and its resourcesprotected java.util.function.Function<org.apache.cassandra.sidecar.config.yaml.SidecarConfigurationImpl.Builder,org.apache.cassandra.sidecar.config.yaml.SidecarConfigurationImpl.Builder>configurationOverrides()Override to provide additional options to configure sidecarstatic com.datastax.driver.core.ClustercreateDriverCluster(org.apache.cassandra.distributed.api.ICluster<? extends org.apache.cassandra.distributed.api.IInstance> dtest)protected voidcreateTestKeyspace(java.lang.String keyspace, java.util.Map<java.lang.String,java.lang.Integer> rf)protected voidcreateTestKeyspace(QualifiedName name, java.util.Map<java.lang.String,java.lang.Integer> rf)protected voidcreateTestTable(QualifiedName name, java.lang.String createTableStatement)protected java.lang.StringgenerateRfString(java.util.Map<java.lang.String,java.lang.Integer> rf)protected abstract voidinitializeSchemaForTest()Initialize required schemas for the tests upfront before the test startsprotected java.lang.Object[][]queryAllData(QualifiedName table)Convenience method to query all data from the providedtableat consistency levelLOCAL_QUORUM.protected java.lang.Object[][]queryAllData(QualifiedName table, org.apache.cassandra.distributed.api.ConsistencyLevel consistencyLevel)Convenience method to query all data from the providedtableat the specified consistency level.protected com.datastax.driver.core.ResultSetqueryAllDataWithDriver(QualifiedName table)Convenience method to query all data from the providedtableat consistency level ALL.protected com.datastax.driver.core.ResultSetqueryAllDataWithDriver(QualifiedName table, org.apache.cassandra.distributed.api.ConsistencyLevel consistency)Convenience method to query all data from the providedtableat the specified consistency level.protected voidsetup()protected voidstartSidecar(org.apache.cassandra.distributed.api.ICluster<? extends org.apache.cassandra.distributed.api.IInstance> cluster)Starts Sidecar configured to run against the provided Cassandracluster.protected org.apache.cassandra.sidecar.server.ServerstartSidecarWithInstances(java.lang.Iterable<? extends org.apache.cassandra.distributed.api.IInstance> instances)Starts Sidecar configured to run with the providedIInstances from the cluster.protected voidstopSidecar()Stops the Sidecar serviceprotected voidtearDown()protected ClusterBuilderConfigurationtestClusterConfiguration()Returns the configuration for the test cluster.protected voidwaitForSchemaReady(long timeout, java.util.concurrent.TimeUnit timeUnit)protected org.apache.cassandra.sidecar.common.server.JmxClientwrapJmxClient(org.apache.cassandra.sidecar.common.server.JmxClient.Builder builder)
-
-
-
Field Detail
-
logger
protected final org.slf4j.Logger logger
-
dnsResolver
protected org.apache.cassandra.sidecar.common.server.dns.DnsResolver dnsResolver
-
cluster
protected IClusterExtension<? extends org.apache.cassandra.distributed.api.IInstance> cluster
-
server
protected org.apache.cassandra.sidecar.server.Server server
-
testVersion
protected TestVersion testVersion
-
mtlsTestHelper
protected MtlsTestHelper mtlsTestHelper
-
-
Method Detail
-
setup
@BeforeAll protected void setup() throws java.lang.Exception- Throws:
java.lang.Exception
-
tearDown
@AfterAll protected void tearDown() throws java.lang.Exception- Throws:
java.lang.Exception
-
testClusterConfiguration
protected ClusterBuilderConfiguration testClusterConfiguration()
Returns the configuration for the test cluster. The default configuration for the cluster has 1 node, 1 DC, 1 data directory per node, with theFeature.GOSSIP,Feature.JMX, andFeature.NATIVE_PROTOCOLfeatures enabled. It uses dynamic port allocation for the Cassandra service ports. This method can be overridden to provide a different configuration for the cluster.- Returns:
- the configuration for the test cluster
-
beforeClusterProvisioning
protected void beforeClusterProvisioning()
Override to perform an action before the cluster provisioning
-
afterClusterProvisioned
protected void afterClusterProvisioned()
Override to perform an action after the cluster has been successfully provisioned
-
initializeSchemaForTest
protected abstract void initializeSchemaForTest()
Initialize required schemas for the tests upfront before the test starts
-
beforeTestStart
protected void beforeTestStart()
Override to perform an action before the tests start
-
beforeSidecarStop
protected void beforeSidecarStop()
Override to perform an action before Sidecar stops
-
beforeClusterShutdown
protected void beforeClusterShutdown()
Override to perform an action before the cluster stops
-
afterClusterShutdown
protected void afterClusterShutdown()
Override to perform an action after the cluster has shutdown
-
createTestKeyspace
protected void createTestKeyspace(QualifiedName name, java.util.Map<java.lang.String,java.lang.Integer> rf)
-
createTestKeyspace
protected void createTestKeyspace(java.lang.String keyspace, java.util.Map<java.lang.String,java.lang.Integer> rf)
-
createTestTable
protected void createTestTable(QualifiedName name, java.lang.String createTableStatement)
-
configurationOverrides
protected java.util.function.Function<org.apache.cassandra.sidecar.config.yaml.SidecarConfigurationImpl.Builder,org.apache.cassandra.sidecar.config.yaml.SidecarConfigurationImpl.Builder> configurationOverrides()
Override to provide additional options to configure sidecar
-
startSidecar
protected void startSidecar(org.apache.cassandra.distributed.api.ICluster<? extends org.apache.cassandra.distributed.api.IInstance> cluster) throws java.lang.InterruptedExceptionStarts Sidecar configured to run against the provided Cassandracluster.- Parameters:
cluster- the cluster to use- Throws:
java.lang.InterruptedException- when the startup times out
-
startSidecarWithInstances
protected org.apache.cassandra.sidecar.server.Server startSidecarWithInstances(java.lang.Iterable<? extends org.apache.cassandra.distributed.api.IInstance> instances) throws java.lang.InterruptedExceptionStarts Sidecar configured to run with the providedIInstances from the cluster.- Parameters:
instances- the Cassandra instances Sidecar will manage- Returns:
- the started server
- Throws:
java.lang.InterruptedException- when the server start operation is interrupted
-
waitForSchemaReady
protected void waitForSchemaReady(long timeout, java.util.concurrent.TimeUnit timeUnit)
-
stopSidecar
protected void stopSidecar() throws java.lang.InterruptedExceptionStops the Sidecar service- Throws:
java.lang.InterruptedException- when stopping sidecar times out
-
closeCluster
protected void closeCluster() throws java.lang.ExceptionCloses the cluster and its resources- Throws:
java.lang.Exception- on an exception generated during cluster shutdown
-
generateRfString
protected java.lang.String generateRfString(java.util.Map<java.lang.String,java.lang.Integer> rf)
-
queryAllData
protected java.lang.Object[][] queryAllData(QualifiedName table)
Convenience method to query all data from the providedtableat consistency levelLOCAL_QUORUM.- Parameters:
table- the qualified Cassandra table name- Returns:
- all the data queried from the table
-
queryAllData
protected java.lang.Object[][] queryAllData(QualifiedName table, org.apache.cassandra.distributed.api.ConsistencyLevel consistencyLevel)
Convenience method to query all data from the providedtableat the specified consistency level.- Parameters:
table- the qualified Cassandra table nameconsistencyLevel- the consistency level to use for querying the data- Returns:
- all the data queried from the table
-
queryAllDataWithDriver
protected com.datastax.driver.core.ResultSet queryAllDataWithDriver(QualifiedName table)
Convenience method to query all data from the providedtableat consistency level ALL.- Parameters:
table- the qualified Cassandra table name- Returns:
- all the data queried from the table
-
queryAllDataWithDriver
protected com.datastax.driver.core.ResultSet queryAllDataWithDriver(QualifiedName table, org.apache.cassandra.distributed.api.ConsistencyLevel consistency)
Convenience method to query all data from the providedtableat the specified consistency level.- Parameters:
table- the qualified Cassandra table nameconsistency- the consistency level to use for querying the data- Returns:
- all the data queried from the table
-
createDriverCluster
public static com.datastax.driver.core.Cluster createDriverCluster(org.apache.cassandra.distributed.api.ICluster<? extends org.apache.cassandra.distributed.api.IInstance> dtest)
-
wrapJmxClient
protected org.apache.cassandra.sidecar.common.server.JmxClient wrapJmxClient(org.apache.cassandra.sidecar.common.server.JmxClient.Builder builder)
-
-