From 7375e89c4811447ef8a3cd91101c2c8000eb19c9 Mon Sep 17 00:00:00 2001 From: Mike Yaacoub Date: Mon, 6 Feb 2023 14:40:39 -0500 Subject: [PATCH] dse example --- .../nosqlbench/adapter/cqld4/Cqld4Space.java | 4 +- .../proof/DSEContainerIntegrationTest.java | 102 ++++++++++++++++++ .../ExampleContainersIntegrationTest.java | 35 ++++-- 3 files changed, 129 insertions(+), 12 deletions(-) create mode 100644 nb5-proof/src/test/java/io/nosqlbench/nb5/proof/DSEContainerIntegrationTest.java diff --git a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/Cqld4Space.java b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/Cqld4Space.java index e64139435..171f32741 100644 --- a/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/Cqld4Space.java +++ b/adapter-cqld4/src/main/java/io/nosqlbench/adapter/cqld4/Cqld4Space.java @@ -96,7 +96,7 @@ public class Cqld4Space implements AutoCloseable { builder.withConfigLoader(dcl); - int port = cfg.getOrDefault("port", 9042); + int port = cfg.getOptional(int.class, "port").orElse(9042); Optional scb = cfg.getOptional(String.class, "secureconnectbundle", "scb"); scb.flatMap(s -> NBIO.all().name(s).first().map(Content::getInputStream)) @@ -284,7 +284,7 @@ public class Cqld4Space implements AutoCloseable { .add(Param.optional("localdc")) .add(Param.optional(List.of("secureconnectbundle", "scb"))) .add(Param.optional(List.of("hosts", "host"))) - .add(Param.defaultTo("port",9041)) + .add(Param.defaultTo("port",9042)) .add(Param.optional("driverconfig", String.class)) .add(Param.optional("username", String.class, "user name (see also password and passfile)")) .add(Param.optional("userfile", String.class, "file to load the username from")) diff --git a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/DSEContainerIntegrationTest.java b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/DSEContainerIntegrationTest.java new file mode 100644 index 000000000..ff0a522d1 --- /dev/null +++ b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/DSEContainerIntegrationTest.java @@ -0,0 +1,102 @@ +/* + * 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.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +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.utility.DockerImageName; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DSEContainerIntegrationTest { + + public static Logger logger = LogManager.getLogger(DSEContainerIntegrationTest.class); + 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 String datacenter = "datacenter1"; + private static Integer mappedPort9042 = 9042; + private static ProcessInvoker invoker = new ProcessInvoker(); + private static CassandraContainer dse; + static { + dse = (CassandraContainer) new CassandraContainer(DockerImageName.parse("datastax/dse-server:6.8.17-ubi7").asCompatibleSubstituteFor("cassandra")).withEnv("DS_LICENSE", "accept").withEnv("CASSANDRA_DC", datacenter).withExposedPorts(9042); + } + @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 + dse.start(); + datacenter = dse.getLocalDatacenter(); + + //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. + mappedPort9042 = dse.getMappedPort(9042); + hostIP = dse.getHost(); + } + + @BeforeEach + public void setUp() { + System.out.println("setup"); + } + + @Test + public void testSimplePutAndGet() { + + 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-iot-dse.yaml" + ); + assertThat(copyResult.exception).isNull(); + String copyOut = String.join("\n", copyResult.getStdoutData()); + + //STEP2: Run the example cassandra workload using the schema tag to create the Cass Baselines keyspace + String[] args = new String[]{ + "java", "-jar", JARNAME, "cql-iot-dse.yaml", "default", "host="+hostIP, "localdc="+datacenter, "port="+ mappedPort9042.toString() + }; + ProcessResult runSchemaResult = invoker.run("run-workload", 30, args); + logger.info("The final command line: " + String.join(" ", args)); + assertThat(runSchemaResult.exception).isNull(); + String runSchemaOut = String.join("\n", runSchemaResult.getStdoutData()); + System.out.println(runSchemaOut); + + //STEP3: Run the example cassandra workload using the rampup phase to create the data in a specific number of cycles +// ProcessResult runRampUpResult = invoker.run("run-workload", 30, "java", "-jar", JARNAME, "run", +// "driver=cql", "workload=cql-keyvalue", "host="+hostIP, "localdc="+datacenter, "port="+ mappedPort9042.toString(), +// "tags=blocks:rampup", "cycles=100k" +// ); +// assertThat(runRampUpResult.exception).isNull(); +// String runRampUpOut = String.join("\n", runRampUpResult.getStdoutData()); +// System.out.println(runRampUpOut); + + 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 index 790e7e2bf..25e2979fc 100644 --- a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainersIntegrationTest.java +++ b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/ExampleContainersIntegrationTest.java @@ -17,6 +17,8 @@ package io.nosqlbench.nb5.proof; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class ExampleContainersIntegrationTest { + public static Logger logger = LogManager.getLogger(ExampleContainersIntegrationTest.class); private final String java = Optional.ofNullable(System.getenv( "JAVA_HOME")).map(v -> v + "/bin/java").orElse("java"); @@ -42,7 +45,7 @@ public class ExampleContainersIntegrationTest { private static String hostIP = "127.0.0.1"; private static String datacenter = "datacenter1"; - private static String mappedPort9042 = "9042"; + private static Integer mappedPort9042 = 9042; private static final Integer EXPOSED_PORT = 9042; private static final CassandraContainer cass = (CassandraContainer) new CassandraContainer().withExposedPorts(9042); @BeforeAll @@ -54,7 +57,7 @@ public class ExampleContainersIntegrationTest { datacenter = cass.getLocalDatacenter(); //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. - mappedPort9042 = cass.getMappedPort(9042).toString(); + mappedPort9042 = cass.getMappedPort(9042); hostIP = cass.getHost(); } @@ -67,20 +70,32 @@ public class ExampleContainersIntegrationTest { public void testSimplePutAndGet() { ProcessInvoker invoker = new ProcessInvoker(); invoker.setLogDir("logs/test"); - //STEP1: Copy the example workload to the local dir +// //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="+datacenter, "port="+ mappedPort9042 - ); - assertThat(runResult.exception).isNull(); - String runOut = String.join("\n", runResult.getStdoutData()); - System.out.println(runOut); + //STEP2: Run the example cassandra workload using the schema tag to create the Cass Baselines keyspace + String[] args = new String[]{ + "java", "-jar", JARNAME, "cql-keyvalue.yaml", "default", "host="+hostIP, "localdc="+datacenter, "port="+ mappedPort9042.toString() + }; + ProcessResult runSchemaResult = invoker.run("run-workload", 30, args); + logger.info("The final command line: " + String.join(" ", args)); + assertThat(runSchemaResult.exception).isNull(); + String runSchemaOut = String.join("\n", runSchemaResult.getStdoutData()); + System.out.println(runSchemaOut); + + //STEP3: Run the example cassandra workload using the rampup phase to create the data in a specific number of cycles + ProcessResult runRampUpResult = invoker.run("run-workload", 30, "java", "-jar", JARNAME, "run", + "driver=cql", "workload=cql-keyvalue", "host="+hostIP, "localdc="+datacenter, "port="+ mappedPort9042.toString(), + "tags=blocks:rampup", "cycles=100k" + ); + assertThat(runRampUpResult.exception).isNull(); + String runRampUpOut = String.join("\n", runRampUpResult.getStdoutData()); + System.out.println(runRampUpOut); + System.out.println("end"); }