use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.
the class AbstractInteropTest method cancelAfterFirstResponse.
@Test(timeout = 10000)
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().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[31415]))).build();
StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create();
StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver);
requestObserver.onNext(request);
assertEquals(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());
if (metricsExpected()) {
assertMetrics("grpc.testing.TestService/FullDuplexCall", Status.Code.CANCELLED);
}
}
use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.
the class AbstractInteropTest method fullDuplexCallShouldSucceed.
@Test(timeout = 10000)
public void fullDuplexCallShouldSucceed() throws Exception {
// Build the request.
List<Integer> responseSizes = Arrays.asList(50, 100, 150, 200);
StreamingOutputCallRequest.Builder streamingOutputBuilder = StreamingOutputCallRequest.newBuilder();
streamingOutputBuilder.setResponseType(COMPRESSABLE);
for (Integer size : responseSizes) {
streamingOutputBuilder.addResponseParametersBuilder().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<StreamingOutputCallRequest>(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);
assertEquals(COMPRESSABLE, response.getPayload().getType());
int length = response.getPayload().getBody().size();
int expectedSize = responseSizes.get(ix % responseSizes.size());
assertEquals("comparison failed at index " + ix, expectedSize, length);
}
if (metricsExpected()) {
assertMetrics("grpc.testing.TestService/FullDuplexCall", Status.Code.OK, requests, recorder.getValues());
}
}
use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.
the class AbstractInteropTest method halfDuplexCallShouldSucceed.
@Test(timeout = 10000)
public void halfDuplexCallShouldSucceed() throws Exception {
// Build the request.
List<Integer> responseSizes = Arrays.asList(50, 100, 150, 200);
StreamingOutputCallRequest.Builder streamingOutputBuilder = StreamingOutputCallRequest.newBuilder();
streamingOutputBuilder.setResponseType(COMPRESSABLE);
for (Integer size : responseSizes) {
streamingOutputBuilder.addResponseParametersBuilder().setSize(size).setIntervalUs(0);
}
final StreamingOutputCallRequest request = streamingOutputBuilder.build();
StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
StreamObserver<StreamingOutputCallRequest> requestStream = asyncStub.halfDuplexCall(recorder);
final int numRequests = 10;
List<StreamingOutputCallRequest> requests = new ArrayList<StreamingOutputCallRequest>(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);
assertEquals(COMPRESSABLE, response.getPayload().getType());
int length = response.getPayload().getBody().size();
int expectedSize = responseSizes.get(ix % responseSizes.size());
assertEquals("comparison failed at index " + ix, expectedSize, length);
}
}
use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.
the class AbstractInteropTest method deadlineExceededServerStreaming.
@Test(timeout = 10000)
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().setResponseType(PayloadType.COMPRESSABLE).addResponseParameters(responseParameters).addResponseParameters(responseParameters).addResponseParameters(responseParameters).addResponseParameters(responseParameters).build();
StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
TestServiceGrpc.newStub(channel).withDeadlineAfter(30, TimeUnit.MILLISECONDS).streamingOutputCall(request, recorder);
recorder.awaitCompletion();
assertEquals(Status.DEADLINE_EXCEEDED.getCode(), Status.fromThrowable(recorder.getError()).getCode());
if (metricsExpected()) {
assertMetrics("grpc.testing.TestService/EmptyCall", Status.Code.OK);
assertClientMetrics("grpc.testing.TestService/StreamingOutputCall", Status.Code.DEADLINE_EXCEEDED);
// Do not check server-side metrics, because the status on the server side is undetermined.
}
}
use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.
the class AbstractInteropTest method statusCodeAndMessage.
@Test(timeout = 10000)
public void statusCodeAndMessage() throws Exception {
int errorCode = 2;
String errorMessage = "test status message";
EchoStatus responseStatus = EchoStatus.newBuilder().setCode(errorCode).setMessage(errorMessage).build();
SimpleRequest simpleRequest = SimpleRequest.newBuilder().setResponseStatus(responseStatus).build();
StreamingOutputCallRequest streamingRequest = StreamingOutputCallRequest.newBuilder().setResponseStatus(responseStatus).build();
// Test UnaryCall
try {
blockingStub.unaryCall(simpleRequest);
fail();
} catch (StatusRuntimeException e) {
assertEquals(Status.UNKNOWN.getCode(), e.getStatus().getCode());
assertEquals(errorMessage, e.getStatus().getDescription());
}
if (metricsExpected()) {
assertClientMetrics("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN);
}
// Test FullDuplexCall
@SuppressWarnings("unchecked") StreamObserver<StreamingOutputCallResponse> responseObserver = mock(StreamObserver.class);
StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver);
requestObserver.onNext(streamingRequest);
requestObserver.onCompleted();
ArgumentCaptor<Throwable> captor = ArgumentCaptor.forClass(Throwable.class);
verify(responseObserver, timeout(operationTimeoutMillis())).onError(captor.capture());
assertEquals(Status.UNKNOWN.getCode(), Status.fromThrowable(captor.getValue()).getCode());
assertEquals(errorMessage, Status.fromThrowable(captor.getValue()).getDescription());
verifyNoMoreInteractions(responseObserver);
if (metricsExpected()) {
assertClientMetrics("grpc.testing.TestService/FullDuplexCall", Status.Code.UNKNOWN);
}
}
Aggregations