use of com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest in project java-bigtable by googleapis.
the class BigtableBackupIT method restoreTableTest.
@Test
public void restoreTableTest() throws InterruptedException, ExecutionException {
String backupId = prefixGenerator.newPrefix();
String restoredTableId = prefixGenerator.newPrefix();
tableAdmin.createBackup(createBackupRequest(backupId));
// Wait 2 minutes so that the RestoreTable API will trigger an optimize restored
// table operation.
Thread.sleep(120 * 1000);
try {
RestoreTableRequest req = RestoreTableRequest.of(targetCluster, backupId).setTableId(restoredTableId);
RestoredTableResult result = tableAdmin.restoreTable(req);
assertWithMessage("Incorrect restored table id").that(result.getTable().getId()).isEqualTo(restoredTableId);
if (result.getOptimizeRestoredTableOperationToken() != null) {
// The assertion might be missing if the test is running against a HDD cluster or an
// optimization is not necessary.
tableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
Table restoredTable = tableAdmin.getTable(restoredTableId);
assertWithMessage("Incorrect restored table id").that(restoredTable.getId()).isEqualTo(restoredTableId);
}
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
tableAdmin.deleteTable(restoredTableId);
}
}
use of com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest in project java-bigtable by googleapis.
the class BigtableTableAdminClientTest method testCreateBackup.
@Test
public void testCreateBackup() {
// Setup
Mockito.when(mockStub.createBackupOperationCallable()).thenReturn(mockCreateBackupOperationCallable);
String backupName = NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID);
Timestamp startTime = Timestamp.newBuilder().setSeconds(123).build();
Timestamp endTime = Timestamp.newBuilder().setSeconds(456).build();
Timestamp expireTime = Timestamp.newBuilder().setSeconds(789).build();
long sizeBytes = 123456789;
CreateBackupRequest req = CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID).setSourceTableId(TABLE_ID);
mockOperationResult(mockCreateBackupOperationCallable, req.toProto(PROJECT_ID, INSTANCE_ID), com.google.bigtable.admin.v2.Backup.newBuilder().setName(backupName).setSourceTable(TABLE_NAME).setStartTime(startTime).setEndTime(endTime).setExpireTime(expireTime).setSizeBytes(sizeBytes).build(), CreateBackupMetadata.newBuilder().setName(backupName).setStartTime(startTime).setEndTime(endTime).setSourceTable(TABLE_NAME).build());
// Execute
Backup actualResult = adminClient.createBackup(req);
// Verify
assertThat(actualResult.getId()).isEqualTo(BACKUP_ID);
assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID);
assertThat(actualResult.getStartTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime)));
assertThat(actualResult.getEndTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime)));
assertThat(actualResult.getExpireTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime)));
assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes);
}
Aggregations