@@ -270,6 +270,9 @@ public void tearDown() {
270270 @ Test
271271 public void
272272 testPoolMaintainer_whenInactiveTransactionAndSessionIsNotFoundOnBackend_removeSessionsFromPool () {
273+ assumeFalse (
274+ "Session pool maintainer test skipped for multiplexed sessions" ,
275+ isMultiplexedSessionsEnabledForRW ());
273276 FakeClock poolMaintainerClock = new FakeClock ();
274277 InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions =
275278 InactiveTransactionRemovalOptions .newBuilder ()
@@ -347,6 +350,9 @@ public void tearDown() {
347350 @ Test
348351 public void
349352 testPoolMaintainer_whenInactiveTransactionAndSessionExistsOnBackend_removeSessionsFromPool () {
353+ assumeFalse (
354+ "Session leaks tests are skipped for multiplexed sessions" ,
355+ isMultiplexedSessionsEnabledForRW ());
350356 FakeClock poolMaintainerClock = new FakeClock ();
351357 InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions =
352358 InactiveTransactionRemovalOptions .newBuilder ()
@@ -482,6 +488,9 @@ public void testPoolMaintainer_whenLongRunningPartitionedUpdateRequest_takeNoAct
482488 */
483489 @ Test
484490 public void testPoolMaintainer_whenPDMLFollowedByInactiveTransaction_removeSessionsFromPool () {
491+ assumeFalse (
492+ "Session leaks tests are skipped for multiplexed sessions" ,
493+ isMultiplexedSessionsEnabledForRW ());
485494 FakeClock poolMaintainerClock = new FakeClock ();
486495 InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions =
487496 InactiveTransactionRemovalOptions .newBuilder ()
@@ -3085,6 +3094,7 @@ public void testDatabaseOrInstanceDoesNotExistOnCreate() {
30853094 .run (transaction -> transaction .executeUpdate (UPDATE_STATEMENT )));
30863095 // No additional requests should have been sent by the client.
30873096 // Note that in case of the use of multiplexed sessions, then we have 2 requests:
3097+ // Note that in case of the use of regular sessions, then we have 1 request:
30883098 // 1. BatchCreateSessions for the session pool.
30893099 // 2. CreateSession for the multiplexed session.
30903100 assertThat (mockSpanner .getRequests ())
@@ -3211,9 +3221,16 @@ public void testDatabaseOrInstanceIsDeletedAndThenRecreated() throws Exception {
32113221 ResourceNotFoundException .class , () -> dbClient .singleUse ().executeQuery (SELECT1 ));
32123222 }
32133223
3214- assertThrows (
3215- ResourceNotFoundException .class ,
3216- () -> dbClient .readWriteTransaction ().run (transaction -> null ));
3224+ if (!spanner .getOptions ().getSessionPoolOptions ().getUseMultiplexedSessionForRW ()) {
3225+ // We only verify this for read-write transactions if we are not using multiplexed
3226+ // sessions. For multiplexed sessions, we don't need any special handling, as deleting the
3227+ // database will also invalidate the multiplexed session, and trying to continue to use it
3228+ // will continue to return an error.
3229+ assertThrows (
3230+ ResourceNotFoundException .class ,
3231+ () -> dbClient .readWriteTransaction ().run (transaction -> null ));
3232+ }
3233+
32173234 assertThat (mockSpanner .getRequests ()).isEmpty ();
32183235 // Now get a new database client. Normally multiple calls to Spanner#getDatabaseClient will
32193236 // return the same instance, but not when the instance has been invalidated by a
@@ -3300,13 +3317,18 @@ public void testAllowNestedTransactions() throws InterruptedException {
33003317 Thread .sleep (1L );
33013318 }
33023319 assertThat (client .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions );
3320+ int expectedMinSessions =
3321+ spanner .getOptions ().getSessionPoolOptions ().getUseMultiplexedSessionForRW ()
3322+ ? minSessions
3323+ : minSessions - 1 ;
33033324 Long res =
33043325 client
33053326 .readWriteTransaction ()
33063327 .allowNestedTransaction ()
33073328 .run (
33083329 transaction -> {
3309- assertThat (client .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions - 1 );
3330+ assertThat (client .pool .getNumberOfSessionsInPool ())
3331+ .isEqualTo (expectedMinSessions );
33103332 return transaction .executeUpdate (UPDATE_STATEMENT );
33113333 });
33123334 assertThat (res ).isEqualTo (UPDATE_COUNT );
@@ -3333,6 +3355,9 @@ public void testNestedTransactionsUsingTwoDatabases() throws InterruptedExceptio
33333355 }
33343356 assertThat (client1 .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions );
33353357 assertThat (client2 .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions );
3358+ // When read-write transaction uses multiplexed sessions, then sessions are not checked out from
3359+ // the session pool.
3360+ int expectedMinSessions = isMultiplexedSessionsEnabledForRW () ? minSessions : minSessions - 1 ;
33363361 Long res =
33373362 client1
33383363 .readWriteTransaction ()
@@ -3341,7 +3366,8 @@ public void testNestedTransactionsUsingTwoDatabases() throws InterruptedExceptio
33413366 transaction -> {
33423367 // Client1 should have 1 session checked out.
33433368 // Client2 should have 0 sessions checked out.
3344- assertThat (client1 .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions - 1 );
3369+ assertThat (client1 .pool .getNumberOfSessionsInPool ())
3370+ .isEqualTo (expectedMinSessions );
33453371 assertThat (client2 .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions );
33463372 Long add =
33473373 client2
@@ -3350,9 +3376,9 @@ public void testNestedTransactionsUsingTwoDatabases() throws InterruptedExceptio
33503376 transaction1 -> {
33513377 // Both clients should now have 1 session checked out.
33523378 assertThat (client1 .pool .getNumberOfSessionsInPool ())
3353- .isEqualTo (minSessions - 1 );
3379+ .isEqualTo (expectedMinSessions );
33543380 assertThat (client2 .pool .getNumberOfSessionsInPool ())
3355- .isEqualTo (minSessions - 1 );
3381+ .isEqualTo (expectedMinSessions );
33563382 try (ResultSet rs = transaction1 .executeQuery (SELECT1 )) {
33573383 if (rs .next ()) {
33583384 return rs .getLong (0 );
@@ -5090,6 +5116,9 @@ public void testRetryOnResourceExhausted() {
50905116
50915117 @ Test
50925118 public void testSessionPoolExhaustedError_containsStackTraces () {
5119+ assumeFalse (
5120+ "Session pool tests are skipped for multiplexed sessions" ,
5121+ isMultiplexedSessionsEnabledForRW ());
50935122 try (Spanner spanner =
50945123 SpannerOptions .newBuilder ()
50955124 .setProjectId (TEST_PROJECT )
@@ -5450,4 +5479,11 @@ private boolean isMultiplexedSessionsEnabled() {
54505479 }
54515480 return spanner .getOptions ().getSessionPoolOptions ().getUseMultiplexedSession ();
54525481 }
5482+
5483+ private boolean isMultiplexedSessionsEnabledForRW () {
5484+ if (spanner .getOptions () == null || spanner .getOptions ().getSessionPoolOptions () == null ) {
5485+ return false ;
5486+ }
5487+ return spanner .getOptions ().getSessionPoolOptions ().getUseMultiplexedSessionForRW ();
5488+ }
54535489}
0 commit comments