use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method exceptionInOnMessageTakesPrecedenceOverServer.
@Test
public void exceptionInOnMessageTakesPrecedenceOverServer() {
DelayedExecutor executor = new DelayedExecutor();
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, executor, CallOptions.DEFAULT, statsTraceCtx, provider, deadlineCancellationExecutor);
call.start(callListener, new Metadata());
verify(stream).start(listenerArgumentCaptor.capture());
final ClientStreamListener streamListener = listenerArgumentCaptor.getValue();
streamListener.headersRead(new Metadata());
RuntimeException failure = new RuntimeException("bad");
doThrow(failure).when(callListener).onMessage(any(Void.class));
/*
* In unary calls, the server closes the call right after responding, so the onClose call is
* queued to run. When messageRead is called, an exception will occur and attempt to cancel the
* stream. However, since the server closed it "first" the second exception is lost leading to
* the call being counted as successful.
*/
streamListener.messageRead(new ByteArrayInputStream(new byte[] {}));
streamListener.closed(Status.OK, new Metadata());
executor.release();
verify(callListener).onClose(statusArgumentCaptor.capture(), Matchers.isA(Metadata.class));
assertThat(statusArgumentCaptor.getValue().getCode()).isEqualTo(Status.Code.CANCELLED);
assertThat(statusArgumentCaptor.getValue().getCause()).isSameAs(failure);
verify(stream).cancel(statusArgumentCaptor.getValue());
assertStatusInStats(Status.Code.CANCELLED);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class DelayedClientTransportTest method startStreamThenShutdownNow.
@Test
public void startStreamThenShutdownNow() {
ClientStream stream = delayedTransport.newStream(method, new Metadata());
stream.start(streamListener);
delayedTransport.shutdownNow(Status.UNAVAILABLE);
verify(transportListener).transportShutdown(any(Status.class));
verify(transportListener).transportTerminated();
verify(streamListener).closed(statusCaptor.capture(), any(Metadata.class));
assertEquals(Status.Code.UNAVAILABLE, statusCaptor.getValue().getCode());
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStream2Test method inboundHeadersReceived_acceptsGzipEncoding.
@Test
public void inboundHeadersReceived_acceptsGzipEncoding() {
AbstractClientStream2 stream = new BaseAbstractClientStream(allocator, statsTraceCtx);
stream.start(mockListener);
Metadata headers = new Metadata();
headers.put(GrpcUtil.MESSAGE_ENCODING_KEY, new Codec.Gzip().getMessageEncoding());
stream.transportState().inboundHeadersReceived(headers);
verify(mockListener).headersRead(headers);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStream2Test method inboundHeadersReceived_acceptsIdentityEncoding.
@Test
public void inboundHeadersReceived_acceptsIdentityEncoding() {
AbstractClientStream2 stream = new BaseAbstractClientStream(allocator, statsTraceCtx);
stream.start(mockListener);
Metadata headers = new Metadata();
headers.put(GrpcUtil.MESSAGE_ENCODING_KEY, Codec.Identity.NONE.getMessageEncoding());
stream.transportState().inboundHeadersReceived(headers);
verify(mockListener).headersRead(headers);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class AbstractClientStream2Test method inboundHeadersReceived_failsIfStatusReported.
@Test
public void inboundHeadersReceived_failsIfStatusReported() {
AbstractClientStream2 stream = new BaseAbstractClientStream(allocator, statsTraceCtx);
stream.start(mockListener);
stream.transportState().transportReportStatus(Status.CANCELLED, false, new Metadata());
TransportState state = stream.transportState();
thrown.expect(IllegalStateException.class);
state.inboundHeadersReceived(new Metadata());
}
Aggregations