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);
}
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);
}
}
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);
}
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);
}
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());
}
}
Aggregations