Search in sources :

Example 6 with StreamingOutputCallResponse

use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse in project grpc-java by grpc.

the class InteropTester method cancelAfterFirstResponse.

public void cancelAfterFirstResponse() throws Exception {
    final StreamingOutputCallRequest request = new StreamingOutputCallRequest();
    request.responseParameters = new Messages.ResponseParameters[1];
    request.responseParameters[0] = new ResponseParameters();
    request.responseParameters[0].size = 31415;
    request.payload = new Payload();
    request.payload.body = new byte[27182];
    final StreamingOutputCallResponse goldenResponse = new StreamingOutputCallResponse();
    goldenResponse.payload = new Payload();
    goldenResponse.payload.type = Messages.COMPRESSABLE;
    goldenResponse.payload.body = new byte[31415];
    ResponseObserver responseObserver = new ResponseObserver();
    StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver);
    requestObserver.onNext(request);
    Object response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    if (!(response instanceof Messages.StreamingOutputCallResponse)) {
        fail("Unexpected: " + response);
    }
    assertMessageEquals(goldenResponse, (Messages.StreamingOutputCallResponse) response);
    requestObserver.onError(new RuntimeException());
    response = responseObserver.responses.poll(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    if (!(response instanceof Throwable)) {
        fail("Unexpected: " + response);
    }
    assertCodeEquals(io.grpc.Status.CANCELLED, io.grpc.Status.fromThrowable((Throwable) response));
}
Also used : Messages(io.grpc.android.integrationtest.nano.Messages) StatusRuntimeException(io.grpc.StatusRuntimeException) ResponseParameters(io.grpc.android.integrationtest.nano.Messages.ResponseParameters) Payload(io.grpc.android.integrationtest.nano.Messages.Payload) StreamingOutputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse)

Example 7 with StreamingOutputCallResponse

use of io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse in project grpc-java by grpc.

the class InteropTester method timeoutOnSleepingServer.

/** Start a fullDuplexCall which the server will not respond, and verify the deadline expires. */
public void timeoutOnSleepingServer() throws Exception {
    TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel).withDeadlineAfter(1, TimeUnit.MILLISECONDS);
    StreamRecorder<StreamingOutputCallResponse> recorder = StreamRecorder.create();
    StreamObserver<StreamingOutputCallRequest> requestObserver = stub.fullDuplexCall(recorder);
    try {
        StreamingOutputCallRequest request = new StreamingOutputCallRequest();
        request.payload = new Messages.Payload();
        request.payload.body = new byte[27182];
        requestObserver.onNext(request);
    } catch (IllegalStateException expected) {
    // This can happen if the stream has already been terminated due to deadline exceeded.
    }
    assertTrue(recorder.awaitCompletion(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
    assertCodeEquals(io.grpc.Status.DEADLINE_EXCEEDED, io.grpc.Status.fromThrowable(recorder.getError()));
}
Also used : Messages(io.grpc.android.integrationtest.nano.Messages) TestServiceGrpc(io.grpc.android.integrationtest.nano.TestServiceGrpc) StreamingOutputCallRequest(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest) StreamingOutputCallResponse(io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse) Payload(io.grpc.android.integrationtest.nano.Messages.Payload)

Aggregations

StreamingOutputCallRequest (io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallRequest)7 StreamingOutputCallResponse (io.grpc.android.integrationtest.nano.Messages.StreamingOutputCallResponse)7 ResponseParameters (io.grpc.android.integrationtest.nano.Messages.ResponseParameters)6 Payload (io.grpc.android.integrationtest.nano.Messages.Payload)4 Messages (io.grpc.android.integrationtest.nano.Messages)3 EmptyProtos (com.google.protobuf.nano.EmptyProtos)1 ClientCall (io.grpc.ClientCall)1 Metadata (io.grpc.Metadata)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 TestServiceGrpc (io.grpc.android.integrationtest.nano.TestServiceGrpc)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1