use of co.paralleluniverse.common.util.CheckedCallable in project quasar by puniverse.
the class FiberAsyncTest method whenCancelRunBlockingInterruptExecutingThread.
@Test
public void whenCancelRunBlockingInterruptExecutingThread() throws Exception {
final AtomicBoolean started = new AtomicBoolean();
final AtomicBoolean interrupted = new AtomicBoolean();
Fiber fiber = new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
FiberAsync.runBlocking(Executors.newSingleThreadExecutor(), new CheckedCallable<Void, RuntimeException>() {
@Override
public Void call() throws RuntimeException {
started.set(true);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
interrupted.set(true);
}
return null;
}
});
}
});
fiber.start();
Thread.sleep(100);
fiber.cancel(true);
try {
fiber.join(5, TimeUnit.MILLISECONDS);
fail("InterruptedException not thrown");
} catch (ExecutionException e) {
if (!(e.getCause() instanceof InterruptedException))
fail("InterruptedException not thrown");
}
Thread.sleep(100);
assertThat(started.get(), is(true));
assertThat(interrupted.get(), is(true));
}
Aggregations