1717
1818import static com .google .cloud .bigtable .test_helpers .env .AbstractTestEnv .TEST_APP_PREFIX ;
1919import static com .google .common .truth .Truth .assertThat ;
20+ import static com .google .common .truth .Truth .assertWithMessage ;
2021import static com .google .common .truth .TruthJUnit .assume ;
2122
2223import com .google .cloud .Policy ;
@@ -136,6 +137,7 @@ public void instanceAndClusterCreationDeletionTest() {
136137 assertThat (client .listInstances ()).contains (instance );
137138
138139 clusterCreationDeletionTestHelper (newInstanceId );
140+ basicClusterOperationTestHelper (newInstanceId , newClusterId );
139141
140142 client .deleteInstance (newInstanceId );
141143 assertThat (client .exists (newInstanceId )).isFalse ();
@@ -149,7 +151,7 @@ public void instanceAndClusterCreationDeletionTest() {
149151 // To improve test runtime, piggyback off the instance creation/deletion test's fresh instance.
150152 // This will avoid the need to copy any existing tables and will also reduce flakiness in case a
151153 // previous run failed to clean up a cluster in the secondary zone.
152- public void clusterCreationDeletionTestHelper (String newInstanceId ) {
154+ private void clusterCreationDeletionTestHelper (String newInstanceId ) {
153155 String newClusterId = AbstractTestEnv .TEST_CLUSTER_PREFIX + Instant .now ().getEpochSecond ();
154156 boolean isClusterDeleted = false ;
155157 client .createCluster (
@@ -184,27 +186,26 @@ public void basicInstanceOperationTest() {
184186 assertThat (client .listInstances ()).contains (instance );
185187 }
186188
187- /* As cluster creation is very expensive operation, so reusing existing clusters to verify rest
188- of the operation.*/
189- @ Test
190- public void basicClusterOperationTest () {
191- List <Cluster > clusters = client .listClusters (instanceId );
192- assertThat (clusters ).isNotEmpty ();
189+ // To improve test runtime, piggyback off the instance creation/deletion test's fresh instance.
190+ private void basicClusterOperationTestHelper (String targetInstanceId , String targetClusterId ) {
191+ List <Cluster > clusters = client .listClusters (targetInstanceId );
193192
194- Cluster existingCluster = clusters .get (0 );
195- String clusterId = existingCluster .getId ();
196- assertThat (client .getCluster (instanceId , clusterId )).isEqualTo (existingCluster );
193+ Cluster targetCluster = null ;
194+ for (Cluster cluster : clusters ) {
195+ if (cluster .getId ().equals (targetClusterId )) {
196+ targetCluster = cluster ;
197+ }
198+ }
199+ assertWithMessage ("Failed to find target cluster id in listClusters" )
200+ .that (targetCluster )
201+ .isNotNull ();
197202
198- if (Instance .Type .PRODUCTION .equals (client .getInstance (instanceId ).getType ())) {
199- int existingClusterNodeSize = existingCluster .getServeNodes ();
200- int freshNumOfNodes = existingClusterNodeSize + 1 ;
203+ assertThat (client .getCluster (targetInstanceId , targetClusterId )).isEqualTo (targetCluster );
201204
202- Cluster resizeCluster = client .resizeCluster (instanceId , clusterId , freshNumOfNodes );
203- assertThat (resizeCluster .getServeNodes ()).isEqualTo (freshNumOfNodes );
205+ int freshNumOfNodes = targetCluster .getServeNodes () + 1 ;
204206
205- assertThat (
206- client .resizeCluster (instanceId , clusterId , existingClusterNodeSize ).getServeNodes ())
207- .isEqualTo (existingClusterNodeSize );
208- }
207+ Cluster resizeCluster =
208+ client .resizeCluster (targetInstanceId , targetClusterId , freshNumOfNodes );
209+ assertThat (resizeCluster .getServeNodes ()).isEqualTo (freshNumOfNodes );
209210 }
210211}
0 commit comments