use of org.osgi.util.promise.TimeoutException in project aries by apache.
the class ChainTest method testTimeout.
@Test
public void testTimeout() throws Exception {
Deferred<String> def = new Deferred<String>();
Promise<String> promise = def.getPromise();
long start = System.nanoTime();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicLong finish = new AtomicLong();
Promise<String> chain = promise.timeout(500).onResolve(new Runnable() {
@Override
public void run() {
finish.set(System.nanoTime());
latch.countDown();
}
});
assertFalse("promise should not be resolved", promise.isDone());
assertFalse("chain should not be resolved", chain.isDone());
assertTrue("Did not time out!", latch.await(1, SECONDS));
assertTrue("Finished too fast", NANOSECONDS.toMillis(finish.get() - start) > 450);
assertFalse("promise should not be resolved", promise.isDone());
assertTrue("chain should now be resolved", chain.isDone());
assertTrue("Should fail with a timeout exception", chain.getFailure() instanceof TimeoutException);
}
Aggregations