Search in sources :

Example 71 with JsonReader

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));
}
Also used : Path(java.nio.file.Path) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Example 72 with JsonReader

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);
}
Also used : JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Example 73 with JsonReader

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)));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Example 74 with JsonReader

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"));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Example 75 with JsonReader

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\""));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Aggregations

JsonReader (com.google.gson.stream.JsonReader)100 StringReader (java.io.StringReader)38 JsonElement (com.google.gson.JsonElement)31 IOException (java.io.IOException)20 JsonObject (com.google.gson.JsonObject)19 Test (org.junit.Test)19 InputStreamReader (java.io.InputStreamReader)18 JsonParser (com.google.gson.JsonParser)12 HumanReadableException (com.facebook.buck.util.HumanReadableException)10 Gson (com.google.gson.Gson)10 JsonWriter (com.google.gson.stream.JsonWriter)10 TypeToken (com.google.gson.reflect.TypeToken)8 Map (java.util.Map)8 JsonToken (com.google.gson.stream.JsonToken)6 HashMap (java.util.HashMap)6 InputStream (java.io.InputStream)5 StringWriter (java.io.StringWriter)5 Type (java.lang.reflect.Type)5 ArrayList (java.util.ArrayList)5 GsonBuilder (com.google.gson.GsonBuilder)4