use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method prepareHeaders_ignoreIdentityEncoding.
@Test
public void prepareHeaders_ignoreIdentityEncoding() {
Metadata m = new Metadata();
ClientCallImpl.prepareHeaders(m, decompressorRegistry, Codec.Identity.NONE, statsTraceCtx);
assertNull(m.get(GrpcUtil.MESSAGE_ENCODING_KEY));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method exceptionInOnReadyTakesPrecedenceOverServer.
@Test
public void exceptionInOnReadyTakesPrecedenceOverServer() {
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();
RuntimeException failure = new RuntimeException("bad");
doThrow(failure).when(callListener).onReady();
/*
* In unary calls, the server closes the call right after responding, so the onClose call is
* queued to run. When onReady 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.onReady();
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 ClientCallImplTest method prepareHeaders_statsCtxAdded.
@Test
public void prepareHeaders_statsCtxAdded() {
Metadata m = new Metadata();
ClientCallImpl.prepareHeaders(m, decompressorRegistry, Codec.Identity.NONE, statsTraceCtx);
assertEquals(parentStatsContext, m.get(statsTraceCtx.getStatsHeader()));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method deadlineExceededBeforeCallStarted.
@Test
public void deadlineExceededBeforeCallStarted() {
CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(0, TimeUnit.SECONDS);
fakeClock.forwardTime(System.nanoTime(), TimeUnit.NANOSECONDS);
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, new SerializingExecutor(Executors.newSingleThreadExecutor()), callOptions, statsTraceCtx, provider, deadlineCancellationExecutor).setDecompressorRegistry(decompressorRegistry);
call.start(callListener, new Metadata());
verify(transport, times(0)).newStream(any(MethodDescriptor.class), any(Metadata.class));
verify(callListener, timeout(1000)).onClose(statusCaptor.capture(), any(Metadata.class));
assertEquals(Status.Code.DEADLINE_EXCEEDED, statusCaptor.getValue().getCode());
assertStatusInStats(Status.Code.DEADLINE_EXCEEDED);
verifyZeroInteractions(provider);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method contextCancellationCancelsStream.
@Test
public void contextCancellationCancelsStream() throws Exception {
// Attach the context which is recorded when the call is created
Context.CancellableContext cancellableContext = Context.current().withCancellation();
Context previous = cancellableContext.attach();
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, new SerializingExecutor(Executors.newSingleThreadExecutor()), CallOptions.DEFAULT, statsTraceCtx, provider, deadlineCancellationExecutor).setDecompressorRegistry(decompressorRegistry);
previous.attach();
call.start(callListener, new Metadata());
Throwable t = new Throwable();
cancellableContext.cancel(t);
verify(stream, times(1)).cancel(statusArgumentCaptor.capture());
verify(stream, times(1)).cancel(statusCaptor.capture());
assertEquals(Status.Code.CANCELLED, statusCaptor.getValue().getCode());
}
Aggregations