use of com.google.cloud.bigtable.admin.v2.models.Backup in project java-bigtable by googleapis.
the class BigtableTableAdminClientTests 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));
}
use of com.google.cloud.bigtable.admin.v2.models.Backup in project java-bigtable by googleapis.
the class BigtableTableAdminClientTests 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);
}
use of com.google.cloud.bigtable.admin.v2.models.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method listBackupsTest2.
@Test
public void listBackupsTest2() throws Exception {
Backup responsesElement = Backup.newBuilder().build();
ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
String parent = "parent-995424086";
ListBackupsPagedResponse pagedListResponse = client.listBackups(parent);
List<Backup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBackupsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBackupsRequest actualRequest = ((ListBackupsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigtable.admin.v2.models.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method listBackupsTest.
@Test
public void listBackupsTest() throws Exception {
Backup responsesElement = Backup.newBuilder().build();
ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
ListBackupsPagedResponse pagedListResponse = client.listBackups(parent);
List<Backup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBackupsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBackupsRequest actualRequest = ((ListBackupsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigtable.admin.v2.models.Backup in project java-bigtable by googleapis.
the class BigtableBackupIT method updateBackupTest.
@Test
public void updateBackupTest() {
String backupId = prefixGenerator.newPrefix();
tableAdmin.createBackup(createBackupRequest(backupId));
Instant expireTime = Instant.now().plus(Duration.ofDays(20));
UpdateBackupRequest req = UpdateBackupRequest.of(targetCluster, backupId).setExpireTime(expireTime);
try {
Backup backup = tableAdmin.updateBackup(req);
assertWithMessage("Incorrect expire time").that(backup.getExpireTime()).isEqualTo(expireTime);
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
}
}
Aggregations