Search in sources :

Example 91 with Cluster

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

the class BaseBigtableTableAdminClientTest method snapshotTableTest3.

@Test
public void snapshotTableTest3() 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();
    Operation resultOperation = Operation.newBuilder().setName("snapshotTableTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    String name = "name3373707";
    ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    String snapshotId = "snapshotId-1113817601";
    String description = "description-1724546052";
    Snapshot actualResponse = client.snapshotTableAsync(name, cluster, snapshotId, description).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SnapshotTableRequest actualRequest = ((SnapshotTableRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(cluster.toString(), actualRequest.getCluster());
    Assert.assertEquals(snapshotId, actualRequest.getSnapshotId());
    Assert.assertEquals(description, actualRequest.getDescription());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : SnapshotTableRequest(com.google.bigtable.admin.v2.SnapshotTableRequest) Snapshot(com.google.bigtable.admin.v2.Snapshot) AbstractMessage(com.google.protobuf.AbstractMessage) ClusterName(com.google.bigtable.admin.v2.ClusterName) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 92 with Cluster

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

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

the class BaseBigtableTableAdminClientTest method getBackupExceptionTest.

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

Example 94 with Cluster

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

Example 95 with Cluster

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

the class BaseBigtableTableAdminClientTest method snapshotTableExceptionTest2.

@Test
public void snapshotTableExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        String cluster = "cluster872092154";
        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) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)93 AbstractMessage (com.google.protobuf.AbstractMessage)38 ByteString (com.google.protobuf.ByteString)32 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)25 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)24 StatusRuntimeException (io.grpc.StatusRuntimeException)24 ExecutionException (java.util.concurrent.ExecutionException)22 Cluster (com.google.cloud.dataproc.v1.Cluster)18 Operation (com.google.longrunning.Operation)18 Cluster (com.google.bigtable.admin.v2.Cluster)16 ClusterName (com.google.bigtable.admin.v2.ClusterName)16 ArrayList (java.util.ArrayList)16 ClusterOperationMetadata (com.google.cloud.dataproc.v1.ClusterOperationMetadata)13 HashMap (java.util.HashMap)13 Cluster (com.google.container.v1.Cluster)12 ClusterControllerClient (com.google.cloud.dataproc.v1.ClusterControllerClient)11 ClusterControllerSettings (com.google.cloud.dataproc.v1.ClusterControllerSettings)11 SoftwareConfig (com.google.cloud.dataproc.v1.SoftwareConfig)9 SnapshotName (com.google.bigtable.admin.v2.SnapshotName)8 ClusterConfig (com.google.cloud.dataproc.v1.ClusterConfig)8