@Test
    void testRouteSpecificPoolRecylcing() throws Exception {
        configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
        final HttpHost target = startServer();

        // This tests what happens when a maxed connection pool needs
        // to kill the last idle connection to a route to build a new
        // one to the same route.

        final int maxConn = 2;

        configureClient(builder -> builder
                .setUserTokenHandler((route, context) -> context.getAttribute("user")));
        final TestClient client = client();

        final PoolingHttpClientConnectionManager connectionManager = client.getConnectionManager();
        connectionManager.setMaxTotal(maxConn);
        connectionManager.setDefaultMaxPerRoute(maxConn);

        // Bottom of the pool : a *keep alive* connection to Route 1.
        final HttpContext context1 = HttpClientContext.create();
        context1.setAttribute("user", "stuff");
        client.execute(target, new HttpGet("/"), context1, response -> {
            EntityUtils.consume(response.getEntity());
            return null;
        });

        // The ConnPoolByRoute now has 1 free connection, out of 2 max
        // The ConnPoolByRoute has one RouteSpcfcPool, that has one free connection
        // for [localhost][stuff]

        Thread.sleep(100);

        // Send a very simple HTTP get (it MUST be simple, no auth, no proxy, no 302, no 401, ...)
        // Send it to another route. Must be a keepalive.
        final HttpContext context2 = HttpClientContext.create();
        client.execute(new HttpHost("127.0.0.1", target.getPort()), new HttpGet("/"), context2, response -> {
            EntityUtils.consume(response.getEntity());
            return null;
        });
        // ConnPoolByRoute now has 2 free connexions, out of its 2 max.
        // The [localhost][stuff] RouteSpcfcPool is the same as earlier
        // And there is a [127.0.0.1][null] pool with 1 free connection

        Thread.sleep(100);

        // This will put the ConnPoolByRoute to the targeted state :
        // [localhost][stuff] will not get reused because this call is [localhost][null]
        // So the ConnPoolByRoute will need to kill one connection (it is maxed out globally).
        // The killed conn is the oldest, which means the first HTTPGet ([localhost][stuff]).
        // When this happens, the RouteSpecificPool becomes empty.
        final HttpContext context3 = HttpClientContext.create();
        client.execute(target, new HttpGet("/"), context3, response -> {
            EntityUtils.consume(response.getEntity());
            return null;
        });

        // If the ConnPoolByRoute did not behave coherently with the RouteSpecificPool
        // this may fail. Ex : if the ConnPool discared the route pool because it was empty,
        // but still used it to build the request3 connection.

    }
Test cases for state-ful connections.
httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java