use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.
the class SuspendTest method testSuspend.
@Test
public void testSuspend() {
SuspendTest test = new SuspendTest();
Fiber co = new Fiber((String) null, null, test);
while (!exec(co)) System.out.println("State=" + co.getState());
System.out.println("State=" + co.getState());
}
use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.
the class SuspendableAnnotationTest method testNonAnnotated.
@Test
public void testNonAnnotated() {
assumeFalse(SystemProperties.isEmptyOrTrue("co.paralleluniverse.fibers.verifyInstrumentation"));
try {
Fiber co = new Fiber((String) null, null, (SuspendableCallable) null) {
@Override
protected Object run() throws SuspendExecution, InterruptedException {
nonsuspendableMethod();
return null;
}
};
exec(co);
exec(co);
exec(co);
} finally {
System.out.println(results);
}
assertEquals(3, results.size());
assertEquals(Arrays.asList("A", "A", "A"), results);
}
use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.
the class SupervisorActor method createStrandForActor.
private Strand createStrandForActor(Strand oldStrand, Actor actor) {
final Strand strand;
if (oldStrand != null)
strand = Strand.clone(oldStrand, actor);
else
strand = new Fiber(actor);
actor.setStrand(strand);
return strand;
}
use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.
the class ThrowTest method testThrow.
@Test
public void testThrow() {
results.clear();
Fiber co = new Fiber((String) null, null, this);
try {
exec(co);
results.add("B");
exec(co);
results.add("D");
exec(co);
assertTrue(false);
} catch (IllegalStateException es) {
assertEquals("bla", es.getMessage());
// assertEquals(LightweightThread.State.FINISHED, co.getState());
} finally {
System.out.println(results);
}
assertEquals(5, results.size());
assertEquals("A", results.get(0));
assertEquals("B", results.get(1));
assertEquals("C", results.get(2));
assertEquals("D", results.get(3));
assertEquals("F", results.get(4));
}
use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.
the class VerificationTest method testVerifyUninstrumentedCallSiteDeclaringAndOwnerOK.
@Test
public final void testVerifyUninstrumentedCallSiteDeclaringAndOwnerOK() throws ExecutionException, InterruptedException, SuspendExecution {
assumeTrue(SystemProperties.isEmptyOrTrue("co.paralleluniverse.fibers.verifyInstrumentation"));
// From https://github.com/puniverse/quasar/issues/255
final IntChannel intChannel = Channels.newIntChannel(1);
try {
new Fiber<>(new SuspendableCallable<Integer>() {
@Override
public Integer run() throws SuspendExecution, InterruptedException {
return intChannel.receive();
}
}).start().join(100, TimeUnit.MILLISECONDS);
} catch (final TimeoutException ignored) {
}
// Should complete without verification exceptions
}
Aggregations