Search in sources :

Example 11 with Cluster

use of com.google.cloud.dataproc.v1.Cluster in project java-dataproc by googleapis.

the class ClusterControllerClientTest method listClustersTest2.

@Test
public void listClustersTest2() throws Exception {
    Cluster responsesElement = Cluster.newBuilder().build();
    ListClustersResponse expectedResponse = ListClustersResponse.newBuilder().setNextPageToken("").addAllClusters(Arrays.asList(responsesElement)).build();
    mockClusterController.addResponse(expectedResponse);
    String projectId = "projectId-894832108";
    String region = "region-934795532";
    String filter = "filter-1274492040";
    ListClustersPagedResponse pagedListResponse = client.listClusters(projectId, region, filter);
    List<Cluster> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getClustersList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockClusterController.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListClustersRequest actualRequest = ((ListClustersRequest) actualRequests.get(0));
    Assert.assertEquals(projectId, actualRequest.getProjectId());
    Assert.assertEquals(region, actualRequest.getRegion());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListClustersPagedResponse(com.google.cloud.dataproc.v1.ClusterControllerClient.ListClustersPagedResponse) Test(org.junit.Test)

Example 12 with Cluster

use of com.google.cloud.dataproc.v1.Cluster in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method createClusterExceptionTest.

@Test
public void createClusterExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableInstanceAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        String clusterId = "clusterId561939637";
        Cluster cluster = Cluster.newBuilder().build();
        client.createClusterAsync(parent, clusterId, cluster).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 : InstanceName(com.google.bigtable.admin.v2.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Cluster(com.google.bigtable.admin.v2.Cluster) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 13 with Cluster

use of com.google.cloud.dataproc.v1.Cluster in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method getClusterTest.

@Test
public void getClusterTest() throws Exception {
    Cluster expectedResponse = Cluster.newBuilder().setName(ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]").toString()).setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setServeNodes(-1288838783).setDefaultStorageType(StorageType.forNumber(0)).setEncryptionConfig(Cluster.EncryptionConfig.newBuilder().build()).build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    Cluster actualResponse = client.getCluster(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetClusterRequest actualRequest = ((GetClusterRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetClusterRequest(com.google.bigtable.admin.v2.GetClusterRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Cluster(com.google.bigtable.admin.v2.Cluster) ClusterName(com.google.bigtable.admin.v2.ClusterName) Test(org.junit.Test)

Example 14 with Cluster

use of com.google.cloud.dataproc.v1.Cluster in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method updateClusterTest.

@Test
public void updateClusterTest() throws Exception {
    Cluster expectedResponse = Cluster.newBuilder().setName(ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]").toString()).setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setServeNodes(-1288838783).setDefaultStorageType(StorageType.forNumber(0)).setEncryptionConfig(Cluster.EncryptionConfig.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("updateClusterTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableInstanceAdmin.addResponse(resultOperation);
    Cluster request = Cluster.newBuilder().setName(ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]").toString()).setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setServeNodes(-1288838783).setDefaultStorageType(StorageType.forNumber(0)).setEncryptionConfig(Cluster.EncryptionConfig.newBuilder().build()).build();
    Cluster actualResponse = client.updateClusterAsync(request).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    Cluster actualRequest = ((Cluster) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertEquals(request.getLocation(), actualRequest.getLocation());
    Assert.assertEquals(request.getState(), actualRequest.getState());
    Assert.assertEquals(request.getServeNodes(), actualRequest.getServeNodes());
    Assert.assertEquals(request.getClusterConfig(), actualRequest.getClusterConfig());
    Assert.assertEquals(request.getDefaultStorageType(), actualRequest.getDefaultStorageType());
    Assert.assertEquals(request.getEncryptionConfig(), actualRequest.getEncryptionConfig());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Cluster(com.google.bigtable.admin.v2.Cluster) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Example 15 with Cluster

use of com.google.cloud.dataproc.v1.Cluster in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method createClusterExceptionTest2.

@Test
public void createClusterExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableInstanceAdmin.addException(exception);
    try {
        String parent = "parent-995424086";
        String clusterId = "clusterId561939637";
        Cluster cluster = Cluster.newBuilder().build();
        client.createClusterAsync(parent, clusterId, cluster).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 : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Cluster(com.google.bigtable.admin.v2.Cluster) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)42 AbstractMessage (com.google.protobuf.AbstractMessage)19 ClusterOperationMetadata (com.google.cloud.dataproc.v1.ClusterOperationMetadata)18 ExecutionException (java.util.concurrent.ExecutionException)18 HashMap (java.util.HashMap)17 Cluster (com.google.bigtable.admin.v2.Cluster)16 Cluster (com.google.cloud.dataproc.v1.Cluster)15 ArrayList (java.util.ArrayList)14 ClusterControllerSettings (com.google.cloud.dataproc.v1.ClusterControllerSettings)12 Cluster (com.google.container.v1.Cluster)12 ClusterConfig (com.google.cloud.dataproc.v1.ClusterConfig)10 ClusterControllerClient (com.google.cloud.dataproc.v1.ClusterControllerClient)10 Operation (com.google.longrunning.Operation)10 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)10 RetryableProvisionException (io.cdap.cdap.runtime.spi.provisioner.RetryableProvisionException)8 IOException (java.io.IOException)8 GeneralSecurityException (java.security.GeneralSecurityException)8 Optional (java.util.Optional)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 GceClusterConfig (com.google.cloud.dataproc.v1.GceClusterConfig)7