Search in sources :

Example 1 with CancelledException

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();
}
Also used : CancellationException(java.util.concurrent.CancellationException) CancelledException(com.google.api.gax.rpc.CancelledException) Test(org.junit.Test)

Example 2 with CancelledException

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();
}
Also used : FakeStatusCode(com.google.api.gax.rpc.testing.FakeStatusCode) CancelledException(com.google.api.gax.rpc.CancelledException) Test(org.junit.Test)

Example 3 with CancelledException

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);
    }
}
Also used : CreateBackupRequest(com.google.spanner.admin.database.v1.CreateBackupRequest) CancelledException(com.google.api.gax.rpc.CancelledException) Backup(com.google.spanner.admin.database.v1.Backup) CreateBackupMetadata(com.google.spanner.admin.database.v1.CreateBackupMetadata) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with CancelledException

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);
    }
}
Also used : CreateDatabaseRequest(com.google.spanner.admin.database.v1.CreateDatabaseRequest) CancelledException(com.google.api.gax.rpc.CancelledException) Database(com.google.spanner.admin.database.v1.Database) CreateDatabaseMetadata(com.google.spanner.admin.database.v1.CreateDatabaseMetadata) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CancelledException (com.google.api.gax.rpc.CancelledException)4 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 FakeStatusCode (com.google.api.gax.rpc.testing.FakeStatusCode)1 Backup (com.google.spanner.admin.database.v1.Backup)1 CreateBackupMetadata (com.google.spanner.admin.database.v1.CreateBackupMetadata)1 CreateBackupRequest (com.google.spanner.admin.database.v1.CreateBackupRequest)1 CreateDatabaseMetadata (com.google.spanner.admin.database.v1.CreateDatabaseMetadata)1 CreateDatabaseRequest (com.google.spanner.admin.database.v1.CreateDatabaseRequest)1 Database (com.google.spanner.admin.database.v1.Database)1 CancellationException (java.util.concurrent.CancellationException)1