Search in sources :

Example 1 with EchoStatus

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

the class AbstractInteropTest method statusCodeAndMessage.

@Test
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());
    }
    assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN);
    // Test FullDuplexCall
    StreamRecorder<StreamingOutputCallResponse> responseObserver = StreamRecorder.create();
    StreamObserver<StreamingOutputCallRequest> requestObserver = asyncStub.fullDuplexCall(responseObserver);
    requestObserver.onNext(streamingRequest);
    requestObserver.onCompleted();
    assertThat(responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS)).isTrue();
    assertThat(responseObserver.getError()).isNotNull();
    Status status = Status.fromThrowable(responseObserver.getError());
    assertEquals(Status.UNKNOWN.getCode(), status.getCode());
    assertEquals(errorMessage, status.getDescription());
    assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.UNKNOWN);
}
Also used : Status(io.grpc.Status) EchoStatus(io.grpc.testing.integration.Messages.EchoStatus) 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

ByteString (com.google.protobuf.ByteString)1 Status (io.grpc.Status)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 EchoStatus (io.grpc.testing.integration.Messages.EchoStatus)1 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)1 StreamingOutputCallRequest (io.grpc.testing.integration.Messages.StreamingOutputCallRequest)1 StreamingOutputCallResponse (io.grpc.testing.integration.Messages.StreamingOutputCallResponse)1 Test (org.junit.Test)1