@@ -270,6 +270,9 @@ public void tearDown() {
270
270
@ Test
271
271
public void
272
272
testPoolMaintainer_whenInactiveTransactionAndSessionIsNotFoundOnBackend_removeSessionsFromPool () {
273
+ assumeFalse (
274
+ "Session pool maintainer test skipped for multiplexed sessions" ,
275
+ isMultiplexedSessionsEnabledForRW ());
273
276
FakeClock poolMaintainerClock = new FakeClock ();
274
277
InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions =
275
278
InactiveTransactionRemovalOptions .newBuilder ()
@@ -347,6 +350,9 @@ public void tearDown() {
347
350
@ Test
348
351
public void
349
352
testPoolMaintainer_whenInactiveTransactionAndSessionExistsOnBackend_removeSessionsFromPool () {
353
+ assumeFalse (
354
+ "Session leaks tests are skipped for multiplexed sessions" ,
355
+ isMultiplexedSessionsEnabledForRW ());
350
356
FakeClock poolMaintainerClock = new FakeClock ();
351
357
InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions =
352
358
InactiveTransactionRemovalOptions .newBuilder ()
@@ -482,6 +488,9 @@ public void testPoolMaintainer_whenLongRunningPartitionedUpdateRequest_takeNoAct
482
488
*/
483
489
@ Test
484
490
public void testPoolMaintainer_whenPDMLFollowedByInactiveTransaction_removeSessionsFromPool () {
491
+ assumeFalse (
492
+ "Session leaks tests are skipped for multiplexed sessions" ,
493
+ isMultiplexedSessionsEnabledForRW ());
485
494
FakeClock poolMaintainerClock = new FakeClock ();
486
495
InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions =
487
496
InactiveTransactionRemovalOptions .newBuilder ()
@@ -3085,6 +3094,7 @@ public void testDatabaseOrInstanceDoesNotExistOnCreate() {
3085
3094
.run (transaction -> transaction .executeUpdate (UPDATE_STATEMENT )));
3086
3095
// No additional requests should have been sent by the client.
3087
3096
// 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:
3088
3098
// 1. BatchCreateSessions for the session pool.
3089
3099
// 2. CreateSession for the multiplexed session.
3090
3100
assertThat (mockSpanner .getRequests ())
@@ -3211,9 +3221,16 @@ public void testDatabaseOrInstanceIsDeletedAndThenRecreated() throws Exception {
3211
3221
ResourceNotFoundException .class , () -> dbClient .singleUse ().executeQuery (SELECT1 ));
3212
3222
}
3213
3223
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
+
3217
3234
assertThat (mockSpanner .getRequests ()).isEmpty ();
3218
3235
// Now get a new database client. Normally multiple calls to Spanner#getDatabaseClient will
3219
3236
// return the same instance, but not when the instance has been invalidated by a
@@ -3300,13 +3317,18 @@ public void testAllowNestedTransactions() throws InterruptedException {
3300
3317
Thread .sleep (1L );
3301
3318
}
3302
3319
assertThat (client .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions );
3320
+ int expectedMinSessions =
3321
+ spanner .getOptions ().getSessionPoolOptions ().getUseMultiplexedSessionForRW ()
3322
+ ? minSessions
3323
+ : minSessions - 1 ;
3303
3324
Long res =
3304
3325
client
3305
3326
.readWriteTransaction ()
3306
3327
.allowNestedTransaction ()
3307
3328
.run (
3308
3329
transaction -> {
3309
- assertThat (client .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions - 1 );
3330
+ assertThat (client .pool .getNumberOfSessionsInPool ())
3331
+ .isEqualTo (expectedMinSessions );
3310
3332
return transaction .executeUpdate (UPDATE_STATEMENT );
3311
3333
});
3312
3334
assertThat (res ).isEqualTo (UPDATE_COUNT );
@@ -3333,6 +3355,9 @@ public void testNestedTransactionsUsingTwoDatabases() throws InterruptedExceptio
3333
3355
}
3334
3356
assertThat (client1 .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions );
3335
3357
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 ;
3336
3361
Long res =
3337
3362
client1
3338
3363
.readWriteTransaction ()
@@ -3341,7 +3366,8 @@ public void testNestedTransactionsUsingTwoDatabases() throws InterruptedExceptio
3341
3366
transaction -> {
3342
3367
// Client1 should have 1 session checked out.
3343
3368
// Client2 should have 0 sessions checked out.
3344
- assertThat (client1 .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions - 1 );
3369
+ assertThat (client1 .pool .getNumberOfSessionsInPool ())
3370
+ .isEqualTo (expectedMinSessions );
3345
3371
assertThat (client2 .pool .getNumberOfSessionsInPool ()).isEqualTo (minSessions );
3346
3372
Long add =
3347
3373
client2
@@ -3350,9 +3376,9 @@ public void testNestedTransactionsUsingTwoDatabases() throws InterruptedExceptio
3350
3376
transaction1 -> {
3351
3377
// Both clients should now have 1 session checked out.
3352
3378
assertThat (client1 .pool .getNumberOfSessionsInPool ())
3353
- .isEqualTo (minSessions - 1 );
3379
+ .isEqualTo (expectedMinSessions );
3354
3380
assertThat (client2 .pool .getNumberOfSessionsInPool ())
3355
- .isEqualTo (minSessions - 1 );
3381
+ .isEqualTo (expectedMinSessions );
3356
3382
try (ResultSet rs = transaction1 .executeQuery (SELECT1 )) {
3357
3383
if (rs .next ()) {
3358
3384
return rs .getLong (0 );
@@ -5090,6 +5116,9 @@ public void testRetryOnResourceExhausted() {
5090
5116
5091
5117
@ Test
5092
5118
public void testSessionPoolExhaustedError_containsStackTraces () {
5119
+ assumeFalse (
5120
+ "Session pool tests are skipped for multiplexed sessions" ,
5121
+ isMultiplexedSessionsEnabledForRW ());
5093
5122
try (Spanner spanner =
5094
5123
SpannerOptions .newBuilder ()
5095
5124
.setProjectId (TEST_PROJECT )
@@ -5450,4 +5479,11 @@ private boolean isMultiplexedSessionsEnabled() {
5450
5479
}
5451
5480
return spanner .getOptions ().getSessionPoolOptions ().getUseMultiplexedSession ();
5452
5481
}
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
+ }
5453
5489
}
0 commit comments