Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format work requests according to ndjson spec #14219

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ final class JsonWorkerProtocol implements WorkerProtocolImpl {

@Override
public void putRequest(WorkRequest request) throws IOException {
// WorkRequests are serialized according to ndjson spec.
// https://github.com/ndjson/ndjson-spec
jsonPrinter.appendTo(request, jsonWriter);
jsonWriter.append(System.lineSeparator());
jsonWriter.flush();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public void testPutRequest_json_success() throws IOException, InterruptedExcepti
testWorker.putRequest(WorkRequest.getDefaultInstance());

OutputStream stdout = testWorker.getFakeSubprocess().getOutputStream();
assertThat(stdout.toString()).isEqualTo("{}");
assertThat(stdout.toString()).isEqualTo("{}" + System.lineSeparator());
}

@Test
public void testGetResponse_json_success() throws IOException, InterruptedException {
TestWorker testWorker = createTestWorker("{}".getBytes(UTF_8), JSON);
TestWorker testWorker = createTestWorker(("{}" + System.lineSeparator()).getBytes(UTF_8), JSON);
WorkResponse readResponse = testWorker.getResponse(0);
WorkResponse response = WorkResponse.getDefaultInstance();

Expand Down Expand Up @@ -151,7 +151,8 @@ public void testPutRequest_json_populatedFields_success()
OutputStream stdout = testWorker.getFakeSubprocess().getOutputStream();
String requestJsonString =
"{\"arguments\":[\"testRequest\"],\"inputs\":"
+ "[{\"path\":\"testPath\",\"digest\":\"dGVzdERpZ2VzdA==\"}],\"requestId\":1,\"verbosity\":11}";
+ "[{\"path\":\"testPath\",\"digest\":\"dGVzdERpZ2VzdA==\"}],\"requestId\":1,\"verbosity\":11}"
+ System.lineSeparator();
assertThat(stdout.toString()).isEqualTo(requestJsonString);
}

Expand All @@ -170,7 +171,7 @@ public void testGetResponse_json_populatedFields_success()

private void verifyGetResponseFailure(String responseString, String expectedError)
throws IOException {
TestWorker testWorker = createTestWorker(responseString.getBytes(UTF_8), JSON);
TestWorker testWorker = createTestWorker((responseString + System.lineSeparator()).getBytes(UTF_8), JSON);
IOException ex = assertThrows(IOException.class, () -> testWorker.getResponse(0));
assertThat(ex).hasMessageThat().contains(expectedError);
}
Expand Down