Search in sources :

Example 16 with Backup

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

the class BigtableTableAdminClientTest method testGetBackup.

@Test
public void testGetBackup() {
    // Setup
    Mockito.when(mockStub.getBackupCallable()).thenReturn(mockGetBackupCallable);
    Timestamp expireTime = Timestamp.newBuilder().setSeconds(123456789).build();
    Timestamp startTime = Timestamp.newBuilder().setSeconds(1234).build();
    Timestamp endTime = Timestamp.newBuilder().setSeconds(5678).build();
    com.google.bigtable.admin.v2.Backup.State state = State.CREATING;
    long sizeBytes = 12345L;
    GetBackupRequest testRequest = GetBackupRequest.newBuilder().setName(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)).build();
    Mockito.when(mockGetBackupCallable.futureCall(testRequest)).thenReturn(ApiFutures.immediateFuture(com.google.bigtable.admin.v2.Backup.newBuilder().setName(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)).setSourceTable(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setExpireTime(expireTime).setStartTime(startTime).setEndTime(endTime).setSizeBytes(sizeBytes).setState(state).build()));
    // Execute
    Backup actualResult = adminClient.getBackup(CLUSTER_ID, BACKUP_ID);
    // Verify
    assertThat(actualResult.getId()).isEqualTo(BACKUP_ID);
    assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID);
    assertThat(actualResult.getExpireTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime)));
    assertThat(actualResult.getStartTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime)));
    assertThat(actualResult.getEndTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime)));
    assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes);
    assertThat(actualResult.getState()).isEqualTo(Backup.State.fromProto(state));
}
Also used : GetBackupRequest(com.google.bigtable.admin.v2.GetBackupRequest) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) State(com.google.bigtable.admin.v2.Backup.State) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 17 with Backup

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

the class BigtableTableAdminClientTest method testUpdateBackup.

@Test
public void testUpdateBackup() {
    // Setup
    Mockito.when(mockStub.updateBackupCallable()).thenReturn(mockUpdateBackupCallable);
    Timestamp expireTime = Timestamp.newBuilder().setSeconds(123456789).build();
    long sizeBytes = 12345L;
    UpdateBackupRequest req = UpdateBackupRequest.of(CLUSTER_ID, BACKUP_ID);
    Mockito.when(mockUpdateBackupCallable.futureCall(req.toProto(PROJECT_ID, INSTANCE_ID))).thenReturn(ApiFutures.immediateFuture(com.google.bigtable.admin.v2.Backup.newBuilder().setName(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)).setSourceTable(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setExpireTime(expireTime).setSizeBytes(sizeBytes).build()));
    // Execute
    Backup actualResult = adminClient.updateBackup(req);
    // Verify
    assertThat(actualResult.getId()).isEqualTo(BACKUP_ID);
    assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID);
    assertThat(actualResult.getExpireTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime)));
    assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes);
}
Also used : Backup(com.google.cloud.bigtable.admin.v2.models.Backup) UpdateBackupRequest(com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 18 with Backup

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

Test (org.junit.Test)15 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)13 ByteString (com.google.protobuf.ByteString)8 Timestamp (com.google.protobuf.Timestamp)6 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)5 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)5 CreateBackupRequest (com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest)5 ListBackupsPage (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPage)3 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)3 UpdateBackupRequest (com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest)3 Instant (org.threeten.bp.Instant)3 Backup (com.google.bigtable.admin.v2.Backup)2 State (com.google.bigtable.admin.v2.Backup.State)2 GetBackupRequest (com.google.bigtable.admin.v2.GetBackupRequest)2 ListBackupsResponse (com.google.bigtable.admin.v2.ListBackupsResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 IOException (java.io.IOException)2 CreateBackupMessage (com.example.cloud.bigtable.scheduledbackups.resource.CreateBackupMessage)1 ApiFuture (com.google.api.core.ApiFuture)1 ClusterName (com.google.bigtable.admin.v2.ClusterName)1