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());
}
}
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());
}
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
* 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);
}
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());
}
}
use of com.google.bigtable.admin.v2.SnapshotName in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method createTableFromSnapshotTest.
@Test
public void createTableFromSnapshotTest() throws Exception {
Table expectedResponse = Table.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).putAllClusterStates(new HashMap<String, Table.ClusterState>()).putAllColumnFamilies(new HashMap<String, ColumnFamily>()).setRestoreInfo(RestoreInfo.newBuilder().build()).build();
Operation resultOperation = Operation.newBuilder().setName("createTableFromSnapshotTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockBigtableTableAdmin.addResponse(resultOperation);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String tableId = "tableId-1552905847";
SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
Table actualResponse = client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateTableFromSnapshotRequest actualRequest = ((CreateTableFromSnapshotRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(tableId, actualRequest.getTableId());
Assert.assertEquals(sourceSnapshot.toString(), actualRequest.getSourceSnapshot());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations