supportedSchemes.register(new Scheme("http", sf, 80));
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(
params, supportedSchemes);
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
HttpResponse response = client.execute(target, new HttpGet("/random/2000"));
if(response.getEntity() != null)
response.getEntity().consumeContent();
assertEquals(1, mgr.getConnectionsInPool());
assertEquals(1, localServer.getAcceptedConnectionCount());
response = client.execute(target, new HttpGet("/random/2000"));
if(response.getEntity() != null)
response.getEntity().consumeContent();
assertEquals(1, mgr.getConnectionsInPool());
assertEquals(1, localServer.getAcceptedConnectionCount());
// Now sleep for 1.1 seconds and let the timeout do its work
Thread.sleep(1100);
response = client.execute(target, new HttpGet("/random/2000"));
if(response.getEntity() != null)
response.getEntity().consumeContent();
assertEquals(1, mgr.getConnectionsInPool());
assertEquals(2, localServer.getAcceptedConnectionCount());
// Do another request just under the 1 second limit & make
// sure we reuse that connection.
Thread.sleep(500);
response = client.execute(target, new HttpGet("/random/2000"));
if(response.getEntity() != null)
response.getEntity().consumeContent();
assertEquals(1, mgr.getConnectionsInPool());
assertEquals(2, localServer.getAcceptedConnectionCount());