From fbc6651e566430dc8ed89556bfdbd9bb64a01b7a Mon Sep 17 00:00:00 2001 From: Dave Fisher Date: Tue, 9 Jul 2024 12:54:09 -0700 Subject: [PATCH 1/5] Interpolate environment in at file processing --- .../main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java b/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java index f47ce4dfa..184a4e6d3 100644 --- a/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java +++ b/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java @@ -19,6 +19,7 @@ package io.nosqlbench.engine.cli.atfiles; import io.nosqlbench.nb.api.nbio.Content; import io.nosqlbench.nb.api.nbio.NBIO; import io.nosqlbench.nb.api.nbio.NBPathsAPI; +import io.nosqlbench.nb.api.system.NBEnvironment; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.snakeyaml.engine.v2.api.Load; @@ -145,8 +146,9 @@ public class NBAtFile { while (iter.hasNext()) { String word = iter.next(); String modified = word.replaceAll("\\$\\{DIR}",parent.toString()); + Optional interpolatedString = NBEnvironment.INSTANCE.interpolate(modified); iter.remove(); - iter.add(modified); + iter.add(interpolatedString.orElse("")); } return formatted; } From 1ff76aebd4e9dcc18e2a4cf1f56dc3552f2f8ac6 Mon Sep 17 00:00:00 2001 From: Dave Fisher Date: Thu, 18 Jul 2024 11:07:30 -0700 Subject: [PATCH 2/5] Throw error when envvar is missing and provide unit tests --- mvn-defaults/pom.xml | 3 +++ .../io/nosqlbench/engine/cli/atfiles/NBAtFile.java | 3 ++- .../nosqlbench/engine/cli/atfiles/NBAtFileTest.java | 11 +++++++++++ .../atfiles/environment_variable_missing.yaml | 1 + .../test/resources/atfiles/envronment_variable.yaml | 1 + 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 nb-engine/nb-engine-cli/src/test/resources/atfiles/environment_variable_missing.yaml create mode 100644 nb-engine/nb-engine-cli/src/test/resources/atfiles/envronment_variable.yaml diff --git a/mvn-defaults/pom.xml b/mvn-defaults/pom.xml index 4a3e01b5b..38641c0bd 100644 --- a/mvn-defaults/pom.xml +++ b/mvn-defaults/pom.xml @@ -573,6 +573,9 @@ false + + value + diff --git a/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java b/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java index aab40dc5f..a81292c71 100644 --- a/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java +++ b/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java @@ -169,8 +169,9 @@ public class NBAtFile { String word = iter.next(); String modified = word.replaceAll("\\$\\{DIR}",parent.toString()); Optional interpolatedString = NBEnvironment.INSTANCE.interpolate(modified); + String value = interpolatedString.orElseThrow(() -> new RuntimeException("Unable to find environment variable or property in text '"+modified+"' in atfile '" + atPath + "'")); iter.remove(); - iter.add(interpolatedString.orElse("")); + iter.add(value); } return formatted; } diff --git a/nb-engine/nb-engine-cli/src/test/java/io/nosqlbench/engine/cli/atfiles/NBAtFileTest.java b/nb-engine/nb-engine-cli/src/test/java/io/nosqlbench/engine/cli/atfiles/NBAtFileTest.java index be2b6e08e..5979472d7 100644 --- a/nb-engine/nb-engine-cli/src/test/java/io/nosqlbench/engine/cli/atfiles/NBAtFileTest.java +++ b/nb-engine/nb-engine-cli/src/test/java/io/nosqlbench/engine/cli/atfiles/NBAtFileTest.java @@ -91,4 +91,15 @@ class NBAtFileTest { assertThat(strings).containsExactly("arg1","arg1","arg1","arg2","arg3","arg3","arg3","deepval"); } + @Test + public void testAtfileEnvironmentVariable() { + LinkedList strings = NBAtFile.includeAt("@src/test/resources/atfiles/environment_variable.yaml"); + assertThat(strings).containsExactly("My value environment"); + } + + @Test + public void testAtfileMissingEnvironmentVariable() { + assertThrows(RuntimeException.class, () -> NBAtFile.includeAt("@src/test/resources/atfiles/environment_variable_missing.yaml:>:")); + } + } diff --git a/nb-engine/nb-engine-cli/src/test/resources/atfiles/environment_variable_missing.yaml b/nb-engine/nb-engine-cli/src/test/resources/atfiles/environment_variable_missing.yaml new file mode 100644 index 000000000..48a8a26df --- /dev/null +++ b/nb-engine/nb-engine-cli/src/test/resources/atfiles/environment_variable_missing.yaml @@ -0,0 +1 @@ +- My ${MISSING_ENV_VAR} environment diff --git a/nb-engine/nb-engine-cli/src/test/resources/atfiles/envronment_variable.yaml b/nb-engine/nb-engine-cli/src/test/resources/atfiles/envronment_variable.yaml new file mode 100644 index 000000000..71f5e2282 --- /dev/null +++ b/nb-engine/nb-engine-cli/src/test/resources/atfiles/envronment_variable.yaml @@ -0,0 +1 @@ +- My ${TEST_ENV_VAR} environment From a8c71656f97a0c2a9170642625d0cba2e64d0b30 Mon Sep 17 00:00:00 2001 From: Dave Fisher Date: Thu, 18 Jul 2024 11:17:02 -0700 Subject: [PATCH 3/5] Correct filename --- .../{envronment_variable.yaml => environment_variable.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nb-engine/nb-engine-cli/src/test/resources/atfiles/{envronment_variable.yaml => environment_variable.yaml} (100%) diff --git a/nb-engine/nb-engine-cli/src/test/resources/atfiles/envronment_variable.yaml b/nb-engine/nb-engine-cli/src/test/resources/atfiles/environment_variable.yaml similarity index 100% rename from nb-engine/nb-engine-cli/src/test/resources/atfiles/envronment_variable.yaml rename to nb-engine/nb-engine-cli/src/test/resources/atfiles/environment_variable.yaml From 34a3ad478a50217a33becd4dcc91d012d7f71ba2 Mon Sep 17 00:00:00 2001 From: Dave Fisher Date: Thu, 18 Jul 2024 11:32:03 -0700 Subject: [PATCH 4/5] OF: Use spaces not tab --- .../main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java b/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java index a81292c71..3901ea6ce 100644 --- a/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java +++ b/nb-engine/nb-engine-cli/src/main/java/io/nosqlbench/engine/cli/atfiles/NBAtFile.java @@ -169,7 +169,7 @@ public class NBAtFile { String word = iter.next(); String modified = word.replaceAll("\\$\\{DIR}",parent.toString()); Optional interpolatedString = NBEnvironment.INSTANCE.interpolate(modified); - String value = interpolatedString.orElseThrow(() -> new RuntimeException("Unable to find environment variable or property in text '"+modified+"' in atfile '" + atPath + "'")); + String value = interpolatedString.orElseThrow(() -> new RuntimeException("Unable to find environment variable or property in text '"+modified+"' in atfile '" + atPath + "'")); iter.remove(); iter.add(value); } From 0b7292c3b53c4bc61b949c004e077dfdf1ca6d5c Mon Sep 17 00:00:00 2001 From: Dave Fisher Date: Tue, 23 Jul 2024 12:59:15 -0700 Subject: [PATCH 5/5] Fix test regex --- .../src/test/java/io/nosqlbench/nb/api/SystemIdTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nb-apis/nb-api/src/test/java/io/nosqlbench/nb/api/SystemIdTest.java b/nb-apis/nb-api/src/test/java/io/nosqlbench/nb/api/SystemIdTest.java index f2b5d3a5c..b9c751964 100644 --- a/nb-apis/nb-api/src/test/java/io/nosqlbench/nb/api/SystemIdTest.java +++ b/nb-apis/nb-api/src/test/java/io/nosqlbench/nb/api/SystemIdTest.java @@ -56,14 +56,14 @@ public class SystemIdTest { @Test public void testPackedNodeId() { String packedNodeId = SystemId.getPackedNodeId(); - assertThat(packedNodeId).matches("[0-9A-Za-z_-]+"); + assertThat(packedNodeId).matches("[0-9A-Za-z_~-]+"); logger.info("packed node id: " + packedNodeId); } @Test public void testGenSessionCode() { String sessionCode=SystemId.genSessionCode(234L); - assertThat(sessionCode).matches("[0-9a-zA-Z~-]+"); + assertThat(sessionCode).matches("[0-9a-zA-Z_~-]+"); logger.info("session code: " + sessionCode); }