use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommandWithIncorrectMessageID.
@Test
public void testReceiveCommandWithIncorrectMessageID() throws IOException {
int messageID = 123;
int differentMessageID = 456;
JsonReader jsonReader = createMockJsonReaderForReceiveCommand(differentMessageID, "command", "/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(String.format("Expected command's \"id\" value to be \"%d\"", messageID)));
}
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveCommandResponseWithMalformedJSON.
@Test
public void testReceiveCommandResponseWithMalformedJSON() throws IOException {
String malformedJson = "><(((('> blub";
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, new JsonReader(new StringReader(malformedJson)), newTempFile());
try {
protocol.receiveCommandResponse(123);
} catch (HumanReadableException e) {
assertThat(e.getMessage(), Matchers.containsString("Error receiving command response"));
}
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method setUp.
@Before
public void setUp() throws IOException {
ProcessExecutorParams fakeParams = ProcessExecutorParams.ofCommand("");
fakeProcess = new FakeProcess(0);
fakeProcessExecutor = new FakeProcessExecutor(ImmutableMap.of(fakeParams, fakeProcess));
fakeLaunchedProcess = fakeProcessExecutor.launchProcess(fakeParams);
dummyJsonWriter = new JsonWriter(new StringWriter());
dummyJsonReader = new JsonReader(new StringReader(""));
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testReceiveHandshakeWithIncorrectType.
@Test
public void testReceiveHandshakeWithIncorrectType() throws IOException {
int handshakeID = 123;
JsonReader jsonReader = createMockJsonReaderForReceiveHandshake(handshakeID, "INCORRECT MESSAGE TYPE", "0");
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 \"type\" to be \"handshake\""));
}
}
use of com.google.gson.stream.JsonReader in project buck by facebook.
the class WorkerProcessProtocolZeroTest method testClose.
@Test
public void testClose() throws IOException {
StringWriter jsonSentToWorkerProcess = new StringWriter();
JsonWriter writer = new JsonWriter(jsonSentToWorkerProcess);
// write an opening bracket now, so the writer doesn't throw due to invalid JSON when it goes
// to write the closing bracket
writer.beginArray();
// add an opening bracket and consume it now, so that the reader doesn't throw due to invalid
// JSON when it goes to read the closing bracket
JsonReader reader = new JsonReader(new StringReader("[]"));
reader.beginArray();
WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, writer, reader, newTempFile());
protocol.close();
String expectedJson = "]";
assertThat(jsonSentToWorkerProcess.toString(), Matchers.endsWith(expectedJson));
assertTrue(fakeProcess.isDestroyed());
}
Aggregations