Java Code Examples for io.grpc.internal.testing.StreamRecorder#awaitCompletion()
The following examples show how to use
io.grpc.internal.testing.StreamRecorder#awaitCompletion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void cancelAfterFirstResponse() throws Exception { final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(ResponseParameters.newBuilder() .setSize(31415)) .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[27182]))) .build(); final StreamingOutputCallResponse goldenResponse = StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[31415]))) .build(); StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver); requestObserver.onNext(request); assertResponse(goldenResponse, responseObserver.firstValue().get()); requestObserver.onError(new RuntimeException()); responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); assertEquals(1, responseObserver.getValues().size()); assertEquals(Status.Code.CANCELLED, Status.fromThrowable(responseObserver.getError()).getCode()); assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.CANCELLED); }
Example 2
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void cancelAfterBegin() throws Exception { StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingInputCallRequest> requestObserver = asyncStub.streamingInputCall(responseObserver); requestObserver.onError(new RuntimeException()); responseObserver.awaitCompletion(); assertEquals(Arrays.<StreamingInputCallResponse>asList(), responseObserver.getValues()); assertEquals(Status.Code.CANCELLED, Status.fromThrowable(responseObserver.getError()).getCode()); if (metricsExpected()) { MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS); checkStartTags(clientStartRecord, "grpc.testing.TestService/StreamingInputCall", true); // CensusStreamTracerModule record final status in the interceptor, thus is guaranteed to be // recorded. The tracer stats rely on the stream being created, which is not always the case // in this test. Therefore we don't check the tracer stats. MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS); checkEndTags( clientEndRecord, "grpc.testing.TestService/StreamingInputCall", Status.CANCELLED.getCode(), true); // Do not check server-side metrics, because the status on the server side is undetermined. } }
Example 3
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Test public void cancelAfterBegin() throws Exception { StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingInputCallRequest> requestObserver = asyncStub.streamingInputCall(responseObserver); requestObserver.onError(new RuntimeException()); responseObserver.awaitCompletion(); assertEquals(Arrays.<StreamingInputCallResponse>asList(), responseObserver.getValues()); assertEquals(Status.Code.CANCELLED, Status.fromThrowable(responseObserver.getError()).getCode()); if (metricsExpected()) { MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS); checkStartTags(clientStartRecord, "grpc.testing.TestService/StreamingInputCall"); // CensusStreamTracerModule record final status in the interceptor, thus is guaranteed to be // recorded. The tracer stats rely on the stream being created, which is not always the case // in this test. Therefore we don't check the tracer stats. MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS); checkEndTags( clientEndRecord, "grpc.testing.TestService/StreamingInputCall", Status.CANCELLED.getCode()); // Do not check server-side metrics, because the status on the server side is undetermined. } }
Example 4
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Test public void cancelAfterFirstResponse() throws Exception { final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(ResponseParameters.newBuilder() .setSize(31415)) .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[27182]))) .build(); final StreamingOutputCallResponse goldenResponse = StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[31415]))) .build(); StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver); requestObserver.onNext(request); assertResponse(goldenResponse, responseObserver.firstValue().get()); requestObserver.onError(new RuntimeException()); responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); assertEquals(1, responseObserver.getValues().size()); assertEquals(Status.Code.CANCELLED, Status.fromThrowable(responseObserver.getError()).getCode()); assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.CANCELLED); }
Example 5
Source File: Http2OkHttpTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void receivedDataForFinishedStream() throws Exception { Messages.ResponseParameters.Builder responseParameters = Messages.ResponseParameters.newBuilder() .setSize(1); Messages.StreamingOutputCallRequest.Builder requestBuilder = Messages.StreamingOutputCallRequest.newBuilder(); for (int i = 0; i < 1000; i++) { requestBuilder.addResponseParameters(responseParameters); } StreamRecorder<Messages.StreamingOutputCallResponse> recorder = StreamRecorder.create(); StreamObserver<Messages.StreamingOutputCallRequest> requestStream = asyncStub.fullDuplexCall(recorder); Messages.StreamingOutputCallRequest request = requestBuilder.build(); requestStream.onNext(request); recorder.firstValue().get(); requestStream.onError(new Exception("failed")); recorder.awaitCompletion(); assertEquals(EMPTY, blockingStub.emptyCall(EMPTY)); }
Example 6
Source File: Http2OkHttpTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Test public void receivedDataForFinishedStream() throws Exception { Messages.ResponseParameters.Builder responseParameters = Messages.ResponseParameters.newBuilder() .setSize(1); Messages.StreamingOutputCallRequest.Builder requestBuilder = Messages.StreamingOutputCallRequest.newBuilder(); for (int i = 0; i < 1000; i++) { requestBuilder.addResponseParameters(responseParameters); } StreamRecorder<Messages.StreamingOutputCallResponse> recorder = StreamRecorder.create(); StreamObserver<Messages.StreamingOutputCallRequest> requestStream = asyncStub.fullDuplexCall(recorder); Messages.StreamingOutputCallRequest request = requestBuilder.build(); requestStream.onNext(request); recorder.firstValue().get(); requestStream.onError(new Exception("failed")); recorder.awaitCompletion(); assertEquals(EMPTY, blockingStub.emptyCall(EMPTY)); }
Example 7
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void deadlineExceededServerStreaming() throws Exception { // warm up the channel and JVM blockingStub.emptyCall(Empty.getDefaultInstance()); ResponseParameters.Builder responseParameters = ResponseParameters.newBuilder() .setSize(1) .setIntervalUs(10000); StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(responseParameters) .addResponseParameters(responseParameters) .addResponseParameters(responseParameters) .addResponseParameters(responseParameters) .build(); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); asyncStub .withDeadlineAfter(30, TimeUnit.MILLISECONDS) .streamingOutputCall(request, recorder); recorder.awaitCompletion(); assertEquals(Status.DEADLINE_EXCEEDED.getCode(), Status.fromThrowable(recorder.getError()).getCode()); assertStatsTrace("grpc.testing.TestService/EmptyCall", Status.Code.OK); if (metricsExpected()) { // Stream may not have been created when deadline is exceeded, thus we don't check tracer // stats. MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS); checkStartTags( clientStartRecord, "grpc.testing.TestService/StreamingOutputCall"); MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS); checkEndTags( clientEndRecord, "grpc.testing.TestService/StreamingOutputCall", Status.Code.DEADLINE_EXCEEDED); // Do not check server-side metrics, because the status on the server side is undetermined. } }
Example 8
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void fullDuplexCallShouldSucceed() throws Exception { // Build the request. List<Integer> responseSizes = Arrays.asList(50, 100, 150, 200); StreamingOutputCallRequest.Builder streamingOutputBuilder = StreamingOutputCallRequest.newBuilder(); for (Integer size : responseSizes) { streamingOutputBuilder.addResponseParameters( ResponseParameters.newBuilder().setSize(size).setIntervalUs(0)); } final StreamingOutputCallRequest request = streamingOutputBuilder.build(); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); StreamObserver<StreamingOutputCallRequest> requestStream = asyncStub.fullDuplexCall(recorder); final int numRequests = 10; List<StreamingOutputCallRequest> requests = new ArrayList<>(numRequests); for (int ix = numRequests; ix > 0; --ix) { requests.add(request); requestStream.onNext(request); } requestStream.onCompleted(); recorder.awaitCompletion(); assertSuccess(recorder); assertEquals(responseSizes.size() * numRequests, recorder.getValues().size()); for (int ix = 0; ix < recorder.getValues().size(); ++ix) { StreamingOutputCallResponse response = recorder.getValues().get(ix); int length = response.getPayload().getBody().size(); int expectedSize = responseSizes.get(ix % responseSizes.size()); assertEquals("comparison failed at index " + ix, expectedSize, length); } assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.OK, requests, recorder.getValues()); }
Example 9
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void emptyStream() throws Exception { StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver); requestObserver.onCompleted(); responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); assertSuccess(responseObserver); assertTrue("Expected an empty stream", responseObserver.getValues().isEmpty()); }
Example 10
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Tests server per-message compression in a streaming response. Ideally we would assert that the * responses have the requested compression, but this is not supported by the API. Given a * compliant server, this test will exercise the code path for receiving a compressed response but * cannot itself verify that the response was compressed. */ public void serverCompressedStreaming() throws Exception { final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters( ResponseParameters.newBuilder() .setCompressed(BoolValue.newBuilder().setValue(true)) .setSize(31415)) .addResponseParameters( ResponseParameters.newBuilder() .setCompressed(BoolValue.newBuilder().setValue(false)) .setSize(92653)) .build(); final List<StreamingOutputCallResponse> goldenResponses = Arrays.asList( StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[31415]))) .build(), StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[92653]))) .build()); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); asyncStub.streamingOutputCall(request, recorder); recorder.awaitCompletion(); assertSuccess(recorder); assertResponses(goldenResponses, recorder.getValues()); }
Example 11
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void serverStreaming() throws Exception { final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(ResponseParameters.newBuilder() .setSize(31415)) .addResponseParameters(ResponseParameters.newBuilder() .setSize(9)) .addResponseParameters(ResponseParameters.newBuilder() .setSize(2653)) .addResponseParameters(ResponseParameters.newBuilder() .setSize(58979)) .build(); final List<StreamingOutputCallResponse> goldenResponses = Arrays.asList( StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[31415]))) .build(), StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[9]))) .build(), StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[2653]))) .build(), StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[58979]))) .build()); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); asyncStub.streamingOutputCall(request, recorder); recorder.awaitCompletion(); assertSuccess(recorder); assertResponses(goldenResponses, recorder.getValues()); }
Example 12
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void serverStreaming() throws Exception { final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(ResponseParameters.newBuilder() .setSize(31415)) .addResponseParameters(ResponseParameters.newBuilder() .setSize(9)) .addResponseParameters(ResponseParameters.newBuilder() .setSize(2653)) .addResponseParameters(ResponseParameters.newBuilder() .setSize(58979)) .build(); final List<StreamingOutputCallResponse> goldenResponses = Arrays.asList( StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[31415]))) .build(), StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[9]))) .build(), StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[2653]))) .build(), StreamingOutputCallResponse.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[58979]))) .build()); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); asyncStub.streamingOutputCall(request, recorder); recorder.awaitCompletion(); assertSuccess(recorder); assertResponses(goldenResponses, recorder.getValues()); }
Example 13
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void deadlineExceededServerStreaming() throws Exception { // warm up the channel and JVM blockingStub.emptyCall(Empty.getDefaultInstance()); ResponseParameters.Builder responseParameters = ResponseParameters.newBuilder() .setSize(1) .setIntervalUs(10000); StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(responseParameters) .addResponseParameters(responseParameters) .addResponseParameters(responseParameters) .addResponseParameters(responseParameters) .build(); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); asyncStub .withDeadlineAfter(30, TimeUnit.MILLISECONDS) .streamingOutputCall(request, recorder); recorder.awaitCompletion(); assertEquals(Status.DEADLINE_EXCEEDED.getCode(), Status.fromThrowable(recorder.getError()).getCode()); assertStatsTrace("grpc.testing.TestService/EmptyCall", Status.Code.OK); if (metricsExpected()) { // Stream may not have been created when deadline is exceeded, thus we don't check tracer // stats. MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS); checkStartTags( clientStartRecord, "grpc.testing.TestService/StreamingOutputCall", true); MetricsRecord clientEndRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS); checkEndTags( clientEndRecord, "grpc.testing.TestService/StreamingOutputCall", Status.Code.DEADLINE_EXCEEDED, true); // Do not check server-side metrics, because the status on the server side is undetermined. } }
Example 14
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void halfDuplexCallShouldSucceed() throws Exception { // Build the request. List<Integer> responseSizes = Arrays.asList(50, 100, 150, 200); StreamingOutputCallRequest.Builder streamingOutputBuilder = StreamingOutputCallRequest.newBuilder(); for (Integer size : responseSizes) { streamingOutputBuilder.addResponseParameters( ResponseParameters.newBuilder().setSize(size).setIntervalUs(0)); } final StreamingOutputCallRequest request = streamingOutputBuilder.build(); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); StreamObserver<StreamingOutputCallRequest> requestStream = asyncStub.halfDuplexCall(recorder); final int numRequests = 10; for (int ix = numRequests; ix > 0; --ix) { requestStream.onNext(request); } requestStream.onCompleted(); recorder.awaitCompletion(); assertSuccess(recorder); assertEquals(responseSizes.size() * numRequests, recorder.getValues().size()); for (int ix = 0; ix < recorder.getValues().size(); ++ix) { StreamingOutputCallResponse response = recorder.getValues().get(ix); int length = response.getPayload().getBody().size(); int expectedSize = responseSizes.get(ix % responseSizes.size()); assertEquals("comparison failed at index " + ix, expectedSize, length); } }
Example 15
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void fullDuplexCallShouldSucceed() throws Exception { // Build the request. List<Integer> responseSizes = Arrays.asList(50, 100, 150, 200); StreamingOutputCallRequest.Builder streamingOutputBuilder = StreamingOutputCallRequest.newBuilder(); for (Integer size : responseSizes) { streamingOutputBuilder.addResponseParameters( ResponseParameters.newBuilder().setSize(size).setIntervalUs(0)); } final StreamingOutputCallRequest request = streamingOutputBuilder.build(); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); StreamObserver<StreamingOutputCallRequest> requestStream = asyncStub.fullDuplexCall(recorder); final int numRequests = 10; List<StreamingOutputCallRequest> requests = new ArrayList<>(numRequests); for (int ix = numRequests; ix > 0; --ix) { requests.add(request); requestStream.onNext(request); } requestStream.onCompleted(); recorder.awaitCompletion(); assertSuccess(recorder); assertEquals(responseSizes.size() * numRequests, recorder.getValues().size()); for (int ix = 0; ix < recorder.getValues().size(); ++ix) { StreamingOutputCallResponse response = recorder.getValues().get(ix); int length = response.getPayload().getBody().size(); int expectedSize = responseSizes.get(ix % responseSizes.size()); assertEquals("comparison failed at index " + ix, expectedSize, length); } assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.OK, requests, recorder.getValues()); }
Example 16
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void emptyStream() throws Exception { StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver); requestObserver.onCompleted(); responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); }
Example 17
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void halfDuplexCallShouldSucceed() throws Exception { // Build the request. List<Integer> responseSizes = Arrays.asList(50, 100, 150, 200); StreamingOutputCallRequest.Builder streamingOutputBuilder = StreamingOutputCallRequest.newBuilder(); for (Integer size : responseSizes) { streamingOutputBuilder.addResponseParameters( ResponseParameters.newBuilder().setSize(size).setIntervalUs(0)); } final StreamingOutputCallRequest request = streamingOutputBuilder.build(); StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create(); StreamObserver<StreamingOutputCallRequest> requestStream = asyncStub.halfDuplexCall(recorder); final int numRequests = 10; for (int ix = numRequests; ix > 0; --ix) { requestStream.onNext(request); } requestStream.onCompleted(); recorder.awaitCompletion(); assertSuccess(recorder); assertEquals(responseSizes.size() * numRequests, recorder.getValues().size()); for (int ix = 0; ix < recorder.getValues().size(); ++ix) { StreamingOutputCallResponse response = recorder.getValues().get(ix); int length = response.getPayload().getBody().size(); int expectedSize = responseSizes.get(ix % responseSizes.size()); assertEquals("comparison failed at index " + ix, expectedSize, length); } }
Example 18
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void clientStreaming() throws Exception { final List<StreamingInputCallRequest> requests = Arrays.asList( StreamingInputCallRequest.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[27182]))) .build(), StreamingInputCallRequest.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[8]))) .build(), StreamingInputCallRequest.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[1828]))) .build(), StreamingInputCallRequest.newBuilder() .setPayload(Payload.newBuilder() .setBody(ByteString.copyFrom(new byte[45904]))) .build()); final StreamingInputCallResponse goldenResponse = StreamingInputCallResponse.newBuilder() .setAggregatedPayloadSize(74922) .build(); StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingInputCallRequest> requestObserver = asyncStub.streamingInputCall(responseObserver); for (StreamingInputCallRequest request : requests) { requestObserver.onNext(request); } requestObserver.onCompleted(); assertEquals(goldenResponse, responseObserver.firstValue().get()); responseObserver.awaitCompletion(); assertThat(responseObserver.getValues()).hasSize(1); Throwable t = responseObserver.getError(); if (t != null) { throw new AssertionError(t); } }
Example 19
Source File: AbstractInteropTest.java From grpc-java with Apache License 2.0 | 4 votes |
/** * Tests client per-message compression for streaming calls. The Java API does not support * inspecting a message's compression level, so this is primarily intended to run against a gRPC * C++ server. */ public void clientCompressedStreaming(boolean probe) throws Exception { final StreamingInputCallRequest expectCompressedRequest = StreamingInputCallRequest.newBuilder() .setExpectCompressed(BoolValue.newBuilder().setValue(true)) .setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[27182]))) .build(); final StreamingInputCallRequest expectUncompressedRequest = StreamingInputCallRequest.newBuilder() .setExpectCompressed(BoolValue.newBuilder().setValue(false)) .setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[45904]))) .build(); final StreamingInputCallResponse goldenResponse = StreamingInputCallResponse.newBuilder().setAggregatedPayloadSize(73086).build(); StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingInputCallRequest> requestObserver = asyncStub.streamingInputCall(responseObserver); if (probe) { // Send a non-compressed message with expectCompress=true. Servers supporting this test case // should return INVALID_ARGUMENT. requestObserver.onNext(expectCompressedRequest); responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); Throwable e = responseObserver.getError(); assertNotNull("expected INVALID_ARGUMENT", e); assertEquals(Status.INVALID_ARGUMENT.getCode(), Status.fromThrowable(e).getCode()); } // Start a new stream responseObserver = StreamRecorder.create(); @SuppressWarnings("unchecked") ClientCallStreamObserver<StreamingInputCallRequest> clientCallStreamObserver = (ClientCallStreamObserver) asyncStub.withCompression("gzip").streamingInputCall(responseObserver); clientCallStreamObserver.setMessageCompression(true); clientCallStreamObserver.onNext(expectCompressedRequest); clientCallStreamObserver.setMessageCompression(false); clientCallStreamObserver.onNext(expectUncompressedRequest); clientCallStreamObserver.onCompleted(); responseObserver.awaitCompletion(); assertSuccess(responseObserver); assertEquals(goldenResponse, responseObserver.firstValue().get()); }
Example 20
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
/** * Tests client per-message compression for streaming calls. The Java API does not support * inspecting a message's compression level, so this is primarily intended to run against a gRPC * C++ server. */ public void clientCompressedStreaming(boolean probe) throws Exception { final StreamingInputCallRequest expectCompressedRequest = StreamingInputCallRequest.newBuilder() .setExpectCompressed(BoolValue.newBuilder().setValue(true)) .setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[27182]))) .build(); final StreamingInputCallRequest expectUncompressedRequest = StreamingInputCallRequest.newBuilder() .setExpectCompressed(BoolValue.newBuilder().setValue(false)) .setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[45904]))) .build(); final StreamingInputCallResponse goldenResponse = StreamingInputCallResponse.newBuilder().setAggregatedPayloadSize(73086).build(); StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create(); StreamObserver<StreamingInputCallRequest> requestObserver = asyncStub.streamingInputCall(responseObserver); if (probe) { // Send a non-compressed message with expectCompress=true. Servers supporting this test case // should return INVALID_ARGUMENT. requestObserver.onNext(expectCompressedRequest); responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); Throwable e = responseObserver.getError(); assertNotNull("expected INVALID_ARGUMENT", e); assertEquals(Status.INVALID_ARGUMENT.getCode(), Status.fromThrowable(e).getCode()); } // Start a new stream responseObserver = StreamRecorder.create(); @SuppressWarnings("unchecked") ClientCallStreamObserver<StreamingInputCallRequest> clientCallStreamObserver = (ClientCallStreamObserver) asyncStub.withCompression("gzip").streamingInputCall(responseObserver); clientCallStreamObserver.setMessageCompression(true); clientCallStreamObserver.onNext(expectCompressedRequest); clientCallStreamObserver.setMessageCompression(false); clientCallStreamObserver.onNext(expectUncompressedRequest); clientCallStreamObserver.onCompleted(); responseObserver.awaitCompletion(); assertSuccess(responseObserver); assertEquals(goldenResponse, responseObserver.firstValue().get()); }