Search in sources :

Example 71 with Instance

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

the class BaseBigtableTableAdminClientTest method modifyColumnFamiliesTest.

@Test
public void modifyColumnFamiliesTest() 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();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    List<ModifyColumnFamiliesRequest.Modification> modifications = new ArrayList<>();
    Table actualResponse = client.modifyColumnFamilies(name, modifications);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ModifyColumnFamiliesRequest actualRequest = ((ModifyColumnFamiliesRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(modifications, actualRequest.getModificationsList());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : TableName(com.google.bigtable.admin.v2.TableName) Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) ModifyColumnFamiliesRequest(com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest) Test(org.junit.Test)

Example 72 with Instance

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

the class BaseBigtableTableAdminClientTest method dropRowRangeExceptionTest.

@Test
public void dropRowRangeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        DropRowRangeRequest request = DropRowRangeRequest.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).build();
        client.dropRowRange(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 73 with Instance

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

the class BigtableInstanceAdminClientTests method testCreateInstanceAutoscaling.

@Test
public void testCreateInstanceAutoscaling() {
    Mockito.when(mockStub.createInstanceOperationCallable()).thenReturn(mockCreateInstanceCallable);
    // Setup
    AutoscalingLimits autoscalingLimits = AutoscalingLimits.newBuilder().setMaxServeNodes(5).setMinServeNodes(1).build();
    AutoscalingTargets autoscalingTargets = AutoscalingTargets.newBuilder().setCpuUtilizationPercent(49).build();
    com.google.bigtable.admin.v2.Cluster.ClusterAutoscalingConfig clusterAutoscalingConfig = com.google.bigtable.admin.v2.Cluster.ClusterAutoscalingConfig.newBuilder().setAutoscalingLimits(autoscalingLimits).setAutoscalingTargets(autoscalingTargets).build();
    com.google.bigtable.admin.v2.CreateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.CreateInstanceRequest.newBuilder().setParent(PROJECT_NAME).setInstanceId(INSTANCE_ID).setInstance(com.google.bigtable.admin.v2.Instance.newBuilder().setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT).setDisplayName(INSTANCE_ID)).putClusters("cluster1", com.google.bigtable.admin.v2.Cluster.newBuilder().setLocation("projects/my-project/locations/us-east1-c").setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.newBuilder().setClusterAutoscalingConfig(clusterAutoscalingConfig).build()).setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD).build()).build();
    com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).build();
    mockOperationResult(mockCreateInstanceCallable, expectedRequest, expectedResponse);
    // Execute
    ClusterAutoscalingConfig autoscalingConfig = ClusterAutoscalingConfig.of(INSTANCE_ID, "cluster1").setCpuUtilizationTargetPercent(49).setMaxNodes(5).setMinNodes(1);
    Instance actualResult = adminClient.createInstance(CreateInstanceRequest.of(INSTANCE_ID).setType(Instance.Type.DEVELOPMENT).addCluster("cluster1", "us-east1-c", autoscalingConfig, StorageType.SSD));
    // Verify
    assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
Also used : AutoscalingTargets(com.google.bigtable.admin.v2.AutoscalingTargets) AutoscalingLimits(com.google.bigtable.admin.v2.AutoscalingLimits) Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) ClusterAutoscalingConfig(com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig) Test(org.junit.Test)

Example 74 with Instance

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

the class BaseBigtableInstanceAdminClientTest method listInstancesTest2.

@Test
public void listInstancesTest2() throws Exception {
    ListInstancesResponse expectedResponse = ListInstancesResponse.newBuilder().addAllInstances(new ArrayList<Instance>()).addAllFailedLocations(new ArrayList<String>()).setNextPageToken("nextPageToken-1386094857").build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListInstancesResponse actualResponse = client.listInstances(parent);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListInstancesRequest actualRequest = ((ListInstancesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListInstancesResponse(com.google.bigtable.admin.v2.ListInstancesResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListInstancesRequest(com.google.bigtable.admin.v2.ListInstancesRequest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 75 with Instance

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

the class BaseBigtableInstanceAdminClientTest method deleteAppProfileExceptionTest.

@Test
public void deleteAppProfileExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableInstanceAdmin.addException(exception);
    try {
        AppProfileName name = AppProfileName.of("[PROJECT]", "[INSTANCE]", "[APP_PROFILE]");
        client.deleteAppProfile(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) 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