use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveHandshakeWithIncorrectID.
@Test
public void testReceiveHandshakeWithIncorrectID() throws IOException {
int handshakeID = 123;
int differentHandshakeID = 456;
JsonReader jsonReader = createMockJsonReaderForReceiveHandshake(differentHandshakeID, "handshake", "0");
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
try {
protocol.receiveHandshake(handshakeID);
} catch (HumanReadableException e) {
assertThat(e.getMessage(), Matchers.containsString(String.format("Expected handshake response's \"id\" value to be \"%d\"", handshakeID)));
}
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommandResponseWithInvalidType.
@Test
public void testReceiveCommandResponseWithInvalidType() throws IOException {
int messageID = 123;
JsonReader jsonReader = createMockJsonReaderForReceiveCommandResponse(messageID, "INVALID RESPONSE TYPE", 0);
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
try {
protocol.receiveCommandResponse(messageID);
} catch (HumanReadableException e) {
assertThat(e.getMessage(), Matchers.containsString("Expected response's \"type\" to be one of"));
}
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveHandshake.
@Test
public void testReceiveHandshake() throws IOException {
int handshakeID = 123;
JsonReader jsonReader = createMockJsonReaderForReceiveHandshake(handshakeID, "handshake", "0");
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
protocol.receiveHandshake(handshakeID);
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommandWithInvalidType.
@Test
public void testReceiveCommandWithInvalidType() throws IOException {
int messageID = 123;
JsonReader jsonReader = createMockJsonReaderForReceiveCommand(messageID, "INVALID RESPONSE TYPE", "/path/to/args", "/path/to/stdout", "/path/to/stderr");
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
try {
protocol.receiveCommand(messageID);
} catch (HumanReadableException e) {
assertThat(e.getMessage(), Matchers.containsString("Expected command's \"type\" to be \"command\""));
}
}
use of com.google.gson.stream.JsonReader in project Minechem by iopleke.
the class ElementHandler method readFromStream.
private static void readFromStream(InputStream stream) {
JsonReader jReader = new JsonReader(new InputStreamReader(stream));
JsonParser parser = new JsonParser();
Set<Map.Entry<String, JsonElement>> elementsSet = parser.parse(jReader).getAsJsonObject().entrySet();
int count = 0;
for (Map.Entry<String, JsonElement> elementEntry : elementsSet) {
if (!elementEntry.getValue().isJsonObject()) {
continue;
}
JsonObject elementObject = elementEntry.getValue().getAsJsonObject();
ElementRegistry.getInstance().registerElement(Integer.parseInt(elementEntry.getKey()), elementObject.get("longName").getAsString(), elementObject.get("shortName").getAsString(), elementObject.get("form").getAsString(), elementObject.get("type").getAsString(), Integer.parseInt(elementObject.get("neutrons").getAsString()));
count++;
}
LogHelper.info("Total of " + count + " elements registered");
}
Aggregations