Skip to content

Commit acdda46

Browse files
authored
Merge branch 'main' into mux-rw-env
2 parents e649f2b + 2d65e88 commit acdda46

File tree

5 files changed

+142
-53
lines changed

5 files changed

+142
-53
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ public void asyncRunnerUpdateAbortedWithoutGettingResult() throws Exception {
214214
BeginTransactionRequest.class,
215215
ExecuteSqlRequest.class,
216216
CommitRequest.class);
217+
} else if (isMultiplexedSessionsEnabled()) {
218+
assertThat(mockSpanner.getRequestTypes())
219+
.containsExactly(
220+
CreateSessionRequest.class,
221+
BatchCreateSessionsRequest.class,
222+
ExecuteSqlRequest.class,
223+
// The retry will use an explicit BeginTransaction RPC because the first statement of
224+
// the transaction did not return a transaction id during the initial attempt.
225+
BeginTransactionRequest.class,
226+
ExecuteSqlRequest.class,
227+
CommitRequest.class);
217228
} else {
218229
assertThat(mockSpanner.getRequestTypes())
219230
.containsExactly(
@@ -263,11 +274,15 @@ public void asyncRunnerWaitsUntilAsyncUpdateHasFinished() throws Exception {
263274
executor);
264275
res.get();
265276
if (isMultiplexedSessionsEnabledForRW()) {
277+
assertThat(mockSpanner.getRequestTypes())
278+
.containsAtLeast(
279+
CreateSessionRequest.class, ExecuteSqlRequest.class, CommitRequest.class);
280+
} else if (isMultiplexedSessionsEnabled()) {
266281
// The mock server could have received a CreateSession request for a multiplexed session, but
267282
// it could also be that that request has not yet reached the server.
268283
assertThat(mockSpanner.getRequestTypes())
269284
.containsAtLeast(
270-
CreateSessionRequest.class, ExecuteSqlRequest.class, CommitRequest.class);
285+
BatchCreateSessionsRequest.class, ExecuteSqlRequest.class, CommitRequest.class);
271286
} else {
272287
assertThat(mockSpanner.getRequestTypes())
273288
.containsExactly(
@@ -416,6 +431,17 @@ public void asyncRunnerBatchUpdateAbortedWithoutGettingResult() throws Exception
416431
ExecuteSqlRequest.class,
417432
ExecuteBatchDmlRequest.class,
418433
CommitRequest.class);
434+
} else if (isMultiplexedSessionsEnabled()) {
435+
assertThat(mockSpanner.getRequestTypes())
436+
.containsExactly(
437+
CreateSessionRequest.class,
438+
BatchCreateSessionsRequest.class,
439+
ExecuteSqlRequest.class,
440+
ExecuteBatchDmlRequest.class,
441+
CommitRequest.class,
442+
ExecuteSqlRequest.class,
443+
ExecuteBatchDmlRequest.class,
444+
CommitRequest.class);
419445
} else {
420446
assertThat(mockSpanner.getRequestTypes())
421447
.containsExactly(
@@ -465,9 +491,14 @@ public void asyncRunnerWaitsUntilAsyncBatchUpdateHasFinished() throws Exception
465491
executor);
466492
res.get();
467493
if (isMultiplexedSessionsEnabledForRW()) {
494+
assertThat(mockSpanner.getRequestTypes())
495+
.containsExactly(
496+
CreateSessionRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
497+
} else if (isMultiplexedSessionsEnabled()) {
468498
assertThat(mockSpanner.getRequestTypes())
469499
.containsExactly(
470500
CreateSessionRequest.class,
501+
BatchCreateSessionsRequest.class,
471502
ExecuteBatchDmlRequest.class,
472503
CommitRequest.class);
473504
} else {

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

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public void asyncTransactionManagerFireAndForgetInvalidUpdate() throws Exception
355355
}
356356
}
357357
}
358-
ImmutableList<Class<? extends Message>> expectedRequestsWithRegularSession =
358+
ImmutableList<Class<? extends Message>> expectedRequests =
359359
ImmutableList.of(
360360
BatchCreateSessionsRequest.class,
361361
// The first update that fails. This will cause a transaction retry.
@@ -367,7 +367,7 @@ public void asyncTransactionManagerFireAndForgetInvalidUpdate() throws Exception
367367
ExecuteSqlRequest.class,
368368
ExecuteSqlRequest.class,
369369
CommitRequest.class);
370-
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSession =
370+
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSessionForRW =
371371
ImmutableList.of(
372372
CreateSessionRequest.class,
373373
// The first update that fails. This will cause a transaction retry.
@@ -381,10 +381,11 @@ public void asyncTransactionManagerFireAndForgetInvalidUpdate() throws Exception
381381
CommitRequest.class);
382382
if (isMultiplexedSessionsEnabledForRW()) {
383383
assertThat(mockSpanner.getRequestTypes())
384-
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSession);
384+
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSessionForRW);
385+
} else if (isMultiplexedSessionsEnabled()) {
386+
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
385387
} else {
386-
assertThat(mockSpanner.getRequestTypes())
387-
.containsExactlyElementsIn(expectedRequestsWithRegularSession);
388+
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
388389
}
389390
}
390391

