Search in sources :

Example 81 with Instance

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

the class BaseBigtableInstanceAdminClientTest method createInstanceTest.

@Test
public void createInstanceTest() throws Exception {
    Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("createInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableInstanceAdmin.addResponse(resultOperation);
    ProjectName parent = ProjectName.of("[PROJECT]");
    String instanceId = "instanceId902024336";
    Instance instance = Instance.newBuilder().build();
    Map<String, Cluster> clusters = new HashMap<>();
    Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance, clusters).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateInstanceRequest actualRequest = ((CreateInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(instanceId, actualRequest.getInstanceId());
    Assert.assertEquals(instance, actualRequest.getInstance());
    Assert.assertEquals(clusters, actualRequest.getClustersMap());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Instance(com.google.bigtable.admin.v2.Instance) ProjectName(com.google.bigtable.admin.v2.ProjectName) HashMap(java.util.HashMap) Cluster(com.google.bigtable.admin.v2.Cluster) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) CreateInstanceRequest(com.google.bigtable.admin.v2.CreateInstanceRequest) Test(org.junit.Test)

Example 82 with Instance

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

the class BaseBigtableInstanceAdminClientTest method updateInstanceExceptionTest.

@Test
public void updateInstanceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableInstanceAdmin.addException(exception);
    try {
        Instance request = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
        client.updateInstance(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Instance(com.google.bigtable.admin.v2.Instance) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 83 with Instance

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

the class BaseBigtableInstanceAdminClientTest method getClusterExceptionTest.

@Test
public void getClusterExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableInstanceAdmin.addException(exception);
    try {
        ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
        client.getCluster(name);
        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 84 with Instance

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

the class BaseBigtableInstanceAdminClientTest method createClusterTest2.

@Test
public void createClusterTest2() 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("createClusterTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableInstanceAdmin.addResponse(resultOperation);
    String parent = "parent-995424086";
    String clusterId = "clusterId561939637";
    Cluster cluster = Cluster.newBuilder().build();
    Cluster actualResponse = client.createClusterAsync(parent, clusterId, cluster).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateClusterRequest actualRequest = ((CreateClusterRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(clusterId, actualRequest.getClusterId());
    Assert.assertEquals(cluster, actualRequest.getCluster());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateClusterRequest(com.google.bigtable.admin.v2.CreateClusterRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Cluster(com.google.bigtable.admin.v2.Cluster) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 85 with Instance

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

the class BaseBigtableInstanceAdminClientTest method getAppProfileTest.

@Test
public void getAppProfileTest() throws Exception {
    AppProfile expectedResponse = AppProfile.newBuilder().setName(AppProfileName.of("[PROJECT]", "[INSTANCE]", "[APP_PROFILE]").toString()).setEtag("etag3123477").setDescription("description-1724546052").build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    AppProfileName name = AppProfileName.of("[PROJECT]", "[INSTANCE]", "[APP_PROFILE]");
    AppProfile actualResponse = client.getAppProfile(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetAppProfileRequest actualRequest = ((GetAppProfileRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetAppProfileRequest(com.google.bigtable.admin.v2.GetAppProfileRequest) AbstractMessage(com.google.protobuf.AbstractMessage) AppProfile(com.google.bigtable.admin.v2.AppProfile) AppProfileName(com.google.bigtable.admin.v2.AppProfileName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)137 AbstractMessage (com.google.protobuf.AbstractMessage)63 ByteString (com.google.protobuf.ByteString)57 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)41 StatusRuntimeException (io.grpc.StatusRuntimeException)41 Instance (com.google.cloud.redis.v1beta1.Instance)34 CloudRedisClient (com.google.cloud.redis.v1beta1.CloudRedisClient)30 Instance (com.google.cloud.compute.v1.Instance)25 Operation (com.google.longrunning.Operation)22 InstanceName (com.google.bigtable.admin.v2.InstanceName)20 InstancesClient (com.google.cloud.compute.v1.InstancesClient)19 ExecutionException (java.util.concurrent.ExecutionException)17 ClusterName (com.google.bigtable.admin.v2.ClusterName)16 Table (com.google.bigtable.admin.v2.Table)16 HashMap (java.util.HashMap)16 TableName (com.google.bigtable.admin.v2.TableName)15 Cluster (com.google.bigtable.admin.v2.Cluster)13 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)13 Operation (com.google.cloud.compute.v1.Operation)13 ArrayList (java.util.ArrayList)13