Search in sources :

Example 1 with IEvent

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);
}
Also used : StringWriter(java.io.StringWriter) IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) IStreamEvent(com.carrotsearch.ant.tasks.junit4.events.IStreamEvent) FailureEvent(com.carrotsearch.ant.tasks.junit4.events.FailureEvent) Charset(java.nio.charset.Charset) IOException(java.io.IOException) WriterOutputStream(com.carrotsearch.randomizedtesting.WriterOutputStream)

Example 2 with IEvent

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);
        }
    }
}
Also used : IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) IStreamEvent(com.carrotsearch.ant.tasks.junit4.events.IStreamEvent) Deserializer(com.carrotsearch.ant.tasks.junit4.events.Deserializer) BootstrapEvent(com.carrotsearch.ant.tasks.junit4.events.BootstrapEvent) OutputStreamWriter(java.io.OutputStreamWriter)

Example 3 with IEvent

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();
}
Also used : IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) IStreamEvent(com.carrotsearch.ant.tasks.junit4.events.IStreamEvent) WriterOutputStream(com.carrotsearch.randomizedtesting.WriterOutputStream)

Example 4 with IEvent

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()));
}
Also used : AppendStdErrEvent(com.carrotsearch.ant.tasks.junit4.events.AppendStdErrEvent) IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) Deserializer(com.carrotsearch.ant.tasks.junit4.events.Deserializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Serializer(com.carrotsearch.ant.tasks.junit4.events.Serializer)

Example 5 with IEvent

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();
    }
}
Also used : AggregatedTestResultEvent(com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent) IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) TestFinishedEvent(com.carrotsearch.ant.tasks.junit4.events.TestFinishedEvent) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

IEvent (com.carrotsearch.ant.tasks.junit4.events.IEvent)5 IStreamEvent (com.carrotsearch.ant.tasks.junit4.events.IStreamEvent)3 Deserializer (com.carrotsearch.ant.tasks.junit4.events.Deserializer)2 WriterOutputStream (com.carrotsearch.randomizedtesting.WriterOutputStream)2 AppendStdErrEvent (com.carrotsearch.ant.tasks.junit4.events.AppendStdErrEvent)1 BootstrapEvent (com.carrotsearch.ant.tasks.junit4.events.BootstrapEvent)1 FailureEvent (com.carrotsearch.ant.tasks.junit4.events.FailureEvent)1 Serializer (com.carrotsearch.ant.tasks.junit4.events.Serializer)1 TestFinishedEvent (com.carrotsearch.ant.tasks.junit4.events.TestFinishedEvent)1 AggregatedTestResultEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent)1 JsonToken (com.carrotsearch.ant.tasks.junit4.gson.stream.JsonToken)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 Charset (java.nio.charset.Charset)1 IdentityHashMap (java.util.IdentityHashMap)1