Skip to content

Commit 03fa988

Browse files
chore: update basicClusterOperationTest to be more robust (#84)
* chore: update basicClusterOperationTest to be more robust The updated version will be run as part of the instance creation test, this will minimize the contention on the shared instance * typo
1 parent f5f70e0 commit 03fa988

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static com.google.cloud.bigtable.test_helpers.env.AbstractTestEnv.TEST_APP_PREFIX;
1919
import static com.google.common.truth.Truth.assertThat;
20+
import static com.google.common.truth.Truth.assertWithMessage;
2021
import static com.google.common.truth.TruthJUnit.assume;
2122

2223
import 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
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/LargeRowIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@
2525
import java.util.Random;
2626
import java.util.UUID;
2727
import java.util.concurrent.TimeUnit;
28+
import java.util.logging.Logger;
2829
import org.junit.ClassRule;
2930
import org.junit.Test;
3031
import org.junit.runner.RunWith;
3132
import org.junit.runners.JUnit4;
3233

3334
@RunWith(JUnit4.class)
3435
public class LargeRowIT {
35-
@ClassRule public static TestEnvRule testEnvRule = new TestEnvRule();
36+
private static final Logger logger = Logger.getLogger(LargeRowIT.class.getName());
37+
38+
@ClassRule public static final TestEnvRule testEnvRule = new TestEnvRule();
3639

3740
@Test
3841
public void testWriteRead() throws Exception {
@@ -45,6 +48,7 @@ public void testWriteRead() throws Exception {
4548
ByteString largeValue = ByteString.copyFrom(largeValueBytes);
4649

4750
// Create a 200 MB row
51+
logger.info("Sending large row, this will take awhile");
4852
for (int i = 0; i < 2; i++) {
4953
testEnvRule
5054
.env()
@@ -55,6 +59,7 @@ public void testWriteRead() throws Exception {
5559
.get(10, TimeUnit.MINUTES);
5660
}
5761

62+
logger.info("Reading large row, this will take awhile");
5863
// Read it back
5964
Row row =
6065
testEnvRule

0 commit comments

Comments
 (0)