Search in sources :

Example 6 with NoopClientCall

use of io.grpc.testing.NoopClientCall in project grpc-java by grpc.

the class ClientCallsTest method unaryBlockingCallFailed.

@Test
public void unaryBlockingCallFailed() throws Exception {
    Integer req = 2;
    final Status status = Status.INTERNAL.withDescription("Unique status");
    final Metadata trailers = new Metadata();
    NoopClientCall<Integer, String> call = new NoopClientCall<Integer, String>() {

        @Override
        public void start(io.grpc.ClientCall.Listener<String> listener, Metadata headers) {
            listener.onClose(status, trailers);
        }
    };
    try {
        ClientCalls.blockingUnaryCall(call, req);
        fail("Should fail");
    } catch (StatusRuntimeException e) {
        assertSame(status, e.getStatus());
        assertSame(trailers, e.getTrailers());
    }
}
Also used : Status(io.grpc.Status) NoopClientCall(io.grpc.testing.NoopClientCall) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

Metadata (io.grpc.Metadata)6 NoopClientCall (io.grpc.testing.NoopClientCall)6 Test (org.junit.Test)6 ClientCall (io.grpc.ClientCall)4 Status (io.grpc.Status)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 StatusRuntimeException (io.grpc.StatusRuntimeException)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1