Search in sources :

Example 6 with Cluster

use of com.google.container.v1beta1.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 7 with Cluster

use of com.google.container.v1beta1.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 8 with Cluster

use of com.google.container.v1beta1.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 9 with Cluster

use of com.google.container.v1beta1.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)

Example 10 with Cluster

use of com.google.container.v1beta1.Cluster in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method createInstanceExceptionTest2.

@Test
public void createInstanceExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableInstanceAdmin.addException(exception);
    try {
        String parent = "parent-995424086";
        String instanceId = "instanceId902024336";
        Instance instance = Instance.newBuilder().build();
        Map<String, Cluster> clusters = new HashMap<>();
        client.createInstanceAsync(parent, instanceId, instance, clusters).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) Instance(com.google.bigtable.admin.v2.Instance) HashMap(java.util.HashMap) 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)38 AbstractMessage (com.google.protobuf.AbstractMessage)17 Cluster (com.google.bigtable.admin.v2.Cluster)16 Cluster (com.google.cloud.dataproc.v1.Cluster)15 ExecutionException (java.util.concurrent.ExecutionException)15 ArrayList (java.util.ArrayList)14 ClusterOperationMetadata (com.google.cloud.dataproc.v1.ClusterOperationMetadata)12 Cluster (com.google.container.v1.Cluster)12 HashMap (java.util.HashMap)11 ClusterControllerClient (com.google.cloud.dataproc.v1.ClusterControllerClient)10 ClusterControllerSettings (com.google.cloud.dataproc.v1.ClusterControllerSettings)10 Operation (com.google.longrunning.Operation)10 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)9 ClusterConfig (com.google.cloud.dataproc.v1.ClusterConfig)7 InstanceGroupConfig (com.google.cloud.dataproc.v1.InstanceGroupConfig)7 ByteString (com.google.protobuf.ByteString)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 ApiException (com.google.api.gax.rpc.ApiException)6 FieldMask (com.google.protobuf.FieldMask)6