public void testStreaming() throws Exception {
WebContainer container = new WebContainer(new MyServlet());
container.start();
HttpClientConnectionPool pool = new HttpClientConnectionPool();
for (int i = 0; i < 100; i++) {
HttpClientConnection con = pool.getHttpClientConnection("localhost", container.getLocalPort());
FutureResponseHandler respHdl = new FutureResponseHandler();
BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + container.getLocalPort() + "/test"), respHdl);
dataSink.write("test");
IHttpResponse response = respHdl.getResponse();
Assert.assertEquals(200, response.getStatus());
BlockingBodyDataSource dataSource = response.getBlockingBody();
Assert.assertEquals("test", dataSource.readStringByLength(4));
dataSink.write("12345");
Assert.assertEquals("12345", dataSource.readStringByLength(5));
dataSink.write("789");
Assert.assertEquals("789", dataSource.readStringByLength(3));
dataSink.close();
con.close();
System.out.print(".");
}
pool.close();
container.stop();
}