Search in sources :

Example 1 with StmtsDocList

use of io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList in project nosqlbench by nosqlbench.

the class ActivityTypeLoader method getDriverAdapter.

private Optional<ActivityType> getDriverAdapter(String activityTypeName, ActivityDef activityDef) {
    Optional<DriverAdapter> oda = DRIVERADAPTER_SPI_FINDER.getOptionally(activityTypeName);
    if (oda.isPresent()) {
        DriverAdapter<?, ?> driverAdapter = oda.get();
        activityDef.getParams().remove("driver");
        if (driverAdapter instanceof NBConfigurable) {
            NBConfigModel cfgModel = ((NBConfigurable) driverAdapter).getConfigModel();
            Optional<String> op_yaml_loc = activityDef.getParams().getOptionalString("yaml", "workload");
            if (op_yaml_loc.isPresent()) {
                Map<String, Object> disposable = new LinkedHashMap<>(activityDef.getParams());
                StmtsDocList workload = StatementsLoader.loadPath(logger, op_yaml_loc.get(), disposable, "activities");
                cfgModel = cfgModel.add(workload.getConfigModel());
            }
            NBConfiguration cfg = cfgModel.apply(activityDef.getParams());
            ((NBConfigurable) driverAdapter).applyConfig(cfg);
        }
        ActivityType activityType = new StandardActivityType<>(driverAdapter, activityDef);
        return Optional.of(activityType);
    } else {
        return Optional.empty();
    }
}
Also used : NBConfigurable(io.nosqlbench.nb.api.config.standard.NBConfigurable) StandardActivityType(io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType) StandardActivityType(io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) NBConfiguration(io.nosqlbench.nb.api.config.standard.NBConfiguration) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) DriverAdapter(io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter) NBConfigModel(io.nosqlbench.nb.api.config.standard.NBConfigModel)

Example 2 with StmtsDocList

use of io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList in project nosqlbench by nosqlbench.

the class NBCLIScenarioParserTemplateVarTest method testThatCLIOverridesWorkForTemplateVars.

@Test
public void testThatCLIOverridesWorkForTemplateVars() {
    NBCLIOptions opts = new NBCLIOptions(new String[] { "local/example-scenarios-templatevars", "tvar1=overridden" });
    List<Cmd> cmds = opts.getCommands();
    cmds.forEach(System.out::println);
    StmtsDocList workload1 = StatementsLoader.loadPath(null, cmds.get(0).getArg("workload"), cmds.get(0).getParams());
    OpTemplate optpl1 = workload1.getStmts().get(0);
    System.out.println("op from cmd1:" + optpl1);
    assertThat(optpl1.getStmt()).contains("cycle {cycle} overridden overridden\n");
}
Also used : OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) Test(org.junit.jupiter.api.Test)

Example 3 with StmtsDocList

use of io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList in project nosqlbench by nosqlbench.

the class NBCLIScenarioParserTemplateVarTest method testMultipleOccurencesOfSameTemplateVar.

@Test
public void testMultipleOccurencesOfSameTemplateVar() {
    NBCLIOptions opts = new NBCLIOptions(new String[] { "local/example-scenarios-templatevars" });
    List<Cmd> cmds = opts.getCommands();
    cmds.forEach(System.out::println);
    StmtsDocList workload1 = StatementsLoader.loadPath(null, cmds.get(0).getArg("workload"), cmds.get(0).getParams());
    OpTemplate optpl1 = workload1.getStmts().get(0);
    System.out.println("op from cmd1:" + optpl1);
    assertThat(optpl1.getStmt()).contains("cycle {cycle} replaced replaced\n");
    StmtsDocList workload2 = StatementsLoader.loadPath(null, cmds.get(1).getArg("workload"), cmds.get(1).getParams());
    OpTemplate optpl2 = workload2.getStmts().get(0);
    System.out.println("op from cmd2:" + optpl2);
    assertThat(optpl2.getStmt()).contains("cycle {cycle} def1 def1\n");
}
Also used : OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) Test(org.junit.jupiter.api.Test)

Example 4 with StmtsDocList

use of io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList in project nosqlbench by nosqlbench.

the class CommandTemplateTest method testCommandTemplateFormat.

@Test
public void testCommandTemplateFormat() {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    StmtsDocList stmtsDocs = StatementsLoader.loadString("" + "statements:\n" + " - s1: test1=foo test2={bar}\n" + "   bindings:\n" + "    bar: NumberNameToString();\n", Map.of());
    OpTemplate optpl = stmtsDocs.getStmts().get(0);
    CommandTemplate ct = new CommandTemplate(optpl);
    String format = gson.toJson(ct);
    System.out.println(format);
}
Also used : OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) Test(org.junit.jupiter.api.Test)

Example 5 with StmtsDocList

use of io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList in project nosqlbench by nosqlbench.

the class OpDefTest method testListOfNamedMap.

@Test
public void testListOfNamedMap() {
    StmtsDocList all = StatementsLoader.loadPath(logger, "testdocs/statement_variants.yaml");
    List<StmtsDoc> docs = all.getStmtDocs();
    StmtsDoc doc2 = docs.get(2);
    assertThat(doc2.getName()).isEqualTo("list-of-named-map");
    assertThat(doc2.getBlocks()).hasSize(1);
    StmtsBlock block1 = doc2.getBlocks().get(0);
    assertThat(block1.getOps()).hasSize(1);
    OpTemplate op0 = block1.getOps().get(0);
    System.out.println(op0.getParams());
    assertThat(op0.getName()).isEqualTo("list-of-named-map--block1--s1");
    assertThat(op0.getOp()).contains(Map.of("p1", "v1", "p2", "v2"));
// System.out.println("here");
// TODO: This needs to be clarified and the logic made less ambiguous
// assertThat(op0.getParams()).hasSize(1);
// assertThat(op0.getParams()).containsExactlyEntriesOf(Map.of("p1", "v2", "p2", "v2", "p3", "v3"));
}
Also used : StmtsDoc(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDoc) OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) StmtsBlock(io.nosqlbench.engine.api.activityconfig.yaml.StmtsBlock) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) Test(org.junit.jupiter.api.Test)

Aggregations

StmtsDocList (io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList)27 OpTemplate (io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate)19 Test (org.junit.jupiter.api.Test)17 StmtsDoc (io.nosqlbench.engine.api.activityconfig.yaml.StmtsDoc)7 StmtsBlock (io.nosqlbench.engine.api.activityconfig.yaml.StmtsBlock)5 IOException (java.io.IOException)4 SequencePlanner (io.nosqlbench.engine.api.activityapi.planning.SequencePlanner)3 SequencerType (io.nosqlbench.engine.api.activityapi.planning.SequencerType)3 StrInterpolator (io.nosqlbench.engine.api.templating.StrInterpolator)3 JsonElement (com.google.gson.JsonElement)2 JsonParser (com.google.gson.JsonParser)2 RawStmtsDocList (io.nosqlbench.engine.api.activityconfig.rawyaml.RawStmtsDocList)2 RawStmtsLoader (io.nosqlbench.engine.api.activityconfig.rawyaml.RawStmtsLoader)2 Scenarios (io.nosqlbench.engine.api.activityconfig.yaml.Scenarios)2 BasicError (io.nosqlbench.nb.api.errors.BasicError)2 Type (java.lang.reflect.Type)2 Path (java.nio.file.Path)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ConnectionString (com.mongodb.ConnectionString)1