});
this.server.start();
DefaultBHttpClientConnection conn = client.createConnection();
HttpHost host = new HttpHost("localhost", this.server.getPort());
try {
for (int r = 0; r < reqNo; r++) {
if (!conn.isOpen()) {
client.connect(host, conn);
}
// Set protocol level to HTTP/1.0
BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest(
"POST", "/", HttpVersion.HTTP_1_0);
byte[] data = testData.get(r);
ByteArrayEntity outgoing = new ByteArrayEntity(data);
post.setEntity(outgoing);
HttpResponse response = this.client.execute(post, host, conn);
Assert.assertEquals(HttpVersion.HTTP_1_1, response.getStatusLine().getProtocolVersion());
byte[] received = EntityUtils.toByteArray(response.getEntity());
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
HttpConnectionMetrics cm = conn.getMetrics();
Assert.assertEquals(reqNo, cm.getRequestCount());
Assert.assertEquals(reqNo, cm.getResponseCount());
} finally {
conn.close();
this.server.shutdown();
}
}