use of com.google.bigtable.admin.v2.AutoscalingTargets in project java-bigtable by googleapis.
the class ClusterAutoscalingConfigTest method testToProto.
@Test
public void testToProto() {
ClusterAutoscalingConfig request = ClusterAutoscalingConfig.of(INSTANCE_ID, CLUSTER_ID).setMaxNodes(10).setMinNodes(3).setCpuUtilizationTargetPercent(30);
PartialUpdateClusterRequest partialUpdateClusterRequestProto = request.toProto(PROJECT_ID);
AutoscalingTargets autoscalingTargets = AutoscalingTargets.newBuilder().setCpuUtilizationPercent(30).build();
AutoscalingLimits autoscalingLimits = AutoscalingLimits.newBuilder().setMinServeNodes(3).setMaxServeNodes(10).build();
Cluster.ClusterAutoscalingConfig clusterAutoscalingConfig = Cluster.ClusterAutoscalingConfig.newBuilder().setAutoscalingTargets(autoscalingTargets).setAutoscalingLimits(autoscalingLimits).build();
Cluster.ClusterConfig clusterConfig = Cluster.ClusterConfig.newBuilder().setClusterAutoscalingConfig(clusterAutoscalingConfig).build();
Cluster cluster = Cluster.newBuilder().setName(NameUtil.formatClusterName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID)).setClusterConfig(clusterConfig).build();
PartialUpdateClusterRequest requestProto = PartialUpdateClusterRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("cluster_config.cluster_autoscaling_config.autoscaling_limits.max_serve_nodes").addPaths("cluster_config.cluster_autoscaling_config.autoscaling_limits.min_serve_nodes").addPaths("cluster_config.cluster_autoscaling_config.autoscaling_targets.cpu_utilization_percent")).setCluster(cluster).build();
assertThat(partialUpdateClusterRequestProto).isEqualTo(requestProto);
}
use of com.google.bigtable.admin.v2.AutoscalingTargets in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest 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));
}
Aggregations