use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommand.
@Test
public void testReceiveCommand() throws Exception {
Path argsPath = Paths.get("args");
Path stdoutPath = Paths.get("out");
Path stderrPath = Paths.get("err");
int messageId = 123;
JsonReader jsonReader = createMockJsonReaderForReceiveCommand(messageId, "command", argsPath.toString(), stdoutPath.toString(), stderrPath.toString());
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
WorkerProcessCommand command = protocol.receiveCommand(messageId);
assertThat(command.getArgsPath(), Matchers.equalToObject(argsPath));
assertThat(command.getStdOutPath(), Matchers.equalToObject(stdoutPath));
assertThat(command.getStdErrPath(), Matchers.equalToObject(stderrPath));
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommandResponse.
@Test
public void testReceiveCommandResponse() throws IOException {
int messageID = 123;
JsonReader jsonReader = createMockJsonReaderForReceiveCommandResponse(messageID, "result", 0);
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
protocol.receiveCommandResponse(messageID);
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommandResponseWithIncorrectMessageID.
@Test
public void testReceiveCommandResponseWithIncorrectMessageID() throws IOException {
int messageID = 123;
int differentMessageID = 456;
JsonReader jsonReader = createMockJsonReaderForReceiveCommandResponse(differentMessageID, "result", 0);
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
try {
protocol.receiveCommandResponse(messageID);
} catch (HumanReadableException e) {
assertThat(e.getMessage(), Matchers.containsString(String.format("Expected response's \"id\" value to be \"%d\"", messageID)));
}
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommandWithMalformedJSON.
@Test
public void testReceiveCommandWithMalformedJSON() throws IOException {
String malformedJson = "><(((('> blub";
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, new JsonReader(new StringReader(malformedJson)), newTempFile());
try {
protocol.receiveCommand(123);
} catch (HumanReadableException e) {
assertThat(e.getMessage(), Matchers.containsString("Error receiving command from external process"));
}
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveHandshakeWithIncorrectProtocolVersion.
@Test
public void testReceiveHandshakeWithIncorrectProtocolVersion() throws IOException {
int handshakeID = 123;
JsonReader jsonReader = createMockJsonReaderForReceiveHandshake(handshakeID, "handshake", "BAD PROTOCOL VERSION");
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
try {
protocol.receiveHandshake(handshakeID);
} catch (HumanReadableException e) {
assertThat(e.getMessage(), Matchers.containsString("Expected handshake response's \"protocol_version\" to be \"0\""));
}
}
Aggregations