use of com.hotels.styx.support.MultithreadedStressTester in project styx by ExpediaGroup.
the class SimpleConnectionPoolStressTest method canRoundTripBorrowedConnectionsFromMultipleThreads.
@Test
public void canRoundTripBorrowedConnectionsFromMultipleThreads() throws InterruptedException {
MultithreadedStressTester stressTester = new MultithreadedStressTester(10, 250);
Random returnOrClose = new Random();
stressTester.stress(() -> {
Connection connection = borrowConnectionSynchronously();
if (returnOrClose.nextBoolean()) {
releaseConnection(connection);
} else {
closeConnection(connection);
}
});
stressTester.shutdown();
assertThat("final busy connection count", pool.stats().busyConnectionCount(), is(0));
assertThat("final available connection count", pool.stats().availableConnectionCount(), is(greaterThanOrEqualTo(0)));
}
Aggregations