Search in sources :

Example 1 with JsonReader

use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonReader in project randomizedtesting by randomizedtesting.

the class FailureEvent method deserialize.

@Override
public void deserialize(JsonReader reader) throws IOException {
    reader.beginObject();
    expectProperty(reader, "description");
    Description description = JsonHelpers.readDescription(reader);
    String message = readStringOrNullProperty(reader, "message");
    String trace = readStringOrNullProperty(reader, "trace");
    String throwableString = readStringOrNullProperty(reader, "throwableString");
    String throwableClass = readStringOrNullProperty(reader, "throwableClass");
    boolean assertionViolation = readBoolean(reader, "assertionViolation");
    boolean assumptionViolation = readBoolean(reader, "assumptionViolation");
    this.failure = new FailureMirror(description, message, trace, throwableString, throwableClass, assertionViolation, assumptionViolation);
    reader.endObject();
}
Also used : Description(org.junit.runner.Description) FailureMirror(com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror)

Example 2 with JsonReader

use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonReader in project randomizedtesting by randomizedtesting.

the class DumpStreamsFromEventStream method main.

public static void main(String[] args) throws Exception {
    File inputFile;
    if (args.length != 1) {
        System.err.println("Usage: [input.events]");
        System.exit(1);
        return;
    } else {
        inputFile = new File(args[0]);
    }
    Closer closer = Closer.create();
    try {
        OutputStream sysout = new BufferedOutputStream(new FileOutputStream(new File(inputFile.getAbsolutePath() + ".sysout")));
        closer.register(sysout);
        OutputStream syserr = new BufferedOutputStream(new FileOutputStream(new File(inputFile.getAbsolutePath() + ".syserr")));
        closer.register(syserr);
        InputStream is = new BufferedInputStream(new FileInputStream(inputFile));
        closer.register(is);
        JsonReader input = new JsonReader(new InputStreamReader(is, Charsets.UTF_8));
        input.setLenient(true);
        JsonToken peek;
        while (true) {
            peek = input.peek();
            if (peek == JsonToken.END_DOCUMENT) {
                return;
            }
            input.beginArray();
            EventType type = EventType.valueOf(input.nextString());
            switch(type) {
                case APPEND_STDERR:
                    IStreamEvent.class.cast(type.deserialize(input)).copyTo(syserr);
                    break;
                case APPEND_STDOUT:
                    IStreamEvent.class.cast(type.deserialize(input)).copyTo(sysout);
                    break;
                default:
                    input.skipValue();
            }
            input.endArray();
        }
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) InputStreamReader(java.io.InputStreamReader) EventType(com.carrotsearch.ant.tasks.junit4.events.EventType) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileInputStream(java.io.FileInputStream) IStreamEvent(com.carrotsearch.ant.tasks.junit4.events.IStreamEvent) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) JsonReader(com.carrotsearch.ant.tasks.junit4.gson.stream.JsonReader) JsonToken(com.carrotsearch.ant.tasks.junit4.gson.stream.JsonToken) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with JsonReader

use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonReader in project randomizedtesting by randomizedtesting.

the class TestRemoteEventSerialization method checkRoundtrip.

private void checkRoundtrip(RemoteEvent event) throws IOException {
    StringWriter sw = new StringWriter();
    final boolean lenient = randomBoolean();
    JsonWriter jw = new JsonWriter(sw);
    jw.setIndent("  ");
    jw.setLenient(lenient);
    event.serialize(jw);
    jw.close();
    String serialized1 = sw.toString();
    JsonReader jr = new JsonReader(new StringReader(serialized1));
    jr.setLenient(lenient);
    RemoteEvent deserialized = event.getType().deserialize(jr);
    // If we serialize again, the contents should be identical.
    sw.getBuffer().setLength(0);
    jw = new JsonWriter(sw);
    jw.setIndent("  ");
    jw.setLenient(lenient);
    deserialized.serialize(jw);
    jw.close();
    String serialized2 = sw.toString();
    if (!serialized2.equals(serialized1)) {
        fail("Roundtrip serialization failed:\n1: " + serialized1 + "\n2: " + serialized2);
    }
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JsonReader(com.carrotsearch.ant.tasks.junit4.gson.stream.JsonReader) JsonWriter(com.carrotsearch.ant.tasks.junit4.gson.stream.JsonWriter)

Aggregations

JsonReader (com.carrotsearch.ant.tasks.junit4.gson.stream.JsonReader)2 EventType (com.carrotsearch.ant.tasks.junit4.events.EventType)1 IStreamEvent (com.carrotsearch.ant.tasks.junit4.events.IStreamEvent)1 FailureMirror (com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror)1 JsonToken (com.carrotsearch.ant.tasks.junit4.gson.stream.JsonToken)1 JsonWriter (com.carrotsearch.ant.tasks.junit4.gson.stream.JsonWriter)1 Closer (com.google.common.io.Closer)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Description (org.junit.runner.Description)1