final HttpContext context = new BasicHttpContext();
final HttpRequest request =
new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
HttpClientConnection conn = getConnection(this.connManager, route);
this.connManager.connect(conn, route, 0, context);
this.connManager.routeComplete(conn, route, context);
context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);
final HttpProcessor httpProcessor = new ImmutableHttpProcessor(
new HttpRequestInterceptor[] { new RequestContent(), new RequestConnControl() });
final HttpRequestExecutor exec = new HttpRequestExecutor();
exec.preProcess(request, httpProcessor, context);
final HttpResponse response = exec.execute(request, conn, context);
Assert.assertEquals("wrong status in first response",
HttpStatus.SC_OK,
response.getStatusLine().getStatusCode());
// check that there are no connections available
try {
// this should fail quickly, connection has not been released
getConnection(this.connManager, route, 100L, TimeUnit.MILLISECONDS);
Assert.fail("ConnectionPoolTimeoutException should have been thrown");
} catch (final ConnectionPoolTimeoutException e) {
// expected
}
// abort the connection
Assert.assertTrue(conn instanceof HttpClientConnection);
conn.shutdown();
this.connManager.releaseConnection(conn, null, -1, null);
// the connection is expected to be released back to the manager
conn = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
Assert.assertFalse("connection should have been closed", conn.isOpen());
this.connManager.releaseConnection(conn, null, -1, null);
this.connManager.shutdown();
}