fix for TEMPLATE support inside named scenarios

This commit is contained in:
Jonathan Shook 2020-03-25 13:05:51 -05:00
parent 0107f5eb42
commit f0a8520d17
3 changed files with 29 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import io.nosqlbench.engine.api.activityconfig.yaml.Scenarios;
import io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList;
import io.nosqlbench.engine.api.exceptions.BasicError;
import io.nosqlbench.engine.api.util.NosqlBenchFiles;
import io.nosqlbench.engine.api.util.StrInterpolator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -44,17 +45,18 @@ public class NBCLIScenarioParser {
}
// Load in user's CLI options
LinkedHashMap<String, String> userCli = new LinkedHashMap<>();
LinkedHashMap<String, String> userParams = new LinkedHashMap<>();
while (arglist.size() > 0
&& arglist.peekFirst().contains("=")
&& !arglist.peekFirst().startsWith("-")) {
String[] arg = arglist.removeFirst().split("=");
arg[0] = Synonyms.canonicalize(arg[0], logger);
if (userCli.containsKey(arg[0])) {
throw new BasicError("duplicate occurence of option on command line: " + arg[0]);
if (userParams.containsKey(arg[0])) {
throw new BasicError("duplicate occurrence of option on command line: " + arg[0]);
}
userCli.put(arg[0], arg[1]);
userParams.put(arg[0], arg[1]);
}
StrInterpolator userParamsInterp = new StrInterpolator(userParams);
// This will hold the command to be prepended to the main arglist
LinkedList<String> buildCmdBuffer = new LinkedList<>();
@ -72,7 +74,8 @@ public class NBCLIScenarioParser {
Pattern cmdpattern = Pattern.compile("(?<name>\\w+)((?<oper>=+)(?<val>.+))?");
for (String cmd : cmds) { // each command line of the named scenario
LinkedHashMap<String, String> usersCopy = new LinkedHashMap<>(userCli);
cmd = userParamsInterp.apply(cmd);
LinkedHashMap<String, String> usersCopy = new LinkedHashMap<>(userParams);
LinkedHashMap<String, CmdArg> cmdline = new LinkedHashMap<>();
String[] cmdparts = cmd.split(" ");

View File

@ -69,4 +69,21 @@ public class NBCLIScenarioParserTest {
List<NBCLIOptions.Cmd> cmds = opts.getCommands();
assertThat(cmds.size()).isEqualTo(6);
}
@Test
public void testThatTemplatesAreExpandedDefault() {
NBCLIOptions opts = new NBCLIOptions(new String[]{ "scenario-test", "template-test"});
List<NBCLIOptions.Cmd> cmds = opts.getCommands();
assertThat(cmds.size()).isEqualTo(1);
assertThat(cmds.get(0).getCmdSpec()).isEqualTo("driver=stdout;cycles=10;workload=activities/scenario-test.yaml;");
}
@Test
public void testThatTemplatesAreExpandedOverride() {
NBCLIOptions opts = new NBCLIOptions(new String[]{ "scenario-test", "template-test", "cycles-test=20"});
List<NBCLIOptions.Cmd> cmds = opts.getCommands();
assertThat(cmds.size()).isEqualTo(1);
assertThat(cmds.get(0).getCmdSpec()).isEqualTo("driver=stdout;cycles=20;cycles-test=20;workload=activities/scenario-test.yaml;");
}
}

View File

@ -2,10 +2,12 @@
scenarios:
default:
- run driver==stdout yaml===scenario-test tags=phase:schema
- run driver=stdout yaml===scenario-test tags=phase:rampup cycles=TEMPLATE(cycles,10)
- run driver=stdout yaml===scenario-test tags=phase:main cycles=TEMPLATE(cycles,10)
- run driver=stdout yaml===scenario-test tags=phase:rampup cycles=TEMPLATE(cycles1,10)
- run driver=stdout yaml===scenario-test tags=phase:main cycles=TEMPLATE(cycles2,10)
schema-only:
- "run driver=stdout yaml=scenario-test tags=phase:schema"
template-test:
with-template: run driver=stdout cycles=TEMPLATE(cycles-test,10)
blocks:
- tags:
phase: schema