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);
}
Aggregations