Search in sources :

Example 1 with StreamingOutputCallRequest

use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.

the class AbstractInteropTest method maxOutboundSize_tooBig.

@Test(timeout = 10000)
public void maxOutboundSize_tooBig() {
    // warm up the channel and JVM
    blockingStub.emptyCall(Empty.getDefaultInstance());
    // set at least one field to ensure the size is non-zero.
    StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().addResponseParameters(ResponseParameters.newBuilder().setSize(1)).build();
    TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel).withMaxOutboundMessageSize(request.getSerializedSize() - 1);
    try {
        stub.streamingOutputCall(request).next();
        fail();
    } catch (StatusRuntimeException ex) {
        Status s = ex.getStatus();
        assertThat(s.getCode()).named(s.toString()).isEqualTo(Status.Code.CANCELLED);
        assertThat(Throwables.getStackTraceAsString(ex)).contains("message too large");
    }
}
Also used : Status(io.grpc.Status) EchoStatus(io.grpc.testing.integration.Messages.EchoStatus) StatusRuntimeException(io.grpc.StatusRuntimeException) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) Test(org.junit.Test)

Example 2 with StreamingOutputCallRequest

use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.

the class AbstractInteropTest method timeoutOnSleepingServer.

/** Start a fullDuplexCall which the server will not respond, and verify the deadline expires. */
@Test(timeout = 10000)
public void timeoutOnSleepingServer() throws Exception {
    TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel).withDeadlineAfter(1, TimeUnit.MILLISECONDS);
    StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create();
    StreamObserver<StreamingOutputCallRequest> requestObserver = stub.fullDuplexCall(responseObserver);
    StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[27182]))).build();
    try {
        requestObserver.onNext(request);
    } catch (IllegalStateException expected) {
    // This can happen if the stream has already been terminated due to deadline exceeded.
    }
    responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS);
    assertEquals(0, responseObserver.getValues().size());
    assertEquals(Status.DEADLINE_EXCEEDED.getCode(), Status.fromThrowable(responseObserver.getError()).getCode());
    if (metricsExpected()) {
        assertClientMetrics("grpc.testing.TestService/FullDuplexCall", Status.Code.DEADLINE_EXCEEDED);
    // Do not check server-side metrics, because the status on the server side is undetermined.
    }
}
Also used : StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 3 with StreamingOutputCallRequest

use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.

the class AbstractInteropTest method exchangeMetadataStreamingCall.

@Test(timeout = 10000)
public void exchangeMetadataStreamingCall() throws Exception {
    TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
    // Capture the metadata exchange
    Metadata fixedHeaders = new Metadata();
    // Send a context proto (as it's in the default extension registry)
    Messages.SimpleContext contextValue = Messages.SimpleContext.newBuilder().setValue("dog").build();
    fixedHeaders.put(METADATA_KEY, contextValue);
    stub = MetadataUtils.attachHeaders(stub, fixedHeaders);
    // .. and expect it to be echoed back in trailers
    AtomicReference<Metadata> trailersCapture = new AtomicReference<Metadata>();
    AtomicReference<Metadata> headersCapture = new AtomicReference<Metadata>();
    stub = MetadataUtils.captureMetadata(stub, headersCapture, trailersCapture);
    List<Integer> responseSizes = Arrays.asList(50, 100, 150, 200);
    Messages.StreamingOutputCallRequest.Builder streamingOutputBuilder = Messages.StreamingOutputCallRequest.newBuilder();
    streamingOutputBuilder.setResponseType(COMPRESSABLE);
    for (Integer size : responseSizes) {
        streamingOutputBuilder.addResponseParametersBuilder().setSize(size).setIntervalUs(0);
    }
    final Messages.StreamingOutputCallRequest request = streamingOutputBuilder.build();
    StreamRecorder<Messages.StreamingOutputCallResponse> recorder = StreamRecorder.create();
    StreamObserver<Messages.StreamingOutputCallRequest> requestStream = stub.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);
    org.junit.Assert.assertEquals(responseSizes.size() * numRequests, recorder.getValues().size());
    // Assert that our side channel object is echoed back in both headers and trailers
    Assert.assertEquals(contextValue, headersCapture.get().get(METADATA_KEY));
    Assert.assertEquals(contextValue, trailersCapture.get().get(METADATA_KEY));
}
Also used : Metadata(io.grpc.Metadata) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.testing.integration.Messages.StreamingOutputCallResponse) Test(org.junit.Test)

Example 4 with StreamingOutputCallRequest

use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.

the class AbstractInteropTest method deadlineExceeded.

@Test(timeout = 10000)
public void deadlineExceeded() {
    // warm up the channel and JVM
    blockingStub.emptyCall(Empty.getDefaultInstance());
    TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel).withDeadlineAfter(10, TimeUnit.MILLISECONDS);
    StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().addResponseParameters(ResponseParameters.newBuilder().setIntervalUs(20000)).build();
    try {
        stub.streamingOutputCall(request).next();
        fail("Expected deadline to be exceeded");
    } catch (StatusRuntimeException ex) {
        assertEquals(Status.DEADLINE_EXCEEDED.getCode(), ex.getStatus().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 : StatusRuntimeException(io.grpc.StatusRuntimeException) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) Test(org.junit.Test)

Example 5 with StreamingOutputCallRequest

use of io.grpc.testing.integration.Messages.StreamingOutputCallRequest in project grpc-java by grpc.

the class AbstractInteropTest method serverStreaming.

@Test(timeout = 10000)
public void serverStreaming() throws Exception {
    final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().setResponseType(PayloadType.COMPRESSABLE).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().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[31415]))).build(), StreamingOutputCallResponse.newBuilder().setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[9]))).build(), StreamingOutputCallResponse.newBuilder().setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[2653]))).build(), StreamingOutputCallResponse.newBuilder().setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[58979]))).build());
    StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
    asyncStub.streamingOutputCall(request, recorder);
    recorder.awaitCompletion();
    assertSuccess(recorder);
    assertEquals(goldenResponses, recorder.getValues());
}
Also used : 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