use of com.carrotsearch.ant.tasks.junit4.events.IEvent in project randomizedtesting by randomizedtesting.
the class AggregatedSuiteResultEvent method serializeEvents.
private void serializeEvents(JsonWriter w, boolean outputStreams) throws IOException {
final Charset charset = getSlave().getCharset();
int lineBuffer = 160;
final StringWriter out = new StringWriter();
final StringWriter err = new StringWriter();
WriterOutputStream stdout = new WriterOutputStream(out, charset, lineBuffer, false);
WriterOutputStream stderr = new WriterOutputStream(err, charset, lineBuffer, false);
for (IEvent evt : getEventStream()) {
try {
switch(evt.getType()) {
case SUITE_FAILURE:
case TEST_IGNORED_ASSUMPTION:
case TEST_IGNORED:
case TEST_STARTED:
case TEST_FINISHED:
case TEST_FAILURE:
flushBoth(w, out, err, stdout, stderr);
w.beginObject();
w.name("event").value(evt.getType().toString());
w.name("description");
JsonHelpers.writeDescription(w, ((IDescribable) evt).getDescription());
if (evt instanceof FailureEvent) {
w.name("failure");
((FailureEvent) evt).serialize(w);
}
w.endObject();
break;
case APPEND_STDOUT:
if (outputStreams) {
flush(APPEND_STDERR, w, stderr, err);
((IStreamEvent) evt).copyTo(stdout);
}
break;
case APPEND_STDERR:
if (outputStreams) {
flush(APPEND_STDOUT, w, stdout, out);
((IStreamEvent) evt).copyTo(stderr);
}
break;
default:
break;
}
} catch (IOException ex) {
// Ignore.
}
}
flushBoth(w, out, err, stdout, stderr);
}
use of com.carrotsearch.ant.tasks.junit4.events.IEvent in project randomizedtesting by randomizedtesting.
the class LocalSlaveStreamHandler method pumpEvents.
/**
* Pump events from event stream.
*/
void pumpEvents(InputStream eventStream) {
try {
Deserializer deserializer = new Deserializer(eventStream, refLoader);
IEvent event = null;
while ((event = deserializer.deserialize()) != null) {
switch(event.getType()) {
case APPEND_STDERR:
case APPEND_STDOUT:
// Ignore these two on activity heartbeats. GH-117
break;
default:
lastActivity = System.currentTimeMillis();
break;
}
try {
switch(event.getType()) {
case QUIT:
eventBus.post(event);
return;
case IDLE:
eventBus.post(new SlaveIdle(stdinWriter));
break;
case BOOTSTRAP:
clientCharset = Charset.forName(((BootstrapEvent) event).getDefaultCharsetName());
stdinWriter = new OutputStreamWriter(stdin, clientCharset);
eventBus.post(event);
break;
case APPEND_STDERR:
case APPEND_STDOUT:
assert streamsBuffer.getFilePointer() == streamsBuffer.length();
final long bufferStart = streamsBuffer.getFilePointer();
IStreamEvent streamEvent = (IStreamEvent) event;
streamEvent.copyTo(streamsBufferWrapper);
final long bufferEnd = streamsBuffer.getFilePointer();
event = new OnDiskStreamEvent(event.getType(), streamsBuffer, bufferStart, bufferEnd);
eventBus.post(event);
break;
default:
eventBus.post(event);
}
} catch (Throwable t) {
warnStream.println("Event bus dispatch error: " + t.toString());
t.printStackTrace(warnStream);
}
}
lastActivity = null;
} catch (Throwable e) {
if (!stopping) {
warnStream.println("Event stream error: " + e.toString());
e.printStackTrace(warnStream);
}
}
}
use of com.carrotsearch.ant.tasks.junit4.events.IEvent in project randomizedtesting by randomizedtesting.
the class ForkedJvmInfo method decodeStreams.
/**
* Filter through events looking for sysouts and syserrs and decode them
* into a character streams. If both {@link Writer} arguments are the same object
* the streams will be combined.
*/
public void decodeStreams(List<IEvent> events, Writer sysout, Writer syserr) throws IOException {
int lineBuffer = 160;
WriterOutputStream stdout = new WriterOutputStream(sysout, getCharset(), lineBuffer, true);
WriterOutputStream stderr = new WriterOutputStream(syserr, getCharset(), lineBuffer, true);
for (IEvent evt : events) {
switch(evt.getType()) {
case APPEND_STDOUT:
if (sysout != null) {
((IStreamEvent) evt).copyTo(stdout);
}
break;
case APPEND_STDERR:
if (syserr != null) {
((IStreamEvent) evt).copyTo(stderr);
}
break;
default:
break;
}
}
stdout.flush();
stderr.flush();
}
use of com.carrotsearch.ant.tasks.junit4.events.IEvent in project randomizedtesting by randomizedtesting.
the class TestJsonByteArrayRoundtrip method check.
private void check(byte[] bytes) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Serializer s = new Serializer(baos);
s.serialize(new AppendStdErrEvent(bytes, 0, bytes.length));
s.flush();
s.close();
Deserializer deserializer = new Deserializer(new ByteArrayInputStream(baos.toByteArray()), Thread.currentThread().getContextClassLoader());
IEvent deserialize = deserializer.deserialize();
Assert.assertTrue(deserialize instanceof AppendStdErrEvent);
AppendStdErrEvent e = ((AppendStdErrEvent) deserialize);
baos.reset();
e.copyTo(baos);
Assert.assertTrue("Exp: " + Arrays.toString(bytes) + "\n" + "was: " + Arrays.toString(baos.toByteArray()), Arrays.equals(bytes, baos.toByteArray()));
}
use of com.carrotsearch.ant.tasks.junit4.events.IEvent in project randomizedtesting by randomizedtesting.
the class TextReport method emitBufferedEvents.
private void emitBufferedEvents(AggregatedSuiteResultEvent e) throws IOException {
final IdentityHashMap<TestFinishedEvent, AggregatedTestResultEvent> eventMap = new IdentityHashMap<>();
for (AggregatedTestResultEvent tre : e.getTests()) {
eventMap.put(tre.getTestFinishedEvent(), tre);
}
final boolean emitOutput = (outputMode != OutputMode.NEVER) && ((outputMode == OutputMode.ALWAYS && !isPassthrough()) || (outputMode == OutputMode.ONERROR && !e.isSuccessful()));
for (IEvent event : e.getEventStream()) {
switch(event.getType()) {
case APPEND_STDOUT:
if (emitOutput)
((IStreamEvent) event).copyTo(outStream);
break;
case APPEND_STDERR:
if (emitOutput)
((IStreamEvent) event).copyTo(errStream);
break;
case TEST_FINISHED:
assert eventMap.containsKey(event);
final AggregatedTestResultEvent aggregated = eventMap.get(event);
if (displayStatus.get(aggregated.getStatus())) {
flushOutput();
emitStatusLine(aggregated, aggregated.getStatus(), aggregated.getExecutionTime());
}
default:
break;
}
}
if (emitOutput) {
flushOutput();
}
}
Aggregations