@@ -594,6 +595,13 @@ public void asyncTransactionManagerWaitsUntilAsyncUpdateHasFinished() throws Exc
594595
assertThat(mockSpanner.getRequestTypes())
595596
.containsExactly(
596597
CreateSessionRequest.class, ExecuteSqlRequest.class, CommitRequest.class);
598+
} else if (isMultiplexedSessionsEnabled()) {
599+
assertThat(mockSpanner.getRequestTypes())
600+
.containsExactly(
601+
CreateSessionRequest.class,
602+
BatchCreateSessionsRequest.class,
603+
ExecuteSqlRequest.class,
604+
CommitRequest.class);
597605
} else {
598606
assertThat(mockSpanner.getRequestTypes())
599607
.containsExactly(
@@ -707,24 +715,25 @@ public void asyncTransactionManagerFireAndForgetInvalidBatchUpdate() throws Exce
707715
}
708716
}
709717
}
710-
ImmutableList<Class<? extends Message>> expectedRequestsWithRegularSession =
718+
ImmutableList<Class<? extends Message>> expectedRequests =
711719
ImmutableList.of(
712720
BatchCreateSessionsRequest.class,
713721
ExecuteBatchDmlRequest.class,
714722
ExecuteBatchDmlRequest.class,
715723
CommitRequest.class);
716-
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSession =
724+
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSessionsRW =
717725
ImmutableList.of(
718726
CreateSessionRequest.class,
719727
ExecuteBatchDmlRequest.class,
720728
ExecuteBatchDmlRequest.class,
721729
CommitRequest.class);
722730
if (isMultiplexedSessionsEnabledForRW()) {
723731
assertThat(mockSpanner.getRequestTypes())
724-
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSession);
732+
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSessionsRW);
733+
} else if (isMultiplexedSessionsEnabled()) {
734+
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
725735
} else {
726-
assertThat(mockSpanner.getRequestTypes())
727-
.containsExactlyElementsIn(expectedRequestsWithRegularSession);
736+
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
728737
}
729738
}
730739

@@ -758,14 +767,14 @@ public void asyncTransactionManagerBatchUpdateAborted() throws Exception {
758767
assertThat(attempt.get()).isEqualTo(2);
759768
// There should only be 1 CommitRequest, as the first attempt should abort already after the
760769
// ExecuteBatchDmlRequest.
761-
ImmutableList<Class<? extends Message>> expectedRequestsWithRegularSession =
770+
ImmutableList<Class<? extends Message>> expectedRequests =
762771
ImmutableList.of(
763772
BatchCreateSessionsRequest.class,
764773
ExecuteBatchDmlRequest.class,
765774
BeginTransactionRequest.class,
766775
ExecuteBatchDmlRequest.class,
767776
CommitRequest.class);
768-
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSession =
777+
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSessionsRW =
769778
ImmutableList.of(
770779
CreateSessionRequest.class,
771780
ExecuteBatchDmlRequest.class,
@@ -774,10 +783,11 @@ public void asyncTransactionManagerBatchUpdateAborted() throws Exception {
774783
CommitRequest.class);
775784
if (isMultiplexedSessionsEnabledForRW()) {
776785
assertThat(mockSpanner.getRequestTypes())
777-
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSession);
786+
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSessionsRW);
787+
} else if (isMultiplexedSessionsEnabled()) {
788+
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
778789
} else {
779-
assertThat(mockSpanner.getRequestTypes())
780-
.containsExactlyElementsIn(expectedRequestsWithRegularSession);
790+
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
781791
}
782792
}
783793

