System.out.println("testMaxTransactions");
IServer server = new HttpServer(new TransactionServerHandler());
ConnectionUtils.start(server);
IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
for (int i = 5; i > 0; --i) {
con.write("GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"User-Agent: me\r\n" +
"\r\n");
String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
int contentLength = QAUtil.readContentLength(header);
con.readByteBufferByLength(contentLength);
if (i == 1) {
Assert.assertTrue(header.indexOf("Connection: close") != -1);
QAUtil.sleep(400);
try {
con.readByte();
Assert.fail("ClosedChannelException expected");
} catch (ClosedChannelException expected) { }
} else {
int start = header.indexOf("Keep-Alive: max=");
int end = header.indexOf("\r\n", start + 1);
int count = Integer.parseInt(header.substring(start + "Keep-Alive: max=".length(), end));
Assert.assertEquals(i - 1, count);
Assert.assertTrue(con.isOpen());
}
}
con.close();
server.close();
}