public void testTimeout() {
try {
final int MY_TIMEOUT = 100;
HttpClient client = new HttpClient();
client.setHost("localhost");
client.setPort(server.getPort());
client.setUri("/volantis/wibble/file.html");
client.setRequestHeaders(headers);
// Keep the server connection busy whilst connecting. This number
// is should be greater than 2 seconds. Note that this delay is not
// enforced because the server will shutdown within 1 second.
server.setDelay(5000);
client.connect(MY_TIMEOUT);
// Shutdown the server and wait for 1/4 sec to guarentee it has
// shut down properly.
server.shutdown();
Thread.currentThread().sleep(250);
long now = System.currentTimeMillis();
// Now attempt to read from the server. The request should timeout
// with the specified timeout value.
try {
StringBuffer response = new StringBuffer();
BufferedReader resp = client.getBufferedReader();
String line;
while ((line = resp.readLine()) != null) {
response.append(line);
}
assertEquals(expectedHTML.toString(), response.toString());