yifan-c commented on code in PR #29:
URL: 
https://github.com/apache/cassandra-analytics/pull/29#discussion_r1446791838


##########
cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/sidecar/testing/SharedClusterIntegrationTestBase.java:
##########
@@ -0,0 +1,417 @@
+/*
+ * 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.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.util.Modules;
+import io.vertx.core.Vertx;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.distributed.UpgradeableCluster;
+import org.apache.cassandra.distributed.api.IInstance;
+import org.apache.cassandra.distributed.api.IInstanceConfig;
+import org.apache.cassandra.distributed.impl.AbstractCluster;
+import org.apache.cassandra.distributed.shared.JMXUtil;
+import org.apache.cassandra.distributed.shared.ShutdownException;
+import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate;
+import org.apache.cassandra.sidecar.cluster.InstancesConfig;
+import org.apache.cassandra.sidecar.cluster.InstancesConfigImpl;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadataImpl;
+import org.apache.cassandra.sidecar.common.CQLSessionProvider;
+import org.apache.cassandra.sidecar.common.JmxClient;
+import org.apache.cassandra.sidecar.common.dns.DnsResolver;
+import org.apache.cassandra.sidecar.common.utils.DriverUtils;
+import org.apache.cassandra.sidecar.common.utils.SidecarVersionProvider;
+import org.apache.cassandra.sidecar.config.JmxConfiguration;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.config.yaml.ServiceConfigurationImpl;
+import org.apache.cassandra.sidecar.config.yaml.SidecarConfigurationImpl;
+import org.apache.cassandra.sidecar.server.MainModule;
+import org.apache.cassandra.sidecar.server.Server;
+import org.apache.cassandra.sidecar.utils.CassandraVersionProvider;
+import org.apache.cassandra.testing.TestUtils;
+import org.apache.cassandra.testing.TestVersion;
+import org.apache.cassandra.testing.TestVersionSupplier;
+
+import static 
org.apache.cassandra.sidecar.testing.CassandraSidecarTestContext.tryGetIntConfig;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * This class provides an opinionated way to run integration tests. The {@link 
#setup()} method runs once at the
+ * beginning of all the tests in the implementation, as well as the {@link 
#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.
+ *
+ * <p>The setup will run the following steps:
+ *
+ * <ol>
+ *     <li>Find the first version from the {@link 
TestVersionSupplier#testVersions()}
+ *     <li>Provision a cluster for the test using the version from the 
previous step (implementer must supply)
+ *     <li>Initialize schemas required for the test (implementer must supply)
+ *     <li>Start sidecar that talks to the provisioned cluster
+ *     <li>(Optional) Run the before test start method (implementer can supply)
+ * </ol>
+ *
+ * <p>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.
+ *
+ * <p>For the teardown of the test the steps are the following:
+ *
+ * <ol>
+ *     <li>(Optional) Before sidecar stops (implementer can supply)
+ *     <li>Stop sidecar
+ *     <li>(Optional) Before cluster shutdowns (implementer can supply)
+ *     <li>Close cluster
+ *     <li>(Optional) Before tear down ends (implementer can supply)
+ * </ol>
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+@ExtendWith(VertxExtension.class)
+public abstract class SharedClusterIntegrationTestBase
+{
+    protected final Logger logger = 
LoggerFactory.getLogger(SharedClusterIntegrationTestBase.class);
+
+    protected Vertx vertx;
+    protected DnsResolver dnsResolver;
+    protected AbstractCluster<? extends IInstance> cluster;
+    protected Server server;
+    protected Injector injector;
+
+    static
+    {
+        // Initialize defaults to configure the in-jvm dtest
+        TestUtils.configureDefaultDTestJarProperties();
+    }
+
+    @BeforeAll
+    protected void setup() throws InterruptedException, IOException
+    {
+        Optional<TestVersion> testVersion = 
TestVersionSupplier.testVersions().findFirst();
+        assertThat(testVersion).isPresent();
+        logger.info("Testing with version={}", testVersion);
+        cluster = provisionCluster(testVersion.get());
+        assertThat(cluster).isNotNull();
+        initializeSchemaForTest();
+        startSidecar(cluster);
+        beforeTestStart();
+    }
+
+    @AfterAll
+    protected void tearDown() throws InterruptedException
+    {
+        beforeSidecarStop();
+        stopSidecar();
+        beforeClusterShutdown();
+        closeCluster();
+        beforeTearDownEnd();
+    }
+
+    /**
+     * @param testVersion the Cassandra version to use for the test
+     * @return a provisioned cluster to use for tests
+     * @throws IOException when provisioning a cluster fails
+     */
+    protected abstract UpgradeableCluster provisionCluster(TestVersion 
testVersion) throws IOException;
+
+    /**
+     * Initialize required schemas for the tests upfront before the test starts
+     */
+    protected abstract void initializeSchemaForTest();
+
+    /**
+     * Override to perform an action before the tests start
+     */
+    protected void beforeTestStart()
+    {
+    }
+
+    /**
+     * Override to perform an action before Sidecar stops
+     */
+    protected void beforeSidecarStop()
+    {
+    }
+
+    /**
+     * Override to perform an action before the cluster stops
+     */
+    protected void beforeClusterShutdown()
+    {
+    }
+
+    /**
+     * Override to perform an action as the last step of the tear down method
+     */
+    protected void beforeTearDownEnd()
+    {
+    }
+
+    protected void createTestKeyspace(QualifiedName name, Map<String, Integer> 
rf)
+    {
+        createTestKeyspace(name.maybeQuotedKeyspace(), rf);
+    }
+
+    protected void createTestKeyspace(String keyspace, Map<String, Integer> rf)
+    {
+        cluster.schemaChangeIgnoringStoppedInstances("CREATE KEYSPACE IF NOT 
EXISTS " + keyspace
+                                                     + " WITH REPLICATION = { 
'class' : 'NetworkTopologyStrategy', " +

Review Comment:
   I guess it is same to assume that we always want to test with 
`NetworkTopologyStrategy`



##########
cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/sidecar/testing/SharedClusterIntegrationTestBase.java:
##########
@@ -0,0 +1,417 @@
+/*
+ * 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.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.util.Modules;
+import io.vertx.core.Vertx;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.distributed.UpgradeableCluster;
+import org.apache.cassandra.distributed.api.IInstance;
+import org.apache.cassandra.distributed.api.IInstanceConfig;
+import org.apache.cassandra.distributed.impl.AbstractCluster;
+import org.apache.cassandra.distributed.shared.JMXUtil;
+import org.apache.cassandra.distributed.shared.ShutdownException;
+import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate;
+import org.apache.cassandra.sidecar.cluster.InstancesConfig;
+import org.apache.cassandra.sidecar.cluster.InstancesConfigImpl;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadataImpl;
+import org.apache.cassandra.sidecar.common.CQLSessionProvider;
+import org.apache.cassandra.sidecar.common.JmxClient;
+import org.apache.cassandra.sidecar.common.dns.DnsResolver;
+import org.apache.cassandra.sidecar.common.utils.DriverUtils;
+import org.apache.cassandra.sidecar.common.utils.SidecarVersionProvider;
+import org.apache.cassandra.sidecar.config.JmxConfiguration;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+import org.apache.cassandra.sidecar.config.yaml.ServiceConfigurationImpl;
+import org.apache.cassandra.sidecar.config.yaml.SidecarConfigurationImpl;
+import org.apache.cassandra.sidecar.server.MainModule;
+import org.apache.cassandra.sidecar.server.Server;
+import org.apache.cassandra.sidecar.utils.CassandraVersionProvider;
+import org.apache.cassandra.testing.TestUtils;
+import org.apache.cassandra.testing.TestVersion;
+import org.apache.cassandra.testing.TestVersionSupplier;
+
+import static 
org.apache.cassandra.sidecar.testing.CassandraSidecarTestContext.tryGetIntConfig;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * This class provides an opinionated way to run integration tests. The {@link 
#setup()} method runs once at the
+ * beginning of all the tests in the implementation, as well as the {@link 
#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.
+ *
+ * <p>The setup will run the following steps:
+ *
+ * <ol>
+ *     <li>Find the first version from the {@link 
TestVersionSupplier#testVersions()}
+ *     <li>Provision a cluster for the test using the version from the 
previous step (implementer must supply)
+ *     <li>Initialize schemas required for the test (implementer must supply)
+ *     <li>Start sidecar that talks to the provisioned cluster
+ *     <li>(Optional) Run the before test start method (implementer can supply)
+ * </ol>
+ *
+ * <p>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.
+ *
+ * <p>For the teardown of the test the steps are the following:
+ *
+ * <ol>
+ *     <li>(Optional) Before sidecar stops (implementer can supply)
+ *     <li>Stop sidecar
+ *     <li>(Optional) Before cluster shutdowns (implementer can supply)
+ *     <li>Close cluster
+ *     <li>(Optional) Before tear down ends (implementer can supply)
+ * </ol>
+ */
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+@ExtendWith(VertxExtension.class)
+public abstract class SharedClusterIntegrationTestBase
+{
+    protected final Logger logger = 
LoggerFactory.getLogger(SharedClusterIntegrationTestBase.class);
+
+    protected Vertx vertx;
+    protected DnsResolver dnsResolver;
+    protected AbstractCluster<? extends IInstance> cluster;
+    protected Server server;
+    protected Injector injector;
+
+    static
+    {
+        // Initialize defaults to configure the in-jvm dtest
+        TestUtils.configureDefaultDTestJarProperties();
+    }
+
+    @BeforeAll
+    protected void setup() throws InterruptedException, IOException
+    {
+        Optional<TestVersion> testVersion = 
TestVersionSupplier.testVersions().findFirst();
+        assertThat(testVersion).isPresent();
+        logger.info("Testing with version={}", testVersion);
+        cluster = provisionCluster(testVersion.get());
+        assertThat(cluster).isNotNull();
+        initializeSchemaForTest();
+        startSidecar(cluster);
+        beforeTestStart();
+    }
+
+    @AfterAll
+    protected void tearDown() throws InterruptedException
+    {
+        beforeSidecarStop();
+        stopSidecar();
+        beforeClusterShutdown();
+        closeCluster();
+        beforeTearDownEnd();

Review Comment:
   nit: how about `afterClusterShutdown`?



-- 
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: commits-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to