use of com.google.bigtable.admin.v2.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method updateBackupExceptionTest.
@Test
public void updateBackupExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableTableAdmin.addException(exception);
try {
Backup backup = Backup.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
client.updateBackup(backup, updateMask);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.bigtable.admin.v2.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method getBackupTest2.
@Test
public void getBackupTest2() throws Exception {
Backup expectedResponse = Backup.newBuilder().setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]").toString()).setSourceTable("sourceTable-95372173").setExpireTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).setEncryptionInfo(EncryptionInfo.newBuilder().build()).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
String name = "name3373707";
Backup actualResponse = client.getBackup(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetBackupRequest actualRequest = ((GetBackupRequest) actualRequests.get(0));
Assert.assertEquals(name, actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method getBackupTest.
@Test
public void getBackupTest() throws Exception {
Backup expectedResponse = Backup.newBuilder().setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]").toString()).setSourceTable("sourceTable-95372173").setExpireTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).setEncryptionInfo(EncryptionInfo.newBuilder().build()).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
Backup actualResponse = client.getBackup(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetBackupRequest actualRequest = ((GetBackupRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method createBackupExceptionTest2.
@Test
public void createBackupExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableTableAdmin.addException(exception);
try {
String parent = "parent-995424086";
String backupId = "backupId2121930365";
Backup backup = Backup.newBuilder().build();
client.createBackupAsync(parent, backupId, backup).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());
}
}
use of com.google.bigtable.admin.v2.Backup in project java-bigtable by googleapis.
the class BigtableTableAdminClientTests method testListBackups.
@Test
public void testListBackups() {
// Setup
Mockito.when(mockStub.listBackupsPagedCallable()).thenReturn(mockListBackupCallable);
com.google.bigtable.admin.v2.ListBackupsRequest testRequest = com.google.bigtable.admin.v2.ListBackupsRequest.newBuilder().setParent(NameUtil.formatClusterName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID)).build();
// 3 Backups spread across 2 pages
List<com.google.bigtable.admin.v2.Backup> expectedProtos = Lists.newArrayList();
for (int i = 0; i < 3; i++) {
expectedProtos.add(com.google.bigtable.admin.v2.Backup.newBuilder().setName(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID + i)).build());
}
// 2 on the first page
ListBackupsPage page0 = Mockito.mock(ListBackupsPage.class);
Mockito.when(page0.getValues()).thenReturn(expectedProtos.subList(0, 2));
Mockito.when(page0.hasNextPage()).thenReturn(true);
// 1 on the last page
ListBackupsPage page1 = Mockito.mock(ListBackupsPage.class);
Mockito.when(page1.getValues()).thenReturn(expectedProtos.subList(2, 3));
// Link page0 to page1
Mockito.when(page0.getNextPageAsync()).thenReturn(ApiFutures.immediateFuture(page1));
// Link page to the response
ListBackupsPagedResponse response0 = Mockito.mock(ListBackupsPagedResponse.class);
Mockito.when(response0.getPage()).thenReturn(page0);
Mockito.when(mockListBackupCallable.futureCall(testRequest)).thenReturn(ApiFutures.immediateFuture(response0));
// Execute
List<String> actualResults = adminClient.listBackups(CLUSTER_ID);
// Verify
List<String> expectedResults = Lists.newArrayList();
for (com.google.bigtable.admin.v2.Backup expectedProto : expectedProtos) {
expectedResults.add(NameUtil.extractBackupIdFromBackupName(expectedProto.getName()));
}
assertThat(actualResults).containsExactlyElementsIn(expectedResults);
}
Aggregations