Search in sources :

Example 6 with SnapshotName

use of com.google.bigtable.admin.v2.SnapshotName in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method createSnapshotExceptionTest.

@Test
@SuppressWarnings("all")
public void createSnapshotExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        SnapshotName name = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
        SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
        client.createSnapshot(name, subscription);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) SubscriptionName(com.google.pubsub.v1.SubscriptionName) SnapshotName(com.google.pubsub.v1.SnapshotName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 7 with SnapshotName

use of com.google.bigtable.admin.v2.SnapshotName in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method deleteSnapshotTest.

@Test
@SuppressWarnings("all")
public void deleteSnapshotTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockSubscriber.addResponse(expectedResponse);
    SnapshotName snapshot = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
    client.deleteSnapshot(snapshot);
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteSnapshotRequest actualRequest = (DeleteSnapshotRequest) actualRequests.get(0);
    Assert.assertEquals(snapshot, actualRequest.getSnapshotAsSnapshotName());
}
Also used : Empty(com.google.protobuf.Empty) DeleteSnapshotRequest(com.google.pubsub.v1.DeleteSnapshotRequest) SnapshotName(com.google.pubsub.v1.SnapshotName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 8 with SnapshotName

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

the class BaseBigtableTableAdminClient method deleteSnapshot.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Permanently deletes the specified snapshot.
 *
 * <p>Note: This is a private alpha release of Cloud Bigtable snapshots. This feature is not
 * currently available to most Cloud Bigtable customers. This feature might be changed in
 * backward-incompatible ways and is not recommended for production use. It is not subject to any
 * SLA or deprecation policy.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * // This snippet has been automatically generated for illustrative purposes only.
 * // It may require modifications to work in your environment.
 * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient =
 *     BaseBigtableTableAdminClient.create()) {
 *   SnapshotName name = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
 *   baseBigtableTableAdminClient.deleteSnapshot(name);
 * }
 * }</pre>
 *
 * @param name Required. The unique name of the snapshot to be deleted. Values are of the form
 *     `projects/{project}/instances/{instance}/clusters/{cluster}/snapshots/{snapshot}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteSnapshot(SnapshotName name) {
    DeleteSnapshotRequest request = DeleteSnapshotRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteSnapshot(request);
}
Also used : DeleteSnapshotRequest(com.google.bigtable.admin.v2.DeleteSnapshotRequest)

Example 9 with SnapshotName

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

the class BaseBigtableTableAdminClientTest method createTableFromSnapshotExceptionTest3.

@Test
public void createTableFromSnapshotExceptionTest3() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        String parent = "parent-995424086";
        String tableId = "tableId-1552905847";
        SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
        client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).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) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) SnapshotName(com.google.bigtable.admin.v2.SnapshotName) Test(org.junit.Test)

Example 10 with SnapshotName

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

the class BaseBigtableTableAdminClientTest method createTableFromSnapshotExceptionTest.

@Test
public void createTableFromSnapshotExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        String tableId = "tableId-1552905847";
        SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
        client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).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 : InstanceName(com.google.bigtable.admin.v2.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) SnapshotName(com.google.bigtable.admin.v2.SnapshotName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)28 SnapshotName (com.google.pubsub.v1.SnapshotName)24 StatusRuntimeException (io.grpc.StatusRuntimeException)14 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)12 AbstractMessage (com.google.protobuf.AbstractMessage)12 Snapshot (com.google.pubsub.v1.Snapshot)10 SnapshotName (com.google.bigtable.admin.v2.SnapshotName)8 ByteString (com.google.protobuf.ByteString)8 HashMap (java.util.HashMap)8 SubscriptionName (com.google.pubsub.v1.SubscriptionName)7 CreateSnapshotRequest (com.google.pubsub.v1.CreateSnapshotRequest)5 SubscriptionAdminClient (com.google.cloud.pubsub.v1.SubscriptionAdminClient)4 Empty (com.google.protobuf.Empty)4 DeleteSnapshotRequest (com.google.pubsub.v1.DeleteSnapshotRequest)3 ApiException (com.google.api.gax.grpc.ApiException)2 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)2 CreateTableFromSnapshotRequest (com.google.bigtable.admin.v2.CreateTableFromSnapshotRequest)2 DeleteSnapshotRequest (com.google.bigtable.admin.v2.DeleteSnapshotRequest)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2 Table (com.google.bigtable.admin.v2.Table)2