System.out.println("start server");
final IServer server = new HttpServer(new ClosingEchoHandler());
server.start();
System.out.println("create client");
IHttpClientEndpoint httpClient = new HttpClient();
System.out.println("run tests");
for (int i = 0; i < 500; i++) {
System.out.print(".");
FutureResponseHandler hdl = new FutureResponseHandler();
HttpRequestHeader header = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/");
header.setContentType("text/plain; charset=UTF-8");
BodyDataSink bodyDataSink = httpClient.send(header, hdl);
if (bodyDataSink.getFlushmode() != FlushMode.SYNC) {
System.out.println("flushmode should be sync");
Assert.fail();
}
for (int k = 0; k < 10; k++) {
try {
byte[] data = QAUtil.generateByteArray(128);
bodyDataSink.write(data);
bodyDataSink.flush();
} catch (Exception e) {
System.out.println("error occured by writing chunk " + e.toString());
Assert.fail();
}
}
bodyDataSink.write("round " + i);
bodyDataSink.close();
IHttpResponse response = hdl.getResponse();
if (!response.hasBody()) {
System.out.println("response should have a body");
Assert.fail();
}
response.getBody().readString();
}
httpClient.close();
}