use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class FiberTest method testCancel1.
@Test
public void testCancel1() throws Exception {
final AtomicBoolean started = new AtomicBoolean();
final AtomicBoolean terminated = new AtomicBoolean();
Fiber fiber = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution {
started.set(true);
try {
Fiber.sleep(100);
fail("InterruptedException not thrown");
} catch (InterruptedException e) {
}
terminated.set(true);
}
});
fiber.start();
Thread.sleep(20);
fiber.cancel(true);
fiber.join(5, TimeUnit.MILLISECONDS);
assertThat(started.get(), is(true));
assertThat(terminated.get(), is(true));
}
use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class FiberTest method testThreadLocals.
@Test
public void testThreadLocals() throws Exception {
final ThreadLocal<String> tl1 = new ThreadLocal<>();
final InheritableThreadLocal<String> tl2 = new InheritableThreadLocal<>();
tl1.set("foo");
tl2.set("bar");
Fiber fiber = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
assertThat(tl1.get(), is(nullValue()));
assertThat(tl2.get(), is("bar"));
tl1.set("koko");
tl2.set("bubu");
assertThat(tl1.get(), is("koko"));
assertThat(tl2.get(), is("bubu"));
Fiber.sleep(100);
assertThat(tl1.get(), is("koko"));
assertThat(tl2.get(), is("bubu"));
}
});
fiber.start();
fiber.join();
assertThat(tl1.get(), is("foo"));
assertThat(tl2.get(), is("bar"));
}
use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class InstrumentationOptimizerTest method testDontSkipForwardsWithLoopBefore.
@Test
public void testDontSkipForwardsWithLoopBefore() throws InterruptedException, SuspendExecution, ExecutionException {
new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
dontSkipForwardsWithLoopBefore();
}
}).start().join();
assertFalse(isOptimized("skipForwardsWithLoopBefore"));
}
use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class InstrumentationOptimizerTest method testSkipForwardsWithLoopAfter.
@Test
public void testSkipForwardsWithLoopAfter() throws InterruptedException, SuspendExecution, ExecutionException {
new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
skipForwardsWithLoopAfter();
}
}).start().join();
assertTrue(isOptimized("skipForwardsWithLoopAfter"));
}
use of co.paralleluniverse.strands.SuspendableRunnable in project quasar by puniverse.
the class InstrumentationOptimizerTest method testSkipForwardsToSuspendableLong.
@Test
public void testSkipForwardsToSuspendableLong() throws InterruptedException, SuspendExecution, ExecutionException {
new Fiber(new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
skipForwardsToSuspendableLong();
}
}).start().join();
assertTrue(isOptimized("skipForwardsToSuspendableLong"));
}
Aggregations