Issue #4809 - Set a max number of requests per connection.

Added test case for idle connections not used for any request.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2020-08-13 19:39:27 +02:00
parent 51d0780041
commit edbc1930b9
1 changed files with 32 additions and 0 deletions

View File

@ -387,6 +387,38 @@ public class ConnectionPoolTest
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;