registry.register("*", new BufferingAsyncRequestHandler(new SimpleService()));
HttpHost target = start(registry, null);
// Bottom of the pool : a *keep alive* connection to Route 1.
HttpContext context1 = new SyncBasicHttpContext();
context1.setAttribute("user", "stuff");
Future<HttpResponse> future1 = this.httpclient.execute(
target, new HttpGet("/"), context1, null);
HttpResponse response1 = future1.get();
Assert.assertNotNull(response1);
Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
// 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.
HttpContext context2 = new SyncBasicHttpContext();
Future<HttpResponse> future2 = this.httpclient.execute(
new HttpHost("127.0.0.1", target.getPort(), target.getSchemeName()),
new HttpGet("/"), context2, null);
HttpResponse response2 = future2.get();
Assert.assertNotNull(response2);
Assert.assertEquals(200, response2.getStatusLine().getStatusCode());
// 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.
HttpContext context3 = new SyncBasicHttpContext();
Future<HttpResponse> future3 = this.httpclient.execute(
target, new HttpGet("/"), context3, null);
HttpResponse response3 = future3.get();
Assert.assertNotNull(response3);
Assert.assertEquals(200, response3.getStatusLine().getStatusCode());