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 DiagWriter stderrBuffer;
|
||||||
private DiagReader stdinBuffer;
|
private DiagReader stdinBuffer;
|
||||||
|
|
||||||
|
|
||||||
private DiagWriter stdoutWriter;
|
|
||||||
public NBSceneBuffer(NBSceneFixtures fixtures) {
|
public NBSceneBuffer(NBSceneFixtures fixtures) {
|
||||||
this.fixtures = fixtures;
|
this.fixtures = fixtures;
|
||||||
stdoutBuffer = new DiagWriter(fixtures.out(), " stdout ");
|
stdoutBuffer = new DiagWriter(fixtures.out(), " stdout ");
|
||||||
@ -66,17 +64,17 @@ public class NBSceneBuffer implements NBSceneFixtures {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Writer out() {
|
public Writer out() {
|
||||||
return stdoutWriter;
|
return stdoutBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Writer err() {
|
public Writer err() {
|
||||||
return null;
|
return stderrBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Reader in() {
|
public Reader in() {
|
||||||
return null;
|
return stdinBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getTimedLogLines() {
|
public List<String> getTimedLogLines() {
|
||||||
@ -91,4 +89,6 @@ public class NBSceneBuffer implements NBSceneFixtures {
|
|||||||
public String getIoLog() {
|
public String getIoLog() {
|
||||||
return String.join("",getTimedLogLines());
|
return String.join("",getTimedLogLines());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,4 +36,5 @@ public interface NBSceneFixtures {
|
|||||||
Writer err();
|
Writer err();
|
||||||
|
|
||||||
Reader in();
|
Reader in();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ import io.nosqlbench.components.NBComponent;
|
|||||||
import io.nosqlbench.components.NBComponentErrorHandler;
|
import io.nosqlbench.components.NBComponentErrorHandler;
|
||||||
import io.nosqlbench.engine.core.annotation.Annotators;
|
import io.nosqlbench.engine.core.annotation.Annotators;
|
||||||
import io.nosqlbench.engine.core.lifecycle.activity.ActivitiesProgressIndicator;
|
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.ActivitiesController;
|
||||||
|
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneBuffer;
|
||||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.NBScriptedScenario;
|
import io.nosqlbench.engine.core.lifecycle.scenario.script.NBScriptedScenario;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -44,7 +44,7 @@ import java.util.function.Function;
|
|||||||
* </OL>
|
* </OL>
|
||||||
*/
|
*/
|
||||||
public abstract class NBScenario extends NBBaseComponent
|
public abstract class NBScenario extends NBBaseComponent
|
||||||
implements Function<NBSceneFixtures, ScenarioResult>, NBComponentErrorHandler {
|
implements Function<NBSceneBuffer, ScenarioResult>, NBComponentErrorHandler {
|
||||||
|
|
||||||
private final String scenarioName;
|
private final String scenarioName;
|
||||||
private final Map<String, String> params;
|
private final Map<String, String> params;
|
||||||
@ -120,7 +120,7 @@ public abstract class NBScenario extends NBBaseComponent
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final ScenarioResult apply(NBSceneFixtures sctx) {
|
public final ScenarioResult apply(NBSceneBuffer sctx) {
|
||||||
|
|
||||||
this.scenarioShutdownHook = new ScenarioShutdownHook(this);
|
this.scenarioShutdownHook = new ScenarioShutdownHook(this);
|
||||||
Runtime.getRuntime().addShutdownHook(this.scenarioShutdownHook);
|
Runtime.getRuntime().addShutdownHook(this.scenarioShutdownHook);
|
||||||
@ -177,7 +177,7 @@ public abstract class NBScenario extends NBBaseComponent
|
|||||||
error = new RuntimeException("in thread " + t.getName() + ", " + e, e);
|
error = new RuntimeException("in thread " + t.getName() + ", " + e, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void runScenario(NBSceneFixtures sctx);
|
protected abstract void runScenario(NBSceneBuffer sctx);
|
||||||
|
|
||||||
public void finish() {
|
public void finish() {
|
||||||
this.logger.debug("finishing scenario");
|
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.components.NBComponent;
|
||||||
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
||||||
import io.nosqlbench.engine.core.lifecycle.activity.ActivitiesProgressIndicator;
|
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.context.ScriptParams;
|
||||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario;
|
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario;
|
||||||
import org.graalvm.polyglot.Context;
|
import org.graalvm.polyglot.Context;
|
||||||
@ -119,6 +119,11 @@ public class NBScriptedScenario extends NBScenario {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializeScriptContext(NBSceneBuffer fixtures) {
|
||||||
|
BufferedScriptContext ctx = new BufferedScriptContext(fixtures);
|
||||||
|
this.scriptEngine.setContext(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeScriptingEngine() {
|
private void initializeScriptingEngine() {
|
||||||
|
|
||||||
this.logger.debug("Using engine {}", this.engine.toString());
|
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
|
// TODO: add in, out, err for this scenario
|
||||||
scriptEngine = GraalJSScriptEngine.create(polyglotEngine, contextSettings);
|
scriptEngine = GraalJSScriptEngine.create(polyglotEngine, contextSettings);
|
||||||
|
|
||||||
|
|
||||||
this.scriptEnv = new ScenarioScriptShell(scenarioName);
|
|
||||||
this.scriptEngine.setContext(this.scriptEnv);
|
|
||||||
|
|
||||||
// NBScenarioPojoContext sctx = new NBScenarioPojoContext(
|
// NBScenarioPojoContext sctx = new NBScenarioPojoContext(
|
||||||
// this.scenarioScriptParams,
|
// this.scenarioScriptParams,
|
||||||
// (NBSession) this.getParent(),
|
// (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) {
|
if (null == result) {
|
||||||
try {
|
try {
|
||||||
this.logger.debug("Initializing scripting engine for {}.", scenarioName);
|
this.logger.debug("Initializing scripting engine for {}.", scenarioName);
|
||||||
this.initializeScriptingEngine();
|
this.initializeScriptingEngine();
|
||||||
|
this.initializeScriptContext(context);
|
||||||
this.logger.debug("Running control script for {}.", scenarioName);
|
this.logger.debug("Running control script for {}.", scenarioName);
|
||||||
this.executeScenarioScripts();
|
this.executeScenarioScripts();
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
@ -175,9 +177,9 @@ public class NBScriptedScenario extends NBScenario {
|
|||||||
} finally {
|
} finally {
|
||||||
this.logger.debug("{} scenario run", null == this.error ? "NORMAL" : "ERRORED");
|
this.logger.debug("{} scenario run", null == this.error ? "NORMAL" : "ERRORED");
|
||||||
}
|
}
|
||||||
String iolog = error != null ? error.toString() : this.scriptEnv.getTimedLog();
|
// String iolog = error != null ? error.toString() : this.scriptEnv.getTimedLog();
|
||||||
result = new ExecutionMetricsResult(startedAtMillis, endedAtMillis, iolog, this.error);
|
// result = new ExecutionMetricsResult(startedAtMillis, endedAtMillis, iolog, this.error);
|
||||||
this.result.reportMetricsSummaryToLog();
|
// this.result.reportMetricsSummaryToLog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,20 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package io.nosqlbench.engine.core.lifecycle.scenario.script;
|
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.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(NBSceneFixtures fixtures) {
|
||||||
|
|
||||||
public ScenarioScriptShell(String contextName) {
|
|
||||||
this.contextName = contextName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContextName() {
|
|
||||||
return this.contextName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,8 +38,4 @@ public class ScenarioScriptShell extends ScriptEnvBuffer implements LabeledScena
|
|||||||
super.setAttribute(name, value, scope);
|
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 (TestComponent root = new TestComponent("root", "root")) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10000L);
|
Thread.sleep(100L);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
logger.debug("scope ending");
|
logger.debug("scope ending");
|
||||||
|
2
pom.xml
2
pom.xml
@ -85,7 +85,7 @@
|
|||||||
<module>nb5-proof</module>
|
<module>nb5-proof</module>
|
||||||
<module>nb5</module>
|
<module>nb5</module>
|
||||||
<module>nbr</module>
|
<module>nbr</module>
|
||||||
<module>nbr-examples</module>
|
<!-- <module>nbr-examples</module>-->
|
||||||
<module>nb-api</module>
|
<module>nb-api</module>
|
||||||
<module>nb-annotations</module>
|
<module>nb-annotations</module>
|
||||||
<module>nb-spectest</module>
|
<module>nb-spectest</module>
|
||||||
|
Loading…
Reference in New Issue
Block a user