mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
rework scenario invocation for better tests, unit test running only
This commit is contained in:
@@ -16,11 +16,8 @@
|
||||
package io.nosqlbench.engine.api.scripting;
|
||||
|
||||
import javax.script.SimpleScriptContext;
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -92,9 +89,9 @@ public class ScriptEnvBuffer extends SimpleScriptContext {
|
||||
|
||||
public List<String> getTimeLogLines() {
|
||||
List<String> log = new ArrayList<String>();
|
||||
Optional.ofNullable(this.stdinBuffer).map(t->t.timedLog).ifPresent(log::addAll);
|
||||
Optional.ofNullable(this.stderrBuffer).map(t->t.timedLog).ifPresent(log::addAll);
|
||||
Optional.ofNullable(this.stdoutBuffer).map(t->t.timedLog).ifPresent(log::addAll);
|
||||
Optional.ofNullable(this.stdinBuffer).map(DiagReader::getTimedLog).ifPresent(log::addAll);
|
||||
Optional.ofNullable(this.stderrBuffer).map(DiagWriter::getTimedLog).ifPresent(log::addAll);
|
||||
Optional.ofNullable(this.stdoutBuffer).map(DiagWriter::getTimedLog).ifPresent(log::addAll);
|
||||
log = log.stream().map(l -> l.endsWith("\n") ? l : l+"\n").collect(Collectors.toList());
|
||||
return log;
|
||||
}
|
||||
@@ -102,87 +99,4 @@ public class ScriptEnvBuffer extends SimpleScriptContext {
|
||||
return getTimeLogLines().stream().collect(Collectors.joining());
|
||||
}
|
||||
|
||||
private class DiagReader extends Reader {
|
||||
Reader wrapped;
|
||||
private final String prefix;
|
||||
CharArrayWriter buffer = new CharArrayWriter(0);
|
||||
private final List<String> timedLog = new ArrayList<String>();
|
||||
|
||||
|
||||
public DiagReader(Reader wrapped, String prefix) {
|
||||
this.wrapped = wrapped; this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(char[] cbuf, int off, int len) throws IOException {
|
||||
String tsprefix = LocalDateTime.now().format(tsformat);
|
||||
|
||||
int read = wrapped.read(cbuf, off, len);
|
||||
buffer.write(cbuf, off, len);
|
||||
|
||||
timedLog.add(tsprefix + prefix + new String(cbuf, off, len));
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
wrapped.close();
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class DiagWriter extends Writer {
|
||||
|
||||
Writer wrapped;
|
||||
private final String prefix;
|
||||
CharArrayWriter buffer = new CharArrayWriter();
|
||||
private final List<String> timedLog = new ArrayList<String>();
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
|
||||
public DiagWriter(Writer wrapped, String prefix) {
|
||||
this.wrapped = wrapped;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(char[] cbuf, int off, int len) throws IOException {
|
||||
String tsprefix = LocalDateTime.now().format(tsformat);
|
||||
|
||||
buffer.write(cbuf, off, len);
|
||||
String text = new String(cbuf, off, len);
|
||||
|
||||
sb.append(text);
|
||||
|
||||
if (text.contains("\n")) {
|
||||
String msgs = sb.toString();
|
||||
String extra = msgs.substring(msgs.lastIndexOf("\n")+1);
|
||||
sb.setLength(0);
|
||||
sb.append(extra);
|
||||
String[] parts = msgs.substring(0,msgs.length()-extra.length()).split("\n");
|
||||
for (String part : parts) {
|
||||
if (!part.isBlank()) {
|
||||
String tslogEntry = tsprefix + prefix + part + "\n";
|
||||
timedLog.add(tslogEntry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wrapped.write(cbuf, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
buffer.flush();
|
||||
wrapped.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
buffer.close();
|
||||
wrapped.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user