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();
}
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();
}
}
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);
}
}
Aggregations