diff --git a/adapter-pulsar/src/main/java/io/nosqlbench/adapter/pulsar/util/PulsarAdapterMetrics.java b/adapter-pulsar/src/main/java/io/nosqlbench/adapter/pulsar/util/PulsarAdapterMetrics.java index c00b55a00..6f0257388 100644 --- a/adapter-pulsar/src/main/java/io/nosqlbench/adapter/pulsar/util/PulsarAdapterMetrics.java +++ b/adapter-pulsar/src/main/java/io/nosqlbench/adapter/pulsar/util/PulsarAdapterMetrics.java @@ -115,9 +115,9 @@ public class PulsarAdapterMetrics { // private static class ProducerGaugeImpl implements Gauge { private final Producer producer; - private final Function valueExtractor; + private final Function valueExtractor; - ProducerGaugeImpl(final Producer producer, final Function valueExtractor) { + ProducerGaugeImpl(final Producer producer, final Function valueExtractor) { this.producer = producer; this.valueExtractor = valueExtractor; } @@ -131,20 +131,20 @@ public class PulsarAdapterMetrics { } } } - private static Gauge producerSafeExtractMetric(final Producer producer, final Function valueExtractor) { + private static Gauge producerSafeExtractMetric(final Producer producer, final Function valueExtractor) { return new ProducerGaugeImpl(producer, valueExtractor); } public void registerProducerApiMetrics(final Producer producer) { ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "total_bytes_sent", - PulsarAdapterMetrics.producerSafeExtractMetric(producer, s -> s.getTotalBytesSent() + s.getNumBytesSent())); + PulsarAdapterMetrics.producerSafeExtractMetric(producer, s -> (double) s.getTotalBytesSent() + s.getNumBytesSent())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "total_msg_sent", - PulsarAdapterMetrics.producerSafeExtractMetric(producer, s -> s.getTotalMsgsSent() + s.getNumMsgsSent())); + PulsarAdapterMetrics.producerSafeExtractMetric(producer, s -> (double) s.getTotalMsgsSent() + s.getNumMsgsSent())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "total_send_failed", - PulsarAdapterMetrics.producerSafeExtractMetric(producer, s -> s.getTotalSendFailed() + s.getNumSendFailed())); + PulsarAdapterMetrics.producerSafeExtractMetric(producer, s -> (double) s.getTotalSendFailed() + s.getNumSendFailed())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "total_ack_received", - PulsarAdapterMetrics.producerSafeExtractMetric(producer, s -> s.getTotalAcksReceived() + s.getNumAcksReceived())); + PulsarAdapterMetrics.producerSafeExtractMetric(producer, s -> (double) s.getTotalAcksReceived() + s.getNumAcksReceived())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "send_bytes_rate", PulsarAdapterMetrics.producerSafeExtractMetric(producer, ProducerStats::getSendBytesRate)); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "send_msg_rate", @@ -158,9 +158,9 @@ public class PulsarAdapterMetrics { // private static class ConsumerGaugeImpl implements Gauge { private final Consumer consumer; - private final Function valueExtractor; + private final Function valueExtractor; - ConsumerGaugeImpl(final Consumer consumer, final Function valueExtractor) { + ConsumerGaugeImpl(final Consumer consumer, final Function valueExtractor) { this.consumer = consumer; this.valueExtractor = valueExtractor; } @@ -175,23 +175,23 @@ public class PulsarAdapterMetrics { } } } - static Gauge consumerSafeExtractMetric(final Consumer consumer, final Function valueExtractor) { + static Gauge consumerSafeExtractMetric(final Consumer consumer, final Function valueExtractor) { return new ConsumerGaugeImpl(consumer, valueExtractor); } public void registerConsumerApiMetrics(final Consumer consumer, final String pulsarApiMetricsPrefix) { ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "total_bytes_recv", - PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> s.getTotalBytesReceived() + s.getNumBytesReceived())); + PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> (double) s.getTotalBytesReceived() + s.getNumBytesReceived())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "total_msg_recv", - PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> s.getTotalMsgsReceived() + s.getNumMsgsReceived())); + PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> (double)s.getTotalMsgsReceived() + s.getNumMsgsReceived())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "total_recv_failed", - PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> s.getTotalReceivedFailed() + s.getNumReceiveFailed())); + PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> (double) s.getTotalReceivedFailed() + s.getNumReceiveFailed())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "total_acks_sent", - PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> s.getTotalAcksSent() + s.getNumAcksSent())); + PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> (double) s.getTotalAcksSent() + s.getNumAcksSent())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "recv_bytes_rate", - PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, ConsumerStats::getRateBytesReceived)); + PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> (double) s.getRateBytesReceived())); ActivityMetrics.gauge(this.pulsarBaseOpDispenser, "recv_msg_rate", - PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, ConsumerStats::getRateMsgsReceived)); + PulsarAdapterMetrics.consumerSafeExtractMetric(consumer, s -> (double) s.getRateMsgsReceived())); } } diff --git a/devdocs/sketches/scenario_invocation.d2 b/devdocs/sketches/scenario_invocation.d2 new file mode 100644 index 000000000..3cb94e030 --- /dev/null +++ b/devdocs/sketches/scenario_invocation.d2 @@ -0,0 +1,76 @@ +fixtures { +# grid-columns:3 + tooltip: Fixtures are the standard set of interfaces that a scenario invocation \ + needs to communicate with any other element or do anything at all. Fixtures are \ + stateful and disposable, i.e. do not reuse them more than once. + io { + label: IO Trace Buffers + tooltip: in the NBSceneBuffer variant of fixtures, IO streams are wrapped in a \ + tracing fixture which intercepts and records all IO in and out. This is done \ + opaquely to the scenario logic. +# grid-columns:1 + in <- tbuf.in + out -> tbuf.out + err -> tbuf.err + tbuf { + label: "Assigned IO Streams" + tooltip: Normal stdin stdout and stderr IO streams are provided for use by scripted \ + and compiled scenario logic. + # grid-columns:1 + in + out + err + } + } + APIs { + grid-columns:2 +# style.stroke-width: 0 + controller { + tooltip: The controller is an Activity Controller which enables \ + full control of activities, including defining, starting, stopping, \ + dynamic modification of parameters, blocking, etc. It is the controller \ + that is responsible for activity lifecycles. + } + params { + tooltip: Scenario parameters are given to the scenario log as part of the \ + fixtures. These can come from the command line or scripting environment. + } + component { + label: + tooltip: The component represents a node in a runtime hierarchy \ + to which all metrics and other fixtures are attached. Each scenario \ + runs within a component context, and all component APIs are exposed \ + directly within the execution context as services. + } + extensions { + tooltip: Extensions are bundled capabilities which can be pulled into \ + a scenario if and when needed. Contributors can build extensions \ + which provide additional services, and these can be loaded into either \ + scripted environments with duck-typing, or into compiled code with type \ + safety. They are also available to result verifier logic when appropriate. + } + } +} + + +logic { +} + +logic <- fixtures.io.in : reads +logic -> fixtures.io.out : writes +logic -> fixtures.io.err : writes + +system { +} + +fixtures.io.tbuf.in <- system : reads +fixtures.io.tbuf.out -> system : writes +fixtures.io.tbuf.err -> system : writes + + +#IO\nbuffers -. "embed" .-> fixtures +# params --> fixtures +# fixtures --> Scenario\ninstance +# Scenario\ninstance --> used\nfixtures +# used\nfixtures -. extract .-> IO\ntraces + diff --git a/devdocs/sketches/scenario_invocation.svg b/devdocs/sketches/scenario_invocation.svg new file mode 100644 index 000000000..2839b0a4a --- /dev/null +++ b/devdocs/sketches/scenario_invocation.svg @@ -0,0 +1,224 @@ +fixturesFixtures are the standard set of interfaces that a scenario invocation needs to communicate with any other element or do anything at all. Fixtures are stateful and disposable, i.e. do not reuse them more than once.logicsystemIO Trace Buffersin the NBSceneBuffer variant of fixtures, IO streams are wrapped in a tracing fixture which intercepts and records all IO in and out. This is done opaquely to the scenario logic.APIsinAssigned IO StreamsNormal stdin stdout and stderr IO streams are provided for use by scripted and compiled scenario logic.outerrcontrollerThe controller is an Activity Controller which enables full control of activities, including defining, starting, stopping, dynamic modification of parameters, blocking, etc. It is the controller that is responsible for activity lifecycles.paramsScenario parameters are given to the scenario log as part of the fixtures. These can come from the command line or scripting environment.<component>The component represents a node in a runtime hierarchy to which all metrics and other fixtures are attached. Each scenario runs within a component context, and all component APIs are exposed directly within the execution context as services.extensionsExtensions are bundled capabilities which can be pulled into a scenario if and when needed. Contributors can build extensions which provide additional services, and these can be loaded into either scripted environments with duck-typing, or into compiled code with type safety. They are also available to result verifier logic when appropriate.inouterr readswriteswritesreadswriteswritesFixtures are the standard set of interfaces that a scenario invocation needs to communicate with any other element or do anything at all. Fixtures are stateful and disposable, i.e. do not reuse them more than once. + + + + + + + + + + + + +in the NBSceneBuffer variant of fixtures, IO streams are wrapped in a tracing fixture which intercepts and records all IO in and out. This is done opaquely to the scenario logic. + + + + + + + + + + + + +Normal stdin stdout and stderr IO streams are provided for use by scripted and compiled scenario logic. + + + + + + + + + + + + +The controller is an Activity Controller which enables full control of activities, including defining, starting, stopping, dynamic modification of parameters, blocking, etc. It is the controller that is responsible for activity lifecycles. + + + + + + + + + + + + +Scenario parameters are given to the scenario log as part of the fixtures. These can come from the command line or scripting environment. + + + + + + + + + + + + +The component represents a node in a runtime hierarchy to which all metrics and other fixtures are attached. Each scenario runs within a component context, and all component APIs are exposed directly within the execution context as services. + + + + + + + + + + + + +Extensions are bundled capabilities which can be pulled into a scenario if and when needed. Contributors can build extensions which provide additional services, and these can be loaded into either scripted environments with duck-typing, or into compiled code with type safety. They are also available to result verifier logic when appropriate. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/devdocs/sketches/scenario_invocation2.d2 b/devdocs/sketches/scenario_invocation2.d2 new file mode 100644 index 000000000..6ddcc1c6a --- /dev/null +++ b/devdocs/sketches/scenario_invocation2.d2 @@ -0,0 +1,9 @@ + +direction: right + +fixtures { + params + buffers +} +fixtures --> scenario --> result + diff --git a/devdocs/sketches/scenario_invocation2.svg b/devdocs/sketches/scenario_invocation2.svg new file mode 100644 index 000000000..e88cd26d1 --- /dev/null +++ b/devdocs/sketches/scenario_invocation2.svg @@ -0,0 +1,106 @@ +fixturesscenarioresultparamsbuffers + + + + + + + diff --git a/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/core/ComponentActivityInstrumentation.java b/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/core/ComponentActivityInstrumentation.java index 7960556d3..d5ae1d02c 100644 --- a/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/core/ComponentActivityInstrumentation.java +++ b/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/core/ComponentActivityInstrumentation.java @@ -27,8 +27,6 @@ import io.nosqlbench.api.engine.metrics.instruments.NBMetricTimer; public class ComponentActivityInstrumentation implements ActivityInstrumentation { - private static final String STRICTMETRICNAMES = "strictmetricnames"; - private static final String WAIT_TIME = "_waittime"; private static final String SERVICE_TIME = "_servicetime"; private static final String RESPONSE_TIME = "_responsetime"; diff --git a/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/ratelimits/HybridRateLimiter.java b/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/ratelimits/HybridRateLimiter.java index 4cae4f528..fc2ac5ce0 100644 --- a/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/ratelimits/HybridRateLimiter.java +++ b/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/ratelimits/HybridRateLimiter.java @@ -91,7 +91,7 @@ public class HybridRateLimiter implements RateLimiter { private String label; private State state = State.Idle; // metrics - private Gauge delayGauge; + private Gauge delayGauge; private Gauge avgRateGauge; private Gauge burstRateGauge; private TokenPool tokens; diff --git a/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/ratelimits/RateLimiters.java b/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/ratelimits/RateLimiters.java index 61988cd5c..1fb1df2d3 100644 --- a/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/ratelimits/RateLimiters.java +++ b/engine-api/src/main/java/io/nosqlbench/engine/api/activityapi/ratelimits/RateLimiters.java @@ -42,7 +42,7 @@ public enum RateLimiters { return RateLimiters.createOrUpdate(def, label, null, new RateSpec(specString)); } - public static class WaitTimeGauge implements Gauge { + public static class WaitTimeGauge implements Gauge { private final RateLimiter rateLimiter; @@ -51,8 +51,8 @@ public enum RateLimiters { } @Override - public Long getValue() { - return this.rateLimiter.getTotalWaitTime(); + public Double getValue() { + return (double)this.rateLimiter.getTotalWaitTime(); } } diff --git a/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLI.java b/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLI.java index 16a1aeba9..7dd04f7fe 100644 --- a/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLI.java +++ b/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLI.java @@ -404,6 +404,11 @@ public class NBCLI implements Function, NBLabeledElement { final LoggerConfigData classicConfigs : options.getClassicHistoConfigs()) ActivityMetrics.addClassicHistos(sessionName, classicConfigs.pattern, classicConfigs.file, classicConfigs.interval); + if (options.getConsoleLogLevel().isGreaterOrEqualTo(NBLogLevel.WARN)) { + options.setWantsStackTraces(true); + NBCLI.logger.debug(() -> "enabling stack traces since log level is " + options.getConsoleLogLevel()); + } + // client machine metrics; TODO: modify pollInterval this.clientMetricChecker = new ClientSystemMetricChecker(10); registerLoadAvgMetrics(); @@ -416,24 +421,13 @@ public class NBCLI implements Function, NBLabeledElement { // intentionally not shown for warn-only NBCLI.logger.info(() -> "console logging level is " + options.getConsoleLogLevel()); - final ScenariosExecutor scenariosExecutor = new ScenariosExecutor("executor-" + sessionName, 1); - if (options.getConsoleLogLevel().isGreaterOrEqualTo(NBLogLevel.WARN)) { - options.setWantsStackTraces(true); - NBCLI.logger.debug(() -> "enabling stack traces since log level is " + options.getConsoleLogLevel()); - } - - // intentionally not shown for warn-only - NBCLI.logger.info(() -> "console logging level is " + options.getConsoleLogLevel()); - /** * At this point, the command stream from the CLI should be handed into the session, and the session should * marshal and transform it for any scenario invocations directly. */ NBSession session = new NBSession( new NBBaseComponent(null), - sessionName, - options.getProgressSpec(), - options.wantsShowScript() + sessionName ); ExecutionResult sessionResult = session.apply(options.getCommands()); sessionResult.printSummary(System.out); diff --git a/engine-core/src/main/java/io/nosqlbench/engine/cli/BasicScriptBuffer.java b/engine-core/src/main/java/io/nosqlbench/engine/cli/BasicScriptBuffer.java index f9d6e49c6..4e7354e29 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/cli/BasicScriptBuffer.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/cli/BasicScriptBuffer.java @@ -68,6 +68,7 @@ public class BasicScriptBuffer implements ScriptBuffer { sb.append("\n"); } break; + case java: case start: // start activity case run: // run activity case await: // await activity diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/activity/ActivityExecutor.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/activity/ActivityExecutor.java index 833b026e4..b41d4cc2d 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/activity/ActivityExecutor.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/activity/ActivityExecutor.java @@ -146,7 +146,7 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P activitylogger.debug("FORCE STOP/before alias=(" + activity.getAlias() + ")"); activity.setRunState(RunState.Stopped); - executorService.shutdown(); + executorService.shutdownNow(); requestStopMotors(); int divisor = 100; @@ -401,7 +401,6 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P shutdownHook = new ActivityExecutorShutdownHook(this); Runtime.getRuntime().addShutdownHook(shutdownHook); - long startAt = System.currentTimeMillis(); Annotators.recordAnnotation(Annotation.newBuilder() .element(this) diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/activity/ActivityLoader.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/activity/ActivityLoader.java index b4fe0fa69..bb386d81c 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/activity/ActivityLoader.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/activity/ActivityLoader.java @@ -40,7 +40,7 @@ public class ActivityLoader { public synchronized Activity loadActivity(ActivityDef activityDef, final NBComponent parent) { activityDef= activityDef.deprecate("yaml","workload").deprecate("type","driver"); - final Activity activity = new StandardActivityType(activityDef, parent).getAssembledActivity(activityDef, this.activityMap, parent); + final Activity activity = new StandardActivityType<>(activityDef, parent).getAssembledActivity(activityDef, this.activityMap, parent); this.activityMap.put(activity.getAlias(),activity); ActivityLoader.logger.debug("Resolved activity for alias '{}'", activityDef.getAlias()); return activity; diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/ActivitiesController.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/ActivitiesController.java index fdbcd290c..ccbd049f2 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/ActivitiesController.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/ActivitiesController.java @@ -325,7 +325,7 @@ public class ActivitiesController extends NBBaseComponent { */ public synchronized void forceStopScenario(int waitTimeMillis, boolean rethrow) { logger.debug("force stopping scenario {}", description()); - activityInfoMap.values().forEach(a -> a.getActivityExecutor().forceStopActivity(10000)); + activityInfoMap.values().forEach(a -> a.getActivityExecutor().forceStopActivity(2000)); logger.debug("Scenario force stopped."); } @@ -451,19 +451,19 @@ public class ActivitiesController extends NBBaseComponent { public void shutdown() { logger.debug(() -> "Requesting ScenarioController shutdown."); - this.activitiesExecutor.shutdown(); - try { - if (!this.activitiesExecutor.awaitTermination(5, TimeUnit.SECONDS)) { - logger.info(() -> "Scenario is being forced to shutdown after waiting 5 seconds for graceful shutdown."); - this.activitiesExecutor.shutdownNow(); - if (!this.activitiesExecutor.awaitTermination(5, TimeUnit.SECONDS)) { - throw new RuntimeException("Unable to shutdown activities executor"); - } - } - } catch (Exception e) { - logger.warn("There was an exception while trying to shutdown the ScenarioController:{}", e, e); - throw new RuntimeException(e); - } + this.activitiesExecutor.shutdownNow(); +// try { +// if (!this.activitiesExecutor.awaitTermination(5, TimeUnit.SECONDS)) { +// logger.info(() -> "Scenario is being forced to shutdown after waiting 5 seconds for graceful shutdown."); +// this.activitiesExecutor.shutdownNow(); +// if (!this.activitiesExecutor.awaitTermination(5, TimeUnit.SECONDS)) { +// logger.warn("Unable to shutdown activities executor gracefully"); +// } +// } +// } catch (Exception e) { +// logger.warn("There was an exception while trying to shutdown the ScenarioController:{}", e, e); +// throw new RuntimeException(e); +// } } } diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBDefaultSceneFixtures.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBDefaultSceneFixtures.java index 4db63209e..03ee2a782 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBDefaultSceneFixtures.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBDefaultSceneFixtures.java @@ -78,11 +78,11 @@ public class NBDefaultSceneFixtures implements NBSceneFixtures { this.in = in; } - public static NBSceneFixtures ofDefault() { + public static NBSceneFixtures ofDefault(String name) { return new NBDefaultSceneFixtures( new ScriptParams(), new NBSession( - new TestComponent("test", "test"), "test", "console:10s", false + new TestComponent("scene", name), "scene~"+name ), new ActivitiesController(), Extensions.ofNone(), @@ -98,7 +98,7 @@ public class NBDefaultSceneFixtures implements NBSceneFixtures { } @Override - public NBComponent session() { + public NBComponent component() { return session; } diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBSceneBuffer.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBSceneBuffer.java index 5c1ab5bac..92889db5c 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBSceneBuffer.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBSceneBuffer.java @@ -16,6 +16,7 @@ package io.nosqlbench.engine.core.lifecycle.scenario.context; +import io.nosqlbench.api.config.standard.TestComponent; import io.nosqlbench.components.NBComponent; import io.nosqlbench.engine.api.scripting.DiagReader; import io.nosqlbench.engine.api.scripting.DiagWriter; @@ -23,7 +24,6 @@ import io.nosqlbench.engine.core.lifecycle.scenario.execution.Extensions; import java.io.PrintWriter; import java.io.Reader; -import java.io.Writer; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -42,15 +42,14 @@ public class NBSceneBuffer implements NBSceneFixtures { stdinBuffer = new DiagReader(fixtures.in(), " stdin "); } - @Override public ScriptParams params() { return fixtures.params(); } @Override - public NBComponent session() { - return fixtures.session(); + public NBComponent component() { + return fixtures.component(); } @Override @@ -69,7 +68,7 @@ public class NBSceneBuffer implements NBSceneFixtures { } @Override - public Writer err() { + public PrintWriter err() { return stderrBuffer; } @@ -87,9 +86,16 @@ public class NBSceneBuffer implements NBSceneFixtures { return log; } - public String getIoLog() { + public String getIOLog() { return String.join("",getTimedLogLines()); } + public NBSceneFixtures asFixtures() { + return (NBSceneFixtures) this; + } + public static NBSceneBuffer init(String name) { + TestComponent root = new TestComponent("scene", "self"); + return new NBSceneBuffer(NBDefaultSceneFixtures.ofDefault(name)); + } } diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBSceneFixtures.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBSceneFixtures.java index 27d6e4b8b..4338bcca8 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBSceneFixtures.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/context/NBSceneFixtures.java @@ -21,12 +21,11 @@ import io.nosqlbench.engine.core.lifecycle.scenario.execution.Extensions; import java.io.PrintWriter; import java.io.Reader; -import java.io.Writer; public interface NBSceneFixtures { ScriptParams params(); - NBComponent session(); + NBComponent component(); ActivitiesController controller(); @@ -34,8 +33,12 @@ public interface NBSceneFixtures { PrintWriter out(); - Writer err(); + PrintWriter err(); Reader in(); + public static NBSceneFixtures NEW(String sceneName) { + return NBDefaultSceneFixtures.ofDefault(sceneName); + } + } diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/direct/NBBaseScenario.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/direct/NBBaseScenario.java index 6e454ac5a..4e4aa558a 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/direct/NBBaseScenario.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/direct/NBBaseScenario.java @@ -25,7 +25,7 @@ import java.util.Map; public abstract class NBBaseScenario extends NBScenario { public NBBaseScenario(NBComponent parentComponent, String scenarioName, Map params, String progressInterval) { - super(parentComponent, scenarioName, params, progressInterval); + super(parentComponent, scenarioName); } @Override diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/NBScenario.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/NBScenario.java index 1872c5b90..dd5fa4103 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/NBScenario.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/NBScenario.java @@ -18,6 +18,7 @@ package io.nosqlbench.engine.core.lifecycle.scenario.execution; import io.nosqlbench.api.annotations.Annotation; import io.nosqlbench.api.annotations.Layer; +import io.nosqlbench.api.labels.NBLabels; import io.nosqlbench.api.metadata.ScenarioMetadata; import io.nosqlbench.api.metadata.SystemId; import io.nosqlbench.components.NBBaseComponent; @@ -26,12 +27,12 @@ import io.nosqlbench.components.NBComponentErrorHandler; import io.nosqlbench.engine.core.annotation.Annotators; import io.nosqlbench.engine.core.lifecycle.activity.ActivitiesProgressIndicator; import io.nosqlbench.engine.core.lifecycle.scenario.context.ActivitiesController; +import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneBuffer; import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures; import io.nosqlbench.engine.core.lifecycle.scenario.script.NBScriptedScenario; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.Map; import java.util.function.Function; /** @@ -44,10 +45,9 @@ import java.util.function.Function; * */ public abstract class NBScenario extends NBBaseComponent - implements Function, NBComponentErrorHandler { - - private final String scenarioName; - private final Map params; + implements + Function, + NBComponentErrorHandler { protected Logger logger = LogManager.getLogger("SCENARIO"); private long startedAtMillis, endedAtMillis; @@ -56,34 +56,24 @@ public abstract class NBScenario extends NBBaseComponent private ActivitiesController activitiesController; private Exception error; - private String progressInterval; + private String progressInterval = "console:10s"; private ActivitiesProgressIndicator activitiesProgressIndicator; - public NBScenario( - NBComponent parentComponent, - String scenarioName, - Map params, - String progressInterval - ) { - super(parentComponent); - this.scenarioName = scenarioName; - this.params = params; - this.progressInterval = progressInterval; - this.activitiesController = new ActivitiesController(); - + public NBScenario(NBComponent parentComponent, String scenarioName) { + super(parentComponent, NBLabels.forKV("scenario",scenarioName)); } public String getScenarioName() { - return scenarioName; + return getLabels().asMap().get("scenario"); } public void forceStopScenario(int i, boolean b) { activitiesController.forceStopScenario(i,b); } - public Map getParams() { - return this.params; - } +// public Map getParams() { +// return this.params; +// } public ActivitiesController getActivitiesController() { return this.activitiesController; @@ -120,7 +110,8 @@ public abstract class NBScenario extends NBBaseComponent * @return */ @Override - public final ScenarioResult apply(NBSceneFixtures sctx) { + public final ScenarioResult apply(NBSceneBuffer sctx) { + this.activitiesController=sctx.controller(); this.scenarioShutdownHook = new ScenarioShutdownHook(this); Runtime.getRuntime().addShutdownHook(this.scenarioShutdownHook); @@ -135,18 +126,18 @@ public abstract class NBScenario extends NBBaseComponent .build() ); - if (!"disabled".equals(progressInterval)) + if (!"disabled".equals(progressInterval) && progressInterval!=null && !progressInterval.isEmpty()) this.activitiesProgressIndicator = new ActivitiesProgressIndicator(activitiesController, this.progressInterval); ScenarioResult result = null; try { - runScenario(sctx); + runScenario(sctx.asFixtures()); final long awaitCompletionTime = 86400 * 365 * 1000L; this.logger.debug("Awaiting completion of scenario and activities for {} millis.", awaitCompletionTime); this.activitiesController.awaitCompletion(awaitCompletionTime); } catch (Exception e) { try { - activitiesController.forceStopScenario(5000, false); + activitiesController.forceStopScenario(3000, false); } catch (final Exception eInner) { this.logger.debug("Found inner exception while forcing stop with rethrow=false: {}", eInner); throw new RuntimeException(e); @@ -156,9 +147,9 @@ public abstract class NBScenario extends NBBaseComponent this.activitiesController.shutdown(); this.endedAtMillis = System.currentTimeMillis(); result = new ScenarioResult( + sctx, startedAtMillis, endedAtMillis, - (error != null) ? error.toString() : "", error ); } @@ -212,11 +203,15 @@ public abstract class NBScenario extends NBBaseComponent private synchronized ScenarioMetadata getScenarioMetadata() { if (null == this.scenarioMetadata) scenarioMetadata = new ScenarioMetadata( startedAtMillis, - scenarioName, + getScenarioName(), SystemId.getNodeId(), SystemId.getNodeFingerprint() ); return this.scenarioMetadata; } + @Override + public String toString() { + return "SCENARIO (" + this.getClass().getSuperclass().getSimpleName()+") { scenarioName: "+getScenarioName()+" }"; + } } diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/ScenarioResult.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/ScenarioResult.java index d6026dcff..aab3bafa4 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/ScenarioResult.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/ScenarioResult.java @@ -18,42 +18,39 @@ package io.nosqlbench.engine.core.lifecycle.scenario.execution; import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneBuffer; -public class ScenarioResult { +public class ScenarioResult extends NBSceneBuffer { private final long startedAt; private final long endedAt; - private final String iolog; - private final Exception error; - - public ScenarioResult(long startedAt, long endedAt, String iolog, Exception error) { - this.startedAt = startedAt; - this.endedAt = endedAt; - this.iolog = iolog; - this.error = error; - } - - public ScenarioResult(ScenarioResult baseResult, NBSceneBuffer bufferedContext) { - this.startedAt = baseResult.startedAt; - this.endedAt = baseResult.endedAt; - String log = bufferedContext.getIoLog(); - this.error = baseResult.error; - if (this.error!=null) { - log+=error.getMessage(); - } - this.iolog = log; + private final Exception exception; + public ScenarioResult(NBSceneBuffer fixtures, long start, long end, Exception exception) { + super(fixtures); + this.startedAt=start; + this.endedAt=end; + this.exception =exception; } public Exception getException() { - return error; + return this.exception; } - public String getIOLog() { - return iolog; + public static ScenarioResult ofError(Exception e, long now) { + return new ScenarioResult(NBSceneBuffer.init("error"),now,now,e); } - @Override - public String toString() { - return ((error!=null)? "ERROR:" + error.toString() : "") + - getIOLog(); + public void report() { + System.out.println(getIOLog()); + if (exception!=null) { + if (exception instanceof RuntimeException rte) { + throw rte; + } else { + throw new RuntimeException(exception); + } + } + } + public void exitWithCode() { + if (exception!=null) { + System.exit(2); + } } } diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/ScenariosExecutor.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/ScenariosExecutor.java index d17e4a4ac..1643ad403 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/ScenariosExecutor.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/execution/ScenariosExecutor.java @@ -55,12 +55,15 @@ public class ScenariosExecutor extends NBBaseComponent { } public synchronized void execute(NBScenario scenario) { + execute(scenario,new ScriptParams()); + } + public synchronized void execute(NBScenario scenario, Map params) { if (submitted.get(scenario.getScenarioName()) != null) { throw new BasicError("Scenario " + scenario.getScenarioName() + " is already defined. Remove it first to reuse the name."); } NBSceneFixtures basecontext = new NBDefaultSceneFixtures( - ScriptParams.of(scenario.getParams()), + ScriptParams.of(params), this.getParent(), scenario.getActivitiesController(), loadExtensions(), @@ -71,7 +74,7 @@ public class ScenariosExecutor extends NBBaseComponent { NBSceneBuffer bufferedContext = new NBSceneBuffer(basecontext); Future future = executor.submit( - () -> new ScenarioResult(scenario.apply(bufferedContext),bufferedContext) // combine basic execution data with trace + () -> scenario.apply(bufferedContext) // combine basic execution data with trace ); SubmittedScenario s = new SubmittedScenario(scenario, future); submitted.put(s.getName(), s); @@ -177,7 +180,7 @@ public class ScenariosExecutor extends NBBaseComponent { } catch (Exception e) { long now = System.currentTimeMillis(); logger.debug("creating exceptional scenario result from getAsyncResultStatus"); - oResult = Optional.of(new ScenarioResult(now, now, "errored output" + e.getMessage(), e)); + oResult = Optional.of(ScenarioResult.ofError(e, now)); } } diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/script/NBScriptedScenario.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/script/NBScriptedScenario.java index 965c2c406..464e29754 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/script/NBScriptedScenario.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/scenario/script/NBScriptedScenario.java @@ -25,6 +25,7 @@ import io.nosqlbench.engine.core.lifecycle.activity.ActivitiesProgressIndicator; import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures; import io.nosqlbench.engine.core.lifecycle.scenario.context.ScriptParams; import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario; +import io.nosqlbench.engine.core.lifecycle.scenario.script.bindings.PolyglotScenarioController; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Engine.Builder; import org.graalvm.polyglot.EnvironmentAccess; @@ -33,6 +34,7 @@ import org.graalvm.polyglot.PolyglotAccess; import javax.script.Compilable; import javax.script.CompiledScript; +import javax.script.ScriptContext; import javax.script.ScriptEngine; import java.io.IOException; import java.nio.ByteBuffer; @@ -44,7 +46,7 @@ import java.nio.file.Paths; import java.util.*; public class NBScriptedScenario extends NBScenario { - private final Invocation invocation; + private final Invocation invocation = Invocation.EXECUTE_SCRIPT; private Exception error; @@ -79,20 +81,16 @@ public class NBScriptedScenario extends NBScenario { public NBScriptedScenario( final String scenarioName, - final String progressInterval, - Map params, - NBComponent parentComponent, - Invocation invocation + NBComponent parentComponent ) { - super(parentComponent, scenarioName, params, progressInterval); + super(parentComponent, scenarioName); this.scenarioName = scenarioName; this.progressInterval = progressInterval; this.parentComponent = parentComponent; - this.invocation = invocation; } public static NBScriptedScenario ofScripted(String name, Map params, NBComponent parent, Invocation invocation) { - return new NBScriptedScenario(name, "console:10s",params,parent,invocation); + return new NBScriptedScenario(name, parent); }; @@ -122,6 +120,7 @@ public class NBScriptedScenario extends NBScenario { private void initializeScriptContext(NBSceneFixtures fixtures) { BufferedScriptContext ctx = new BufferedScriptContext(fixtures); this.scriptEngine.setContext(ctx); + ctx.getBindings(ScriptContext.ENGINE_SCOPE).put("scenario",new PolyglotScenarioController(fixtures.controller())); } private void initializeScriptingEngine() { @@ -248,15 +247,15 @@ public class NBScriptedScenario extends NBScenario { return "name:'" + scenarioName + '\''; } - public void addScenarioScriptParams(final ScriptParams scenarioScriptParams) { - this.scenarioScriptParams = scenarioScriptParams; - } +// public void addScenarioScriptParams(final ScriptParams scenarioScriptParams) { +// this.scenarioScriptParams = scenarioScriptParams; +// } - public void addScenarioScriptParams(final Map scriptParams) { - this.addScenarioScriptParams(new ScriptParams() {{ - this.putAll(scriptParams); - }}); - } +// public void addScenarioScriptParams(final Map scriptParams) { +// this.addScenarioScriptParams(new ScriptParams() {{ +// this.putAll(scriptParams); +// }}); +// } } diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/session/CmdParamsBuffer.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/session/CmdParamsBuffer.java new file mode 100644 index 000000000..6d44753fb --- /dev/null +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/session/CmdParamsBuffer.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.engine.core.lifecycle.session; + +import io.nosqlbench.engine.cli.Cmd; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.*; + +public class CmdParamsBuffer { + private final Logger logger = LogManager.getLogger(CmdParamsBuffer.class); + private List cmds = new ArrayList<>(); + + public CmdParamsBuffer() {} + public CmdParamsBuffer(List cmds) { + this.cmds.addAll(cmds); + } + + public void add(Cmd... cmd) { + this.cmds.addAll(Arrays.asList(cmd)); + } + + public Map getGlobalParams() { + Map params = new LinkedHashMap<>(); + for (Cmd cmd : cmds) { + switch (cmd.getCmdType()) { + case script: + case fragment: + case java: + combineGlobalParams(params,cmd); + break; + default: + } + } + + return params; + } + + /** + * Merge the params from the command into the global params map, but ensure that users know + * if they are overwriting values, which could cause difficult to find bugs in their scripts. + * + * @param scriptParams The existing global params map + * @param cmd The command containing the new params to merge in + */ + private void combineGlobalParams(Map scriptParams, Cmd cmd) { + for (String newkey : cmd.getParams().keySet()) { + String newvalue = cmd.getParams().get(newkey); + + if (scriptParams.containsKey(newkey)) { + logger.warn("command '" + cmd.getCmdType() + "' overwrote param '" + newkey + " as " + newvalue); + } + scriptParams.put(newkey, newvalue); + } + } + +} diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/session/NBSession.java b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/session/NBSession.java index 25763429f..0c5f76971 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/session/NBSession.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/lifecycle/session/NBSession.java @@ -17,7 +17,9 @@ package io.nosqlbench.engine.core.lifecycle.session; import io.nosqlbench.api.labels.NBLabeledElement; +import io.nosqlbench.api.spi.SimpleServiceLoader; import io.nosqlbench.components.NBBaseComponent; +import io.nosqlbench.components.NBComponent; import io.nosqlbench.components.NBComponentSubScope; import io.nosqlbench.engine.cli.BasicScriptBuffer; import io.nosqlbench.engine.cli.Cmd; @@ -29,10 +31,14 @@ import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario; import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosExecutor; import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosResults; import io.nosqlbench.engine.core.lifecycle.scenario.script.NBScriptedScenario; +import io.nosqlbench.nb.annotations.Maturity; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.List; +import java.util.Map; import java.util.function.Function; /** @@ -44,8 +50,6 @@ import java.util.function.Function; public class NBSession extends NBBaseComponent implements Function, ExecutionResult> { private final static Logger logger = LogManager.getLogger(NBSession.class); private final String sessionName; - private final String progressSpec; - private final boolean wantsDryRun; public enum STATUS { OK, @@ -55,14 +59,10 @@ public class NBSession extends NBBaseComponent implements Function, Ex public NBSession( NBLabeledElement labelContext, - String sessionName, - String progressSpec, - boolean wantsDryRun + String sessionName ) { super(null, labelContext.getLabels().and("session", sessionName)); this.sessionName = sessionName; - this.progressSpec = progressSpec; - this.wantsDryRun = wantsDryRun; } public ExecutionResult apply(List cmds) { @@ -71,6 +71,8 @@ public class NBSession extends NBBaseComponent implements Function, Ex logger.info("No commands provided."); } + Map params = new CmdParamsBuffer(cmds).getGlobalParams(); + ResultCollector collector = new ResultCollector(); try (ResultContext results = new ResultContext(collector)) { @@ -78,13 +80,13 @@ public class NBSession extends NBBaseComponent implements Function, Ex NBScenario scenario; if (cmds.get(0).getCmdType().equals(Cmd.CmdType.java)) { - scenario = buildJavaScenario(cmds, wantsDryRun); + scenario = buildJavaScenario(cmds); } else { - scenario = buildJavacriptScenario(cmds, wantsDryRun); + scenario = buildJavacriptScenario(cmds); } try (NBComponentSubScope scope = new NBComponentSubScope(scenario)) { assert scenario != null; - scenariosExecutor.execute(scenario); + scenariosExecutor.execute(scenario,params); // this.doReportSummaries(this.reportSummaryTo, this.result); } @@ -106,16 +108,18 @@ public class NBSession extends NBBaseComponent implements Function, Ex } results.output(scenariosResults.getExecutionSummary()); + results.ok(); } return collector.toExecutionResult(); } - private NBScenario buildJavacriptScenario(List cmds, boolean dryrun) { - NBScriptedScenario.Invocation invocation = dryrun ? - NBScriptedScenario.Invocation.RENDER_SCRIPT : - NBScriptedScenario.Invocation.EXECUTE_SCRIPT; + private NBScenario buildJavacriptScenario(List cmds) { +// boolean dryrun; +// NBScriptedScenario.Invocation invocation = dryrun ? +// NBScriptedScenario.Invocation.RENDER_SCRIPT : +// NBScriptedScenario.Invocation.EXECUTE_SCRIPT; final ScriptBuffer buffer = new BasicScriptBuffer().add(cmds.toArray(new Cmd[0])); final String scriptData = buffer.getParsedScript(); @@ -123,21 +127,35 @@ public class NBSession extends NBBaseComponent implements Function, Ex final ScriptParams scriptParams = new ScriptParams(); scriptParams.putAll(buffer.getCombinedParams()); - final NBScriptedScenario scenario = new NBScriptedScenario( - sessionName, - progressSpec, - scriptParams, - this, - invocation - ); + final NBScriptedScenario scenario = new NBScriptedScenario(sessionName, this); scenario.addScriptText(scriptData); - scenario.addScenarioScriptParams(scriptParams); return scenario; } - private NBScenario buildJavaScenario(List cmds, boolean dryrun) { - return null; + private NBScenario buildJavaScenario(List cmds) { + if (cmds.size()!=1) { + throw new RuntimeException("java scenarios require exactly 1 java command"); + } + Cmd javacmd = cmds.get(0); + String mainClass = javacmd.getArg("main_class"); + SimpleServiceLoader loader = new SimpleServiceLoader<>(NBScenario.class, Maturity.Any); + List> namedProviders = loader.getNamedProviders(mainClass); + SimpleServiceLoader.Component provider = namedProviders.get(0); + Class type = provider.provider.type(); + try { + Constructor constructor = type.getConstructor(NBComponent.class, String.class); + NBScenario scenario = constructor.newInstance(this, sessionName); + return scenario; + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } } } diff --git a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/ActivityMetrics.java b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/ActivityMetrics.java index cddce51cc..f4c3d8477 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/ActivityMetrics.java +++ b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/ActivityMetrics.java @@ -268,14 +268,14 @@ public class ActivityMetrics { public static NBMetricGauge gauge(NBMetricGauge gauge) { final NBLabels labels = gauge.getLabels(); - return (NBMetricGauge) register(labels, () -> new NBMetricGaugeWrapper<>(labels, gauge)); + return (NBMetricGauge) register(labels, () -> new NBMetricGaugeWrapper(labels, gauge)); } @SuppressWarnings("unchecked") - public static Gauge gauge(NBLabeledElement parent, String metricFamilyName, Gauge gauge) { + public static Gauge gauge(NBLabeledElement parent, String metricFamilyName, Gauge gauge) { final NBLabels labels = parent.getLabels().and("name", sanitize(metricFamilyName)); - return (Gauge) register(labels, () -> new NBMetricGaugeWrapper<>(labels, gauge)); + return (Gauge) register(labels, () -> new NBMetricGaugeWrapper(labels, gauge)); } private static MetricRegistry lookupRegistry() { diff --git a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/DoubleSummaryGauge.java b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/DoubleSummaryGauge.java index 4ca527693..8f062a476 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/DoubleSummaryGauge.java +++ b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/DoubleSummaryGauge.java @@ -26,7 +26,7 @@ import java.util.function.DoubleConsumer; /** * Create a discrete stat reservoir as a gauge. */ -public class DoubleSummaryGauge implements NBMetricGauge, DoubleConsumer { +public class DoubleSummaryGauge implements NBMetricGauge, DoubleConsumer { private final NBLabels labels; private final Stat stat; private final DoubleSummaryStatistics stats; diff --git a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBFunctionGauge.java b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBFunctionGauge.java index 6db691daa..d7908a264 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBFunctionGauge.java +++ b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBFunctionGauge.java @@ -23,7 +23,7 @@ import io.nosqlbench.components.NBComponent; import java.util.Map; import java.util.function.Supplier; -public class NBFunctionGauge implements NBMetricGauge { +public class NBFunctionGauge implements NBMetricGauge { private final Supplier source; private final NBLabeledElement parent; diff --git a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBMetricGauge.java b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBMetricGauge.java index bff4072a9..b4aff9cc3 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBMetricGauge.java +++ b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBMetricGauge.java @@ -18,6 +18,6 @@ package io.nosqlbench.api.engine.metrics.instruments; import com.codahale.metrics.Gauge; -public interface NBMetricGauge extends Gauge, NBMetric { +public interface NBMetricGauge extends Gauge, NBMetric { } diff --git a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBMetricGaugeWrapper.java b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBMetricGaugeWrapper.java index 56bce54ed..6f45b0ebb 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBMetricGaugeWrapper.java +++ b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/instruments/NBMetricGaugeWrapper.java @@ -19,18 +19,18 @@ package io.nosqlbench.api.engine.metrics.instruments; import com.codahale.metrics.Gauge; import io.nosqlbench.api.labels.NBLabels; -public class NBMetricGaugeWrapper implements NBMetricGauge, NBMetric { +public class NBMetricGaugeWrapper implements NBMetricGauge, NBMetric { - private final Gauge gauge; + private final Gauge gauge; private final NBLabels labels; - public NBMetricGaugeWrapper(NBLabels labels, Gauge gauge) { + public NBMetricGaugeWrapper(NBLabels labels, Gauge gauge) { this.gauge = gauge; this.labels = labels; } @Override - public T getValue() { + public Double getValue() { return gauge.getValue(); } diff --git a/nb-api/src/main/java/io/nosqlbench/components/NBBaseComponent.java b/nb-api/src/main/java/io/nosqlbench/components/NBBaseComponent.java index 8758d477b..e3954381c 100644 --- a/nb-api/src/main/java/io/nosqlbench/components/NBBaseComponent.java +++ b/nb-api/src/main/java/io/nosqlbench/components/NBBaseComponent.java @@ -32,17 +32,19 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone private final NBLabels labels; public NBBaseComponent(NBComponent parentComponent) { - this(parentComponent,NBLabels.forKV()); + this(parentComponent, NBLabels.forKV()); } + public NBBaseComponent(NBComponent parentComponent, NBLabels componentSpecificLabelsOnly) { this.labels = componentSpecificLabelsOnly; - if (parentComponent!=null) { + if (parentComponent != null) { parent = parentComponent; parent.attachChild(this); } else { - parent=null; + parent = null; } } + @Override public NBComponent getParent() { return parent; @@ -74,7 +76,7 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone @Override public NBLabels getLabels() { - return (this.parent==null) ? labels : this.parent.getLabels().and(labels); + return (this.parent == null) ? labels : this.parent.getLabels().and(labels); } @Override @@ -83,7 +85,7 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone while (tree.hasNext()) { NBComponent c = tree.next(); NBMetric metric = c.lookupMetric(name); - if (metric!=null) return metric; + if (metric != null) return metric; } return null; } @@ -99,6 +101,17 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone return found; } + @Override + public NBMetric findOneMetricInTree(String pattern) { + List found = findMetricsInTree(pattern); + if (found.size() != 1) { + System.out.println("Runtime Components and Metrics at this time:\n"+NBComponentFormats.formatAsTree(this)); + throw new RuntimeException("Found " + found.size() + " metrics with pattern '" + pattern + "', expected exactly 1"); + } + return found.get(0); + + } + @Override public void beforeDetach() { logger.debug("before detach " + description()); @@ -117,7 +130,7 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone logger.error(e); } finally { logger.debug("detaching " + description()); - if (parent!=null) { + if (parent != null) { parent.detachChild(this); } } diff --git a/nb-api/src/main/java/io/nosqlbench/components/NBComponentFormats.java b/nb-api/src/main/java/io/nosqlbench/components/NBComponentFormats.java new file mode 100644 index 000000000..3ed9f2c71 --- /dev/null +++ b/nb-api/src/main/java/io/nosqlbench/components/NBComponentFormats.java @@ -0,0 +1,27 @@ +package io.nosqlbench.components; + +import java.util.Iterator; + +public class NBComponentFormats { + public static String formatAsTree(NBBaseComponent base) { + StringBuilder sb = new StringBuilder(); + PrintVisitor pv = new PrintVisitor(sb); + NBComponentTraversal.visitDepthFirst(base,pv); + return sb.toString(); + } + + private final static class PrintVisitor implements NBComponentTraversal.Visitor { + + private final StringBuilder builder; + + public PrintVisitor(StringBuilder sb) { + this.builder = sb; + } + + @Override + public void visit(NBComponent component, int depth) { + builder.append(String.format("%03d %s\n",depth,component)); + } + } + +} diff --git a/nb-api/src/main/java/io/nosqlbench/components/NBComponentTraversal.java b/nb-api/src/main/java/io/nosqlbench/components/NBComponentTraversal.java index c95c04f3c..6b1315066 100644 --- a/nb-api/src/main/java/io/nosqlbench/components/NBComponentTraversal.java +++ b/nb-api/src/main/java/io/nosqlbench/components/NBComponentTraversal.java @@ -18,6 +18,7 @@ package io.nosqlbench.components; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; public class NBComponentTraversal { @@ -25,6 +26,17 @@ public class NBComponentTraversal { return new iterDepthFirst(component); } + public static void visitDepthFirst(NBComponent component, Visitor visitor) { + visitDepthFirst(component,visitor,0); + } + private static void visitDepthFirst(NBComponent component, Visitor visitor, int depth) { + visitor.visit(component,depth); + List children = component.getChildren(); + for (NBComponent child : children) { + visitDepthFirst(child,visitor,depth+1); + } + } + public static Iterator traverseBreadth(NBComponent component) { return new IterBreadthFirst(component); } @@ -71,4 +83,7 @@ public class NBComponentTraversal { } } + public interface Visitor { + void visit(NBComponent component, int depth); + } } diff --git a/nb-api/src/main/java/io/nosqlbench/components/NBFinders.java b/nb-api/src/main/java/io/nosqlbench/components/NBFinders.java index 63e3c95be..9f42d8849 100644 --- a/nb-api/src/main/java/io/nosqlbench/components/NBFinders.java +++ b/nb-api/src/main/java/io/nosqlbench/components/NBFinders.java @@ -17,6 +17,8 @@ package io.nosqlbench.components; import io.nosqlbench.api.engine.metrics.instruments.NBMetric; +import io.nosqlbench.api.engine.metrics.instruments.NBMetricCounter; +import io.nosqlbench.api.engine.metrics.instruments.NBMetricGauge; public class NBFinders { private final NBBaseComponent base; @@ -31,6 +33,32 @@ public class NBFinders { metric = base.findOneMetricInTree(pattern); return metric; } + private T findOneMetricWithType(String pattern, Class clazz) { + NBMetric found = metric(pattern); + if (found==null) { + System.out.println(NBComponentFormats.formatAsTree(base)); + throw new RuntimeException("unable to find metric with pattern '" + pattern + "'"); + } + if (clazz.isAssignableFrom(found.getClass())) { + return clazz.cast(found); + } else { + throw new RuntimeException( + "found metric with pattern '" + pattern + "'" + + ", but it was type " + + found.getClass().getSimpleName() + " (not a " + + clazz.getSimpleName() +")" + ); + } + } + + + public NBMetricGauge metricGauge(String pattern) { + return findOneMetricWithType(pattern, NBMetricGauge.class); + } + + public NBMetricCounter metricCounter(String pattern) { + return findOneMetricWithType(pattern, NBMetricCounter.class); + } } diff --git a/nb-api/src/main/java/io/nosqlbench/components/NBMetricsQuery.java b/nb-api/src/main/java/io/nosqlbench/components/NBMetricsQuery.java index 20267aa03..486be40d1 100644 --- a/nb-api/src/main/java/io/nosqlbench/components/NBMetricsQuery.java +++ b/nb-api/src/main/java/io/nosqlbench/components/NBMetricsQuery.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Optional; public interface NBMetricsQuery { + /** * If you have the serialized open metrics name of a metric, you can ask for it * this way and get a direct result. @@ -36,12 +37,6 @@ public interface NBMetricsQuery { List findMetricsInTree(String pattern); - default NBMetric findOneMetricInTree(String pattern) { - List found = findMetricsInTree(pattern); - if (found.size()!=1) { - throw new RuntimeException("Found " + found.size() + " metrics with pattern '" + pattern + "', expected exactly 1"); - } - return found.get(0); - } + NBMetric findOneMetricInTree(String pattern); } diff --git a/nb-api/src/test/java/io/nosqlbench/components/NBComponentTraversalTest.java b/nb-api/src/test/java/io/nosqlbench/components/NBComponentTraversalTest.java index 818f61768..ca859bd78 100644 --- a/nb-api/src/test/java/io/nosqlbench/components/NBComponentTraversalTest.java +++ b/nb-api/src/test/java/io/nosqlbench/components/NBComponentTraversalTest.java @@ -58,4 +58,13 @@ class NBComponentTraversalTest { assertThat(wider).containsExactly(a,sub1,sub2,dotX,dotY); } + @Test + public void testDepthFirstVisitor() { + NBComponentTraversal.visitDepthFirst(a, new NBComponentTraversal.Visitor() { + @Override + public void visit(NBComponent component, int depth) { + System.out.println(">".repeat(depth)+":"+component.description()); + } + }); + } } diff --git a/nbr-examples/src/main/resources/log4j2.xml b/nbr-examples/src/main/resources/log4j2.xml new file mode 100644 index 000000000..447e8454c --- /dev/null +++ b/nbr-examples/src/main/resources/log4j2.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + %d %p %C{1.} [%t] %m%n + + + + + + + + + + + + + + + + + diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/DirectRuntimeScenarioTests.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/DirectRuntimeScenarioTests.java deleted file mode 100644 index 82a7778fe..000000000 --- a/nbr-examples/src/test/java/io/nosqlbench/nbr/DirectRuntimeScenarioTests.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2023 nosqlbench - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.nosqlbench.nbr; - -import io.nosqlbench.api.config.standard.TestComponent; -import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosExecutor; -import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosResults; -import io.nosqlbench.nbr.examples.SCDryRunScenarioTest; -import org.junit.jupiter.api.Test; - -import java.util.Map; - -public class DirectRuntimeScenarioTests { - - @Test - public void testDirect() { - TestComponent testC = new TestComponent("testroot", "testroot"); - SCDryRunScenarioTest sc1 = new SCDryRunScenarioTest(TestComponent.EMPTY_COMPONENT, "test", Map.of(), "console:1s"); - ScenariosExecutor executor = new ScenariosExecutor(TestComponent.EMPTY_COMPONENT, "test", 1); - executor.execute(sc1); - ScenariosResults results = executor.awaitAllResults(); - System.out.println(results); - } -} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/SCBaseScenario.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/SCBaseScenario.java new file mode 100644 index 000000000..e6494be67 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/SCBaseScenario.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.engine.core.lifecycle.scenario.context.ActivitiesController; +import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures; +import io.nosqlbench.engine.core.lifecycle.scenario.context.ScriptParams; +import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario; + +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; + +public abstract class SCBaseScenario extends NBScenario { + protected NBComponent component; + protected Reader stdin; + protected PrintWriter stdout; + protected Writer stderr; + protected ActivitiesController controller; + protected ScriptParams params; + + public SCBaseScenario(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + @Override + protected void runScenario(NBSceneFixtures shell) { + this.component = shell.component(); + this.stdin = shell.in(); + this.stdout = shell.out(); + this.stderr = shell.err(); + this.controller = shell.controller(); + this.params = shell.params(); + invoke(); + } + + public abstract void invoke(); + +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/SCDryRunScenarioTest.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/SCDryRunScenarioTest.java deleted file mode 100644 index 82e91b166..000000000 --- a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/SCDryRunScenarioTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2023 nosqlbench - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.nosqlbench.nbr.examples; - -import io.nosqlbench.api.engine.activityimpl.ActivityDef; -import io.nosqlbench.components.NBComponent; -import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures; -import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario; - -import java.util.Map; - -public class SCDryRunScenarioTest extends NBScenario { - public SCDryRunScenarioTest(NBComponent parentComponent, String scenarioName, Map params, String progressInterval) { - super(parentComponent, scenarioName, params, progressInterval); - } - - /** - * print('starting activity activity_error'); - * scenario.start(activitydef1); - * scenario.waitMillis(2000); - * activities.activity_error.threads = "unparsable"; - * scenario.awaitActivity("activity_error"); - * print("awaited activity"); - */ - @Override - protected void runScenario(NBSceneFixtures shell) { - - /** - * activitydef1 = { - * "alias": "activity_error", - * "driver": "diag", - * "cycles": "0..1500000", - * "threads": "1", - * "targetrate": "10", - * "op": "log: modulo=1" - * }; - */ - var activitydef1 = Map.of("alias", "activity_error", - "driver", "diag", - "cycles", "0..1500000", - "threads", "1", - "targetrate", "10", - "op", "log: modulo=1"); - - - // print('starting activity activity_error'); - shell.out().write("starting activity activity_error"); - - // scenario.start(activitydef1); - shell.controller().start(activitydef1); - - // scenario.waitMillis(2000); - shell.controller().waitMillis(2000); - - // activities.activity_error.threads = "unparsable"; - ActivityDef def = shell.controller().getActivityDef("activity_error"); - def.getParams().set("threads","unparsable"); - - // scenario.awaitActivity("activity_error"); - shell.controller().awaitActivity("activity_error", Long.MAX_VALUE); - - // print("awaited activity"); - - shell.out().println("awaited activity"); - } -} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/ScriptExampleTests.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/ScriptExampleTests.java index 1359a004a..41b9fd47a 100644 --- a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/ScriptExampleTests.java +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/ScriptExampleTests.java @@ -61,7 +61,7 @@ public class ScriptExampleTests { ScenariosExecutor executor = new ScenariosExecutor(new TestComponent("test","test"),ScriptExampleTests.class.getSimpleName() + ":" + scriptname, 1); NBScriptedScenario s = NBScriptedScenario.ofScripted(scenarioName,Map.of(),new TestComponent("test","test"), NBScriptedScenario.Invocation.EXECUTE_SCRIPT); - s.addScenarioScriptParams(paramsMap); +// s.addScenarioScriptParams(paramsMap); ClassLoader cl = ScriptExampleTests.class.getClassLoader(); String script; @@ -78,7 +78,7 @@ public class ScriptExampleTests { } s.addScriptText(script); // s.addScriptText("load('classpath:scripts/async/" + scriptname + ".js');"); - executor.execute(s); + executor.execute(s,paramsMap); ScenariosResults scenariosResults = executor.awaitAllResults(); ScenarioResult scenarioResult = scenariosResults.getOne(); executor.shutdownNow(); diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/flow.md b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/flow.md new file mode 100644 index 000000000..7667bf3e2 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/flow.md @@ -0,0 +1,12 @@ +# Scenario Invocation + +```mermaid +flowchart LR + + IO\nbuffers -. "embed" .-> fixtures + params --> fixtures + fixtures --> Scenario\ninstance + Scenario\ninstance --> used\nfixtures + used\nfixtures -. extract .-> IO\ntraces + +``` diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/DirectRuntimeScenarioTests.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/DirectRuntimeScenarioTests.java new file mode 100644 index 000000000..a25f55c66 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/DirectRuntimeScenarioTests.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.api.config.standard.TestComponent; +import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneBuffer; +import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario; +import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenarioResult; +import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosExecutor; +import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosResults; +import io.nosqlbench.nbr.examples.injava.*; +import org.junit.jupiter.api.Test; + +public class DirectRuntimeScenarioTests { + + private final TestComponent testC = new TestComponent("testroot", "testroot"); + @Test + public void testDirect() { + TestComponent testC = new TestComponent("testroot", "testroot"); + SC_activity_error sc1 = new SC_activity_error(TestComponent.EMPTY_COMPONENT, "test"); + ScenariosExecutor executor = new ScenariosExecutor(TestComponent.EMPTY_COMPONENT, "test", 1); + executor.execute(sc1); + ScenariosResults results = executor.awaitAllResults(); + System.out.println(results); + } + + @Test + public void testSC_activit_init_error() { + SC_start_stop_diag scenario = new SC_start_stop_diag(testC, "SC_start_stop_diag"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("SC_start_stop_diag")); + } + + @Test + public void test_SC_activity_error() { + NBScenario scenario = new SC_activity_error(testC,"test_SC_activity_error"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_activity_error")); + } + @Test + public void test_SC_activity_init_error() { + NBScenario scenario = new SC_activity_init_error(testC,"test_SC_activity_init_error"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_activity_init_error")); + } + @Test + public void test_SC_await_finished() { + NBScenario scenario = new SC_await_finished(testC,"test_SC_await_finished"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_await_finished")); + } + @Test + public void test_SC_basicdiag() { + NBScenario scenario = new SC_basicdiag(testC,"test_SC_basicdiag"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_basicdiag")); + } + @Test + public void test_SC_blockingrun() { + NBScenario scenario = new SC_blockingrun(testC,"test_SC_blockingrun"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_blockingrun")); + } + @Test + public void test_SC_cocycledelay_bursty() { + NBScenario scenario = new SC_cocycledelay_bursty(testC,"test_SC_cocycledelay_bursty"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_cocycledelay_bursty")); + result.report(); + } + @Test + public void test_SC_cocycledelay_strict() { + NBScenario scenario = new SC_cocycledelay_strict(testC,"test_SC_cocycledelay_strict"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_cocycledelay_strict")); + } + @Test + public void test_SC_cycle_rate() { + NBScenario scenario = new SC_cycle_rate(testC,"test_SC_cycle_rate"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_cycle_rate")); + } + @Test + public void test_SC_cycle_rate_change() { + NBScenario scenario = new SC_cycle_rate_change(testC,"test_SC_cycle_rate_change"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_cycle_rate_change")); + } + @Test + public void test_SC_extension_csvmetrics() { + NBScenario scenario = new SC_extension_csvmetrics(testC,"test_SC_extension_csvmetrics"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_extension_csvmetrics")); + } + @Test + public void test_SC_extension_csvoutput() { + NBScenario scenario = new SC_extension_csvoutput(testC,"test_SC_extension_csvoutput"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_extension_csvoutput")); + } + @Test + public void test_SC_extension_histostatslogger() { + NBScenario scenario = new SC_extension_histostatslogger(testC,"test_SC_extension_histostatslogger"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_extension_histostatslogger")); + } + @Test + public void test_SC_extension_shutdown_hook() { + NBScenario scenario = new SC_extension_shutdown_hook(testC,"test_SC_extension_shutdown_hook"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_extension_shutdown_hook")); + } + @Test + public void test_SC_histologger() { + NBScenario scenario = new SC_histologger(testC,"test_SC_histologger"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_histologger")); + } + @Test + public void test_SC_linkedinput() { + NBScenario scenario = new SC_linkedinput(testC,"test_SC_linkedinput"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_linkedinput")); + } + @Test + public void test_SC_optimo() { + NBScenario scenario = new SC_optimo(testC,"test_SC_optimo"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_optimo")); + } + @Test + public void test_SC_params_variable() { + NBScenario scenario = new SC_params_variable(testC,"test_SC_params_variable"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_params_variable")); + } + @Test + public void test_SC_readmetrics() { + NBScenario scenario = new SC_readmetrics(testC,"test_SC_readmetrics"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_readmetrics")); + } + @Test + public void test_SC_speedcheck() { + NBScenario scenario = new SC_speedcheck(testC,"test_SC_speedcheck"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_speedcheck")); + } + @Test + public void test_SC_start_stop_diag() { + NBScenario scenario = new SC_start_stop_diag(testC,"test_SC_start_stop_diag"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_start_stop_diag")); + } + @Test + public void test_SC_threadchange() { + NBScenario scenario = new SC_threadchange(testC,"test_SC_threadchange"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_threadchange")); + } + @Test + public void test_SC_threadspeeds() { + NBScenario scenario = new SC_threadspeeds(testC,"test_SC_threadspeeds"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_threadspeeds")); + } + @Test + public void test_SC_undef_param() { + NBScenario scenario = new SC_undef_param(testC, "test_SC_undef_param"); + ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_undef_param")); + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_activity_error.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_activity_error.java new file mode 100644 index 000000000..8bfa405fa --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_activity_error.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +import java.util.Map; + +public class SC_activity_error extends SCBaseScenario { + public SC_activity_error(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + @Override + protected void runScenario(NBSceneFixtures shell) { + +// HdrHistoLogPluginData hdrHistoLogPluginData = new HdrHistoLogPluginData(); +// HdrHistoLogPlugin histologplugin = hdrHistoLogPluginData.getExtensionObject(...); +// histologplugin.logHistoIntervals(...); + +// HdrHistoLogPlugin logplugin = shell.extensions().get("histologger",HdrHistoLogPlugin.class); + +// var serviceojbect = extensions.get("histologger"); + +// AttachedMetricsSummaryReporter reporter = shell.runtime().create().summaryReporter(5, "labelname", "labelvalue"); + + } + + /** + * Equivalent to javascript form: + *
{@code
+     * activitydef1 = {
+     *  "alias": "activity_error",
+     *  "driver": "diag",
+     *  "cycles": "0..1500000",
+     *  "threads": "1",
+     *  "targetrate": "10",
+     *  "op": "log: modulo=1"
+     * };
+     *
+     * print('starting activity activity_error');
+     * scenario.start(activitydef1);
+     * scenario.waitMillis(2000);
+     * activities.activity_error.threads = "unparsable";
+     * scenario.awaitActivity("activity_error");
+     * print("awaited activity");
+     * 
+ */ + @Override + public void invoke() { + var activitydef1 = Map.of("alias", "activity_error", + "driver", "diag", + "cycles", "0..1500000", + "threads", "1", + "targetrate", "10", + "op", "log: modulo=1" + ); + stdout.write("starting activity activity_error"); + controller.start(activitydef1); + controller.waitMillis(2000); + controller.getActivityDef("activity_error").getParams().set("threads","unparsable"); // forced error + controller.awaitActivity("activity_error", Long.MAX_VALUE); + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_activity_init_error.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_activity_init_error.java new file mode 100644 index 000000000..2b4caa823 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_activity_init_error.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario; +import io.nosqlbench.nb.annotations.Service; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +import java.util.Map; + +@Service(value=NBScenario.class,selector="activity_init_error") +public class SC_activity_init_error extends SCBaseScenario { + public SC_activity_init_error(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef1 = {
+     *     "alias" : "activity_init_error",
+     *     "driver" : "diag",
+     *     "cycles" : "invalid",
+     *     "threads" : "1",
+     *     "targetrate" : "500",
+     *     "unknown_config" : "unparsable",
+     *     "op" : "noop"
+     * };
+     *
+     * print('starting activity activity_init_error');
+     * scenario.start(activitydef1);
+     * scenario.waitMillis(2000);
+     * scenario.awaitActivity("activity_init_error");
+     * print("awaited activity");}
+ * + */ + @Override + public void invoke() { + var activitydef1 = Map.of( + "alias","activity_init_error", + "driver","diag", + "cycles","invalid", + "threads","1", + "targetrate","500", + "unknown_config","unparsable", + "op","noop" + ); + + stdout.println("starting activity activity_init_error"); + controller.start(activitydef1); + controller.waitMillis(2000); + controller.awaitActivity("activity_init_error",Long.MAX_VALUE); + stdout.println("awaited activity"); + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_await_finished.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_await_finished.java new file mode 100644 index 000000000..2a91a1af0 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_await_finished.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.engine.cli.Cmd; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +import java.util.Map; + +public class SC_await_finished extends SCBaseScenario { + public SC_await_finished(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /** + *
{@code
+     * activitydef1 = {
+     *     "alias" : "activity_to_await",
+     *     "driver" : "diag",
+     *     "cycles" : "0..1500",
+     *     "threads" : "1",
+     *     "targetrate" : "500",
+     *     "op" : "noop"
+     * };
+     *
+     * print('starting activity teststartstopdiag');
+     * scenario.start(activitydef1);
+     * scenario.awaitActivity("activity_to_await");
+     * print("awaited activity");
+     * }
+ */ + @Override + public void invoke() { + var activitydef1 = Map.of( + "alias", "activity_to_await", + "driver", "diag", + "cycles", "0..1500", + "threads", "1", + "targetrate", "500", + "op", "noop" + ); + stdout.println("starting activity activity_to_await"); + controller.start(activitydef1); + controller.awaitActivity("activity_to_await",1000L); + stdout.println("awaited activity"); + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_basicdiag.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_basicdiag.java new file mode 100644 index 000000000..97a4fde6f --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_basicdiag.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +import java.util.Map; + +public class SC_basicdiag extends SCBaseScenario { + public SC_basicdiag(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * basic_diag = params.withOverrides({
+     *     "alias" : "basic_diag",
+     *     "driver" : "diag"
+     * });
+     *
+     *
+     * print('starting activity basic_diag');
+     * scenario.start(basic_diag);
+     * }
+ */ + @Override + public void invoke() { + var basic_diag = params.withOverrides( + Map.of("alias","basic_diag","driver","diag") + ); + stdout.println("starting activity basic_diag"); + controller.start(basic_diag); + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_blockingrun.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_blockingrun.java new file mode 100644 index 000000000..f1fa374d9 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_blockingrun.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +import java.util.Map; + +public class SC_blockingrun extends SCBaseScenario { + public SC_blockingrun(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef1 = {
+     *     "alias" : "blockingactivity1",
+     *     "driver" : "diag",
+     *     "cycles" : "0..100000",
+     *     "threads" : "1",
+     *     "interval" : "2000",
+     *     "op":"noop"
+     * };
+     * activitydef2 = {
+     *     "alias" : "blockingactivity2",
+     *     "driver" : "diag",
+     *     "cycles" : "0..100000",
+     *     "threads" : "1",
+     *     "interval" : "2000",
+     *     "op":"noop"
+     * };
+     *
+     *
+     * print('running blockingactivity1');
+     * scenario.run(10000,activitydef1);
+     * print('blockingactivity1 finished');
+     * print('running blockingactivity2');
+     * scenario.run(10000,activitydef2);
+     * print('blockingactivity2 finished');
+     * }
+ */ + @Override + public void invoke() { + var activitydef1 = Map.of( + "alias","blockactivity1","driver","diag", + "cycles","0..100000","threads","1", + "interval","2000","op","noop" + ); + + var activitydef2 = Map.of( + "alias", "blockingactivity2","driver","diag", + "cycles","0..100000","threads","1", + "interval","2000", "op","noop" + ); + + stdout.println("running blockingactivity1"); + controller.run(activitydef1); + stdout.println("blockingactivity1 finished"); + stdout.println("running blockingactivity2"); + controller.run(activitydef2); + stdout.println("blockingactivity2 finished"); + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_bursty.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_bursty.java new file mode 100644 index 000000000..08ec571f8 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_bursty.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.api.engine.metrics.instruments.NBMetricCounter; +import io.nosqlbench.api.engine.metrics.instruments.NBMetricGauge; +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +import java.util.Map; + +public class SC_cocycledelay_bursty extends SCBaseScenario { + public SC_cocycledelay_bursty(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /** + *
{@code
+     * co_cycle_delay_bursty = {
+     *     "alias": "co_cycle_delay_bursty",
+     *     "driver": "diag",
+     *     "cycles": "0..1000000",
+     *     "threads": "10",
+     *     "cyclerate": "1000,1.5",
+     *     "op" : "diagrate: diagrate=500"
+     * };
+     *
+     * print('starting activity co_cycle_delay_bursty');
+     * scenario.start(co_cycle_delay_bursty);
+     * for (i = 0; i < 5; i++) {
+     *     scenario.waitMillis(1000);
+     *     if (!scenario.isRunningActivity('co_cycle_delay_bursty')) {
+     *         print("scenario exited prematurely, aborting.");
+     *         break;
+     *     }
+     *     print("backlogging, cycles=" + metrics.co_cycle_delay_bursty.cycles_servicetime.count +
+     *         " waittime=" + metrics.co_cycle_delay_bursty.cycles_waittime.value +
+     *         " diagrate=" + activities.co_cycle_delay_bursty.diagrate +
+     *         " cyclerate=" + activities.co_cycle_delay_bursty.cyclerate
+     *     );
+     * }
+     * print('step1 metrics.waittime=' + metrics.co_cycle_delay_bursty.cycles_waittime.value);
+     * activities.co_cycle_delay_bursty.diagrate = "10000";
+     *
+     * for (i = 0; i < 10; i++) {
+     *     if (!scenario.isRunningActivity('co_cycle_delay_bursty')) {
+     *         print("scenario exited prematurely, aborting.");
+     *         break;
+     *     }
+     *     print("recovering, cycles=" + metrics.co_cycle_delay_bursty.cycles_servicetime.count +
+     *         " waittime=" + metrics.co_cycle_delay_bursty.cycles_waittime.value +
+     *         " diagrate=" + activities.co_cycle_delay_bursty.diagrate +
+     *         " cyclerate=" + activities.co_cycle_delay_bursty.cyclerate
+     *     );
+     *
+     *     scenario.waitMillis(1000);
+     *     if (metrics.co_cycle_delay_bursty.cycles_waittime.value < 50000000) {
+     *         print("waittime trended back down as expected, exiting on iteration " + i);
+     *         break;
+     *     }
+     * }
+     * //scenario.awaitActivity("co_cycle_delay");
+     * print('step2 metrics.waittime=' + metrics.co_cycle_delay_bursty.cycles_waittime.value);
+     * scenario.stop(co_cycle_delay_bursty);
+     * print("stopped activity co_cycle_delay_bursty");
+     * }
+ */ + @Override + public void invoke() { + var co_cycle_delay_bursty = Map.of( + "alias", "co_cycle_delay_bursty", + "driver", "diag", + "cycles", "0..1000000", + "threads", "1", + "cyclerate", "10,1.5", + "op", "log: level=info" + ); + + controller.waitMillis(1000); + stdout.println("starting activity co_cycle_delay_bursty"); + controller.start(co_cycle_delay_bursty); + + NBMetricCounter service_time_counter = find().metricCounter("activity=co_cycle_delay_bursty,name=cycles_servicetime"); + NBMetricGauge wait_time_gauge = find().metricGauge("activity=co_cycle_delay_bursty,name=cycles_waittime"); + String diagrate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("diagrate").toString(); + String cyclerate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("cyclerate").toString(); +// +// for (int i = 0; i < 5; i++) { +// controller.waitMillis(1000); +// if (!controller.isRunningActivity(co_cycle_delay_bursty)) { +// stdout.println("scenario exited prematurely, aborting."); +// break; +// } +// diagrate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("diagrate").toString(); +// cyclerate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("cyclerate").toString(); +// stdout.println( +// "backlogging, cycles=" + service_time_counter.getCount() + +// " waittime=" + wait_time_gauge.getValue() + +// " diagrate=" + diagrate + +// " cyclerate=" + cyclerate +// ); +// } +// +// stdout.println("step1 metrics.waittime=" + wait_time_gauge.getValue()); +// controller.getActivityDef("co_cycle_delay_bursty").getParams().put("diagrate", "10000"); +// +// for (int i = 0; i < 10; i++) { +// if (!controller.isRunningActivity("co_cycle_delay_bursty")) { +// stdout.println("scenario exited prematurely, aborting."); +// break; +// } +// diagrate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("diagrate").toString(); +// cyclerate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("cyclerate").toString(); +// +// stdout.println( +// "recovering, cycles=" + service_time_counter.getCount() + +// " waittime=" + wait_time_gauge.getValue() + +// " diagrate=" + diagrate + +// " cyclerate=" + cyclerate +// ); +// +// controller.waitMillis(1000); +// if (wait_time_gauge.getValue() < 50000000) { +// stdout.println("waittime trended back down as expected, exiting on iteration " + i); +// break; +// } +// } +// +// stdout.println("step2 metrics.waittime=" + wait_time_gauge.getValue()); +// controller.stop(co_cycle_delay_bursty); +// +// stdout.println("stopped activity co_cycle_delay_bursty"); + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_bursty_backup.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_bursty_backup.java new file mode 100644 index 000000000..304287924 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_bursty_backup.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.api.engine.metrics.instruments.NBMetricCounter; +import io.nosqlbench.api.engine.metrics.instruments.NBMetricGauge; +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +import java.util.Map; + +public class SC_cocycledelay_bursty_backup extends SCBaseScenario { + public SC_cocycledelay_bursty_backup(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /** + *
{@code
+     * co_cycle_delay_bursty = {
+     *     "alias": "co_cycle_delay_bursty",
+     *     "driver": "diag",
+     *     "cycles": "0..1000000",
+     *     "threads": "10",
+     *     "cyclerate": "1000,1.5",
+     *     "op" : "diagrate: diagrate=500"
+     * };
+     *
+     * print('starting activity co_cycle_delay_bursty');
+     * scenario.start(co_cycle_delay_bursty);
+     * for (i = 0; i < 5; i++) {
+     *     scenario.waitMillis(1000);
+     *     if (!scenario.isRunningActivity('co_cycle_delay_bursty')) {
+     *         print("scenario exited prematurely, aborting.");
+     *         break;
+     *     }
+     *     print("backlogging, cycles=" + metrics.co_cycle_delay_bursty.cycles_servicetime.count +
+     *         " waittime=" + metrics.co_cycle_delay_bursty.cycles_waittime.value +
+     *         " diagrate=" + activities.co_cycle_delay_bursty.diagrate +
+     *         " cyclerate=" + activities.co_cycle_delay_bursty.cyclerate
+     *     );
+     * }
+     * print('step1 metrics.waittime=' + metrics.co_cycle_delay_bursty.cycles_waittime.value);
+     * activities.co_cycle_delay_bursty.diagrate = "10000";
+     *
+     * for (i = 0; i < 10; i++) {
+     *     if (!scenario.isRunningActivity('co_cycle_delay_bursty')) {
+     *         print("scenario exited prematurely, aborting.");
+     *         break;
+     *     }
+     *     print("recovering, cycles=" + metrics.co_cycle_delay_bursty.cycles_servicetime.count +
+     *         " waittime=" + metrics.co_cycle_delay_bursty.cycles_waittime.value +
+     *         " diagrate=" + activities.co_cycle_delay_bursty.diagrate +
+     *         " cyclerate=" + activities.co_cycle_delay_bursty.cyclerate
+     *     );
+     *
+     *     scenario.waitMillis(1000);
+     *     if (metrics.co_cycle_delay_bursty.cycles_waittime.value < 50000000) {
+     *         print("waittime trended back down as expected, exiting on iteration " + i);
+     *         break;
+     *     }
+     * }
+     * //scenario.awaitActivity("co_cycle_delay");
+     * print('step2 metrics.waittime=' + metrics.co_cycle_delay_bursty.cycles_waittime.value);
+     * scenario.stop(co_cycle_delay_bursty);
+     * print("stopped activity co_cycle_delay_bursty");
+     * }
+ */ + @Override + public void invoke() { + var co_cycle_delay_bursty = Map.of( + "alias", "co_cycle_delay_bursty", + "driver", "diag", + "cycles", "0..1000000", + "threads", "1", + "cyclerate", "1000,1.5", + "op", "diagrate: diagrate=500" + ); + + + stdout.println("starting activity co_cycle_delay_bursty"); + controller.start(co_cycle_delay_bursty); + + NBMetricCounter service_time_counter = find().metricCounter("activity=co_cycle_delay_bursty,name=cycles_servicetime"); + NBMetricGauge wait_time_gauge = find().metricGauge("activity=co_cycle_delay_bursty,name=cycles_waittime"); + String diagrate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("diagrate").toString(); + String cyclerate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("cyclerate").toString(); + + for (int i = 0; i < 5; i++) { + controller.waitMillis(1000); + if (!controller.isRunningActivity(co_cycle_delay_bursty)) { + stdout.println("scenario exited prematurely, aborting."); + break; + } + diagrate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("diagrate").toString(); + cyclerate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("cyclerate").toString(); + stdout.println( + "backlogging, cycles=" + service_time_counter.getCount() + + " waittime=" + wait_time_gauge.getValue() + + " diagrate=" + diagrate + + " cyclerate=" + cyclerate + ); + } + + stdout.println("step1 metrics.waittime=" + wait_time_gauge.getValue()); + controller.getActivityDef("co_cycle_delay_bursty").getParams().put("diagrate", "10000"); + + for (int i = 0; i < 10; i++) { + if (!controller.isRunningActivity("co_cycle_delay_bursty")) { + stdout.println("scenario exited prematurely, aborting."); + break; + } + diagrate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("diagrate").toString(); + cyclerate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("cyclerate").toString(); + + stdout.println( + "recovering, cycles=" + service_time_counter.getCount() + + " waittime=" + wait_time_gauge.getValue() + + " diagrate=" + diagrate + + " cyclerate=" + cyclerate + ); + + controller.waitMillis(1000); + if (wait_time_gauge.getValue() < 50000000) { + stdout.println("waittime trended back down as expected, exiting on iteration " + i); + break; + } + } + + stdout.println("step2 metrics.waittime=" + wait_time_gauge.getValue()); + controller.stop(co_cycle_delay_bursty); + + stdout.println("stopped activity co_cycle_delay_bursty"); + + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_strict.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_strict.java new file mode 100644 index 000000000..1a18b280f --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cocycledelay_strict.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_cocycledelay_strict extends SCBaseScenario { + public SC_cocycledelay_strict(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * co_cycle_delay = {
+     *     "alias" : "co_cycle_delay",
+     *     "driver" : "diag",
+     *     "cycles" : "0..10000",
+     *     "threads" : "1",
+     *     "cyclerate" : "1000,1.0",
+     *     "op" : "diagrate:diagrate=800"
+     * };
+     *
+     * print('starting activity co_cycle_delay');
+     * scenario.start(co_cycle_delay);
+     * scenario.waitMillis(4000);
+     * print('step1 cycles_waittime=' + metrics.co_cycle_delay.cycles_waittime.value);
+     * activities.co_cycle_delay.diagrate="10000";
+     * for(i=0;i<5;i++) {
+     *     if (! scenario.isRunningActivity('co_cycle_delay')) {
+     *         print("scenario exited prematurely, aborting.");
+     *         break;
+     *     }
+     *     print("iteration " + i + " waittime now " + metrics.co_cycle_delay.cycles_waittime.value);
+     *     scenario.waitMillis(1000);
+     * }
+     *
+     *
+     * //scenario.awaitActivity("co_cycle_delay");
+     * print('step2 cycles_waittime=' + metrics.co_cycle_delay.cycles_waittime.value);
+     * print("awaited activity");
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cycle_rate.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cycle_rate.java new file mode 100644 index 000000000..19e3ae71c --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cycle_rate.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_cycle_rate extends SCBaseScenario { + public SC_cycle_rate(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef = {
+     *     "alias" : "cycle_rate",
+     *     "driver" : "diag",
+     *     "cycles" : "2500",
+     *     "threads" : "10",
+     *     "cyclerate" : "500",
+     *     "op" : "noop"
+     * };
+     *
+     * scenario.run(activitydef);
+     *
+     * print("current cycle = " + metrics.cycle_rate.cycles_servicetime.count);
+     * print("mean cycle rate = " + metrics.cycle_rate.cycles_servicetime.meanRate);
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cycle_rate_change.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cycle_rate_change.java new file mode 100644 index 000000000..b62dc3210 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_cycle_rate_change.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_cycle_rate_change extends SCBaseScenario { + public SC_cycle_rate_change(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef = {
+     *     "alias" : "cycle_rate_change",
+     *     "driver" : "diag",
+     *     "cycles" : "0..1000000",
+     *     "threads" : "10",
+     *     "cyclerate" : "2000",
+     *     "interval" : "2000",
+     *     "op" : "noop"
+     * };
+     *
+     * print('starting cycle_rate_change');
+     * scenario.start(activitydef);
+     * print('started');
+     * print('cyclerate at 0ms:' + activities.cycle_rate_change.cyclerate);
+     * scenario.waitMillis(500);
+     * activities.cycle_rate_change.cyclerate='1000';
+     * print("measured cycle increment per second is expected to adjust to 1000");
+     *
+     * print('cyclerate now:' + activities.cycle_rate_change.cyclerate);
+     *
+     * var lastcount=metrics.cycle_rate_change.cycles_servicetime.count;
+     * for(i=0;i<20;i++) {
+     *     scenario.waitMillis(1000);
+     *     var nextcount=metrics.cycle_rate_change.cycles_servicetime.count;
+     *     var cycles = (nextcount - lastcount);
+     *     print("new this second: " + (nextcount - lastcount));
+     *     print(" waittime: " + metrics.cycle_rate_change.cycles_waittime.value);
+     *     lastcount=nextcount;
+     *     if (cycles>700 && cycles<1300) {
+     *         print("cycles adjusted, exiting on iteration " + i);
+     *         break;
+     *     }
+     * }
+     * scenario.stop(activitydef);
+     * print('cycle_rate_change activity finished');
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_csvmetrics.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_csvmetrics.java new file mode 100644 index 000000000..3d8a8c55c --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_csvmetrics.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_extension_csvmetrics extends SCBaseScenario { + public SC_extension_csvmetrics(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * var csvlogger = csvmetrics.log("logs/csvmetricstestdir");
+     *
+     * activitydef = {
+     *     "alias" : "csvmetrics",
+     *     "driver" : "diag",
+     *     "cycles" : "50000",
+     *     "threads" : "1",
+     *     "op": "log: level=debug",
+     *     "rate" : "100.0"
+     * };
+     * scenario.start(activitydef);
+     * scenario.waitMillis(500);
+     *
+     * csvlogger.add(metrics.csvmetrics.cycles_servicetime);
+     * csvlogger.start(500,"MILLISECONDS");
+     *
+     * scenario.waitMillis(2000);
+     * scenario.stop(activitydef);
+     *
+     * csvlogger.report();
+     * }
+ */ + @Override + public void invoke() { + // TODO create().csvmetrics.... + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_csvoutput.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_csvoutput.java new file mode 100644 index 000000000..d858e1bc3 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_csvoutput.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_extension_csvoutput extends SCBaseScenario { + public SC_extension_csvoutput(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * var csvlogger = csvoutput.open("logs/csvoutputtestfile.csv","header1","header2");
+     *
+     * csvlogger.write({"header1": "value1","header2":"value2"});
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_histostatslogger.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_histostatslogger.java new file mode 100644 index 000000000..9d5c88b5e --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_histostatslogger.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_extension_histostatslogger extends SCBaseScenario { + public SC_extension_histostatslogger(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef = {
+     *     "alias" : "testhistostatslogger",
+     *     "driver" : "diag",
+     *     "cycles" : "50000",
+     *     "threads" : "5",
+     *     "rate" : "100.0",
+     *     "op" : "noop"
+     * };
+     *
+     * histostatslogger.logHistoStats("testing extention histostatslogger", ".*", "logs/histostats.csv", "0.5s");
+     * print("started logging to logs/histostats.csv for all metrics at 1/2" +
+     *     " second intervals.");
+     * scenario.start(activitydef);
+     * scenario.waitMillis(4000);
+     * scenario.stop(activitydef);
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/engine-core/src/test/java/io/nosqlbench/engine/core/script/NBScenarioContextBufferTest.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_shutdown_hook.java similarity index 50% rename from engine-core/src/test/java/io/nosqlbench/engine/core/script/NBScenarioContextBufferTest.java rename to nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_shutdown_hook.java index 86bfb2cdd..bf6bf2224 100644 --- a/engine-core/src/test/java/io/nosqlbench/engine/core/script/NBScenarioContextBufferTest.java +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_extension_shutdown_hook.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 nosqlbench + * Copyright (c) 2023 nosqlbench * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,24 @@ * limitations under the License. */ -package io.nosqlbench.engine.core.script; +package io.nosqlbench.nbr.examples.injava; -import io.nosqlbench.engine.api.scripting.ScriptEnvBuffer; -import org.junit.jupiter.api.Test; +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; -import java.io.IOException; - -import static org.assertj.core.api.Assertions.assertThat; - -public class NBScenarioContextBufferTest { - - @Test - public void shouldCaptureLoggedOutput() throws IOException { - ScriptEnvBuffer seb = new ScriptEnvBuffer(); - seb.getWriter().write("out\n"); - assertThat(seb.getStdoutText()).isEqualTo("out\n"); +public class SC_extension_shutdown_hook extends SCBaseScenario { + public SC_extension_shutdown_hook(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); } + /**
{@code
+     * shutdown.addShutdownHook('testfunc', function f() {
+     *     print("shutdown hook running");
+     * });
+     * }
+ */ + @Override + public void invoke() { + + } } diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_histologger.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_histologger.java new file mode 100644 index 000000000..73560c901 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_histologger.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_histologger extends SCBaseScenario { + public SC_histologger(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef = {
+     *     "alias" : "testhistologger",
+     *     "driver" : "diag",
+     *     "cycles" : "1000",
+     *     "threads" : "20",
+     *     "interval" : "2000",
+     *     "targetrate" : "100.0",
+     *     "op" : "noop"
+     * };
+     *
+     * histologger.logHistoIntervals("testing extention histologger", ".*", "hdrhistodata.log", "0.5s");
+     * print("started logging to hdrhistodata.log for all metrics at 1/2 second intervals.");
+     *
+     * scenario.start(activitydef);
+     * scenario.waitMillis(3000);
+     * scenario.stop(activitydef);
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_linkedinput.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_linkedinput.java new file mode 100644 index 000000000..f83dd6e17 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_linkedinput.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_linkedinput extends SCBaseScenario { + public SC_linkedinput(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * var leader = {
+     *     driver: 'diag',
+     *     alias: 'leader',
+     *     targetrate: '10000',
+     *     op: 'log:level=info'
+     * };
+     *
+     * var follower = {
+     *     driver: 'diag',
+     *     alias: 'follower',
+     *     // linkinput: 'leader',
+     *     op: 'log:level=INFO'
+     * };
+     *
+     * scenario.start(leader);
+     * print("started leader");
+     * scenario.start(follower);
+     * print("started follower");
+     *
+     * scenario.waitMillis(500);
+     *
+     * scenario.stop(leader);
+     * print("stopped leader");
+     * scenario.stop(follower);
+     * print("stopped follower");
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_optimo.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_optimo.java new file mode 100644 index 000000000..e96f1b2f9 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_optimo.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_optimo extends SCBaseScenario { + public SC_optimo(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * var optimo = optimos.init();
+     *
+     * optimo.param('pa', 0.0, 200000.0);
+     * optimo.param('pb', 0.0, 200000.0);
+     *
+     * optimo.setInitialRadius(10000.0).setStoppingRadius(0.001).setMaxEval(1000);
+     *
+     * optimo.setObjectiveFunction(
+     *     function (values) {
+     *         // var arraydata = Java.from(ary);
+     *         print("ary:" + JSON.stringify(values));
+     *
+     *         var a = 0.0 + values.pa;
+     *         var b = 0.0 + values.pb;
+     *
+     *         var result = 1000000 - ((Math.abs(100 - a) + Math.abs(100 - b)));
+     *         print("a=" + a + ",b=" + b + ", r=" + result);
+     *         return result;
+     *     }
+     * );
+     *
+     * var result = optimo.optimize();
+     *
+     * print("optimized result was " + result);
+     * print("map of result was " + result.getMap());
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_params_variable.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_params_variable.java new file mode 100644 index 000000000..9d103f5b0 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_params_variable.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_params_variable extends SCBaseScenario { + public SC_params_variable(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * print('params["one"]=\'' + params["one"] + "'");
+     * print('params["three"]=\'' + params["three"] + "'");
+     *
+     * var overrides = {
+     *   'three': "five"
+     * };
+     *
+     * var overridden = params.withOverrides(overrides);
+     *
+     * print('overridden["three"] [overridden-three-five]=\'' + overridden["three"] + "'");
+     *
+     * var defaults = {
+     *     'four': "niner"
+     * };
+     *
+     * var defaulted = params.withDefaults(defaults);
+     *
+     * print('defaulted.get["four"] [defaulted-four-niner]=\'' + defaulted["four"] + "'");
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_readmetrics.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_readmetrics.java new file mode 100644 index 000000000..2d12ae123 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_readmetrics.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_readmetrics extends SCBaseScenario { + public SC_readmetrics(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef = {
+     *     "alias" : "testactivity",
+     *     "driver" : "diag",
+     *     "cycles" : "0..1000000000",
+     *     "threads" : "25",
+     *     "interval" : "2000",
+     *     "op" : "noop"
+     * };
+     *
+     * scenario.start(activitydef);
+     *
+     * scenario.waitMillis(500);
+     * while (metrics.testactivity.cycles_servicetime.count < 1000) {
+     *     print('waiting 10ms because cycles<10000 : ' + metrics.testactivity.cycles_servicetime.count);
+     *     scenario.waitMillis(10);
+     *
+     * }
+     * scenario.stop(activitydef);
+     * print("count: " + metrics.testactivity.cycles_servicetime.count);
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_speedcheck.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_speedcheck.java new file mode 100644 index 000000000..4d1e2ced1 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_speedcheck.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_speedcheck extends SCBaseScenario { + public SC_speedcheck(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef = {
+     *     "alias" : "speedcheck",
+     *     "driver" : "diag",
+     *     "cycles" : "50000",
+     *     "threads" : "20",
+     *     "interval" : "2000",
+     *     "targetrate" : "10000.0",
+     *     "op": "noop"
+     * };
+     *
+     * print("running 5E5 cycles at 1E5 cps ~~ 5 seconds worth");
+     * scenario.start(activitydef);
+     *
+     * while (scenario.isRunningActivity(activitydef)) {
+     *     achievedRate = metrics.speedcheck.cycles.servicetime.meanRate;
+     *     currentCycle = metrics.speedcheck.cycles.servicetime.count;
+     *     print("currentCycle = " + currentCycle + ", mean rate = " + achievedRate);
+     *     scenario.waitMillis(1000);
+     * }
+     *
+     * achievedRate = metrics.speedcheck.cycles.servicetime.meanRate;
+     * currentCycle = metrics.speedcheck.cycles.servicetime.count;
+     * print("last update - currentCycle = " + currentCycle + ", mean rate = " + achievedRate);
+     *
+     *
+     * scenario.stop(activitydef);
+     * //print('stopped scenario');
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_start_stop_diag.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_start_stop_diag.java new file mode 100644 index 000000000..c0f00fc30 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_start_stop_diag.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +import java.util.Map; + +public class SC_start_stop_diag extends SCBaseScenario { + public SC_start_stop_diag(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     *
+     * activitydef = {
+     *     "alias" : "teststartstopdiag",
+     *     "driver" : "diag",
+     *     "cycles" : "0..1000000000",
+     *     "threads" : "5",
+     *     "interval" : "2000",
+     *     "op" : "noop",
+     *     "rate" : "5"
+     * };
+     *
+     * print('starting activity teststartstopdiag');
+     * scenario.start(activitydef);
+     *
+     * print('waiting 500 ms');
+     * scenario.waitMillis(500);
+     *
+     * print('waited, stopping activity teststartstopdiag');
+     * scenario.stop(activitydef);
+     *
+     * print('stopped activity teststartstopdiag');
+     *
+     * }
+ */ + @Override + public void invoke() { + + var activitydef = Map.of( + "alias" , "teststartstopdiag", + "driver" , "diag", + "cycles" , "0..1000000000", + "threads" , "5", + "interval" , "2000", + "op" , "noop", + "rate" , "5"); + + stdout.println("starting activity teststartstopdiag"); + controller.start(activitydef); + + stdout.println("waiting 500 ms"); + controller.waitMillis(500); + + stdout.println("waited, stopping activity teststartstopdiag"); + controller.stop(activitydef); + + stdout.println("stopped activity teststartstopdiag"); + + } +} diff --git a/nbr-examples/src/test/resources/scripts/examples/extensions.js b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_template.java similarity index 55% rename from nbr-examples/src/test/resources/scripts/examples/extensions.js rename to nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_template.java index 2b087b431..6917c9c5e 100644 --- a/nbr-examples/src/test/resources/scripts/examples/extensions.js +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_template.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 nosqlbench + * Copyright (c) 2023 nosqlbench * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,5 +14,22 @@ * limitations under the License. */ -var sum= adder.getSum(12,34); -print('sum is ' + sum); +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_template extends SCBaseScenario { + public SC_template(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     *
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_threadchange.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_threadchange.java new file mode 100644 index 000000000..df3e49b3f --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_threadchange.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_threadchange extends SCBaseScenario { + public SC_threadchange(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * scenario.start("driver=diag;alias=threadchange;cycles=0..60000;threads=1;interval=2000;op='noop';rate=1000");
+     * activities.threadchange.threads=1;
+     * print("threads now " + activities.threadchange.threads);
+     * print('waiting 500 ms');
+     * scenario.waitMillis(500);
+     *
+     * activities.threadchange.threads=5;
+     * print("threads now " + activities.threadchange.threads);
+     * scenario.stop('threadchange');
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_threadspeeds.java b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_threadspeeds.java new file mode 100644 index 000000000..5a2b79aa9 --- /dev/null +++ b/nbr-examples/src/test/java/io/nosqlbench/nbr/examples/injava/SC_threadspeeds.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.nbr.examples.injava; + +import io.nosqlbench.components.NBComponent; +import io.nosqlbench.nbr.examples.SCBaseScenario; + +public class SC_threadspeeds extends SCBaseScenario { + public SC_threadspeeds(NBComponent parentComponent, String scenarioName) { + super(parentComponent, scenarioName); + } + + /**
{@code
+     * activitydef = {
+     *     "alias" : "threadspeeds",
+     *     "driver" : "diag",
+     *     "cycles" : "0..4000000000000",
+     *     "threads" : "1",
+     *     "interval" : "10000",
+     *     "targetrate" : "1000000",
+     *     "op": "noop"
+     * };
+     * scenario.start(activitydef);
+     *
+     * var speeds = [];
+     * var latencies = [];
+     *
+     * function aTestCycle(threads, index) {
+     *     activities.threadspeeds.threads = threads; // dynamically adjust the active threads for this activity
+     *     scenario.waitMillis(60000);                // wait for 1 minute to get a clean 1 minute average speed
+     * //     scenario.waitMillis(5000);                // wait for 1 minute to get a clean 1 minute average speed
+     *     speeds[threads]= metrics.threadspeeds.cycles.oneMinuteRate; // record 1 minute avg speed
+     *     print("speeds:" + speeds.toString());
+     *
+     * }
+     *
+     * var min=1;
+     * var max=256;
+     * var mid=Math.floor((min+max)/2)|0;
+     *
+     * [min,mid,max].forEach(aTestCycle);
+     *
+     * while (min{@code
+     * print("params from command line:");
+     * print(params);
+     * print('before: params["three"]:' + params["three"]);
+     * print('before: params.three:' + params.three);
+     *
+     * var overrides = {
+     *   'three': "undef",
+     * };
+     *
+     * print("params.three after overriding with three:UNDEF");
+     * params = params.withOverrides({'three':'UNDEF'});
+     * print(params);
+     * print('after: params["three"]:' + params["three"]);
+     * print('after: params.three:' + params.three);
+     * }
+ */ + @Override + public void invoke() { + + } +} diff --git a/nbr-examples/src/test/resources/scripts/examples/awaitfinished.js b/nbr-examples/src/test/resources/scripts/examples/await_finished.js similarity index 100% rename from nbr-examples/src/test/resources/scripts/examples/awaitfinished.js rename to nbr-examples/src/test/resources/scripts/examples/await_finished.js diff --git a/pom.xml b/pom.xml index 2b82c4774..399e8f983 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ nbr nb-spectest - nbr-examples + adapter-diag @@ -85,7 +85,7 @@ nb5-proof nb5 nbr - nbr-examples + nb-api nb-annotations nb-spectest @@ -165,16 +165,6 @@ - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 3.4.5 - - - - Jonathan Shook