Search in sources :

Example 31 with Backup

use of com.google.bigtable.admin.v2.Backup in project java-spanner by googleapis.

the class DatabaseAdminClientImplTest method createEncryptedBackup.

@Test
public void createEncryptedBackup() throws ExecutionException, InterruptedException {
    final OperationFuture<Backup, CreateBackupMetadata> rawOperationFuture = OperationFutureUtil.immediateOperationFuture("createBackup", getEncryptedBackupProto(), CreateBackupMetadata.getDefaultInstance());
    final Timestamp t = Timestamp.ofTimeMicroseconds(TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()) + TimeUnit.HOURS.toMicros(28));
    final com.google.cloud.spanner.Backup backup = client.newBackupBuilder(BackupId.of(PROJECT_ID, INSTANCE_ID, BK_ID)).setDatabase(DatabaseId.of(PROJECT_ID, INSTANCE_ID, DB_ID)).setExpireTime(t).setEncryptionConfig(EncryptionConfigs.customerManagedEncryption(KMS_KEY_NAME)).build();
    when(rpc.createBackup(backup)).thenReturn(rawOperationFuture);
    final OperationFuture<com.google.cloud.spanner.Backup, CreateBackupMetadata> op = client.createBackup(backup);
    assertThat(op.isDone()).isTrue();
    assertThat(op.get().getId().getName()).isEqualTo(BK_NAME);
    assertThat(op.get().getEncryptionInfo().getKmsKeyVersion()).isEqualTo(KMS_KEY_VERSION);
}
Also used : Backup(com.google.spanner.admin.database.v1.Backup) CreateBackupMetadata(com.google.spanner.admin.database.v1.CreateBackupMetadata) Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Example 32 with Backup

use of com.google.bigtable.admin.v2.Backup 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 33 with Backup

use of com.google.bigtable.admin.v2.Backup in project java-spanner by googleapis.

the class MockDatabaseAdminServiceImplTest method listBackups.

@Test
public void listBackups() {
    createTestDb();
    createTestBackup();
    ListBackupsPagedResponse response = client.listBackups(TEST_PARENT);
    List<String> backups = new ArrayList<>();
    for (Backup bck : response.iterateAll()) {
        backups.add(bck.getName());
    }
    assertThat(backups).containsExactly(TEST_BCK_NAME);
}
Also used : Backup(com.google.spanner.admin.database.v1.Backup) ArrayList(java.util.ArrayList) ListBackupsPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse) Test(org.junit.Test)

Example 34 with Backup

use of com.google.bigtable.admin.v2.Backup in project java-spanner by googleapis.

the class MockDatabaseAdminServiceImplTest method getBackup.

@Test
public void getBackup() {
    createTestDb();
    createTestBackup();
    Backup bck = client.getBackup(TEST_BCK_NAME);
    assertThat(bck.getName()).isEqualTo(TEST_BCK_NAME);
}
Also used : Backup(com.google.spanner.admin.database.v1.Backup) Test(org.junit.Test)

Example 35 with Backup

use of com.google.bigtable.admin.v2.Backup in project java-spanner by googleapis.

the class DatabaseAdminClientTest method createBackupExceptionTest.

@Test
public void createBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        Backup backup = Backup.newBuilder().build();
        String backupId = "backupId2121930365";
        client.createBackupAsync(parent, backup, backupId).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Backup(com.google.spanner.admin.database.v1.Backup) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)36 Backup (com.google.spanner.admin.database.v1.Backup)21 AbstractMessage (com.google.protobuf.AbstractMessage)15 ByteString (com.google.protobuf.ByteString)14 Backup (com.google.bigtable.admin.v2.Backup)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)8 StatusRuntimeException (io.grpc.StatusRuntimeException)8 ArrayList (java.util.ArrayList)6 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)5 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)5 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)5 CreateBackupMetadata (com.google.spanner.admin.database.v1.CreateBackupMetadata)5 ExecutionException (java.util.concurrent.ExecutionException)5 BackupName (com.google.bigtable.admin.v2.BackupName)4 GetBackupRequest (com.google.bigtable.admin.v2.GetBackupRequest)4 Timestamp (com.google.cloud.Timestamp)4 Operation (com.google.longrunning.Operation)4 FieldMask (com.google.protobuf.FieldMask)4 CreateBackupRequest (com.google.spanner.admin.database.v1.CreateBackupRequest)4 ClusterName (com.google.bigtable.admin.v2.ClusterName)3