public void testReleaseOnEntityWriteTo() throws Exception {
this.mgr.setDefaultMaxPerRoute(1);
this.mgr.setMaxTotal(1);
// Zero connections in the pool
PoolStats stats = this.mgr.getTotalStats();
Assert.assertEquals(0, stats.getAvailable());
// Get some random data
final HttpGet httpget = new HttpGet("/random/20000");
final HttpHost target = getServerHttp();
final HttpResponse response = this.httpclient.execute(target, httpget);
ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
try {
connreq.get(250, TimeUnit.MILLISECONDS);
Assert.fail("ConnectionPoolTimeoutException should have been thrown");
} catch (final ConnectionPoolTimeoutException expected) {
}
final HttpEntity e = response.getEntity();
Assert.assertNotNull(e);
final ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
e.writeTo(outsteam);
// Expect one connection in the pool
stats = this.mgr.getTotalStats();
Assert.assertEquals(1, stats.getAvailable());
// Make sure one connection is available
connreq = this.mgr.requestConnection(new HttpRoute(target), null);
final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);