Search in sources :

Example 1 with MultithreadedStressTester

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)));
}
Also used : Random(java.util.Random) Connection(com.hotels.styx.client.Connection) MultithreadedStressTester(com.hotels.styx.support.MultithreadedStressTester) Test(org.junit.jupiter.api.Test)

Aggregations

Connection (com.hotels.styx.client.Connection)1 MultithreadedStressTester (com.hotels.styx.support.MultithreadedStressTester)1 Random (java.util.Random)1 Test (org.junit.jupiter.api.Test)1