Search in sources :

Example 6 with CreateBackupRequest

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);
    }
}
Also used : RestoreTableRequest(com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest) Table(com.google.cloud.bigtable.admin.v2.models.Table) RestoredTableResult(com.google.cloud.bigtable.admin.v2.models.RestoredTableResult) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 7 with CreateBackupRequest

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);
}
Also used : CreateBackupRequest(com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) ByteString(com.google.protobuf.ByteString) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Backup (com.google.cloud.bigtable.admin.v2.models.Backup)5 CreateBackupRequest (com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest)5 ByteString (com.google.protobuf.ByteString)5 Test (org.junit.Test)5 Instant (org.threeten.bp.Instant)3 Timestamp (com.google.protobuf.Timestamp)2 CreateBackupMessage (com.example.cloud.bigtable.scheduledbackups.resource.CreateBackupMessage)1 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)1 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)1 RestoreTableRequest (com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest)1 RestoredTableResult (com.google.cloud.bigtable.admin.v2.models.RestoredTableResult)1 Table (com.google.cloud.bigtable.admin.v2.models.Table)1 UpdateBackupRequest (com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest)1 IOException (java.io.IOException)1