Search in sources :

Example 26 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 27 with Cluster

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

the class BaseBigtableTableAdminClientTest method createBackupTest.

@Test
public void createBackupTest() 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);
    ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    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.toString(), 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) ClusterName(com.google.bigtable.admin.v2.ClusterName) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 28 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)

Example 29 with Cluster

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

the class BaseBigtableTableAdminClientTest method snapshotTableTest2.

@Test
public void snapshotTableTest2() 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);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    String cluster = "cluster872092154";
    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.toString(), actualRequest.getName());
    Assert.assertEquals(cluster, 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) TableName(com.google.bigtable.admin.v2.TableName) AbstractMessage(com.google.protobuf.AbstractMessage) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 30 with Cluster

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

the class BigtableInstanceAdminClientTests method testDisableAutoscaling.

@Test
public void testDisableAutoscaling() {
    Mockito.when(mockStub.partialUpdateClusterOperationCallable()).thenReturn(mockPartialUpdateClusterCallable);
    // Setup
    com.google.bigtable.admin.v2.Cluster cluster = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.newBuilder().build()).setServeNodes(30).build();
    PartialUpdateClusterRequest expectedRequest = PartialUpdateClusterRequest.newBuilder().setCluster(cluster).setUpdateMask(FieldMask.newBuilder().addPaths("cluster_config.cluster_autoscaling_config").addPaths("serve_nodes").build()).build();
    com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setLocation(NameUtil.formatLocationName(PROJECT_ID, "us-east1-c")).setServeNodes(30).build();
    mockOperationResult(mockPartialUpdateClusterCallable, expectedRequest, expectedResponse);
    // Execute
    Cluster actualResult = adminClient.disableClusterAutoscaling(INSTANCE_ID, CLUSTER_ID, 30);
    // Verify
    assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
Also used : PartialUpdateClusterRequest(com.google.bigtable.admin.v2.PartialUpdateClusterRequest) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) 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