@@ -1294,7 +1294,7 @@ public void blockAndTimeoutOnPoolExhaustion_withAcquireSessionTimeout() throws E
1294
1294
.setMinSessions (minSessions )
1295
1295
.setMaxSessions (1 )
1296
1296
.setInitialWaitForSessionTimeoutMillis (20L )
1297
- .setAcquireSessionTimeout (Duration . ofMillis ( 20L ) )
1297
+ .setAcquireSessionTimeout (null )
1298
1298
.build ();
1299
1299
setupMockSessionCreation ();
1300
1300
pool = createPool ();
@@ -1307,29 +1307,30 @@ public void blockAndTimeoutOnPoolExhaustion_withAcquireSessionTimeout() throws E
1307
1307
Future <Void > fut =
1308
1308
executor .submit (
1309
1309
() -> {
1310
- latch .countDown ();
1311
1310
PooledSessionFuture session = pool .getSession ();
1311
+ latch .countDown ();
1312
+ session .get ();
1312
1313
session .close ();
1313
1314
return null ;
1314
1315
});
1315
1316
// Wait until the background thread is actually waiting for a session.
1316
1317
latch .await ();
1317
1318
// Wait until the request has timed out.
1318
- int waitCount = 0 ;
1319
- while (pool .getNumWaiterTimeouts () == 0L && waitCount < 5000 ) {
1320
- Thread .sleep (1L );
1321
- waitCount ++;
1319
+ Stopwatch watch = Stopwatch .createStarted ();
1320
+ while (pool .getNumWaiterTimeouts () == 0L && watch .elapsed (TimeUnit .MILLISECONDS ) < 1000 ) {
1321
+ Thread .yield ();
1322
1322
}
1323
1323
// Return the checked out session to the pool so the async request will get a session and
1324
1324
// finish.
1325
1325
checkedOutSession .close ();
1326
1326
// Verify that the async request also succeeds.
1327
1327
fut .get (10L , TimeUnit .SECONDS );
1328
1328
executor .shutdown ();
1329
+ assertTrue (executor .awaitTermination (10L , TimeUnit .SECONDS ));
1329
1330
1330
1331
// Verify that the session was returned to the pool and that we can get it again.
1331
- Session session = pool .getSession ();
1332
- assertThat (session ).isNotNull ();
1332
+ PooledSessionFuture session = pool .getSession ();
1333
+ assertThat (session . get () ).isNotNull ();
1333
1334
session .close ();
1334
1335
assertThat (pool .getNumWaiterTimeouts ()).isAtLeast (1L );
1335
1336
}
0 commit comments