public void testConnectTimeout()
throws Exception
{
try (BackloggedServer server = new BackloggedServer()) {
HttpClientConfig config = new HttpClientConfig();
config.setConnectTimeout(new Duration(5, MILLISECONDS));
config.setReadTimeout(new Duration(2, SECONDS));
Request request = prepareGet()
.setUri(new URI(scheme, null, host, server.getPort(), "/", null, null))
.build();
long start = System.nanoTime();
try {
executeRequest(config, request, new CaptureExceptionResponseHandler());
fail("expected exception");
}
catch (CapturedException e) {
Throwable t = e.getCause();
if (!isConnectTimeout(t)) {
fail("unexpected exception: " + t);
}
assertLessThan(nanosSince(start), new Duration(300, MILLISECONDS));
}
}
}