mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
script env tests now working
This commit is contained in:
parent
17052eaadf
commit
65db41b22a
@ -34,8 +34,6 @@ public class NBSceneBuffer implements NBSceneFixtures {
|
||||
private DiagWriter stderrBuffer;
|
||||
private DiagReader stdinBuffer;
|
||||
|
||||
|
||||
private DiagWriter stdoutWriter;
|
||||
public NBSceneBuffer(NBSceneFixtures fixtures) {
|
||||
this.fixtures = fixtures;
|
||||
stdoutBuffer = new DiagWriter(fixtures.out(), " stdout ");
|
||||
@ -66,17 +64,17 @@ public class NBSceneBuffer implements NBSceneFixtures {
|
||||
|
||||
@Override
|
||||
public Writer out() {
|
||||
return stdoutWriter;
|
||||
return stdoutBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer err() {
|
||||
return null;
|
||||
return stderrBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader in() {
|
||||
return null;
|
||||
return stdinBuffer;
|
||||
}
|
||||
|
||||
public List<String> getTimedLogLines() {
|
||||
@ -91,4 +89,6 @@ public class NBSceneBuffer implements NBSceneFixtures {
|
||||
public String getIoLog() {
|
||||
return String.join("",getTimedLogLines());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -36,4 +36,5 @@ public interface NBSceneFixtures {
|
||||
Writer err();
|
||||
|
||||
Reader in();
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ import io.nosqlbench.components.NBComponent;
|
||||
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.NBSceneFixtures;
|
||||
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.script.NBScriptedScenario;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -44,7 +44,7 @@ import java.util.function.Function;
|
||||
* </OL>
|
||||
*/
|
||||
public abstract class NBScenario extends NBBaseComponent
|
||||
implements Function<NBSceneFixtures, ScenarioResult>, NBComponentErrorHandler {
|
||||
implements Function<NBSceneBuffer, ScenarioResult>, NBComponentErrorHandler {
|
||||
|
||||
private final String scenarioName;
|
||||
private final Map<String, String> params;
|
||||
@ -120,7 +120,7 @@ public abstract class NBScenario extends NBBaseComponent
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public final ScenarioResult apply(NBSceneFixtures sctx) {
|
||||
public final ScenarioResult apply(NBSceneBuffer sctx) {
|
||||
|
||||
this.scenarioShutdownHook = new ScenarioShutdownHook(this);
|
||||
Runtime.getRuntime().addShutdownHook(this.scenarioShutdownHook);
|
||||
@ -177,7 +177,7 @@ public abstract class NBScenario extends NBBaseComponent
|
||||
error = new RuntimeException("in thread " + t.getName() + ", " + e, e);
|
||||
}
|
||||
|
||||
protected abstract void runScenario(NBSceneFixtures sctx);
|
||||
protected abstract void runScenario(NBSceneBuffer sctx);
|
||||
|
||||
public void finish() {
|
||||
this.logger.debug("finishing scenario");
|
||||
|
@ -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.engine.core.lifecycle.scenario.script;
|
||||
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneBuffer;
|
||||
|
||||
import javax.script.SimpleScriptContext;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
|
||||
public class BufferedScriptContext extends SimpleScriptContext {
|
||||
private final NBSceneBuffer fixtures;
|
||||
|
||||
public BufferedScriptContext(NBSceneBuffer fixtures) {
|
||||
this.fixtures = fixtures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getReader() { // stdin
|
||||
return fixtures.in();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer getWriter() { // stdout
|
||||
return fixtures.out();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer getErrorWriter() { // stderr
|
||||
return fixtures.err();
|
||||
}
|
||||
|
||||
}
|
@ -22,7 +22,7 @@ import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
||||
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.NBSceneBuffer;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScriptParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario;
|
||||
import org.graalvm.polyglot.Context;
|
||||
@ -119,6 +119,11 @@ public class NBScriptedScenario extends NBScenario {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void initializeScriptContext(NBSceneBuffer fixtures) {
|
||||
BufferedScriptContext ctx = new BufferedScriptContext(fixtures);
|
||||
this.scriptEngine.setContext(ctx);
|
||||
}
|
||||
|
||||
private void initializeScriptingEngine() {
|
||||
|
||||
this.logger.debug("Using engine {}", this.engine.toString());
|
||||
@ -145,10 +150,6 @@ public class NBScriptedScenario extends NBScenario {
|
||||
// TODO: add in, out, err for this scenario
|
||||
scriptEngine = GraalJSScriptEngine.create(polyglotEngine, contextSettings);
|
||||
|
||||
|
||||
this.scriptEnv = new ScenarioScriptShell(scenarioName);
|
||||
this.scriptEngine.setContext(this.scriptEnv);
|
||||
|
||||
// NBScenarioPojoContext sctx = new NBScenarioPojoContext(
|
||||
// this.scenarioScriptParams,
|
||||
// (NBSession) this.getParent(),
|
||||
@ -163,11 +164,12 @@ public class NBScriptedScenario extends NBScenario {
|
||||
//
|
||||
}
|
||||
|
||||
protected synchronized void runScenario(NBSceneFixtures context) {
|
||||
protected synchronized void runScenario(NBSceneBuffer context) {
|
||||
if (null == result) {
|
||||
try {
|
||||
this.logger.debug("Initializing scripting engine for {}.", scenarioName);
|
||||
this.initializeScriptingEngine();
|
||||
this.initializeScriptContext(context);
|
||||
this.logger.debug("Running control script for {}.", scenarioName);
|
||||
this.executeScenarioScripts();
|
||||
} catch (final Exception e) {
|
||||
@ -175,9 +177,9 @@ public class NBScriptedScenario extends NBScenario {
|
||||
} finally {
|
||||
this.logger.debug("{} scenario run", null == this.error ? "NORMAL" : "ERRORED");
|
||||
}
|
||||
String iolog = error != null ? error.toString() : this.scriptEnv.getTimedLog();
|
||||
result = new ExecutionMetricsResult(startedAtMillis, endedAtMillis, iolog, this.error);
|
||||
this.result.reportMetricsSummaryToLog();
|
||||
// String iolog = error != null ? error.toString() : this.scriptEnv.getTimedLog();
|
||||
// result = new ExecutionMetricsResult(startedAtMillis, endedAtMillis, iolog, this.error);
|
||||
// this.result.reportMetricsSummaryToLog();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,20 +15,12 @@
|
||||
*/
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario.script;
|
||||
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.engine.api.scripting.ScriptEnvBuffer;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures;
|
||||
|
||||
public class ScenarioScriptShell extends ScriptEnvBuffer implements LabeledScenarioContext {
|
||||
public class ScenarioScriptShell extends ScriptEnvBuffer {
|
||||
|
||||
private final String contextName;
|
||||
|
||||
public ScenarioScriptShell(String contextName) {
|
||||
this.contextName = contextName;
|
||||
}
|
||||
|
||||
public String getContextName() {
|
||||
return this.contextName;
|
||||
public ScenarioScriptShell(NBSceneFixtures fixtures) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,8 +38,4 @@ public class ScenarioScriptShell extends ScriptEnvBuffer implements LabeledScena
|
||||
super.setAttribute(name, value, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBLabels getLabels() {
|
||||
return NBLabels.forKV("scenario", this.contextName);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class AttachedMetricsSummaryReporterTest {
|
||||
try (TestComponent root = new TestComponent("root", "root")) {
|
||||
|
||||
try {
|
||||
Thread.sleep(10000L);
|
||||
Thread.sleep(100L);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
logger.debug("scope ending");
|
||||
|
Loading…
Reference in New Issue
Block a user