From d33d7fe5153f0ec8ef5c509b2629ff0562f54eed Mon Sep 17 00:00:00 2001 From: MikeYaacoubStax Date: Thu, 2 Feb 2023 17:01:54 -0500 Subject: [PATCH] refactored test name to include IntegrationTest for maven test detection --- .../nb5/proof/ExampleContainers.java | 65 --------------- .../ExampleContainersIntegrationTest.java | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+), 65 deletions(-) delete mode 100644 nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainers.java create mode 100644 nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainersIntegrationTest.java diff --git a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainers.java b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainers.java deleted file mode 100644 index 34098e685..000000000 --- a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainers.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2023 nosqlbench - * - * Licensed 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 io.nosqlbench.nb5.proof; - - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.utility.DockerImageName; - -import java.io.IOException; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ExampleContainers { - - private final String java = Optional.ofNullable(System.getenv( - "JAVA_HOME")).map(v -> v + "/bin/java").orElse("java"); - - private final static String JARNAME = "../nb5/target/nb5.jar"; -// private static GenericContainer cass= new CassandraContainer("cassandra").withExposedPorts(9042); - - public static GenericContainer redis = new GenericContainer<>(DockerImageName.parse("redis:latest")) - .withExposedPorts(6379); - @BeforeAll - public static void initContainer() { - redis.start(); - - } - - @BeforeEach - public void setUp() { - System.out.println("setup"); - } - - @Test - public void testSimplePutAndGet() { - ProcessInvoker invoker = new ProcessInvoker(); - invoker.setLogDir("logs/test"); - ProcessResult result = invoker.run("test-workloads", 30, - "java", "-jar", JARNAME, "--list-workloads" - ); - assertThat(result.exception).isNull(); - String stdout = String.join("\n", result.getStdoutData()); - System.out.println(stdout); - System.out.println("end"); - } - -} diff --git a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainersIntegrationTest.java b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainersIntegrationTest.java new file mode 100644 index 000000000..b8e262837 --- /dev/null +++ b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainersIntegrationTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed 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 io.nosqlbench.nb5.proof; + + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.CassandraContainer; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.CassandraQueryWaitStrategy; +import org.testcontainers.utility.DockerImageName; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ExampleContainersIntegrationTest { + + private final String java = Optional.ofNullable(System.getenv( + "JAVA_HOME")).map(v -> v + "/bin/java").orElse("java"); + + private final static String JARNAME = "../nb5/target/nb5.jar"; +// private static GenericContainer cass= new CassandraContainer("cassandra").withExposedPorts(9042); + + private static String hostIP = "127.0.0.1"; + private static final Integer EXPOSED_PORT = 9042; + public static GenericContainer cass = new CassandraContainer<>(DockerImageName.parse("cassandra:latest")) + .withExposedPorts(EXPOSED_PORT).withAccessToHost(true).waitingFor(new CassandraQueryWaitStrategy()); + @BeforeAll + public static void initContainer() { + //STEP0:Start the test container and expose the 9042 port on the local host. + //So that the docker bridge controller exposes the port to our process invoker that will run nb5 + //and target cassandra on that docker container + cass.start(); + + //When running with a local Docker daemon, exposed ports will usually be reachable on localhost. + // However, in some CI environments they may instead be reachable on a different host. + hostIP = cass.getHost(); + + } + + @BeforeEach + public void setUp() { + System.out.println("setup"); + } + + @Test + public void testSimplePutAndGet() { + ProcessInvoker invoker = new ProcessInvoker(); + invoker.setLogDir("logs/test"); + //STEP1: Copy the example workload to the local dir + ProcessResult copyResult = invoker.run("copy-workload", 30, + "java", "-jar", JARNAME, "--copy=activities/baselines/cql-keyvalue.yaml" + ); + assertThat(copyResult.exception).isNull(); + String copyOut = String.join("\n", copyResult.getStdoutData()); + + //STEP2: Run the example cassandra workload using the default params ( + ProcessResult runResult = invoker.run("run-workload", 30, "java", "-jar", JARNAME, "run", + "driver=cql", "workload=cql-keyvalue", "host="+hostIP, "localdc=datacenter1" + ); + assertThat(runResult.exception).isNull(); + String runOut = String.join("\n", runResult.getStdoutData()); + System.out.println(runOut); + System.out.println("end"); + } + +}