mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
basic component lifetimes working
This commit is contained in:
@@ -74,7 +74,7 @@ import java.util.ServiceLoader.Provider;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NBCLI extends NBBaseComponent implements Function<String[], Integer> {
|
||||
public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
||||
|
||||
private static Logger logger;
|
||||
private static final LoggerConfig loggerConfig;
|
||||
@@ -88,17 +88,14 @@ public class NBCLI extends NBBaseComponent implements Function<String[], Integer
|
||||
}
|
||||
|
||||
private final String commandName;
|
||||
|
||||
private NBLabels labels;
|
||||
private String sessionName;
|
||||
private String sessionCode;
|
||||
private long sessionTime;
|
||||
private NBLabels extraLabels = NBLabels.forKV();
|
||||
private NBLabels labels = NBLabels.forKV("appname","nosqlbench");
|
||||
|
||||
private ClientSystemMetricChecker clientMetricChecker;
|
||||
|
||||
public NBCLI(final String commandName) {
|
||||
super(null, NBLabels.forKV("appname","nosqlbench"));
|
||||
this.commandName = commandName;
|
||||
}
|
||||
|
||||
@@ -166,14 +163,9 @@ public class NBCLI extends NBBaseComponent implements Function<String[], Integer
|
||||
NBCLI.loggerConfig.setConsoleLevel(NBLogLevel.ERROR);
|
||||
this.sessionTime = System.currentTimeMillis();
|
||||
final NBCLIOptions globalOptions = new NBCLIOptions(args, Mode.ParseGlobalsOnly);
|
||||
this.extraLabels=globalOptions.getLabelMap();
|
||||
|
||||
this.labels=globalOptions.getLabelMap();
|
||||
this.sessionCode = SystemId.genSessionCode(sessionTime);
|
||||
this.sessionName = SessionNamer.format(globalOptions.getSessionName(), sessionTime).replaceAll("SESSIONCODE", sessionCode);
|
||||
this.labels = NBLabels.forKV()
|
||||
.and("appname", "nosqlbench")
|
||||
.and("node", SystemId.getNodeId())
|
||||
.and(globalOptions.getLabelMap());
|
||||
|
||||
NBCLI.loggerConfig
|
||||
.setSessionName(sessionName)
|
||||
@@ -439,7 +431,7 @@ public class NBCLI extends NBBaseComponent implements Function<String[], Integer
|
||||
* marshal and transform it for any scenario invocations directly.
|
||||
*/
|
||||
NBSession session = new NBSession(
|
||||
this,
|
||||
new NBBaseComponent(null),
|
||||
sessionName,
|
||||
options.getProgressSpec(),
|
||||
options.getReportSummaryTo(),
|
||||
@@ -595,7 +587,7 @@ public class NBCLI extends NBBaseComponent implements Function<String[], Integer
|
||||
|
||||
@Override
|
||||
public NBLabels getLabels() {
|
||||
return (extraLabels==null) ? super.getLabels() : super.getLabels().and(extraLabels);
|
||||
return labels;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.nosqlbench.api.errors.BasicError;
|
||||
import io.nosqlbench.api.labels.NBLabelSpec;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.logging.NBLogLevel;
|
||||
import io.nosqlbench.api.metadata.SystemId;
|
||||
import io.nosqlbench.api.system.NBStatePath;
|
||||
import io.nosqlbench.engine.api.metrics.IndicatorMode;
|
||||
import io.nosqlbench.engine.cli.Cmd.CmdType;
|
||||
@@ -133,7 +134,8 @@ public class NBCLIOptions {
|
||||
// private static final String DEFAULT_CONSOLE_LOGGING_PATTERN = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n";
|
||||
|
||||
|
||||
private NBLabels labels = NBLabels.forKV();
|
||||
private NBLabels labels = NBLabels.forKV("appname", "nosqlbench")
|
||||
.and("node",SystemId.getNodeId());
|
||||
private final List<Cmd> cmdList = new ArrayList<>();
|
||||
private int logsMax;
|
||||
private boolean wantsVersionShort;
|
||||
|
||||
@@ -20,6 +20,8 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provide a result type back to a caller, including the start and end times,
|
||||
@@ -53,8 +55,15 @@ public class ExecutionResult {
|
||||
public ExecutionResult(long startedAt, long endedAt, String iolog, Exception error) {
|
||||
this.startedAt = startedAt;
|
||||
this.endedAt = endedAt;
|
||||
List<String> elements = new ArrayList<>();
|
||||
if (iolog!=null && iolog.isEmpty()) {
|
||||
elements.add(iolog);
|
||||
}
|
||||
if (error!=null) {
|
||||
elements.add("ERROR:" + error);
|
||||
}
|
||||
this.exception = error;
|
||||
this.iolog = ((iolog != null) ? iolog + "\n\n" : "") + exception;
|
||||
this.iolog = String.join("\n",elements);
|
||||
this.status = (error==null) ? Status.OK : Status.ERROR;
|
||||
logger.debug("populating "+status+" scenario result");
|
||||
|
||||
@@ -73,7 +82,7 @@ public class ExecutionResult {
|
||||
}
|
||||
|
||||
public String getIOLog() {
|
||||
return this.iolog;
|
||||
return this.iolog==null? "" : iolog;
|
||||
}
|
||||
|
||||
public long getElapsedMillis() {
|
||||
@@ -88,5 +97,14 @@ public class ExecutionResult {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExecutionResult{" +
|
||||
"status=" + status +
|
||||
", startedAt=" + startedAt +
|
||||
", endedAt=" + endedAt +
|
||||
", exception=" + exception +
|
||||
", iolog='" + iolog + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.nosqlbench.api.engine.metrics.instruments.NBFunctionGauge;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricGauge;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.components.NBComponentSubScope;
|
||||
import io.nosqlbench.engine.api.activityapi.core.*;
|
||||
import io.nosqlbench.engine.api.activityimpl.MotorState;
|
||||
import io.nosqlbench.api.annotations.Annotation;
|
||||
@@ -397,7 +398,9 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
|
||||
|
||||
@Override
|
||||
public ExecutionResult call() throws Exception {
|
||||
shutdownHook=new ActivityExecutorShutdownHook(this);
|
||||
try (NBComponentSubScope scope = new NBComponentSubScope(activity)) {
|
||||
|
||||
shutdownHook = new ActivityExecutorShutdownHook(this);
|
||||
Runtime.getRuntime().addShutdownHook(shutdownHook);
|
||||
long startAt = System.currentTimeMillis();
|
||||
|
||||
@@ -422,7 +425,7 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
|
||||
} catch (Exception e) {
|
||||
this.exception = e;
|
||||
} finally {
|
||||
stoppedAt=System.currentTimeMillis();
|
||||
stoppedAt = System.currentTimeMillis();
|
||||
unregisterMetrics();
|
||||
activity.shutdownActivity();
|
||||
activity.closeAutoCloseables();
|
||||
@@ -432,6 +435,8 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This waits for at least one motor to be in running, finished or stopped state.
|
||||
* A motor with enough cycles to read will go into a running state. A motor which has
|
||||
@@ -463,6 +468,7 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
|
||||
NBMetricGauge gauge = new NBFunctionGauge(activity, () -> (double) this.motors.size(), "threads");
|
||||
this.threadsGauge = ActivityMetrics.gauge(gauge);
|
||||
}
|
||||
|
||||
private void unregisterMetrics() {
|
||||
if (this.threadsGauge != null) {
|
||||
ActivityMetrics.unregister(this.threadsGauge);
|
||||
@@ -571,8 +577,8 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
|
||||
} else {
|
||||
logger.warn("Activity was interrupted by process exit, shutting down ungracefully. Annotations are still submitted.");
|
||||
}
|
||||
if (shutdownHook==null) return; // In case of a race condition, only prevented by object monitor
|
||||
else shutdownHook=null;
|
||||
if (shutdownHook == null) return; // In case of a race condition, only prevented by object monitor
|
||||
else shutdownHook = null;
|
||||
|
||||
stoppedAt = System.currentTimeMillis(); //TODO: Make only one endedAtMillis assignment
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.engine.api.activityapi.core.Activity;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.Scenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.NBScenario;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -35,9 +35,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class ActivityLoader {
|
||||
private static final Logger logger = LogManager.getLogger("ACTIVITIES");
|
||||
private final Map<String, Activity> activityMap = new ConcurrentHashMap<>();
|
||||
private final Scenario scenario;
|
||||
private final NBScenario scenario;
|
||||
|
||||
public ActivityLoader(final Scenario scenario) {
|
||||
public ActivityLoader(final NBScenario scenario) {
|
||||
this.scenario = scenario;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class Scenario extends NBBaseComponent implements Callable<ExecutionMetricsResult> {
|
||||
public class NBScenario extends NBBaseComponent implements Callable<ExecutionMetricsResult> {
|
||||
|
||||
private final String reportSummaryTo;
|
||||
private final Path logsPath;
|
||||
@@ -85,11 +85,6 @@ public class Scenario extends NBBaseComponent implements Callable<ExecutionMetri
|
||||
EXECUTE_SCRIPT
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBLabels getLabels() {
|
||||
return this.parentComponent.getLabels().and("scenario", this.scenarioName);
|
||||
}
|
||||
|
||||
public enum State {
|
||||
Scheduled,
|
||||
Running,
|
||||
@@ -114,7 +109,7 @@ public class Scenario extends NBBaseComponent implements Callable<ExecutionMetri
|
||||
Graalvm
|
||||
}
|
||||
|
||||
public Scenario(
|
||||
public NBScenario(
|
||||
final String scenarioName,
|
||||
final String progressInterval,
|
||||
final String reportSummaryTo,
|
||||
@@ -133,9 +128,9 @@ public class Scenario extends NBBaseComponent implements Callable<ExecutionMetri
|
||||
this.invocation = invocation;
|
||||
}
|
||||
|
||||
public static Scenario forTesting(final String name, final String reportSummaryTo, NBComponent parent) {
|
||||
public static NBScenario forTesting(final String name, final String reportSummaryTo, NBComponent parent) {
|
||||
|
||||
return new Scenario(
|
||||
return new NBScenario(
|
||||
name,
|
||||
"console:10s",
|
||||
reportSummaryTo,
|
||||
@@ -146,7 +141,7 @@ public class Scenario extends NBBaseComponent implements Callable<ExecutionMetri
|
||||
);
|
||||
}
|
||||
|
||||
public Scenario setLogger(final Logger logger) {
|
||||
public NBScenario setLogger(final Logger logger) {
|
||||
this.logger = logger;
|
||||
return this;
|
||||
}
|
||||
@@ -155,13 +150,13 @@ public class Scenario extends NBBaseComponent implements Callable<ExecutionMetri
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
public Scenario addScriptText(final String scriptText) {
|
||||
public NBScenario addScriptText(final String scriptText) {
|
||||
this.scripts.add(scriptText);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Scenario addScriptFiles(final String... args) {
|
||||
public NBScenario addScriptFiles(final String... args) {
|
||||
for (final String scriptFile : args) {
|
||||
final Path scriptPath = Paths.get(scriptFile);
|
||||
byte[] bytes = new byte[0];
|
||||
@@ -462,7 +457,7 @@ public class Scenario extends NBBaseComponent implements Callable<ExecutionMetri
|
||||
if ((null == o) || (this.getClass() != o.getClass())) {
|
||||
return false;
|
||||
}
|
||||
final Scenario scenario = (Scenario) o;
|
||||
final NBScenario scenario = (NBScenario) o;
|
||||
return Objects.equals(this.scenarioName, scenario.scenarioName);
|
||||
}
|
||||
|
||||
@@ -48,11 +48,11 @@ public class ScenarioController implements NBLabeledElement {
|
||||
private final ActivityLoader activityLoader;
|
||||
|
||||
private final Map<String, ActivityRuntimeInfo> activityInfoMap = new ConcurrentHashMap<>();
|
||||
private final Scenario scenario;
|
||||
private final NBScenario scenario;
|
||||
|
||||
private final ExecutorService activitiesExecutor;
|
||||
|
||||
public ScenarioController(Scenario scenario) {
|
||||
public ScenarioController(NBScenario scenario) {
|
||||
this.scenario = scenario;
|
||||
this.activityLoader = new ActivityLoader(scenario);
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -20,10 +20,10 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ScenarioShutdownHook extends Thread {
|
||||
|
||||
private final Scenario scenario;
|
||||
private final NBScenario scenario;
|
||||
private final Logger logger;
|
||||
|
||||
public ScenarioShutdownHook(Scenario scenario) {
|
||||
public ScenarioShutdownHook(NBScenario scenario) {
|
||||
this.scenario = scenario;
|
||||
logger = scenario.getLogger();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -48,7 +48,7 @@ public class ScenariosExecutor {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public synchronized void execute(Scenario scenario) {
|
||||
public synchronized void execute(NBScenario scenario) {
|
||||
if (submitted.get(scenario.getScenarioName()) != null) {
|
||||
throw new BasicError("Scenario " + scenario.getScenarioName() + " is already defined. Remove it first to reuse the name.");
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class ScenariosExecutor {
|
||||
throw new RuntimeException("executor still runningScenarios after awaiting all results for " + timeout
|
||||
+ "ms. isTerminated:" + executor.isTerminated() + " isShutdown:" + executor.isShutdown());
|
||||
}
|
||||
Map<Scenario, ExecutionMetricsResult> scenarioResultMap = new LinkedHashMap<>();
|
||||
Map<NBScenario, ExecutionMetricsResult> scenarioResultMap = new LinkedHashMap<>();
|
||||
getAsyncResultStatus()
|
||||
.entrySet()
|
||||
.forEach(
|
||||
@@ -142,9 +142,9 @@ public class ScenariosExecutor {
|
||||
*
|
||||
* @return map of async results, with incomplete results as Optional.empty()
|
||||
*/
|
||||
public Map<Scenario, Optional<ExecutionMetricsResult>> getAsyncResultStatus() {
|
||||
public Map<NBScenario, Optional<ExecutionMetricsResult>> getAsyncResultStatus() {
|
||||
|
||||
Map<Scenario, Optional<ExecutionMetricsResult>> optResults = new LinkedHashMap<>();
|
||||
Map<NBScenario, Optional<ExecutionMetricsResult>> optResults = new LinkedHashMap<>();
|
||||
|
||||
for (SubmittedScenario submittedScenario : submitted.values()) {
|
||||
Future<ExecutionMetricsResult> resultFuture = submittedScenario.getResultFuture();
|
||||
@@ -167,7 +167,7 @@ public class ScenariosExecutor {
|
||||
return optResults;
|
||||
}
|
||||
|
||||
public Optional<Scenario> getPendingScenario(String scenarioName) {
|
||||
public Optional<NBScenario> getPendingScenario(String scenarioName) {
|
||||
return Optional.ofNullable(submitted.get(scenarioName)).map(SubmittedScenario::getScenario);
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public class ScenariosExecutor {
|
||||
|
||||
public synchronized void stopScenario(String scenarioName, boolean rethrow) {
|
||||
logger.debug("#stopScenario(name=" + scenarioName + ", rethrow="+ rethrow+")");
|
||||
Optional<Scenario> pendingScenario = getPendingScenario(scenarioName);
|
||||
Optional<NBScenario> pendingScenario = getPendingScenario(scenarioName);
|
||||
if (pendingScenario.isPresent()) {
|
||||
pendingScenario.get().getScenarioController().forceStopScenario(10000, true);
|
||||
} else {
|
||||
@@ -204,7 +204,7 @@ public class ScenariosExecutor {
|
||||
public synchronized void deleteScenario(String scenarioName) {
|
||||
stopScenario(scenarioName, false);
|
||||
|
||||
Optional<Scenario> pendingScenario = getPendingScenario(scenarioName);
|
||||
Optional<NBScenario> pendingScenario = getPendingScenario(scenarioName);
|
||||
if (pendingScenario.isPresent()) {
|
||||
submitted.remove(scenarioName);
|
||||
logger.info(() -> "cancelled scenario " + scenarioName);
|
||||
@@ -224,15 +224,15 @@ public class ScenariosExecutor {
|
||||
}
|
||||
|
||||
private static class SubmittedScenario {
|
||||
private final Scenario scenario;
|
||||
private final NBScenario scenario;
|
||||
private final Future<ExecutionMetricsResult> resultFuture;
|
||||
|
||||
SubmittedScenario(Scenario scenario, Future<ExecutionMetricsResult> resultFuture) {
|
||||
SubmittedScenario(NBScenario scenario, Future<ExecutionMetricsResult> resultFuture) {
|
||||
this.scenario = scenario;
|
||||
this.resultFuture = resultFuture;
|
||||
}
|
||||
|
||||
public Scenario getScenario() {
|
||||
public NBScenario getScenario() {
|
||||
return scenario;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@ public class ScenariosResults {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ScenariosResults.class);
|
||||
private final String scenariosExecutorName;
|
||||
private final Map<Scenario, ExecutionMetricsResult> scenarioResultMap = new LinkedHashMap<>();
|
||||
private final Map<NBScenario, ExecutionMetricsResult> scenarioResultMap = new LinkedHashMap<>();
|
||||
|
||||
|
||||
public ScenariosResults(ScenariosExecutor scenariosExecutor) {
|
||||
this.scenariosExecutorName = scenariosExecutor.getName();
|
||||
}
|
||||
|
||||
public ScenariosResults(ScenariosExecutor scenariosExecutor, Map<Scenario, ExecutionMetricsResult> map) {
|
||||
public ScenariosResults(ScenariosExecutor scenariosExecutor, Map<NBScenario, ExecutionMetricsResult> map) {
|
||||
this.scenariosExecutorName = scenariosExecutor.getName();
|
||||
scenarioResultMap.putAll(map);
|
||||
}
|
||||
@@ -58,8 +58,8 @@ public class ScenariosResults {
|
||||
}
|
||||
|
||||
public void reportToLog() {
|
||||
for (Map.Entry<Scenario, ExecutionMetricsResult> entry : this.scenarioResultMap.entrySet()) {
|
||||
Scenario scenario = entry.getKey();
|
||||
for (Map.Entry<NBScenario, ExecutionMetricsResult> entry : this.scenarioResultMap.entrySet()) {
|
||||
NBScenario scenario = entry.getKey();
|
||||
ExecutionMetricsResult oresult = entry.getValue();
|
||||
|
||||
logger.info(() -> "results for scenario: " + scenario);
|
||||
|
||||
@@ -20,13 +20,14 @@ import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.components.NBComponentSubScope;
|
||||
import io.nosqlbench.engine.cli.BasicScriptBuffer;
|
||||
import io.nosqlbench.engine.cli.Cmd;
|
||||
import io.nosqlbench.engine.cli.ScriptBuffer;
|
||||
import io.nosqlbench.engine.core.lifecycle.ExecutionResult;
|
||||
import io.nosqlbench.engine.core.lifecycle.process.NBCLIErrorHandler;
|
||||
import io.nosqlbench.engine.core.lifecycle.process.ShutdownManager;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.Scenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.NBScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.ScenariosExecutor;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.ScenariosResults;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.ScriptParams;
|
||||
@@ -82,9 +83,9 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
|
||||
|
||||
try (ResultContext results = new ResultContext(collector)) {
|
||||
final ScenariosExecutor scenariosExecutor = new ScenariosExecutor("executor-" + sessionName, 1);
|
||||
Scenario.Invocation invocation = wantsShowScript ? Scenario.Invocation.RENDER_SCRIPT : Scenario.Invocation.EXECUTE_SCRIPT;
|
||||
NBScenario.Invocation invocation = wantsShowScript ? NBScenario.Invocation.RENDER_SCRIPT : NBScenario.Invocation.EXECUTE_SCRIPT;
|
||||
|
||||
final Scenario scenario = new Scenario(
|
||||
final NBScenario scenario = new NBScenario(
|
||||
sessionName,
|
||||
progressSpec,
|
||||
reportSummaryTo,
|
||||
@@ -93,6 +94,7 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
|
||||
this,
|
||||
invocation
|
||||
);
|
||||
try (NBComponentSubScope s = new NBComponentSubScope(scenario)) {
|
||||
|
||||
final ScriptBuffer buffer = new BasicScriptBuffer().add(cmds.toArray(new Cmd[0]));
|
||||
final String scriptData = buffer.getParsedScript();
|
||||
@@ -126,6 +128,9 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
|
||||
}
|
||||
|
||||
results.output(scenariosResults.getExecutionSummary());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return collector.toExecutionResult();
|
||||
}
|
||||
|
||||
@@ -18,20 +18,20 @@ package io.nosqlbench.engine.core;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.engine.api.scripting.ScriptEnvBuffer;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.Scenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.NBScenario;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ScenarioTest {
|
||||
private final Logger logger = LogManager.getLogger(ScenarioTest.class);
|
||||
public class NBScenarioTest {
|
||||
private final Logger logger = LogManager.getLogger(NBScenarioTest.class);
|
||||
|
||||
@Test
|
||||
public void shouldLoadScriptText() {
|
||||
ScriptEnvBuffer buffer = new ScriptEnvBuffer();
|
||||
Scenario scenario = Scenario.forTesting("testing", "stdout:300", new TestComponent());
|
||||
NBScenario scenario = NBScenario.forTesting("testing", "stdout:300", new TestComponent());
|
||||
scenario.addScriptText("print('loaded script environment...');\n");
|
||||
try {
|
||||
var result=scenario.call();
|
||||
@@ -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.
|
||||
@@ -23,7 +23,7 @@ import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ScenarioContextBufferTest {
|
||||
public class NBScenarioContextBufferTest {
|
||||
|
||||
@Test
|
||||
public void shouldCaptureLoggedOutput() throws IOException {
|
||||
@@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.engine.core.script;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.Scenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.NBScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.ScenariosExecutor;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.ScenariosResults;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@@ -29,7 +29,7 @@ public class ScenariosExecutorTest {
|
||||
@Disabled
|
||||
public void testAwaitOnTime() {
|
||||
ScenariosExecutor e = new ScenariosExecutor(ScenariosExecutorTest.class.getSimpleName(), 1);
|
||||
Scenario s = Scenario.forTesting("testing", "stdout:3000", new TestComponent());
|
||||
NBScenario s = NBScenario.forTesting("testing", "stdout:3000", new TestComponent());
|
||||
s.addScriptText("load('classpath:scripts/asyncs.js');\nsetTimeout(\"print('waited')\",5000);\n");
|
||||
e.execute(s);
|
||||
ScenariosResults scenariosResults = e.awaitAllResults();
|
||||
|
||||
@@ -19,37 +19,49 @@ package io.nosqlbench.api.config.standard;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class TestComponent extends NBBaseComponent {
|
||||
private final static Logger logger = LogManager.getLogger("RUNTIME");
|
||||
|
||||
public static final NBComponent INSTANCE = new TestComponent();
|
||||
|
||||
public TestComponent(String... labels) {
|
||||
super(null,NBLabels.forKV((Object[]) labels));
|
||||
// logger.trace("new component " + description());
|
||||
}
|
||||
|
||||
public TestComponent(NBComponent parent, String... labels) {
|
||||
super(parent, NBLabels.forKV((Object[]) labels));
|
||||
// logger.trace("new component " + description());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getLabels().linearizeAsMetrics() + " ("+this.getClass().getSimpleName()+")";
|
||||
return description();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBComponent attach(NBComponent... children) {
|
||||
System.out.println("attaching children:" +
|
||||
Arrays.stream(children).map(c -> c.getLabels().linearizeAsMetrics()).toList());
|
||||
return super.attach(children);
|
||||
public NBComponent attachChild(NBComponent... children) {
|
||||
for (NBComponent child : children) {
|
||||
// logger.debug("attaching " + child.description());
|
||||
super.attachChild(child);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBComponent detach(NBComponent... children) {
|
||||
System.out.println("detaching children:" +
|
||||
Arrays.stream(children).map(c -> c.getLabels().linearizeAsMetrics()).toList());
|
||||
return super.detach(children);
|
||||
public NBComponent detachChild(NBComponent... children) {
|
||||
for (NBComponent child : children) {
|
||||
// logger.debug("detaching " + child.description());
|
||||
super.detachChild(child);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeDetach() {
|
||||
// logger.debug("before detach " + description());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,9 @@ public class MapLabels implements NBLabels {
|
||||
|
||||
@Override
|
||||
public String linearizeAsMetrics() {
|
||||
if (labels.isEmpty()) {
|
||||
return "{}";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
ArrayList<String> keys = new ArrayList<>(this.labels.keySet());
|
||||
Collections.sort(keys);
|
||||
|
||||
@@ -31,11 +31,10 @@ public interface NBLabeledElement {
|
||||
}
|
||||
|
||||
NBLabels getLabels();
|
||||
|
||||
class BasicLabeledElement implements NBLabeledElement {
|
||||
private final NBLabels labels;
|
||||
public BasicLabeledElement(final String... kvs) {
|
||||
labels=NBLabels.forKV(kvs);
|
||||
labels=NBLabels.forKV((Object[]) kvs);
|
||||
}
|
||||
|
||||
public BasicLabeledElement(final Map<String, String> labels) {
|
||||
@@ -48,4 +47,9 @@ public interface NBLabeledElement {
|
||||
}
|
||||
}
|
||||
|
||||
default String description() {
|
||||
return this.getClass().getSimpleName() + " " + this.getLabels().linearizeAsMetrics();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,15 @@ package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class NBBaseComponent extends NBBaseComponentMetrics implements NBComponent {
|
||||
private final static Logger logger = LogManager.getLogger("RUNTIME");
|
||||
private final NBComponent parent;
|
||||
private final List<NBComponent> children = new ArrayList<>();
|
||||
private final NBLabels labels;
|
||||
@@ -36,7 +38,7 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone
|
||||
this.labels = componentSpecificLabelsOnly;
|
||||
if (parentComponent!=null) {
|
||||
parent = parentComponent;
|
||||
parent.attach(this);
|
||||
parent.attachChild(this);
|
||||
} else {
|
||||
parent=null;
|
||||
}
|
||||
@@ -47,14 +49,21 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBComponent attach(NBComponent... children) {
|
||||
this.children.addAll(Arrays.asList(children));
|
||||
public NBComponent attachChild(NBComponent... children) {
|
||||
for (NBComponent child : children) {
|
||||
logger.debug(() -> "attaching " + child.description() + " to parent " + this.description());
|
||||
this.children.add(child);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBComponent detach(NBComponent... children) {
|
||||
this.children.removeAll(Arrays.asList(children));
|
||||
public NBComponent detachChild(NBComponent... children) {
|
||||
for (NBComponent child : children) {
|
||||
logger.debug(() -> "detaching " + child.description() + " from " + this.description());
|
||||
this.children.remove(child);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -89,4 +98,9 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeDetach() {
|
||||
logger.debug("before detach " + description());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,11 @@ public interface NBComponent extends NBLabeledElement, NBComponentMetrics, NBMet
|
||||
|
||||
NBComponent getParent();
|
||||
|
||||
NBComponent attach(NBComponent... children);
|
||||
NBComponent attachChild(NBComponent... children);
|
||||
|
||||
NBComponent detach(NBComponent... children);
|
||||
NBComponent detachChild(NBComponent... children);
|
||||
|
||||
List<NBComponent> getChildren();
|
||||
|
||||
default void beforeDetach() {}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class NBComponentSubScope implements AutoCloseable {
|
||||
}
|
||||
@Override
|
||||
public void close() throws RuntimeException {
|
||||
component.getParent().detach(component);
|
||||
component.beforeDetach();
|
||||
component.getParent().detachChild(component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
* <P>Components are structured hierarchically. All components exist within the scope of their parent, with the only
|
||||
* exception being the root component, which has no parent. Components always know their parent from construction time.
|
||||
* After a component is constructed, it is informed of children components being added and removed via
|
||||
* {@link io.nosqlbench.components.NBComponent#attach} and {@link io.nosqlbench.components.NBComponent#detach}
|
||||
* {@link io.nosqlbench.components.NBComponent#attachChild} and {@link io.nosqlbench.components.NBComponent#detachChild}
|
||||
* methods.</P>
|
||||
*
|
||||
* <P>Component logic should interact with other components using the component interfaces and types. No contextual
|
||||
|
||||
@@ -17,9 +17,12 @@
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class NBComponentLifecycleTest {
|
||||
private final static Logger logger = LogManager.getLogger(NBComponentLifecycleTest.class);
|
||||
|
||||
@Test
|
||||
public void testBasicLifecycleHooks() {
|
||||
@@ -28,13 +31,13 @@ class NBComponentLifecycleTest {
|
||||
TestComponent node2 = new TestComponent(root, "node2", "node2");
|
||||
|
||||
try (NBComponentSubScope scope = new NBComponentSubScope(node1)) {
|
||||
System.out.println("node1 active");
|
||||
logger.info(node1.description() + " active");
|
||||
}
|
||||
try (NBComponentSubScope scope = new NBComponentSubScope(node2)) {
|
||||
System.out.println("node2 active");
|
||||
logger.info(node2.description() + " active");
|
||||
}
|
||||
|
||||
System.out.print("all inactive");
|
||||
logger.info("all inactive");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ class NBComponentViewsTest {
|
||||
|
||||
var root2 = new TestComponent("a", "b");
|
||||
|
||||
root2.attach(new TestComponent(root2, "c", "d")
|
||||
.attach(new TestComponent("U", "V"))
|
||||
.attach(new TestComponent("Y", "Z")))
|
||||
.attach(new TestComponent("e", "f"));
|
||||
root2.attachChild(new TestComponent(root2, "c", "d")
|
||||
.attachChild(new TestComponent("U", "V"))
|
||||
.attachChild(new TestComponent("Y", "Z")))
|
||||
.attachChild(new TestComponent("e", "f"));
|
||||
|
||||
System.out.println("root1:\n" + NBComponentViews.treeView(root1));
|
||||
System.out.println("root1:\n" + NBComponentViews.treeView(root1, c -> String.valueOf(c.hashCode())));
|
||||
|
||||
@@ -18,7 +18,7 @@ package io.nosqlbench.nbr.examples;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.Scenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.NBScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.ScenariosExecutor;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.ScenariosResults;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
@@ -56,7 +56,7 @@ public class ScriptExampleTests {
|
||||
String scenarioName = "scenario " + scriptname;
|
||||
System.out.println("=".repeat(29) + " Running integration test for example scenario: " + scenarioName);
|
||||
ScenariosExecutor executor = new ScenariosExecutor(ScriptExampleTests.class.getSimpleName() + ":" + scriptname, 1);
|
||||
Scenario s = Scenario.forTesting(scenarioName,"stdout:300", new TestComponent());
|
||||
NBScenario s = NBScenario.forTesting(scenarioName,"stdout:300", new TestComponent());
|
||||
|
||||
s.addScenarioScriptParams(paramsMap);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user