Search in sources :

Example 11 with StreamingOutputCallRequest

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);
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 12 with StreamingOutputCallRequest

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());
    }
}
Also used : ArrayList(java.util.ArrayList) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 13 with StreamingOutputCallRequest

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);
    }
}
Also used : ArrayList(java.util.ArrayList) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 14 with StreamingOutputCallRequest

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.
    }
}
Also used : ResponseParameters(io.grpc.testing.integration.Messages.ResponseParameters) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 15 with StreamingOutputCallRequest

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);
    }
}
Also used : EchoStatus(io.grpc.testing.integration.Messages.EchoStatus) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Aggregations

StreamingOutputCallRequest (io.grpc.testing.integration.Messages.StreamingOutputCallRequest)16 Test (org.junit.Test)15 StreamingOutputCallResponse (io.grpc.testing.integration.Messages.StreamingOutputCallResponse)10 StatusRuntimeException (io.grpc.StatusRuntimeException)5 EchoStatus (io.grpc.testing.integration.Messages.EchoStatus)4 Metadata (io.grpc.Metadata)3 Status (io.grpc.Status)3 ArrayList (java.util.ArrayList)3 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ByteString (com.google.protobuf.ByteString)1 ClientCall (io.grpc.ClientCall)1 ResponseParameters (io.grpc.testing.integration.Messages.ResponseParameters)1 SimpleResponse (io.grpc.testing.integration.Messages.SimpleResponse)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1