@@ -809,18 +819,17 @@ public void asyncTransactionManagerBatchUpdateAbortedBeforeFirstStatement() thro
809819
assertThat(attempt.get()).isEqualTo(2);
810820
// There should only be 1 CommitRequest, as the first attempt should abort already after the
811821
// ExecuteBatchDmlRequest.
812-
ImmutableList<Class<? extends Message>> expectedRequestsWithRegularSession =
822+
ImmutableList<Class<? extends Message>> expectedRequests =
813823
ImmutableList.of(
814824
BatchCreateSessionsRequest.class,
815825
ExecuteBatchDmlRequest.class,
816826
BeginTransactionRequest.class,
817827
ExecuteBatchDmlRequest.class,
818828
CommitRequest.class);
819-
// There should only be 1 CommitRequest, as the first attempt should abort already after the
820-
// ExecuteBatchDmlRequest.
821-
// When requests run using multiplexed session, the BatchCreateSessionsRequest will not be
829+
// When requests run using multiplexed session with read-write enabled, the
830+
// BatchCreateSessionsRequest will not be
822831
// triggered because we are creating an empty pool during initialization.
823-
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSession =
832+
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSessionsRW =
824833
ImmutableList.of(
825834
CreateSessionRequest.class,
826835
ExecuteBatchDmlRequest.class,
@@ -829,10 +838,11 @@ public void asyncTransactionManagerBatchUpdateAbortedBeforeFirstStatement() thro
829838
CommitRequest.class);
830839
if (isMultiplexedSessionsEnabledForRW()) {
831840
assertThat(mockSpanner.getRequestTypes())
832-
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSession);
841+
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSessionsRW);
842+
} else if (isMultiplexedSessionsEnabled()) {
843+
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
833844
} else {
834-
assertThat(mockSpanner.getRequestTypes())
835-
.containsExactlyElementsIn(expectedRequestsWithRegularSession);
845+
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
836846
}
837847
}
838848

@@ -882,15 +892,15 @@ public void asyncTransactionManagerWithBatchUpdateCommitAborted() throws Excepti
882892
} finally {
883893
mockSpanner.putStatementResult(StatementResult.update(UPDATE_STATEMENT, UPDATE_COUNT));
884894
}
885-
ImmutableList<Class<? extends Message>> expectedRequestsWithRegularSession =
895+
ImmutableList<Class<? extends Message>> expectedRequests =
886896
ImmutableList.of(
887897
BatchCreateSessionsRequest.class,
888898
ExecuteBatchDmlRequest.class,
889899
CommitRequest.class,
890900
BeginTransactionRequest.class,
891901
ExecuteBatchDmlRequest.class,
892902
CommitRequest.class);
893-
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSession =
903+
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSessionsRW =
894904
ImmutableList.of(
895905
CreateSessionRequest.class,
896906
ExecuteBatchDmlRequest.class,
@@ -900,10 +910,11 @@ public void asyncTransactionManagerWithBatchUpdateCommitAborted() throws Excepti
900910
CommitRequest.class);
901911
if (isMultiplexedSessionsEnabledForRW()) {
902912
assertThat(mockSpanner.getRequestTypes())
903-
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSession);
913+
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSessionsRW);
914+
} else if (isMultiplexedSessionsEnabled()) {
915+
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
904916
} else {
905-
assertThat(mockSpanner.getRequestTypes())
906-
.containsExactlyElementsIn(expectedRequestsWithRegularSession);
917+
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
907918
}
908919
}
909920

@@ -941,6 +952,11 @@ public void asyncTransactionManagerBatchUpdateAbortedWithoutGettingResult() thro
941952
}
942953
assertThat(attempt.get()).isEqualTo(2);
943954
List<Class<? extends AbstractMessage>> requests = mockSpanner.getRequestTypes();
955+
// Remove the CreateSession requests for multiplexed sessions, as those are not relevant for
956+
// this test if multiplexed session for read-write is not enabled.
957+
if (!isMultiplexedSessionsEnabledForRW()) {
958+
requests.removeIf(request -> request == CreateSessionRequest.class);
959+
}
944960
int size = Iterables.size(requests);
945961
assertThat(size).isIn(Range.closed(5, 6));
946962
if (size == 5) {
@@ -1008,18 +1024,19 @@ public void asyncTransactionManagerWithBatchUpdateCommitFails() {
10081024
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
10091025
assertThat(e.getMessage()).contains("mutation limit exceeded");
10101026
}
1011-
ImmutableList<Class<? extends Message>> expectedRequestsWithRegularSession =
1027+
ImmutableList<Class<? extends Message>> expectedRequests =
10121028
ImmutableList.of(
10131029
BatchCreateSessionsRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
1014-
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSession =
1030+
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSessionsRW =
10151031
ImmutableList.of(
10161032
CreateSessionRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
10171033
if (isMultiplexedSessionsEnabledForRW()) {
10181034
assertThat(mockSpanner.getRequestTypes())
1019-
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSession);
1035+
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSessionsRW);
1036+
} else if (isMultiplexedSessionsEnabled()) {
1037+
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
10201038
} else {
1021-
assertThat(mockSpanner.getRequestTypes())
1022-
.containsExactlyElementsIn(expectedRequestsWithRegularSession);
1039+
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
10231040
}
10241041
}
10251042

