From 1e58ea964370d96bea2f232284aafbe7ab83f65f Mon Sep 17 00:00:00 2001 From: Mike Yaacoub Date: Fri, 24 Feb 2023 18:08:45 -0500 Subject: [PATCH 1/6] Relying solely on nb5 jar to get testcontainer workloads --- nb5-proof/pom.xml | 2 +- .../proof/WorkloadContainerVerifications.java | 99 +++++++++++++------ 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/nb5-proof/pom.xml b/nb5-proof/pom.xml index 101f582e2..3d9917d75 100644 --- a/nb5-proof/pom.xml +++ b/nb5-proof/pom.xml @@ -94,7 +94,7 @@ - 1 + 0 false **/*Container*Verification*.java diff --git a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java index 936d2691c..e78281fff 100644 --- a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java +++ b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java @@ -34,6 +34,8 @@ import java.net.InetSocketAddress; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -63,20 +65,31 @@ public class WorkloadContainerVerifications { private final static String BASIC_CHECK_IDENTIFIER = "basic_check"; private static final CassandraContainer cass = (CassandraContainer) new CassandraContainer(DockerImageName.parse("cassandra:latest")) .withExposedPorts(9042).withAccessToHost(true); - private static Map> basicWorkloadsMapPerDriver = null; + private static Map> basicWorkloadsMapPerDriver = null; @BeforeAll public static void listWorkloads() { + //List the tests we would like to run + ProcessInvoker invoker = new ProcessInvoker(); + //STEP1: Copy the example workload to the local dir + ProcessResult listResult = invoker.run("list-workloads", 30, + "java", "-jar", JARNAME, "--list-workloads", "--include=examples" + ); + assertThat(listResult.exception).isNull(); + String listOut = String.join("\n", listResult.getStdoutData()); - List workloads = List.of(); + + // Define the regular expression pattern + String regex = "/(.+?/)+.+?\\.yaml"; + Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); + + Matcher matcher = pattern.matcher(listOut); + ArrayList matchedPaths = new ArrayList<>(); + + while (matcher.find()) { + matchedPaths.add(matcher.group()); + } basicWorkloadsMapPerDriver = new HashMap<>(); - try { - workloads = NBCLIScenarioParser.getWorkloadsWithScenarioScripts(true, "examples"); - } catch (Exception e) { - throw new RuntimeException("Error while getting workloads:" + e.getMessage(), e); - } - for (Driver driver : Driver.values()) { - basicWorkloadsMapPerDriver.put(driver, getBasicCheckWorkloadsForDriver(workloads, BASIC_CHECK_IDENTIFIER, driver.getName())); - } + getBasicCheckWorkloadsForEachDriver(matchedPaths, BASIC_CHECK_IDENTIFIER); } @@ -90,11 +103,10 @@ public class WorkloadContainerVerifications { else if (basicWorkloadsMapPerDriver.get(Driver.CQL).size() == 0) return; - for(WorkloadDesc workloadDesc : basicWorkloadsMapPerDriver.get(Driver.CQL)) + for(String workloadPath : basicWorkloadsMapPerDriver.get(Driver.CQL)) { - String path = workloadDesc.getYamlPath(); - int lastSlashIndex = path.lastIndexOf('/'); - String shortName = path.substring(lastSlashIndex + 1); + int lastSlashIndex = workloadPath.lastIndexOf('/'); + String shortName = workloadPath.substring(lastSlashIndex + 1); if(shortName.equals("cql-iot-dse.yaml")) continue; //STEP0:Start the test container and expose the 9042 port on the local host. @@ -111,7 +123,7 @@ public class WorkloadContainerVerifications { String hostIP = cass.getHost(); - //STEP1: Run the example cassandra workload using the schema tag to create the Cass Baselines keyspace + //STEP1: Run the example cassandra workload using the schema tag to create the Cass Baselines keyspace String[] args = new String[]{ "java", "-jar", JARNAME, shortName, BASIC_CHECK_IDENTIFIER, "host="+ hostIP, "localdc="+ datacenter, "port="+ mappedPort9042.toString(), "table=keyvalue", "keyspace=baselines" }; @@ -172,7 +184,7 @@ public class WorkloadContainerVerifications { // System.out.println(e.getMessage()); // fail(); // } finally { - cass.stop(); + cass.stop(); // } } } @@ -185,27 +197,52 @@ public class WorkloadContainerVerifications { This method filters the input list of workloads to output the subset of workloads that include a specific scenario (input) and run the specified driver */ - public static List getBasicCheckWorkloadsForDriver(List workloads ,String scenarioFilter, String driver) { - String substring = "driver=" + driver; - ArrayList workloadsForDriver = new ArrayList<>(); - for (WorkloadDesc workload : workloads) { - if(workload.getScenarioNames().contains(scenarioFilter)) { - try { - Path yamlPath = Path.of(workload.getYamlPath()); - List lines = Files.readAllLines(yamlPath); - for (String line : lines) { - if (line.contains(substring)) { - workloadsForDriver.add(workload); + private static void getBasicCheckWorkloadsForEachDriver(List workloadPaths ,String scenarioFilter) { + for (String workloadPath : workloadPaths) { + try { + int lastSlashIndex = workloadPath.lastIndexOf('/'); + String shortName = workloadPath.substring(lastSlashIndex + 1); + String[] args = new String[]{ + "java", "-jar", JARNAME, shortName, scenarioFilter, "--show-script" + }; + ProcessInvoker invoker = new ProcessInvoker(); + ProcessResult runShowScriptResult = invoker.run("run-workload", 10, args); + assertThat(runShowScriptResult.exception).isNull(); + String listOut = String.join("\n", runShowScriptResult.getStdoutData()); + Pattern pattern = Pattern.compile("'driver':\\s*'(.+?)'"); + + // Use the Matcher class to find the substring in the long string and extract the value of X + Matcher matcher = pattern.matcher(listOut); + if (matcher.find()) { + String scenarioDriverValue = matcher.group(1); + for (Driver driverType : Driver.values()) + { + if(driverType.getName().equals(scenarioDriverValue)) + { + if(basicWorkloadsMapPerDriver.containsKey(driverType)) + { + List currentList = basicWorkloadsMapPerDriver.get(driverType); + // Modify the list by adding new strings to it + currentList.add(workloadPath); + // Put the updated list back into the HashMap using the same key + basicWorkloadsMapPerDriver.put(driverType, currentList); + } + else + { + List pathList = new ArrayList<>(); + pathList.add(workloadPath); + basicWorkloadsMapPerDriver.put(driverType, pathList); + } break; } } - } catch (Exception e) { - logger.error("Error reading file " + workload.getYamlPath() + ": " + e.getMessage()); - break; } + + } catch (Exception e) { + logger.error("Error reading file " + workloadPath + ": " + e.getMessage()); + break; } } - return workloadsForDriver; } From 8a6e47c1eae3e94c02f496009ff4857bdfe2ef77 Mon Sep 17 00:00:00 2001 From: Mike Yaacoub Date: Mon, 27 Feb 2023 12:09:30 -0500 Subject: [PATCH 2/6] Removed reliance on NBIO and moved to reliance on nb5 package --- .../nb5/proof/WorkloadContainerVerifications.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java index e78281fff..d9909d81b 100644 --- a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java +++ b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java @@ -188,14 +188,11 @@ public class WorkloadContainerVerifications { // } } } - @AfterEach - public void cleanup(){ - System.out.println("setup"); - } /* This method filters the input list of workloads to output the subset of workloads - that include a specific scenario (input) and run the specified driver + that include a specific scenario (input) and maps all workloads with that scenario to + a key which is their common driver */ private static void getBasicCheckWorkloadsForEachDriver(List workloadPaths ,String scenarioFilter) { for (String workloadPath : workloadPaths) { @@ -206,12 +203,12 @@ public class WorkloadContainerVerifications { "java", "-jar", JARNAME, shortName, scenarioFilter, "--show-script" }; ProcessInvoker invoker = new ProcessInvoker(); - ProcessResult runShowScriptResult = invoker.run("run-workload", 10, args); + ProcessResult runShowScriptResult = invoker.run("run-show-script", 10, args); assertThat(runShowScriptResult.exception).isNull(); String listOut = String.join("\n", runShowScriptResult.getStdoutData()); Pattern pattern = Pattern.compile("'driver':\\s*'(.+?)'"); - // Use the Matcher class to find the substring in the long string and extract the value of X + // Use the Matcher class to find the substring in the output script that defines the driver Matcher matcher = pattern.matcher(listOut); if (matcher.find()) { String scenarioDriverValue = matcher.group(1); From 80567a6732aefa0522547e61b5133f1b1193e083 Mon Sep 17 00:00:00 2001 From: Mike Yaacoub Date: Mon, 27 Feb 2023 12:09:55 -0500 Subject: [PATCH 3/6] Reactivate testcontainers profile in release and preview yamls --- .github/workflows/preview.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 153c1fd43..8b43931c8 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -65,7 +65,7 @@ jobs: - name: build preview revision run: | - mvn clean verify -Drevision="${{ env.PREVIEW_VERSION }}" + mvn clean verify -Drevision="${{ env.PREVIEW_VERSION }}" -P enable-container-tests - name: Setup docker buildx uses: docker/setup-buildx-action@v2.2.1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 167821d57..166dfe940 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,7 +62,7 @@ jobs: - name: build release revision run: | - mvn clean verify -Drevision="${{ env.RELEASE_VERSION }}" + mvn clean package -Drevision="${{ env.RELEASE_VERSION }}" -P enable-container-tests - name: Setup docker buildx uses: docker/setup-buildx-action@v2.2.1 From caf13f7b6f864063cb1fcf372ae94d1e6a4081e7 Mon Sep 17 00:00:00 2001 From: Mike Yaacoub Date: Mon, 27 Feb 2023 12:10:39 -0500 Subject: [PATCH 4/6] Removed unused resources --- .../nb5/proof/WorkloadContainerVerifications.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java index d9909d81b..7a96ab8b8 100644 --- a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java +++ b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java @@ -17,29 +17,17 @@ package io.nosqlbench.nb5.proof; - - -import com.datastax.oss.driver.api.core.CqlSession; -import com.datastax.oss.driver.api.core.cql.ResultSet; -import com.datastax.oss.driver.api.core.cql.Row; -import io.nosqlbench.engine.api.scenarios.NBCLIScenarioParser; -import io.nosqlbench.engine.api.scenarios.WorkloadDesc; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.*; import org.testcontainers.containers.CassandraContainer; import org.testcontainers.utility.DockerImageName; -import java.net.InetSocketAddress; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; public class WorkloadContainerVerifications { private enum Driver { @@ -59,8 +47,6 @@ public class WorkloadContainerVerifications { } } public static Logger logger = LogManager.getLogger(WorkloadContainerVerifications.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 final static String BASIC_CHECK_IDENTIFIER = "basic_check"; private static final CassandraContainer cass = (CassandraContainer) new CassandraContainer(DockerImageName.parse("cassandra:latest")) From 991674882642ba040fa0f733f224ed60fb72726b Mon Sep 17 00:00:00 2001 From: Mike Yaacoub Date: Mon, 27 Feb 2023 12:10:44 -0500 Subject: [PATCH 5/6] NB5-948-Reactivate forkCount for nosqlbench root lifecycle activation --- nb5-proof/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nb5-proof/pom.xml b/nb5-proof/pom.xml index 3d9917d75..101f582e2 100644 --- a/nb5-proof/pom.xml +++ b/nb5-proof/pom.xml @@ -94,7 +94,7 @@ - 0 + 1 false **/*Container*Verification*.java From fa853835ed1955a21336582b8ab038338cf4b3e8 Mon Sep 17 00:00:00 2001 From: Mike Yaacoub Date: Wed, 1 Mar 2023 09:56:05 -0500 Subject: [PATCH 6/6] increasing ProcessInvoker Timeout for github actions to pass --- .../io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java index 7a96ab8b8..68ba5b8ca 100644 --- a/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java +++ b/nb5-proof/src/test/java/io/nosqlbench/nb5/proof/WorkloadContainerVerifications.java @@ -114,7 +114,7 @@ public class WorkloadContainerVerifications { "java", "-jar", JARNAME, shortName, BASIC_CHECK_IDENTIFIER, "host="+ hostIP, "localdc="+ datacenter, "port="+ mappedPort9042.toString(), "table=keyvalue", "keyspace=baselines" }; logger.info("The final command line: " + String.join(" ", args)); - ProcessResult runSchemaResult = invoker.run("run-workload", 30, args); + ProcessResult runSchemaResult = invoker.run("run-workload", 60, args); //STEP 2 Check runSchemaOut for errors