Merge pull request #1975 from nosqlbench/environment_in_atfile

Interpolate environment in at file processing
This commit is contained in:
Jonathan Shook 2024-07-23 15:59:19 -05:00 committed by GitHub
commit 9695e23b58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 3 deletions

View File

@ -573,6 +573,9 @@
</includes>
<useSystemClassLoader>false
</useSystemClassLoader> <!-- fixes reflection tests -->
<environmentVariables>
<TEST_ENV_VAR>value</TEST_ENV_VAR>
</environmentVariables>
</configuration>
</plugin>

View File

@ -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);
}

View File

@ -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.jetbrains.annotations.NotNull;
@ -166,8 +167,10 @@ public class NBAtFile {
while (iter.hasNext()) {
String word = iter.next();
String modified = word.replaceAll("\\$\\{DIR}",parent.toString());
Optional<String> 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(modified);
iter.add(value);
}
return formatted;
}

View File

@ -91,4 +91,15 @@ class NBAtFileTest {
assertThat(strings).containsExactly("arg1","arg1","arg1","arg2","arg3","arg3","arg3","deepval");
}
@Test
public void testAtfileEnvironmentVariable() {
LinkedList<String> 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:>:"));
}
}

View File

@ -0,0 +1 @@
- My ${TEST_ENV_VAR} environment

View File

@ -0,0 +1 @@
- My ${MISSING_ENV_VAR} environment