Skip to content

Commit e94496f

Browse files
committed
more test assertions
1 parent b74b453 commit e94496f

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/LocationAwareSharedBackendReplicaHarnessTest.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public void readWriteTransactionAbortedCommitUsesReadAffinityReplicaForBypassTra
503503
throws Exception {
504504
try (SharedBackendReplicaHarness harness = SharedBackendReplicaHarness.create(2);
505505
Spanner spanner = createSpanner(harness)) {
506-
configureBackend(harness, singleRowReadResultSet("b"));
506+
configureBackend(harness, singleRowReadResultSet("b"), /* leaderReplicaIndex= */ 1);
507507
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(PROJECT, INSTANCE, DATABASE));
508508

509509
seedLocationMetadata(client);
@@ -538,17 +538,11 @@ public void readWriteTransactionAbortedCommitUsesReadAffinityReplicaForBypassTra
538538
.withDescription("commit aborted on routed replica")
539539
.asRuntimeException());
540540
}
541-
542-
transaction.buffer(
543-
Mutation.newInsertOrUpdateBuilder("NoRecipeTable")
544-
.set("id")
545-
.to("row-1")
546-
.build());
547541
return null;
548542
});
549543

550544
assertEquals(2, attempts.get());
551-
assertTrue(firstReplicaIndex.get() >= 0);
545+
assertEquals(1, firstReplicaIndex.get());
552546
int secondReplicaIndex = 1 - firstReplicaIndex.get();
553547
assertEquals(
554548
2,
@@ -603,6 +597,14 @@ private static Spanner createSpanner(SharedBackendReplicaHarness harness) {
603597
private static void configureBackend(
604598
SharedBackendReplicaHarness harness, com.google.spanner.v1.ResultSet readResultSet)
605599
throws TextFormat.ParseException {
600+
configureBackend(harness, readResultSet, /* leaderReplicaIndex= */ 0);
601+
}
602+
603+
private static void configureBackend(
604+
SharedBackendReplicaHarness harness,
605+
com.google.spanner.v1.ResultSet readResultSet,
606+
int leaderReplicaIndex)
607+
throws TextFormat.ParseException {
606608
Statement readStatement =
607609
StatementResult.createReadStatement(
608610
TABLE, KeySet.singleKey(Key.of("b")), Arrays.asList("k"));
@@ -611,7 +613,7 @@ private static void configureBackend(
611613
StatementResult.query(
612614
SEED_QUERY,
613615
singleRowReadResultSet("seed").toBuilder()
614-
.setCacheUpdate(cacheUpdate(harness))
616+
.setCacheUpdate(cacheUpdate(harness, leaderReplicaIndex))
615617
.build()));
616618
}
617619

@@ -664,6 +666,12 @@ private static int findReplicaWithRequest(SharedBackendReplicaHarness harness, S
664666

665667
private static CacheUpdate cacheUpdate(SharedBackendReplicaHarness harness)
666668
throws TextFormat.ParseException {
669+
return cacheUpdate(harness, /* leaderReplicaIndex= */ 0);
670+
}
671+
672+
private static CacheUpdate cacheUpdate(
673+
SharedBackendReplicaHarness harness, int leaderReplicaIndex)
674+
throws TextFormat.ParseException {
667675
RecipeList recipes = readRecipeList();
668676
RoutingHint routingHint = exactReadRoutingHint(recipes);
669677
ByteString limitKey = routingHint.getLimitKey();
@@ -685,7 +693,7 @@ private static CacheUpdate cacheUpdate(SharedBackendReplicaHarness harness)
685693
Group.newBuilder()
686694
.setGroupUid(1L)
687695
.setGeneration(com.google.protobuf.ByteString.copyFromUtf8("gen1"))
688-
.setLeaderIndex(0)
696+
.setLeaderIndex(leaderReplicaIndex)
689697
.addTablets(
690698
Tablet.newBuilder()
691699
.setTabletUid(11L)

0 commit comments

Comments
 (0)