mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Adding Changes
This commit is contained in:
@@ -130,7 +130,7 @@ public class NBCLIScenarioPreprocessorTest {
|
||||
"driver", "stdout",
|
||||
"labels", "workload:scenario_test,scenario:schema_only",
|
||||
"step", "schema",
|
||||
"tags", "block:\"schema.*\"",
|
||||
"tags", "block:schema.*",
|
||||
"workload", "scenario_test"
|
||||
));
|
||||
NBCLIOptions opts1 = new NBCLIOptions(new String[]{"scenario_test", "schema_only", "doundef=20"}, NBCLIOptions.Mode.ParseAllOptions);
|
||||
@@ -185,7 +185,7 @@ public class NBCLIScenarioPreprocessorTest {
|
||||
"driver", "stdout",
|
||||
"labels", "workload:scenario_test,scenario:schema_only",
|
||||
"step", "schema",
|
||||
"tags", "block:\"schema.*\"",
|
||||
"tags", "block:schema.*",
|
||||
"workload", "scenario_test"
|
||||
));
|
||||
NBCLIOptions opts1 = new NBCLIOptions(new String[]{"example_scenarios", "namedsteps.one", "testparam1=testvalue2"}, NBCLIOptions.Mode.ParseAllOptions);
|
||||
@@ -201,4 +201,37 @@ public class NBCLIScenarioPreprocessorTest {
|
||||
.isThrownBy(() -> new NBCLIOptions(new String[]{"scenario_test", "duplicate_param"}, NBCLIOptions.Mode.ParseAllOptions))
|
||||
.withMessageContaining("Duplicate occurrence of parameter \"threads\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandSplitter() {
|
||||
String normalCmd = "run driver=stdout tags==block:main-read cycles==10 threads=auto param=test1";
|
||||
assertThat(NBCLIScenarioPreprocessor.splitCommand(normalCmd))
|
||||
.isEqualTo(List.of("run", "driver=stdout", "tags==block:main-read", "cycles==10", "threads=auto", "param=test1"));
|
||||
|
||||
// param='test1' or pram="test1" -> param=test1
|
||||
String quotedParamCmd = "run driver=stdout tags==block:\"main.*\" cycles==10 threads=auto param='test1'";
|
||||
assertThat(NBCLIScenarioPreprocessor.splitCommand(quotedParamCmd))
|
||||
.isEqualTo(List.of("run", "driver=stdout", "tags==block:main.*", "cycles==10", "threads=auto", "param=test1"));
|
||||
|
||||
// param="test 1" or params='test 1' -> param=test 1
|
||||
String paramWithSpaceCmd = "run driver=stdout tags==block:\"main.*\" cycles==10 threads=auto param='test 1'";
|
||||
assertThat(NBCLIScenarioPreprocessor.splitCommand(paramWithSpaceCmd))
|
||||
.isEqualTo(List.of("run", "driver=stdout", "tags==block:main.*", "cycles==10", "threads=auto", "param=test 1"));
|
||||
|
||||
// param=\"test1\" -> param="test1", param=\'test1\' -> param='test1'
|
||||
String escapingQuotesParamCmd = "run driver=stdout tags==block:'main.*' cycles==10 threads=auto param=\\\"test1\\\"";
|
||||
assertThat(NBCLIScenarioPreprocessor.splitCommand(escapingQuotesParamCmd))
|
||||
.isEqualTo(List.of("run", "driver=stdout", "tags==block:main.*", "cycles==10", "threads=auto", "param=\"test1\""));
|
||||
|
||||
// param=test1\\test2 -> param=test1\test2
|
||||
String escapingSlashParamCmd = "run driver=stdout tags==block:'main.*' cycles==10 threads=auto param=test1\\\\test2";
|
||||
assertThat(NBCLIScenarioPreprocessor.splitCommand(escapingSlashParamCmd))
|
||||
.isEqualTo(List.of("run", "driver=stdout", "tags==block:main.*", "cycles==10", "threads=auto", "param=test1\\test2"));
|
||||
|
||||
// param="test1 -> unclosed quote "
|
||||
String unclosedQuoteCmd = "run driver=stdout tags==block:'main.*' cycles==10 threads=auto param=\"test1";
|
||||
assertThatExceptionOfType(BasicError.class)
|
||||
.isThrownBy(() -> NBCLIScenarioPreprocessor.splitCommand(unclosedQuoteCmd))
|
||||
.withMessageContaining("Unclosed double quote found in scenario cmd");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,10 +252,66 @@ public class NBCLIScenarioPreprocessor {
|
||||
|
||||
private static final Pattern WordAndMaybeAssignment = Pattern.compile("(?<name>\\w[-_\\d\\w.]+)((?<oper>=+)(?<val>.+))?");
|
||||
|
||||
public static List<String> splitCommand(String cmd) {
|
||||
List<String> cmdSplit = new ArrayList<>();
|
||||
Stack<Character> stack = new Stack<>();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (char c : cmd.toCharArray()) {
|
||||
switch (c) {
|
||||
case ' ':
|
||||
if (!stack.isEmpty() && (stack.peek() == '\'' || stack.peek() == '\"')) {
|
||||
builder.append(c);
|
||||
} else if (!builder.isEmpty()) {
|
||||
cmdSplit.add(builder.toString());
|
||||
builder.delete(0, builder.length());
|
||||
}
|
||||
break;
|
||||
case '\"':
|
||||
case '\'':
|
||||
if (!stack.isEmpty()) {
|
||||
if (stack.peek() == c) {
|
||||
stack.pop();
|
||||
} else if (stack.peek() == '\\') {
|
||||
stack.pop();
|
||||
builder.append(c);
|
||||
} else {
|
||||
stack.push(c);
|
||||
}
|
||||
} else {
|
||||
stack.push(c);
|
||||
}
|
||||
break;
|
||||
case '\\':
|
||||
if (!stack.isEmpty() && stack.peek() == c) {
|
||||
stack.pop();
|
||||
builder.append(c);
|
||||
} else {
|
||||
stack.push(c);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
if (!stack.isEmpty()) {
|
||||
if (stack.peek() == '\'') {
|
||||
throw new BasicError("Unclosed single quote found in scenario cmd '" + cmd + "'");
|
||||
} else if (stack.peek() == '\"') {
|
||||
throw new BasicError("Unclosed double quote found in scenario cmd '" + cmd + "'");
|
||||
} else {
|
||||
throw new BasicError("Unused escape character \"\\\" found in scenario cmd '" + cmd + "'");
|
||||
}
|
||||
}
|
||||
if (!builder.isEmpty()) {
|
||||
cmdSplit.add(builder.toString());
|
||||
}
|
||||
return cmdSplit;
|
||||
}
|
||||
|
||||
private static LinkedHashMap<String, SCNamedParam> parseStep(String cmd, String stepName, String scenarioName) {
|
||||
LinkedHashMap<String, SCNamedParam> parsedStep = new LinkedHashMap<>();
|
||||
|
||||
String[] namedStepPieces = cmd.split(" +");
|
||||
List<String> namedStepPieces = splitCommand(cmd);
|
||||
for (String commandFragment : namedStepPieces) {
|
||||
Matcher matcher = WordAndMaybeAssignment.matcher(commandFragment);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user