Search in sources :

Example 1 with WriterOutputStream

use of com.carrotsearch.randomizedtesting.WriterOutputStream 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 WriterOutputStream

use of com.carrotsearch.randomizedtesting.WriterOutputStream 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 3 with WriterOutputStream

use of com.carrotsearch.randomizedtesting.WriterOutputStream in project randomizedtesting by randomizedtesting.

the class TextReport method onSuiteStart.

@Subscribe
public void onSuiteStart(AggregatedSuiteStartedEvent e) throws IOException {
    final Charset charset = e.getSlave().getCharset();
    outStream = new WriterOutputStream(outWriter, charset, DEFAULT_MAX_LINE_WIDTH, true);
    errStream = new WriterOutputStream(errWriter, charset, DEFAULT_MAX_LINE_WIDTH, true);
    if (showSuiteSummary && isPassthrough()) {
        SuiteStartedEvent evt = e.getSuiteStartedEvent();
        emitSuiteStart(evt.getDescription(), evt.getStartTimestamp());
    }
}
Also used : SuiteStartedEvent(com.carrotsearch.ant.tasks.junit4.events.SuiteStartedEvent) AggregatedSuiteStartedEvent(com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedSuiteStartedEvent) Charset(java.nio.charset.Charset) WriterOutputStream(com.carrotsearch.randomizedtesting.WriterOutputStream) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

WriterOutputStream (com.carrotsearch.randomizedtesting.WriterOutputStream)3 IEvent (com.carrotsearch.ant.tasks.junit4.events.IEvent)2 IStreamEvent (com.carrotsearch.ant.tasks.junit4.events.IStreamEvent)2 Charset (java.nio.charset.Charset)2 FailureEvent (com.carrotsearch.ant.tasks.junit4.events.FailureEvent)1 SuiteStartedEvent (com.carrotsearch.ant.tasks.junit4.events.SuiteStartedEvent)1 AggregatedSuiteStartedEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedSuiteStartedEvent)1 Subscribe (com.google.common.eventbus.Subscribe)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1