use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method methodInfoDeadlinePropagatedToStream.
@Test
public void methodInfoDeadlinePropagatedToStream() {
ArgumentCaptor<CallOptions> callOptionsCaptor = ArgumentCaptor.forClass(null);
CallOptions callOptions = baseCallOptions.withDeadline(Deadline.after(2000, SECONDS));
// Case: config Deadline expires later than CallOptions Deadline
Map<String, ?> rawMethodConfig = ImmutableMap.of("timeout", "3000s");
MethodInfo methodInfo = new MethodInfo(rawMethodConfig, false, 0, 0);
callOptions = callOptions.withOption(MethodInfo.KEY, methodInfo);
ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, MoreExecutors.directExecutor(), callOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
call.start(callListener, new Metadata());
verify(clientStreamProvider).newStream(same(method), callOptionsCaptor.capture(), any(Metadata.class), any(Context.class));
Deadline actualDeadline = callOptionsCaptor.getValue().getDeadline();
assertThat(actualDeadline).isLessThan(Deadline.after(2001, SECONDS));
// Case: config Deadline expires earlier than CallOptions Deadline
rawMethodConfig = ImmutableMap.of("timeout", "1000s");
methodInfo = new MethodInfo(rawMethodConfig, false, 0, 0);
callOptions = callOptions.withOption(MethodInfo.KEY, methodInfo);
call = new ClientCallImpl<>(method, MoreExecutors.directExecutor(), callOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
call.start(callListener, new Metadata());
verify(clientStreamProvider, times(2)).newStream(same(method), callOptionsCaptor.capture(), any(Metadata.class), any(Context.class));
actualDeadline = callOptionsCaptor.getValue().getDeadline();
assertThat(actualDeadline).isLessThan(Deadline.after(1001, SECONDS));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method deadlineExceededBeforeCallStarted.
@Test
public void deadlineExceededBeforeCallStarted() {
CallOptions callOptions = baseCallOptions.withDeadlineAfter(0, TimeUnit.SECONDS);
fakeClock.forwardTime(System.nanoTime(), TimeUnit.NANOSECONDS);
ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, new SerializingExecutor(Executors.newSingleThreadExecutor()), callOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
call.start(callListener, new Metadata());
verify(streamTracerFactory).newClientStreamTracer(any(StreamInfo.class), any(Metadata.class));
verify(clientStreamProvider, never()).newStream((MethodDescriptor<?, ?>) any(MethodDescriptor.class), any(CallOptions.class), any(Metadata.class), any(Context.class));
verify(callListener, timeout(1000)).onClose(statusCaptor.capture(), any(Metadata.class));
assertEquals(Status.Code.DEADLINE_EXCEEDED, statusCaptor.getValue().getCode());
assertThat(statusCaptor.getValue().getDescription()).startsWith("ClientCall started after deadline exceeded");
verifyNoInteractions(clientStreamProvider);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method callOptionsPropagatedToTransport.
@Test
public void callOptionsPropagatedToTransport() {
final CallOptions callOptions = baseCallOptions.withAuthority("dummy_value");
final ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, MoreExecutors.directExecutor(), callOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
final Metadata metadata = new Metadata();
call.start(callListener, metadata);
verify(clientStreamProvider).newStream(same(method), same(callOptions), same(metadata), any(Context.class));
}
use of org.apache.beam.vendor.grpc.v1p43p2.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<>(method, new SerializingExecutor(Executors.newSingleThreadExecutor()), baseCallOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
cancellableContext.detach(previous);
call.start(callListener, new Metadata());
Throwable t = new Throwable();
cancellableContext.cancel(t);
verify(stream, times(1)).cancel(statusArgumentCaptor.capture());
Status streamStatus = statusArgumentCaptor.getValue();
assertEquals(Status.Code.CANCELLED, streamStatus.getCode());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method halfClosedShouldNotBeReady.
@Test
public void halfClosedShouldNotBeReady() {
when(stream.isReady()).thenReturn(true);
ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, MoreExecutors.directExecutor(), baseCallOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector);
call.start(callListener, new Metadata());
assertThat(call.isReady()).isTrue();
call.halfClose();
assertThat(call.isReady()).isFalse();
}
Aggregations