use of com.google.api.gax.rpc.CancelledException in project gax-java by googleapis.
the class TracedClientStreamingCallableTest method testOperationCancelled.
@Test
public void testOperationCancelled() {
ApiStreamObserver<String> clientStream = tracedCallable.clientStreamingCall(outerResponseObsever, callContext);
clientStream.onError(new CancellationException("explicitly cancelled"));
innerCallable.responseObserver.onError(new CancelledException("fake exception that would be generated by a client cancelling the rpc", null, FakeStatusCode.of(Code.CANCELLED), false));
verify(tracer, times(1)).operationCancelled();
}
use of com.google.api.gax.rpc.CancelledException in project gax-java by googleapis.
the class TracedServerStreamingCallableTest method testOperationCancelled.
@Test
public void testOperationCancelled() {
tracedCallable.call("test", responseObserver, callContext);
responseObserver.getController().cancel();
MockServerStreamingCall<String, String> innerCall = innerCallable.popLastCall();
innerCall.getController().getObserver().onError(new CancelledException("fake cancel", null, new FakeStatusCode(Code.CANCELLED), false));
assertThat(responseObserver.isDone()).isTrue();
verify(tracer, times(1)).operationCancelled();
}
use of com.google.api.gax.rpc.CancelledException in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImplTest method createTestBackup.
private Backup createTestBackup() {
CreateBackupRequest request = CreateBackupRequest.newBuilder().setBackupId("test-bck").setBackup(Backup.newBuilder().setDatabase(TEST_DB_NAME).setExpireTime(Timestamp.newBuilder().setSeconds(System.currentTimeMillis() * 1000L + TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS))).build()).setParent(TEST_PARENT).build();
OperationFuture<Backup, CreateBackupMetadata> op = client.createBackupOperationCallable().futureCall(request);
try {
return op.get();
} catch (ExecutionException e) {
if (e.getCause() != null && e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new CancelledException(e, FakeStatusCode.of(Code.CANCELLED), false);
}
}
use of com.google.api.gax.rpc.CancelledException in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImplTest method createTestDb.
private Database createTestDb() {
CreateDatabaseRequest request = CreateDatabaseRequest.newBuilder().setCreateStatement("CREATE DATABASE `test-db`").addAllExtraStatements(Arrays.asList("CREATE TABLE FOO", "CREATE TABLE BAR")).setParent(TEST_PARENT).build();
OperationFuture<Database, CreateDatabaseMetadata> op = client.createDatabaseOperationCallable().futureCall(request);
try {
return op.get();
} catch (ExecutionException e) {
if (e.getCause() != null && e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new CancelledException(e, FakeStatusCode.of(Code.CANCELLED), false);
}
}
Aggregations