Search in sources :

Example 1 with BackupName

use of com.google.bigtable.admin.v2.BackupName in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClient method deleteBackup.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a pending or completed Cloud Bigtable backup.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient =
 *     BaseBigtableTableAdminClient.create()) {
 *   BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
 *   baseBigtableTableAdminClient.deleteBackup(name);
 * }
 * }</pre>
 *
 * @param name Required. Name of the backup to delete. Values are of the form
 *     `projects/{project}/instances/{instance}/clusters/{cluster}/backups/{backup}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteBackup(BackupName name) {
    DeleteBackupRequest request = DeleteBackupRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteBackup(request);
}
Also used : DeleteBackupRequest(com.google.bigtable.admin.v2.DeleteBackupRequest)

Example 2 with BackupName

use of com.google.bigtable.admin.v2.BackupName in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method deleteBackupTest.

@Test
public void deleteBackupTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
    client.deleteBackup(name);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteBackupRequest actualRequest = ((DeleteBackupRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteBackupRequest(com.google.bigtable.admin.v2.DeleteBackupRequest) BackupName(com.google.bigtable.admin.v2.BackupName) Test(org.junit.Test)

Example 3 with BackupName

use of com.google.bigtable.admin.v2.BackupName in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method deleteBackupExceptionTest.

@Test
public void deleteBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
        client.deleteBackup(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) BackupName(com.google.bigtable.admin.v2.BackupName) Test(org.junit.Test)

Example 4 with BackupName

use of com.google.bigtable.admin.v2.BackupName 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 5 with BackupName

use of com.google.bigtable.admin.v2.BackupName in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method getBackupExceptionTest.

@Test
public void getBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
        client.getBackup(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) BackupName(com.google.bigtable.admin.v2.BackupName) Test(org.junit.Test)

Aggregations

BackupName (com.google.bigtable.admin.v2.BackupName)4 Test (org.junit.Test)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 DeleteBackupRequest (com.google.bigtable.admin.v2.DeleteBackupRequest)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 Backup (com.google.bigtable.admin.v2.Backup)1 GetBackupRequest (com.google.bigtable.admin.v2.GetBackupRequest)1 Empty (com.google.protobuf.Empty)1