use of org.apache.beam.vendor.grpc.v1p43p2.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);
}
use of org.apache.beam.vendor.grpc.v1p43p2.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);
}
use of org.apache.beam.vendor.grpc.v1p43p2.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());
}
use of org.apache.beam.vendor.grpc.v1p43p2.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;
}
use of org.apache.beam.vendor.grpc.v1p43p2.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);
}
Aggregations