@@ -1044,18 +1061,19 @@ public void asyncTransactionManagerWaitsUntilAsyncBatchUpdateHasFinished() throw
10441061
}
10451062
}
10461063
}
1047-
ImmutableList<Class<? extends Message>> expectedRequestsWithRegularSession =
1064+
ImmutableList<Class<? extends Message>> expectedRequests =
10481065
ImmutableList.of(
10491066
BatchCreateSessionsRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
1050-
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSession =
1067+
ImmutableList<Class<? extends Message>> expectedRequestsWithMultiplexedSessionsRW =
10511068
ImmutableList.of(
10521069
CreateSessionRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
1053-
if (isMultiplexedSessionsEnabled()) {
1070+
if (isMultiplexedSessionsEnabledForRW()) {
10541071
assertThat(mockSpanner.getRequestTypes())
1055-
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSession);
1072+
.containsExactlyElementsIn(expectedRequestsWithMultiplexedSessionsRW);
1073+
} else if (isMultiplexedSessionsEnabled()) {
1074+
assertThat(mockSpanner.getRequestTypes()).containsAtLeastElementsIn(expectedRequests);
10561075
} else {
1057-
assertThat(mockSpanner.getRequestTypes())
1058-
.containsExactlyElementsIn(expectedRequestsWithRegularSession);
1076+
assertThat(mockSpanner.getRequestTypes()).containsExactlyElementsIn(expectedRequests);
10591077
}
10601078
}
10611079

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,14 +3142,20 @@ public void testDatabaseOrInstanceDoesNotExistOnCreate() {
31423142
.readWriteTransaction()
31433143
.run(transaction -> transaction.executeUpdate(UPDATE_STATEMENT)));
31443144
// No additional requests should have been sent by the client.
3145-
// Note that in case of the use of regular sessions, then we have 1 request:
3146-
// 1. BatchCreateSessions for the session pool.
3147-
// Note that in case of the use of multiplexed sessions for read-only and read-write,
3148-
// then we have 1 request:
3149-
// 1. CreateSession for the multiplexed session.
3150-
// There will be no BatchCreateSessions request in case of multiplexed sessions, because
3151-
// the session pool options has min size of 0.
3152-
assertThat(mockSpanner.getRequests()).hasSize(1);
3145+
if (spanner.getOptions().getSessionPoolOptions().getUseMultiplexedSession()
3146+
&& !spanner.getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW()) {
3147+
// Note that in case of the use of multiplexed sessions for read-only alone, then we
3148+
// have 2 requests:
3149+
// 1. BatchCreateSessions for the session pool.
3150+
// 2. CreateSession for the multiplexed session.
3151+
assertThat(mockSpanner.getRequests()).hasSize(2);
3152+
} else {
3153+
// Note that in case of the use of regular sessions, then we have 1 request:
3154+
// BatchCreateSessions for the session pool.
3155+
// Note that in case of the use of multiplexed sessions for read-write, then we have 1
3156+
// request: CreateSession for the multiplexed session.
3157+
assertThat(mockSpanner.getRequests()).hasSize(1);
3158+
}
31533159
}
31543160
}
31553161
mockSpanner.reset();

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ public void transactionRunner() {
469469
"Transaction Attempt Succeeded");
470470
expectedReadWriteTransactionEventsCount = 4;
471471
}
472-
473472
DatabaseClient client = getClient();
474473
TransactionRunner runner = client.readWriteTransaction();
475474
runner.run(transaction -> transaction.executeUpdate(UPDATE_STATEMENT));
@@ -540,7 +539,6 @@ public void transactionRunnerWithError() {
540539
"CloudSpannerOperation.BatchCreateSessions",
541540
"CloudSpannerOperation.ExecuteUpdate",
542541
"CloudSpanner.ReadWriteTransaction");
543-
544542
if (isMultiplexedSessionsEnabledForRW()) {
545543
expectedReadWriteTransactionErrorEvents =
546544
ImmutableList.of(
@@ -549,7 +547,6 @@ public void transactionRunnerWithError() {
549547
"exception");
550548
expectedReadWriteTransactionErrorEventsCount = 3;
551549
}
552-
553550
DatabaseClient client = getClient();
554551
TransactionRunner runner = client.readWriteTransaction();
555552
SpannerException e =

0 commit comments

Comments
 (0)