Search in sources :

Example 46 with CallOptions

use of io.grpc.CallOptions in project grpc-java by grpc.

the class ClientCallImplTest method contextDeadlineShouldOverrideLargerMetadataTimeout.

@Test
public void contextDeadlineShouldOverrideLargerMetadataTimeout() {
    long deadlineNanos = TimeUnit.SECONDS.toNanos(1);
    Context context = Context.current().withDeadlineAfter(deadlineNanos, TimeUnit.NANOSECONDS, deadlineCancellationExecutor);
    context.attach();
    CallOptions callOpts = CallOptions.DEFAULT.withDeadlineAfter(2, TimeUnit.SECONDS);
    ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, MoreExecutors.directExecutor(), callOpts, statsTraceCtx, provider, deadlineCancellationExecutor);
    Metadata headers = new Metadata();
    call.start(callListener, headers);
    assertTrue(headers.containsKey(GrpcUtil.TIMEOUT_KEY));
    Long timeout = headers.get(GrpcUtil.TIMEOUT_KEY);
    assertNotNull(timeout);
    long deltaNanos = TimeUnit.MILLISECONDS.toNanos(400);
    assertTimeoutBetween(timeout, deadlineNanos - deltaNanos, deadlineNanos);
}
Also used : Context(io.grpc.Context) StatsContext(com.google.instrumentation.stats.StatsContext) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 47 with CallOptions

use of io.grpc.CallOptions in project grpc-java by grpc.

the class ClientCallImplTest method contextDeadlineShouldNotOverrideSmallerMetadataTimeout.

@Test
public void contextDeadlineShouldNotOverrideSmallerMetadataTimeout() {
    long deadlineNanos = TimeUnit.SECONDS.toNanos(2);
    Context context = Context.current().withDeadlineAfter(deadlineNanos, TimeUnit.NANOSECONDS, deadlineCancellationExecutor);
    context.attach();
    CallOptions callOpts = CallOptions.DEFAULT.withDeadlineAfter(1, TimeUnit.SECONDS);
    ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, MoreExecutors.directExecutor(), callOpts, statsTraceCtx, provider, deadlineCancellationExecutor);
    Metadata headers = new Metadata();
    call.start(callListener, headers);
    assertTrue(headers.containsKey(GrpcUtil.TIMEOUT_KEY));
    Long timeout = headers.get(GrpcUtil.TIMEOUT_KEY);
    assertNotNull(timeout);
    long callOptsNanos = TimeUnit.SECONDS.toNanos(1);
    long deltaNanos = TimeUnit.MILLISECONDS.toNanos(400);
    assertTimeoutBetween(timeout, callOptsNanos - deltaNanos, callOptsNanos);
}
Also used : Context(io.grpc.Context) StatsContext(com.google.instrumentation.stats.StatsContext) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 48 with CallOptions

use of io.grpc.CallOptions in project grpc-java by grpc.

the class AbstractStubTest method withWaitForReady.

@Test()
public void withWaitForReady() {
    NoopStub stub = new NoopStub(channel);
    CallOptions callOptions = stub.getCallOptions();
    assertFalse(callOptions.isWaitForReady());
    stub = stub.withWaitForReady();
    callOptions = stub.getCallOptions();
    assertTrue(callOptions.isWaitForReady());
}
Also used : CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 49 with CallOptions

use of io.grpc.CallOptions in project google-cloud-java by GoogleCloudPlatform.

the class GrpcSpannerRpc method doStreamingCall.

private <T> StreamingCall doStreamingCall(MethodDescriptor<T, PartialResultSet> method, T request, ResultStreamConsumer consumer, @Nullable String resource, @Nullable Long channelHint) {
    final Context context = Context.current();
    // TODO: Add deadline based on context.
    CallOptions callOptions = credentials == null ? CallOptions.DEFAULT : CallOptions.DEFAULT.withCallCredentials(credentials);
    final ClientCall<T, PartialResultSet> call = new MetadataClientCall<>(pick(channelHint, channels).newCall(method, callOptions), newMetadata(resource));
    ResultSetStreamObserver<T> observer = new ResultSetStreamObserver<T>(consumer, context, call);
    ClientCalls.asyncServerStreamingCall(call, request, observer);
    return observer;
}
Also used : Context(io.grpc.Context) CallOptions(io.grpc.CallOptions) PartialResultSet(com.google.spanner.v1.PartialResultSet)

Example 50 with CallOptions

use of io.grpc.CallOptions in project google-cloud-java by GoogleCloudPlatform.

the class GrpcSpannerRpc method doUnaryCall.

private <ReqT, RespT> Future<RespT> doUnaryCall(MethodDescriptor<ReqT, RespT> method, ReqT request, @Nullable String resource, @Nullable Long channelHint) {
    CallOptions callOptions = credentials == null ? CallOptions.DEFAULT : CallOptions.DEFAULT.withCallCredentials(credentials);
    final ClientCall<ReqT, RespT> call = new MetadataClientCall<>(pick(channelHint, channels).newCall(method, callOptions), newMetadata(resource));
    return ClientCalls.futureUnaryCall(call, request);
}
Also used : CallOptions(io.grpc.CallOptions)

Aggregations

CallOptions (io.grpc.CallOptions)81 Test (org.junit.Test)61 Metadata (io.grpc.Metadata)50 Channel (io.grpc.Channel)36 MethodDescriptor (io.grpc.MethodDescriptor)28 ClientInterceptor (io.grpc.ClientInterceptor)23 ManagedChannel (io.grpc.ManagedChannel)18 ClientStreamTracer (io.grpc.ClientStreamTracer)17 ClientCall (io.grpc.ClientCall)15 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)11 Status (io.grpc.Status)11 Context (io.grpc.Context)10 Subchannel (io.grpc.LoadBalancer.Subchannel)10 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)10 ForwardingSubchannel (io.grpc.util.ForwardingSubchannel)9 SimpleForwardingClientCall (io.grpc.ForwardingClientCall.SimpleForwardingClientCall)8 NoopClientCall (io.grpc.internal.NoopClientCall)8 SocketAddress (java.net.SocketAddress)8 SimpleForwardingClientCallListener (io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener)7 ByteString (com.google.protobuf.ByteString)6