Search in sources :

Example 16 with SnapshotName

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

the class SubscriptionAdminClientTest method createSnapshotTest.

@Test
@SuppressWarnings("all")
public void createSnapshotTest() {
    SnapshotName name2 = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
    TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
    Snapshot expectedResponse = Snapshot.newBuilder().setNameWithSnapshotName(name2).setTopicWithTopicName(topic).build();
    mockSubscriber.addResponse(expectedResponse);
    SnapshotName name = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    Snapshot actualResponse = client.createSnapshot(name, subscription);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSnapshotRequest actualRequest = (CreateSnapshotRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsSnapshotName());
    Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
Also used : Snapshot(com.google.pubsub.v1.Snapshot) CreateSnapshotRequest(com.google.pubsub.v1.CreateSnapshotRequest) SubscriptionName(com.google.pubsub.v1.SubscriptionName) SnapshotName(com.google.pubsub.v1.SnapshotName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Example 17 with SnapshotName

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

the class SubscriptionAdminClientTest method deleteSnapshotExceptionTest.

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

Example 18 with SnapshotName

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

the class BaseBigtableTableAdminClientTest method getSnapshotTest.

@Test
public void getSnapshotTest() throws Exception {
    Snapshot expectedResponse = Snapshot.newBuilder().setName(SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]").toString()).setSourceTable(Table.newBuilder().build()).setDataSizeBytes(-2110122398).setCreateTime(Timestamp.newBuilder().build()).setDeleteTime(Timestamp.newBuilder().build()).setDescription("description-1724546052").build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    SnapshotName name = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
    Snapshot actualResponse = client.getSnapshot(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetSnapshotRequest actualRequest = ((GetSnapshotRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Snapshot(com.google.bigtable.admin.v2.Snapshot) AbstractMessage(com.google.protobuf.AbstractMessage) GetSnapshotRequest(com.google.bigtable.admin.v2.GetSnapshotRequest) SnapshotName(com.google.bigtable.admin.v2.SnapshotName) Test(org.junit.Test)

Example 19 with SnapshotName

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

the class BaseBigtableTableAdminClientTest method getSnapshotExceptionTest.

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

Example 20 with SnapshotName

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

the class BaseBigtableTableAdminClientTest method createTableFromSnapshotTest3.

@Test
public void createTableFromSnapshotTest3() 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);
    String parent = "parent-995424086";
    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, actualRequest.getParent());
    Assert.assertEquals(tableId, actualRequest.getTableId());
    Assert.assertEquals(sourceSnapshot.toString(), actualRequest.getSourceSnapshot());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) CreateTableFromSnapshotRequest(com.google.bigtable.admin.v2.CreateTableFromSnapshotRequest) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) SnapshotName(com.google.bigtable.admin.v2.SnapshotName) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) 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