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