use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testDisableAutoscaling.
@Test
public void testDisableAutoscaling() {
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(com.google.bigtable.admin.v2.Cluster.ClusterConfig.newBuilder().build()).setServeNodes(30).build();
PartialUpdateClusterRequest expectedRequest = PartialUpdateClusterRequest.newBuilder().setCluster(cluster).setUpdateMask(FieldMask.newBuilder().addPaths("cluster_config.cluster_autoscaling_config").addPaths("serve_nodes").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")).setServeNodes(30).build();
mockOperationResult(mockPartialUpdateClusterCallable, expectedRequest, expectedResponse);
// Execute
Cluster actualResult = adminClient.disableClusterAutoscaling(INSTANCE_ID, CLUSTER_ID, 30);
// Verify
assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testCreateCluster.
@Test
public void testCreateCluster() {
// Setup
Mockito.when(mockStub.createClusterOperationCallable()).thenReturn(mockCreateClusterCallable);
com.google.bigtable.admin.v2.CreateClusterRequest expectedRequest = com.google.bigtable.admin.v2.CreateClusterRequest.newBuilder().setParent(INSTANCE_NAME).setClusterId(CLUSTER_ID).setCluster(com.google.bigtable.admin.v2.Cluster.newBuilder().setLocation("projects/my-project/locations/us-east1-c").setServeNodes(3).setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD)).build();
com.google.bigtable.admin.v2.Cluster expectedResponse = com.google.bigtable.admin.v2.Cluster.newBuilder().setName(CLUSTER_NAME).build();
mockOperationResult(mockCreateClusterCallable, expectedRequest, expectedResponse);
// Execute
Cluster actualResult = adminClient.createCluster(CreateClusterRequest.of(INSTANCE_ID, CLUSTER_ID).setZone("us-east1-c").setServeNodes(3).setStorageType(StorageType.SSD));
// Verify
assertThat(actualResult).isEqualTo(Cluster.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method listBackupsTest.
@Test
public void listBackupsTest() throws Exception {
Backup responsesElement = Backup.newBuilder().build();
ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
ListBackupsPagedResponse pagedListResponse = client.listBackups(parent);
List<Backup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBackupsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBackupsRequest actualRequest = ((ListBackupsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientIT method createClusterWithManualScalingTest.
@Test
public void createClusterWithManualScalingTest() {
String newInstanceId = prefixGenerator.newPrefix();
String newClusterId = newInstanceId + "-c1";
try {
client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD).setDisplayName("Multi-Cluster-Instance-Test").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
String clusterId = prefixGenerator.newPrefix();
CreateClusterRequest createClusterRequest = CreateClusterRequest.of(newInstanceId, clusterId).setZone(testEnvRule.env().getSecondaryZone()).setScalingMode(StaticClusterSize.of(5));
Cluster cluster = client.createCluster(createClusterRequest);
assertThat(cluster.getId()).contains(clusterId);
assertThat(cluster.getServeNodes()).isEqualTo(5);
assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(0);
assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(0);
assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(0);
} catch (Exception e) {
Assert.fail("error in the test: " + e.getMessage());
} finally {
client.deleteInstance(newInstanceId);
}
}
use of com.google.cloud.bigtable.admin.v2.models.Cluster in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientIT method instanceAndClusterCreationDeletionTest.
/**
* To optimize test run time, instance & cluster creation is tested at the same time
*/
@Test
public void instanceAndClusterCreationDeletionTest() {
String newInstanceId = prefixGenerator.newPrefix();
String newClusterId = newInstanceId;
client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 3, StorageType.SSD).setDisplayName("Fresh-Instance-Name").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
try {
assertThat(client.exists(newInstanceId)).isTrue();
client.updateInstance(UpdateInstanceRequest.of(newInstanceId).setDisplayName("Test-Instance-Name"));
Instance instance = client.getInstance(newInstanceId);
assertThat(instance.getDisplayName()).isEqualTo("Test-Instance-Name");
assertThat(client.listInstances()).contains(instance);
clusterCreationDeletionTestHelper(newInstanceId);
basicClusterOperationTestHelper(newInstanceId, newClusterId);
client.deleteInstance(newInstanceId);
assertThat(client.exists(newInstanceId)).isFalse();
} finally {
if (client.exists(newInstanceId)) {
client.deleteInstance(newInstanceId);
}
}
}
Aggregations