});
this.server.start();
final DefaultBHttpClientConnection conn = client.createConnection();
final HttpHost host = new HttpHost("localhost", this.server.getPort());
try {
for (int r = 0; r < reqNo; r++) {
if (!conn.isOpen()) {
client.connect(host, conn);
}
final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
final byte[] data = testData.get(r);
final ByteArrayEntity outgoing = new ByteArrayEntity(data);
outgoing.setChunked(true);
post.setEntity(outgoing);
final HttpResponse response = this.client.execute(post, host, conn);
final byte[] received = EntityUtils.toByteArray(response.getEntity());
final byte[] expected = testData.get(r);
Assert.assertEquals(expected.length, received.length);
for (int i = 0; i < expected.length; i++) {
Assert.assertEquals(expected[i], received[i]);
}
if (!this.client.keepAlive(response)) {
conn.close();
}
}
//Verify the connection metrics
final HttpConnectionMetrics cm = conn.getMetrics();
Assert.assertEquals(reqNo, cm.getRequestCount());
Assert.assertEquals(reqNo, cm.getResponseCount());
} finally {
conn.close();
this.server.shutdown();
}
}