/** * Sends a cancellation request to the server for the operation with name {@code operationName}. * * @param operationName The name of the operation to cancel. * @return the future which completes once the operation is canceled on the server side. */ public ApiFuture<Void> cancel(String operationName) { return cancel(operationName, null); }
/** * Sends a cancellation request to the server for the operation with name {@code operationName}. * * @param operationName The name of the operation to cancel. * @return the future which completes once the operation is canceled on the server side. */ public ApiFuture<Void> cancel(String operationName) { return cancel(operationName, null); }
@Override public ApiFuture<Void> cancel(String operationName, ApiCallContext thisCallContext) { return OperationCallable.this.cancel( operationName, defaultCallContext.merge(thisCallContext)); } };
@Override public ApiFuture<Void> cancel(String operationName, ApiCallContext thisCallContext) { return OperationCallable.this.cancel( operationName, defaultCallContext.merge(thisCallContext)); } };
@Test public void testCancelOperation() throws Exception { String opName = "testCancelOperation"; LongRunningClient longRunningClient = mockCancelOperation(StatusCode.Code.OK); ClientContext mockContext = getClientContext(new FakeChannel(), executor); OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable( getUnexpectedStartCallable(), callSettings, mockContext, longRunningClient); ApiFuture<Void> future = callable.cancel(opName); assertThat(future.get()).isNull(); }
@Test public void callCancel() throws Exception { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(defaultCallContext); OperationFuture<String, Long> operationFuture = callable.futureCall(45); callable.cancel(operationFuture.getName()).get(); Truth.assertThat(stashCallable.wasCancelCalled()).isTrue(); Truth.assertThat(stashCallable.getCancelContext()).isSameAs(defaultCallContext); }
@Test public void callCancelWithContext() throws Exception { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); OperationFuture<String, Long> operationFuture = callable.futureCall(45); callable.cancel(operationFuture.getName(), context).get(); Truth.assertThat(stashCallable.wasCancelCalled()).isTrue(); FakeCallContext actualContext = (FakeCallContext) stashCallable.getCancelContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }