Search in sources :

Example 6 with StreamingOutputCallResponse

use of io.grpc.testing.integration.Messages.StreamingOutputCallResponse 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 7 with StreamingOutputCallResponse

use of io.grpc.testing.integration.Messages.StreamingOutputCallResponse 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 8 with StreamingOutputCallResponse

use of io.grpc.testing.integration.Messages.StreamingOutputCallResponse 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 9 with StreamingOutputCallResponse

use of io.grpc.testing.integration.Messages.StreamingOutputCallResponse 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)9 StreamingOutputCallResponse (io.grpc.testing.integration.Messages.StreamingOutputCallResponse)9 Test (org.junit.Test)9 Metadata (io.grpc.Metadata)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 EchoStatus (io.grpc.testing.integration.Messages.EchoStatus)2 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)2 ArrayList (java.util.ArrayList)2 ByteString (com.google.protobuf.ByteString)1 ClientCall (io.grpc.ClientCall)1 Status (io.grpc.Status)1 ResponseParameters (io.grpc.testing.integration.Messages.ResponseParameters)1 SimpleResponse (io.grpc.testing.integration.Messages.SimpleResponse)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1