final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
final CountDownLatch getLatch = new CountDownLatch(1);
final CountDownLatch startLatch = new CountDownLatch(1);
final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
final HttpContext context = new BasicHttpContext();
final HttpGet httpget = new HttpGet("a");
new Thread(new Runnable() {
public void run() {
try {
try {
if(!startLatch.await(1, TimeUnit.SECONDS))
throw new RuntimeException("Took too long to start!");
} catch(InterruptedException interrupted) {
throw new RuntimeException("Never started!", interrupted);
}
client.execute(getServerHttp(), httpget, context);
} catch(Throwable t) {
throwableRef.set(t);
} finally {
getLatch.countDown();
}
}
}).start();
httpget.abort();
startLatch.countDown();
assertTrue("should have finished get request", getLatch.await(1, TimeUnit.SECONDS));
assertTrue("should be instanceof IOException, was: " + throwableRef.get(),
throwableRef.get() instanceof IOException);