RequestHandler reqHdl = new RequestHandler();
HttpServer server = new HttpServer(reqHdl);
server.start();
HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
con.setOption(IConnection.SO_RCVBUF, 64);
FutureResponseHandler rh = new FutureResponseHandler();
BodyDataSink clientDataSink = con.send(new HttpRequestHeader("POST", "text/plain"), rh);
clientDataSink.setFlushmode(FlushMode.ASYNC);
clientDataSink.write(QAUtil.generateByteArray(300));
QAUtil.sleep(500);
clientDataSink.write(QAUtil.generateByteArray(400));
NonBlockingBodyDataSource serverDataSource = rh.getResponse().getNonBlockingBody();
con.suspendReceiving();
for (int i = 0; i < 10; i++) {
clientDataSink.write(QAUtil.generateByteArray(40000));
QAUtil.sleep(100);
System.out.println("datSink pending data: " + clientDataSink.getPendingWriteDataSize());
}
Assert.assertTrue(clientDataSink.getPendingWriteDataSize() > 100000);
Assert.assertTrue(serverDataSource.available() < 400000);
con.resumeReceiving();
QAUtil.sleep(3000);
Assert.assertTrue(serverDataSource.available() > 400000);
con.close();
server.close();
}