Class SharedClusterIntegrationTestBase


  • @TestInstance(PER_CLASS)
    @ExtendWith(io.vertx.junit5.VertxExtension.class)
    public abstract class SharedClusterIntegrationTestBase
    extends java.lang.Object
    This class provides an opinionated way to run integration tests. The setup() method runs once at the beginning of all the tests in the implementation, as well as the tearDown() 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:

    1. Find the first version from the TestVersionSupplier.testVersions()
    2. (Optional) Before cluster provisioning (implementer can supply)
    3. Provision a cluster for the test using the version from the previous step (implementer must supply)
    4. (Optional) After cluster provisioned (implementer can supply)
    5. Initialize schemas required for the test (implementer must supply)
    6. Start sidecar that talks to the provisioned cluster
    7. (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:

    1. (Optional) Before sidecar stops (implementer can supply)
    2. Stop sidecar
    3. (Optional) Before cluster shutdowns (implementer can supply)
    4. Close cluster
    5. (Optional) Before tear down ends (implementer can supply)
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void afterClusterProvisioned()
      Override to perform an action after the cluster has been successfully provisioned
      protected void afterClusterShutdown()
      Override to perform an action after the cluster has shutdown
      protected void beforeClusterProvisioning()
      Override to perform an action before the cluster provisioning
      protected void beforeClusterShutdown()
      Override to perform an action before the cluster stops
      protected void beforeSidecarStop()
      Override to perform an action before Sidecar stops
      protected void beforeTestStart()
      Override to perform an action before the tests start
      protected void closeCluster()
      Closes the cluster and its resources
      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
      static com.datastax.driver.core.Cluster createDriverCluster​(org.apache.cassandra.distributed.api.ICluster<? extends org.apache.cassandra.distributed.api.IInstance> dtest)  
      protected void createTestKeyspace​(java.lang.String keyspace, java.util.Map<java.lang.String,​java.lang.Integer> rf)  
      protected void createTestKeyspace​(QualifiedName name, java.util.Map<java.lang.String,​java.lang.Integer> rf)  
      protected void createTestTable​(QualifiedName name, java.lang.String createTableStatement)  
      protected java.lang.String generateRfString​(java.util.Map<java.lang.String,​java.lang.Integer> rf)  
      protected abstract void initializeSchemaForTest()
      Initialize required schemas for the tests upfront before the test starts
      protected java.lang.Object[][] queryAllData​(QualifiedName table)
      Convenience method to query all data from the provided table at consistency level LOCAL_QUORUM.
      protected java.lang.Object[][] queryAllData​(QualifiedName table, org.apache.cassandra.distributed.api.ConsistencyLevel consistencyLevel)
      Convenience method to query all data from the provided table at the specified consistency level.
      protected com.datastax.driver.core.ResultSet queryAllDataWithDriver​(QualifiedName table)
      Convenience method to query all data from the provided table at consistency level ALL.
      protected com.datastax.driver.core.ResultSet queryAllDataWithDriver​(QualifiedName table, org.apache.cassandra.distributed.api.ConsistencyLevel consistency)
      Convenience method to query all data from the provided table at the specified consistency level.
      protected void setup()  
      protected void startSidecar​(org.apache.cassandra.distributed.api.ICluster<? extends org.apache.cassandra.distributed.api.IInstance> cluster)
      Starts Sidecar configured to run against the provided Cassandra cluster.
      protected org.apache.cassandra.sidecar.server.Server startSidecarWithInstances​(java.lang.Iterable<? extends org.apache.cassandra.distributed.api.IInstance> instances)
      Starts Sidecar configured to run with the provided IInstances from the cluster.
      protected void stopSidecar()
      Stops the Sidecar service
      protected void tearDown()  
      protected ClusterBuilderConfiguration testClusterConfiguration()
      Returns the configuration for the test cluster.
      protected void waitForSchemaReady​(long timeout, java.util.concurrent.TimeUnit timeUnit)  
      protected org.apache.cassandra.sidecar.common.server.JmxClient wrapJmxClient​(org.apache.cassandra.sidecar.common.server.JmxClient.Builder builder)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • SharedClusterIntegrationTestBase

        public SharedClusterIntegrationTestBase()
    • 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 the Feature.GOSSIP, Feature.JMX, and Feature.NATIVE_PROTOCOL features 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.InterruptedException
        Starts Sidecar configured to run against the provided Cassandra cluster.
        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.InterruptedException
        Starts Sidecar configured to run with the provided IInstances 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.InterruptedException
        Stops the Sidecar service
        Throws:
        java.lang.InterruptedException - when stopping sidecar times out
      • closeCluster

        protected void closeCluster()
                             throws java.lang.Exception
        Closes 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 provided table at consistency level LOCAL_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 provided table at the specified consistency level.
        Parameters:
        table - the qualified Cassandra table name
        consistencyLevel - 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 provided table at 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 provided table at the specified consistency level.
        Parameters:
        table - the qualified Cassandra table name
        consistency - 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)