public GrpcCallContext withRequestParamsDynamicHeaderOption(String requestParams) { CallOptions newCallOptions = CallOptionsUtil.putRequestParamsDynamicHeaderOption(callOptions, requestParams); return withCallOptions(newCallOptions); }
/** {@inheritDoc} */ @Override public GrpcCallContext withTracer(@Nonnull ApiTracer tracer) { Preconditions.checkNotNull(tracer); return withCallOptions(callOptions.withOption(TRACER_KEY, tracer)); }
/** {@inheritDoc} */ @Override public GrpcCallContext withTracer(@Nonnull ApiTracer tracer) { Preconditions.checkNotNull(tracer); return withCallOptions(callOptions.withOption(TRACER_KEY, tracer)); }
public GrpcCallContext withRequestParamsDynamicHeaderOption(String requestParams) { CallOptions newCallOptions = CallOptionsUtil.putRequestParamsDynamicHeaderOption(callOptions, requestParams); return withCallOptions(newCallOptions); }
@Override public GrpcCallContext withCredentials(Credentials newCredentials) { Preconditions.checkNotNull(newCredentials); CallCredentials callCredentials = MoreCallCredentials.from(newCredentials); return withCallOptions(callOptions.withCallCredentials(callCredentials)); }
private GrpcCallContext addHandlers(GrpcCallContext grpcCallContext) { return Preconditions.checkNotNull(grpcCallContext) .withCallOptions( CallOptionsUtil.putMetadataHandlerOption(grpcCallContext.getCallOptions(), this)); }
private GrpcCallContext addHandlers(GrpcCallContext grpcCallContext) { return Preconditions.checkNotNull(grpcCallContext) .withCallOptions( CallOptionsUtil.putMetadataHandlerOption(grpcCallContext.getCallOptions(), this)); }
@Override public GrpcCallContext withCredentials(Credentials newCredentials) { Preconditions.checkNotNull(newCredentials); CallCredentials callCredentials = MoreCallCredentials.from(newCredentials); return withCallOptions(callOptions.withCallCredentials(callCredentials)); }
@Test public void testTimeoutAfterDeadline() { MethodDescriptor<Color, Money> descriptor = FakeServiceGrpc.METHOD_RECOGNIZE; @SuppressWarnings("unchecked") ClientCall<Color, Money> mockClientCall = Mockito.mock(ClientCall.class); @SuppressWarnings("unchecked") ClientCall.Listener<Money> mockListener = Mockito.mock(ClientCall.Listener.class); @SuppressWarnings("unchecked") Channel mockChannel = Mockito.mock(ManagedChannel.class); ArgumentCaptor<CallOptions> capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class); Mockito.when(mockChannel.newCall(Mockito.eq(descriptor), capturedCallOptions.capture())) .thenReturn(mockClientCall); // Configure a timeout that occurs after the grpc deadline Deadline priorDeadline = Deadline.after(5, TimeUnit.SECONDS); Duration timeout = Duration.ofSeconds(10); GrpcCallContext context = GrpcCallContext.createDefault() .withChannel(mockChannel) .withCallOptions(CallOptions.DEFAULT.withDeadline(priorDeadline)) .withTimeout(timeout); GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata()); // Verify that the timeout is ignored Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isEqualTo(priorDeadline); }
GrpcCallContext.createDefault() .withChannel(mockChannel) .withCallOptions(CallOptions.DEFAULT.withDeadline(subsequentDeadline)) .withTimeout(timeout);
@Test public void testMergeWithCustomCallOptions() { CallOptions.Key<String> key = CallOptions.Key.createWithDefault("somekey", "somedefault"); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault() .withCallOptions(CallOptions.DEFAULT.withOption(key, "somevalue")); GrpcCallContext merged = (GrpcCallContext) ctx1.merge(ctx2); Truth.assertThat(merged.getCallOptions().getOption(key)) .isNotEqualTo(ctx1.getCallOptions().getOption(key)); Truth.assertThat(merged.getCallOptions().getOption(key)) .isEqualTo(ctx2.getCallOptions().getOption(key)); }