use of com.google.longrunning.CancelOperationRequest in project gax-java by googleapis.
the class OperationsClient method cancelOperation.
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Starts asynchronous cancellation on a long-running operation. The server makes a best effort to
* cancel the operation, but success is not guaranteed. If the server doesn't support this method,
* it returns `google.rpc.Code.UNIMPLEMENTED`. Clients can use
* [Operations.GetOperation][google.longrunning.Operations.GetOperation] or other methods to check
* whether the cancellation succeeded or whether the operation completed despite cancellation. On
* successful cancellation, the operation is not deleted; instead, it becomes an operation with an
* [Operation.error][google.longrunning.Operation.error] value with a
* [google.rpc.Status.code][google.rpc.Status.code] of 1, corresponding to `Code.CANCELLED`.
*
* <p>Sample code:
*
* <pre>{@code
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "name3373707";
* operationsClient.cancelOperation(name);
* }
* }</pre>
*
* @param name The name of the operation resource to be cancelled.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void cancelOperation(String name) {
CancelOperationRequest request = CancelOperationRequest.newBuilder().setName(name).build();
cancelOperation(request);
}
use of com.google.longrunning.CancelOperationRequest in project java-spanner by googleapis.
the class GapicSpannerRpc method cancelOperation.
@Override
public void cancelOperation(String name) throws SpannerException {
acquireAdministrativeRequestsRateLimiter();
final CancelOperationRequest request = CancelOperationRequest.newBuilder().setName(name).build();
final GrpcCallContext context = newCallContext(null, name, request, OperationsGrpc.getCancelOperationMethod());
runWithRetryOnAdministrativeRequestsExceeded(() -> {
get(databaseAdminStub.getOperationsStub().cancelOperationCallable().futureCall(request, context));
return null;
});
}
use of com.google.longrunning.CancelOperationRequest in project gax-java by googleapis.
the class GrpcLongRunningClientTest method cancel.
@Test
public void cancel() {
OperationsStub operationsStub = mock(OperationsStub.class);
when(operationsStub.cancelOperationCallable()).thenReturn(new UnaryCallable<CancelOperationRequest, Empty>() {
@Override
public ApiFuture<Empty> futureCall(CancelOperationRequest request, ApiCallContext context) {
if (!request.getName().equals("poseidon")) {
return ApiFutures.immediateFailedFuture(new IllegalStateException("Unexpected request: " + request));
} else {
return ApiFutures.immediateFuture(Empty.getDefaultInstance());
}
}
});
LongRunningClient longRunningClient = new GrpcLongRunningClient(operationsStub);
Truth.assertThat(longRunningClient.cancelOperationCallable().call("poseidon")).isNull();
}
use of com.google.longrunning.CancelOperationRequest in project bazel-buildfarm by bazelbuild.
the class BuildFarmServerTest method cancelledOperationHasCancelledState.
@Test
public void cancelledOperationHasCancelledState() throws IOException, InterruptedException {
Operation operation = executeAction(createSimpleAction());
OperationsGrpc.OperationsBlockingStub operationsStub = OperationsGrpc.newBlockingStub(inProcessChannel);
// should be available with cancelled state
Operation preCancelOperation = getOperation(operation.getName());
assertThat(preCancelOperation.getDone()).isFalse();
CancelOperationRequest cancelRequest = CancelOperationRequest.newBuilder().setName(operation.getName()).build();
operationsStub.cancelOperation(cancelRequest);
Operation cancelledOperation = getOperation(operation.getName());
assertThat(cancelledOperation.getDone()).isTrue();
assertThat(cancelledOperation.getResultCase()).isEqualTo(Operation.ResultCase.RESPONSE);
ExecuteResponse executeResponse = cancelledOperation.getResponse().unpack(ExecuteResponse.class);
assertThat(executeResponse.getStatus().getCode()).isEqualTo(Code.CANCELLED.getNumber());
}
use of com.google.longrunning.CancelOperationRequest in project bazel-buildfarm by bazelbuild.
the class BuildFarmServerTest method canceledOperationIsNoLongerOutstanding.
@Test
public void canceledOperationIsNoLongerOutstanding() throws IOException, InterruptedException {
Operation operation = executeAction(createSimpleAction());
// should appear in outstanding list
ListOperationsRequest listRequest = ListOperationsRequest.newBuilder().setName(INSTANCE_NAME + "/operations").setPageSize(1024).build();
OperationsGrpc.OperationsBlockingStub operationsStub = OperationsGrpc.newBlockingStub(inProcessChannel);
ListOperationsResponse listResponse = operationsStub.listOperations(listRequest);
assertThat(Iterables.transform(listResponse.getOperationsList(), Operation::getName)).containsExactly(operation.getName());
CancelOperationRequest cancelRequest = CancelOperationRequest.newBuilder().setName(operation.getName()).build();
operationsStub.cancelOperation(cancelRequest);
// should now be gone
listResponse = operationsStub.listOperations(listRequest);
assertThat(listResponse.getOperationsList()).isEmpty();
}
Aggregations