@Override public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext inputContext) { Preconditions.checkNotNull(request); Preconditions.checkNotNull(inputContext); return new ListenableFutureToApiFuture<>( ClientCalls.futureUnaryCall(GrpcClientCalls.newCall(descriptor, inputContext), request)); }
@Override public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext inputContext) { Preconditions.checkNotNull(request); Preconditions.checkNotNull(inputContext); return new ListenableFutureToApiFuture<>( ClientCalls.futureUnaryCall(GrpcClientCalls.newCall(descriptor, inputContext), request)); }
/** * Submits an attempt for execution in a different thread. * * @param retryingFuture the future previously returned by {@link #createFuture(Callable, * RetryingContext)} * @return submitted attempt future */ @Override public ApiFuture<ResponseT> submit(RetryingFuture<ResponseT> retryingFuture) { try { ListenableFuture<ResponseT> attemptFuture = scheduler.schedule( retryingFuture.getCallable(), retryingFuture.getAttemptSettings().getRandomizedRetryDelay().toMillis(), TimeUnit.MILLISECONDS); return new ListenableFutureToApiFuture<>(attemptFuture); } catch (RejectedExecutionException e) { return ApiFutures.immediateFailedFuture(e); } } }
/** * Submits an attempt for execution in a different thread. * * @param retryingFuture the future previously returned by {@link #createFuture(Callable, * RetryingContext)} * @return submitted attempt future */ @Override public ApiFuture<ResponseT> submit(RetryingFuture<ResponseT> retryingFuture) { try { ListenableFuture<ResponseT> attemptFuture = scheduler.schedule( retryingFuture.getCallable(), retryingFuture.getAttemptSettings().getRandomizedRetryDelay().toMillis(), TimeUnit.MILLISECONDS); return new ListenableFutureToApiFuture<>(attemptFuture); } catch (RejectedExecutionException e) { return ApiFutures.immediateFailedFuture(e); } } }
new ListenableFutureToApiFuture<>(futureError); executor.shutdown();
@Test public void testFutureCallInitialCancel() throws Exception { String opName = "testFutureCallInitialCancel"; OperationSnapshot initialOperation = getOperation(opName, null, null, null, false); OperationSnapshot resultOperation = getOperation(opName, null, null, null, false); UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation); LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.OK, resultOperation); OperationCallableImpl<Integer, Color, Currency> callableImpl = Callables.longRunningOperationImpl( initialCallable, callSettings, initialContext, longRunningClient); OperationFutureImpl<Color, Currency> future = callableImpl.futureCall( new ListenableFutureToApiFuture<>( Futures.<OperationSnapshot>immediateCancelledFuture()), FakeCallContext.createDefault()); Exception exception = null; try { future.get(3, TimeUnit.SECONDS); } catch (CancellationException e) { exception = e; } assertThat(exception).isNotNull(); assertThat(future.isDone()).isTrue(); assertThat(future.isCancelled()).isTrue(); assertThat(future.getInitialFuture().isDone()).isTrue(); assertThat(future.getInitialFuture().isCancelled()).isTrue(); assertFutureCancelMetaCancel(future); assertThat(executor.getIterationsCount()).isEqualTo(0); }