Search in sources :

Example 16 with Cluster

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

the class BaseBigtableTableAdminClientTest method deleteSnapshotTest.

@Test
public void deleteSnapshotTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    SnapshotName name = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
    client.deleteSnapshot(name);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteSnapshotRequest actualRequest = ((DeleteSnapshotRequest) 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) DeleteSnapshotRequest(com.google.bigtable.admin.v2.DeleteSnapshotRequest) SnapshotName(com.google.bigtable.admin.v2.SnapshotName) Test(org.junit.Test)

Example 17 with Cluster

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

the class BaseBigtableTableAdminClientTest method createBackupTest2.

@Test
public void createBackupTest2() 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();
    Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    String parent = "parent-995424086";
    String backupId = "backupId2121930365";
    Backup backup = Backup.newBuilder().build();
    Backup actualResponse = client.createBackupAsync(parent, backupId, backup).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(backupId, actualRequest.getBackupId());
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateBackupRequest(com.google.bigtable.admin.v2.CreateBackupRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.bigtable.admin.v2.Backup) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 18 with Cluster

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

the class BaseBigtableTableAdminClientTest method listSnapshotsExceptionTest.

@Test
public void listSnapshotsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
        client.listSnapshots(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 19 with Cluster

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

the class BaseBigtableTableAdminClientTest method listSnapshotsTest.

@Test
public void listSnapshotsTest() throws Exception {
    Snapshot responsesElement = Snapshot.newBuilder().build();
    ListSnapshotsResponse expectedResponse = ListSnapshotsResponse.newBuilder().setNextPageToken("").addAllSnapshots(Arrays.asList(responsesElement)).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    ListSnapshotsPagedResponse pagedListResponse = client.listSnapshots(parent);
    List<Snapshot> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSnapshotsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSnapshotsRequest actualRequest = ((ListSnapshotsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Snapshot(com.google.bigtable.admin.v2.Snapshot) ListSnapshotsRequest(com.google.bigtable.admin.v2.ListSnapshotsRequest) ListSnapshotsResponse(com.google.bigtable.admin.v2.ListSnapshotsResponse) ListSnapshotsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListSnapshotsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ClusterName(com.google.bigtable.admin.v2.ClusterName) Test(org.junit.Test)

Example 20 with Cluster

use of com.google.bigtable.admin.v2.Cluster 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)

Aggregations

Test (org.junit.Test)59 AbstractMessage (com.google.protobuf.AbstractMessage)28 ByteString (com.google.protobuf.ByteString)27 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)20 StatusRuntimeException (io.grpc.StatusRuntimeException)20 Cluster (com.google.bigtable.admin.v2.Cluster)16 Operation (com.google.longrunning.Operation)16 ExecutionException (java.util.concurrent.ExecutionException)15 ClusterName (com.google.bigtable.admin.v2.ClusterName)14 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)10 HashMap (java.util.HashMap)10 SnapshotName (com.google.bigtable.admin.v2.SnapshotName)8 Backup (com.google.bigtable.admin.v2.Backup)7 Snapshot (com.google.bigtable.admin.v2.Snapshot)7 WeightedCluster (io.envoyproxy.envoy.config.route.v3.WeightedCluster)7 PartialUpdateClusterRequest (com.google.bigtable.admin.v2.PartialUpdateClusterRequest)5 FieldMask (com.google.protobuf.FieldMask)5 ArrayList (java.util.ArrayList)5 BackupName (com.google.bigtable.admin.v2.BackupName)4 InstanceName (com.google.bigtable.admin.v2.InstanceName)4