use of co.paralleluniverse.fibers.SuspendExecution in project quasar by puniverse.
the class ChannelTest method whenReceiveNotCalledFromOwnerThenThrowException4.
@Ignore
@Test
public void whenReceiveNotCalledFromOwnerThenThrowException4() throws Exception {
assumeTrue(Debug.isAssertionsEnabled());
final Channel<String> ch = newChannel();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
ch.receive();
} catch (InterruptedException ex) {
throw new AssertionError(ex);
} catch (SuspendExecution e) {
throw new AssertionError(e);
}
}
});
thread.start();
Thread.sleep(100);
ch.send("a message");
boolean thrown = false;
try {
ch.receive();
} catch (Throwable e) {
thrown = true;
}
assertTrue(thrown);
thread.join();
}
use of co.paralleluniverse.fibers.SuspendExecution in project quasar by puniverse.
the class AbstractFuture method get.
@Override
@Suspendable
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
try {
if (done)
return getValue();
long left = unit.toNanos(timeout);
final long deadline = System.nanoTime() + left;
Object token = sync.register();
try {
for (int i = 0; !done; i++) {
sync.await(i, left, TimeUnit.NANOSECONDS);
left = deadline - System.nanoTime();
if (left <= 0)
throw new TimeoutException();
}
} finally {
sync.unregister(token);
}
return getValue();
} catch (SuspendExecution e) {
throw new AssertionError(e);
}
}
use of co.paralleluniverse.fibers.SuspendExecution 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.fibers.SuspendExecution 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.fibers.SuspendExecution 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