From 8d6d763a8a7a0d2d0e19a3af12d918becbb2c113 Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Mon, 13 Oct 2025 10:08:58 -0400 Subject: [PATCH 1/2] test: attempt to fix flaky test that throws NPE --- .../admin/v2/BigtableInstanceAdminClientTests.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java index 92174437908e..9a2d8cf6bb2c 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java @@ -1215,6 +1215,10 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() { // Setup Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); + Set clusterIds = new HashSet(); + clusterIds.add("cluster-id-1"); + clusterIds.add("cluster-id-2"); + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) @@ -1225,8 +1229,7 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() { .setMultiClusterRoutingUseAny( com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny .newBuilder() - .addClusterIds("cluster-id-1") - .addClusterIds("cluster-id-2") + .addAllClusterIds(clusterIds) .setRowAffinity( com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny .RowAffinity.newBuilder() @@ -1239,8 +1242,7 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() { .setDescription("my description") .setMultiClusterRoutingUseAny( com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() - .addClusterIds("cluster-id-1") - .addClusterIds("cluster-id-2") + .addAllClusterIds(clusterIds) .setRowAffinity( com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny .RowAffinity.newBuilder() @@ -1251,9 +1253,6 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() { .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute - Set clusterIds = new HashSet(); - clusterIds.add("cluster-id-1"); - clusterIds.add("cluster-id-2"); AppProfile actualResult = adminClient.createAppProfile( CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) From 67d1bf3f243aea4b74a2d08d6a4e48b6acf613a3 Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Tue, 14 Oct 2025 11:24:00 -0400 Subject: [PATCH 2/2] use tree set --- .../bigtable/admin/v2/BigtableInstanceAdminClientTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java index 9a2d8cf6bb2c..617a5334a3c7 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java @@ -75,9 +75,9 @@ import com.google.protobuf.FieldMask; import io.grpc.Status; import io.grpc.Status.Code; -import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Before; @@ -1215,7 +1215,9 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() { // Setup Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); - Set clusterIds = new HashSet(); + // We want to make sure the expected request has the same ordering as the request we build + // from CreateAppProfileRequest. Use a TreeSet to for stable ordering. + Set clusterIds = new TreeSet<>(); clusterIds.add("cluster-id-1"); clusterIds.add("cluster-id-2");