use of io.grpc.Metadata in project grpc-java by grpc.
the class DelayedClientTransportTest method newStreamThenShutdownTransportThenCancelStream.
@Test
public void newStreamThenShutdownTransportThenCancelStream() {
ClientStream stream = delayedTransport.newStream(method, new Metadata());
delayedTransport.shutdown();
verify(transportListener).transportShutdown(any(Status.class));
verify(transportListener, times(0)).transportTerminated();
assertEquals(1, delayedTransport.getPendingStreamsCount());
stream.cancel(Status.CANCELLED);
verify(transportListener).transportTerminated();
assertEquals(0, delayedTransport.getPendingStreamsCount());
verifyNoMoreInteractions(mockRealTransport);
verifyNoMoreInteractions(mockRealStream);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class DelayedClientTransportTest method startThenCancelStreamWithoutSetTransport.
@Test
public void startThenCancelStreamWithoutSetTransport() {
ClientStream stream = delayedTransport.newStream(method, new Metadata());
stream.start(streamListener);
assertEquals(1, delayedTransport.getPendingStreamsCount());
stream.cancel(Status.CANCELLED);
assertEquals(0, delayedTransport.getPendingStreamsCount());
verify(streamListener).closed(same(Status.CANCELLED), any(Metadata.class));
verifyNoMoreInteractions(mockRealTransport);
verifyNoMoreInteractions(mockRealStream);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class DelayedStreamTest method listener_allQueued.
@Test
public void listener_allQueued() {
final Metadata headers = new Metadata();
final InputStream message1 = mock(InputStream.class);
final InputStream message2 = mock(InputStream.class);
final Metadata trailers = new Metadata();
final Status status = Status.UNKNOWN.withDescription("unique status");
final InOrder inOrder = inOrder(listener);
stream.start(listener);
stream.setStream(new NoopClientStream() {
@Override
public void start(ClientStreamListener passedListener) {
passedListener.onReady();
passedListener.headersRead(headers);
passedListener.messageRead(message1);
passedListener.onReady();
passedListener.messageRead(message2);
passedListener.closed(status, trailers);
verifyNoMoreInteractions(listener);
}
});
inOrder.verify(listener).onReady();
inOrder.verify(listener).headersRead(headers);
inOrder.verify(listener).messageRead(message1);
inOrder.verify(listener).onReady();
inOrder.verify(listener).messageRead(message2);
inOrder.verify(listener).closed(status, trailers);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method authorityNotPropagatedToStream.
@Test
public void authorityNotPropagatedToStream() {
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, MoreExecutors.directExecutor(), // Don't provide an authority
CallOptions.DEFAULT, statsTraceCtx, provider, deadlineCancellationExecutor).setDecompressorRegistry(decompressorRegistry);
call.start(callListener, new Metadata());
verify(stream, never()).setAuthority(any(String.class));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method contextAlreadyCancelledNotifiesImmediately.
@Test
public void contextAlreadyCancelledNotifiesImmediately() throws Exception {
// Attach the context which is recorded when the call is created
Context.CancellableContext cancellableContext = Context.current().withCancellation();
Throwable cause = new Throwable();
cancellableContext.cancel(cause);
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();
final SettableFuture<Status> statusFuture = SettableFuture.create();
call.start(new ClientCall.Listener<Void>() {
@Override
public void onClose(Status status, Metadata trailers) {
statusFuture.set(status);
}
}, new Metadata());
// Caller should receive onClose callback.
Status status = statusFuture.get(5, TimeUnit.SECONDS);
assertEquals(Status.Code.CANCELLED, status.getCode());
assertSame(cause, status.getCause());
assertStatusInStats(Status.Code.CANCELLED);
// Following operations should be no-op.
call.request(1);
call.sendMessage(null);
call.halfClose();
// Stream should never be created.
verifyZeroInteractions(transport);
try {
call.sendMessage(null);
fail("Call has been cancelled");
} catch (IllegalStateException ise) {
// expected
}
}
Aggregations