Search in sources :

Example 21 with Backup

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Backup(com.google.bigtable.admin.v2.Backup) StatusRuntimeException(io.grpc.StatusRuntimeException) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 22 with Backup

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

Example 23 with Backup

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) GetBackupRequest(com.google.bigtable.admin.v2.GetBackupRequest) Backup(com.google.bigtable.admin.v2.Backup) BackupName(com.google.bigtable.admin.v2.BackupName) Test(org.junit.Test)

Example 24 with Backup

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());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Backup(com.google.bigtable.admin.v2.Backup) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 25 with Backup

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

Aggregations

Test (org.junit.Test)36 Backup (com.google.spanner.admin.database.v1.Backup)21 AbstractMessage (com.google.protobuf.AbstractMessage)15 ByteString (com.google.protobuf.ByteString)14 Backup (com.google.bigtable.admin.v2.Backup)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)8 StatusRuntimeException (io.grpc.StatusRuntimeException)8 ArrayList (java.util.ArrayList)6 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)5 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)5 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)5 CreateBackupMetadata (com.google.spanner.admin.database.v1.CreateBackupMetadata)5 ExecutionException (java.util.concurrent.ExecutionException)5 BackupName (com.google.bigtable.admin.v2.BackupName)4 GetBackupRequest (com.google.bigtable.admin.v2.GetBackupRequest)4 Timestamp (com.google.cloud.Timestamp)4 Operation (com.google.longrunning.Operation)4 FieldMask (com.google.protobuf.FieldMask)4 CreateBackupRequest (com.google.spanner.admin.database.v1.CreateBackupRequest)4 ClusterName (com.google.bigtable.admin.v2.ClusterName)3