Skip to content

Commit

Permalink
Issue #4809 - Set a max number of requests per connection.
Browse files Browse the repository at this point in the history
Added test case for idle connections not used for any request.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Aug 13, 2020
1 parent 51d0780 commit edbc193
Showing 1 changed file with 32 additions and 0 deletions.
Expand Up @@ -387,6 +387,38 @@ public void testConnectionMaxUsage(ConnectionPoolFactory factory) throws Excepti
assertEquals(0, connectionPool.getConnectionCount());
}

@ParameterizedTest
@MethodSource("pools")
public void testIdleTimeoutNoRequests(ConnectionPoolFactory factory) throws Exception
{
startServer(new EmptyServerHandler());
startClient(destination ->
{
try
{
ConnectionPool connectionPool = factory.factory.newConnectionPool(destination);
connectionPool.preCreateConnections(1).get();
return connectionPool;
}
catch (Exception x)
{
throw new RuntimeException(x);
}
});
long idleTimeout = 1000;
client.setIdleTimeout(idleTimeout);

// Trigger the creation of a destination, that will create the connection pool.
HttpDestination destination = client.resolveDestination(new Origin("http", "localhost", connector.getLocalPort()));
AbstractConnectionPool connectionPool = (AbstractConnectionPool)destination.getConnectionPool();
assertEquals(1, connectionPool.getConnectionCount());

// Wait for the pre-created connections to idle timeout.
Thread.sleep(idleTimeout + idleTimeout / 2);

assertEquals(0, connectionPool.getConnectionCount());
}

private static class ConnectionPoolFactory
{
private final String name;
Expand Down

0 comments on commit edbc193

Please sign in to comment.