/** Waits for the initialFuture to resolve and then starts to poll the return operation. */ OperationFutureImpl<ResponseT, MetadataT> futureCall( ApiFuture<OperationSnapshot> initialFuture, ApiCallContext callContext) { RecheckingCallable<RequestT, OperationSnapshot> callable = new RecheckingCallable<>( new OperationCheckingCallable<RequestT>(longRunningClient, initialFuture), executor); // NOTE: OperationCheckingCallable will compose its own request using the resolved // initialFuture. So the request parameter to futureCall is ignored RetryingFuture<OperationSnapshot> pollingFuture = callable.futureCall(null, callContext); return new OperationFutureImpl<>( pollingFuture, initialFuture, responseTransformer, metadataTransformer); }
@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); }
/** Waits for the initialFuture to resolve and then starts to poll the return operation. */ OperationFutureImpl<ResponseT, MetadataT> futureCall( ApiFuture<OperationSnapshot> initialFuture, ApiCallContext callContext) { RecheckingCallable<RequestT, OperationSnapshot> callable = new RecheckingCallable<>( new OperationCheckingCallable<RequestT>(longRunningClient, initialFuture), executor); // NOTE: OperationCheckingCallable will compose its own request using the resolved // initialFuture. So the request parameter to futureCall is ignored RetryingFuture<OperationSnapshot> pollingFuture = callable.futureCall(null, callContext); return new OperationFutureImpl<>( pollingFuture, initialFuture, responseTransformer, metadataTransformer); }
new OperationFutureImpl<>( pollingFuture, initialFuture, responseTransform, metadataTransform);