mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
simplify methods further with fewer logger parameters
This commit is contained in:
@@ -16,13 +16,13 @@
|
||||
|
||||
package io.nosqlbench.engine.api.activityconfig;
|
||||
|
||||
import io.nosqlbench.api.content.Content;
|
||||
import io.nosqlbench.api.content.NBIO;
|
||||
import io.nosqlbench.api.errors.BasicError;
|
||||
import io.nosqlbench.engine.api.activityconfig.rawyaml.RawStmtsDocList;
|
||||
import io.nosqlbench.engine.api.activityconfig.rawyaml.RawStmtsLoader;
|
||||
import io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList;
|
||||
import io.nosqlbench.engine.api.templating.StrInterpolator;
|
||||
import io.nosqlbench.api.content.Content;
|
||||
import io.nosqlbench.api.content.NBIO;
|
||||
import io.nosqlbench.api.errors.BasicError;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -31,10 +31,26 @@ import java.util.Optional;
|
||||
|
||||
public class StatementsLoader {
|
||||
|
||||
public static String[] YAML_EXTENSIONS = new String[]{"yaml","yml"};
|
||||
|
||||
private final static Logger logger = LogManager.getLogger(StatementsLoader.class);
|
||||
|
||||
public static String[] YAML_EXTENSIONS = new String[]{"yaml","yml", "json", "jsonnet"};
|
||||
|
||||
public static StmtsDocList loadContent(Content<?> content, Map<String,String> params) {
|
||||
return loadString(content.get().toString(),params);
|
||||
}
|
||||
|
||||
public static StmtsDocList loadPath(String path, Map<String,?> params, String... searchPaths) {
|
||||
RawStmtsDocList list = null;
|
||||
Optional<Content<?>> oyaml = NBIO.all().prefix(searchPaths).name(path).extension(YAML_EXTENSIONS).first();
|
||||
String content = oyaml.map(Content::asString).orElseThrow(() -> new BasicError("Unable to load " + path));
|
||||
return loadString(content,params);
|
||||
}
|
||||
public static StmtsDocList loadPath(
|
||||
String path,
|
||||
String... searchPaths) {
|
||||
return loadPath(path, Map.of(), searchPaths);
|
||||
}
|
||||
|
||||
public static StmtsDocList loadString(String yamlContent, Map<String,?> params) {
|
||||
|
||||
StrInterpolator transformer = new StrInterpolator(params);
|
||||
@@ -48,11 +64,7 @@ public class StatementsLoader {
|
||||
return layered;
|
||||
}
|
||||
|
||||
public static StmtsDocList loadStmt(
|
||||
Logger logger,
|
||||
String statement,
|
||||
Map<String,?> params
|
||||
) {
|
||||
public static StmtsDocList loadStmt(String statement, Map<String,?> params) {
|
||||
StrInterpolator transformer = new StrInterpolator(params);
|
||||
statement = transformer.apply(statement);
|
||||
RawStmtsDocList rawStmtsDocList = RawStmtsDocList.forSingleStatement(statement);
|
||||
@@ -64,32 +76,6 @@ public class StatementsLoader {
|
||||
return layered;
|
||||
}
|
||||
|
||||
public static StmtsDocList loadContent(
|
||||
Logger logger,
|
||||
Content<?> content,
|
||||
Map<String,String> params
|
||||
) {
|
||||
return loadString(content.get().toString(),params);
|
||||
}
|
||||
|
||||
public static StmtsDocList loadPath(
|
||||
Logger logger,
|
||||
String path,
|
||||
Map<String,?> params,
|
||||
String... searchPaths) {
|
||||
|
||||
RawStmtsDocList list = null;
|
||||
Optional<Content<?>> oyaml = NBIO.all().prefix(searchPaths).name(path).extension(YAML_EXTENSIONS).first();
|
||||
String content = oyaml.map(Content::asString).orElseThrow(() -> new BasicError("Unable to load " + path));
|
||||
return loadString(content,params);
|
||||
}
|
||||
|
||||
|
||||
public static StmtsDocList loadPath(
|
||||
Logger logger,
|
||||
String path,
|
||||
String... searchPaths) {
|
||||
return loadPath(logger, path, Map.of(), searchPaths);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class StmtsDocList implements Iterable<StmtsDoc> {
|
||||
}
|
||||
|
||||
public static NBConfigModelExpander TEMPLATE_VAR_EXPANDER = workload -> {
|
||||
StmtsDocList loaded = StatementsLoader.loadPath(logger, (String) workload, "activities");
|
||||
StmtsDocList loaded = StatementsLoader.loadPath((String) workload, "activities");
|
||||
return loaded.getConfigModel();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,7 @@ public class StatementsLoaderTest {
|
||||
|
||||
@Test
|
||||
public void testTemplateVarSubstitution() {
|
||||
StmtsDocList stmtsDocs = StatementsLoader.loadPath(null, "activities/template_vars", "src/test/resources");
|
||||
StmtsDocList stmtsDocs = StatementsLoader.loadPath("activities/template_vars", "src/test/resources");
|
||||
assertThat(stmtsDocs).isNotNull();
|
||||
List<StmtsDoc> docs = stmtsDocs.getStmtDocs();
|
||||
assertThat(docs).hasSize(1);
|
||||
@@ -46,7 +46,7 @@ public class StatementsLoaderTest {
|
||||
public void testInvalidYamlProperties() {
|
||||
Exception caught = null;
|
||||
try {
|
||||
StatementsLoader.loadPath(null, "activities/invalid_prop", "src/test/resources");
|
||||
StatementsLoader.loadPath("activities/invalid_prop", "src/test/resources");
|
||||
} catch (Exception e) {
|
||||
caught = e;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ public class OpDefTest {
|
||||
@Test
|
||||
public void testLayering() {
|
||||
|
||||
StmtsDocList all = StatementsLoader.loadPath(logger, "testdocs/docs_blocks_stmts.yaml");
|
||||
StmtsDocList all = StatementsLoader.loadPath("testdocs/docs_blocks_stmts.yaml");
|
||||
assertThat(all).isNotNull();
|
||||
assertThat(all.getStmtDocs()).hasSize(2);
|
||||
StmtsDoc doc1 = all.getStmtDocs().get(0);
|
||||
@@ -64,7 +64,7 @@ public class OpDefTest {
|
||||
|
||||
@Test
|
||||
public void testStatementRendering() {
|
||||
StmtsDocList all = StatementsLoader.loadPath(logger, "testdocs/docs_blocks_stmts.yaml");
|
||||
StmtsDocList all = StatementsLoader.loadPath("testdocs/docs_blocks_stmts.yaml");
|
||||
assertThat(all).isNotNull();
|
||||
assertThat(all.getStmtDocs()).hasSize(2);
|
||||
StmtsDoc doc1 = all.getStmtDocs().get(0);
|
||||
@@ -79,7 +79,7 @@ public class OpDefTest {
|
||||
|
||||
@Test
|
||||
public void testConsumableMapState() {
|
||||
StmtsDocList all = StatementsLoader.loadPath(logger, "testdocs/docs_blocks_stmts.yaml");
|
||||
StmtsDocList all = StatementsLoader.loadPath("testdocs/docs_blocks_stmts.yaml");
|
||||
List<StmtsDoc> docs = all.getStmtDocs();
|
||||
StmtsDoc block1 = docs.get(1);
|
||||
List<OpTemplate> stmts = block1.getStmts();
|
||||
@@ -94,7 +94,7 @@ public class OpDefTest {
|
||||
|
||||
@Test
|
||||
public void testMapOfMaps() {
|
||||
StmtsDocList all = StatementsLoader.loadPath(logger, "testdocs/statement_variants.yaml");
|
||||
StmtsDocList all = StatementsLoader.loadPath("testdocs/statement_variants.yaml");
|
||||
List<StmtsDoc> docs = all.getStmtDocs();
|
||||
StmtsDoc doc0 = docs.get(0);
|
||||
assertThat(doc0.getName()).isEqualTo("map-of-maps");
|
||||
@@ -115,7 +115,7 @@ public class OpDefTest {
|
||||
|
||||
@Test
|
||||
public void testBasicStringStmt() {
|
||||
StmtsDocList all = StatementsLoader.loadPath(logger, "testdocs/statement_variants.yaml");
|
||||
StmtsDocList all = StatementsLoader.loadPath("testdocs/statement_variants.yaml");
|
||||
List<StmtsDoc> docs = all.getStmtDocs();
|
||||
StmtsDoc doc1 = docs.get(1);
|
||||
assertThat(doc1.getName()).isEqualTo("string-statement");
|
||||
@@ -130,7 +130,7 @@ public class OpDefTest {
|
||||
|
||||
@Test
|
||||
public void testListOfNamedMap() {
|
||||
StmtsDocList all = StatementsLoader.loadPath(logger, "testdocs/statement_variants.yaml");
|
||||
StmtsDocList all = StatementsLoader.loadPath("testdocs/statement_variants.yaml");
|
||||
List<StmtsDoc> docs = all.getStmtDocs();
|
||||
StmtsDoc doc2 = docs.get(2);
|
||||
assertThat(doc2.getName()).isEqualTo("list-of-named-map");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,7 +35,7 @@ public class StmtEscapingTest {
|
||||
@BeforeAll
|
||||
public static void testLayering() {
|
||||
|
||||
StmtsDocList all = StatementsLoader.loadPath(logger, "testdocs/escaped_stmts.yaml");
|
||||
StmtsDocList all = StatementsLoader.loadPath("testdocs/escaped_stmts.yaml");
|
||||
assertThat(all).isNotNull();
|
||||
assertThat(all.getStmtDocs()).hasSize(1);
|
||||
StmtsDoc doc1 = all.getStmtDocs().get(0);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,7 @@ public class ParsedStmtOpTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void testLoadYaml() {
|
||||
doclist = StatementsLoader.loadPath(logger, "testdocs/bindings.yaml");
|
||||
doclist = StatementsLoader.loadPath("testdocs/bindings.yaml");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ public class StmtDetailOverrideTest {
|
||||
@Test
|
||||
public void testStmtOverrides() {
|
||||
|
||||
StmtsDocList doclist = StatementsLoader.loadPath(logger, "testdocs/stmt_details.yaml");
|
||||
StmtsDocList doclist = StatementsLoader.loadPath("testdocs/stmt_details.yaml");
|
||||
|
||||
assertThat(doclist).isNotNull();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,7 +50,7 @@ public class StmtsDocListTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void testLoadYaml() {
|
||||
doclist = StatementsLoader.loadPath(logger, "testdocs/docs_blocks_stmts.yaml");
|
||||
doclist = StatementsLoader.loadPath("testdocs/docs_blocks_stmts.yaml");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user