Skip to content

Commit a3c02fe

Browse files
authored
test: attempt to fix flaky test that throws NPE (#2693)
* test: attempt to fix flaky test that throws NPE * use tree set
1 parent 469290e commit a3c02fe

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
import com.google.protobuf.FieldMask;
7676
import io.grpc.Status;
7777
import io.grpc.Status.Code;
78-
import java.util.HashSet;
7978
import java.util.List;
8079
import java.util.Set;
80+
import java.util.TreeSet;
8181
import java.util.concurrent.atomic.AtomicBoolean;
8282
import java.util.concurrent.atomic.AtomicInteger;
8383
import org.junit.Before;
@@ -1215,6 +1215,12 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() {
12151215
// Setup
12161216
Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable);
12171217

1218+
// We want to make sure the expected request has the same ordering as the request we build
1219+
// from CreateAppProfileRequest. Use a TreeSet to for stable ordering.
1220+
Set<String> clusterIds = new TreeSet<>();
1221+
clusterIds.add("cluster-id-1");
1222+
clusterIds.add("cluster-id-2");
1223+
12181224
com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest =
12191225
com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder()
12201226
.setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID))
@@ -1225,8 +1231,7 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() {
12251231
.setMultiClusterRoutingUseAny(
12261232
com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny
12271233
.newBuilder()
1228-
.addClusterIds("cluster-id-1")
1229-
.addClusterIds("cluster-id-2")
1234+
.addAllClusterIds(clusterIds)
12301235
.setRowAffinity(
12311236
com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny
12321237
.RowAffinity.newBuilder()
@@ -1239,8 +1244,7 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() {
12391244
.setDescription("my description")
12401245
.setMultiClusterRoutingUseAny(
12411246
com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder()
1242-
.addClusterIds("cluster-id-1")
1243-
.addClusterIds("cluster-id-2")
1247+
.addAllClusterIds(clusterIds)
12441248
.setRowAffinity(
12451249
com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny
12461250
.RowAffinity.newBuilder()
@@ -1251,9 +1255,6 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() {
12511255
.thenReturn(ApiFutures.immediateFuture(expectedResponse));
12521256

12531257
// Execute
1254-
Set<String> clusterIds = new HashSet<String>();
1255-
clusterIds.add("cluster-id-1");
1256-
clusterIds.add("cluster-id-2");
12571258
AppProfile actualResult =
12581259
adminClient.createAppProfile(
12591260
CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID)

0 commit comments

Comments
 (0)