use of com.google.bigtable.admin.v2.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTests method testPartialUpdateCluster.
@Test
public void testPartialUpdateCluster() {
Mockito.when(mockStub.partialUpdateClusterOperationCallable()).thenReturn(mockPartialUpdateClusterCallable);
// Setup
com.google.bigtable.admin.v2.Cluster cluster = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setClusterConfig(clusterConfig).build();
PartialUpdateClusterRequest expectedRequest = PartialUpdateClusterRequest.newBuilder().setCluster(cluster).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").build()).build();
com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).setLocation(NameUtil.formatLocationName(PROJECT_ID, "us-east1-c")).setClusterConfig(clusterConfig).build();
mockOperationResult(mockPartialUpdateClusterCallable, expectedRequest, expectedResponse);
// Execute
Cluster actualResult = adminClient.updateClusterAutoscalingConfig(ClusterAutoscalingConfig.of(INSTANCE_ID, CLUSTER_ID).setMaxNodes(10).setMinNodes(2).setCpuUtilizationTargetPercent(22));
// Verify
assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
use of com.google.bigtable.admin.v2.Cluster in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method createClusterTest.
@Test
public void createClusterTest() 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);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
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.toString(), actualRequest.getParent());
Assert.assertEquals(clusterId, actualRequest.getClusterId());
Assert.assertEquals(cluster, actualRequest.getCluster());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.Cluster in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method listHotTabletsTest.
@Test
public void listHotTabletsTest() throws Exception {
HotTablet responsesElement = HotTablet.newBuilder().build();
ListHotTabletsResponse expectedResponse = ListHotTabletsResponse.newBuilder().setNextPageToken("").addAllHotTablets(Arrays.asList(responsesElement)).build();
mockBigtableInstanceAdmin.addResponse(expectedResponse);
ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
ListHotTabletsPagedResponse pagedListResponse = client.listHotTablets(parent);
List<HotTablet> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getHotTabletsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListHotTabletsRequest actualRequest = ((ListHotTabletsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.Cluster 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()));
}
use of com.google.bigtable.admin.v2.Cluster 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.
}
}
Aggregations