Search in sources :

Example 11 with ClusterName

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

the class BaseBigtableTableAdminClientTest method snapshotTableExceptionTest3.

@Test
public void snapshotTableExceptionTest3() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        String name = "name3373707";
        ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
        String snapshotId = "snapshotId-1113817601";
        String description = "description-1724546052";
        client.snapshotTableAsync(name, cluster, snapshotId, description).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) StatusRuntimeException(io.grpc.StatusRuntimeException) ClusterName(com.google.bigtable.admin.v2.ClusterName) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 12 with ClusterName

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

the class BaseBigtableTableAdminClientTest method snapshotTableExceptionTest.

@Test
public void snapshotTableExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
        String snapshotId = "snapshotId-1113817601";
        String description = "description-1724546052";
        client.snapshotTableAsync(name, cluster, snapshotId, description).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 : TableName(com.google.bigtable.admin.v2.TableName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ClusterName(com.google.bigtable.admin.v2.ClusterName) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 13 with ClusterName

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

the class BaseBigtableTableAdminClientTest method listBackupsExceptionTest.

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

Example 14 with ClusterName

use of com.google.bigtable.admin.v2.ClusterName 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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.bigtable.admin.v2.Backup) ListBackupsRequest(com.google.bigtable.admin.v2.ListBackupsRequest) ClusterName(com.google.bigtable.admin.v2.ClusterName) ListBackupsResponse(com.google.bigtable.admin.v2.ListBackupsResponse) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) Test(org.junit.Test)

Example 15 with ClusterName

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

the class BaseBigtableInstanceAdminClient method deleteCluster.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a cluster from an instance.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (BaseBigtableInstanceAdminClient baseBigtableInstanceAdminClient =
 *     BaseBigtableInstanceAdminClient.create()) {
 *   ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
 *   baseBigtableInstanceAdminClient.deleteCluster(name);
 * }
 * }</pre>
 *
 * @param name Required. The unique name of the cluster to be deleted. Values are of the form
 *     `projects/{project}/instances/{instance}/clusters/{cluster}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteCluster(ClusterName name) {
    DeleteClusterRequest request = DeleteClusterRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteCluster(request);
}
Also used : DeleteClusterRequest(com.google.bigtable.admin.v2.DeleteClusterRequest)

Aggregations

ClusterName (com.google.bigtable.admin.v2.ClusterName)14 Test (org.junit.Test)14 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 AbstractMessage (com.google.protobuf.AbstractMessage)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 ByteString (com.google.protobuf.ByteString)6 Backup (com.google.bigtable.admin.v2.Backup)3 Snapshot (com.google.bigtable.admin.v2.Snapshot)3 Operation (com.google.longrunning.Operation)3 ExecutionException (java.util.concurrent.ExecutionException)3 DeleteClusterRequest (com.google.bigtable.admin.v2.DeleteClusterRequest)2 SnapshotTableRequest (com.google.bigtable.admin.v2.SnapshotTableRequest)2 TableName (com.google.bigtable.admin.v2.TableName)2 Cluster (com.google.bigtable.admin.v2.Cluster)1 CreateBackupRequest (com.google.bigtable.admin.v2.CreateBackupRequest)1 GetClusterRequest (com.google.bigtable.admin.v2.GetClusterRequest)1 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)1 ListBackupsResponse (com.google.bigtable.admin.v2.ListBackupsResponse)1 ListSnapshotsRequest (com.google.bigtable.admin.v2.ListSnapshotsRequest)1 ListSnapshotsResponse (com.google.bigtable.admin.v2.ListSnapshotsResponse)1