Search in sources :

Example 46 with Fiber

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());
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Test(org.junit.Test)

Example 47 with Fiber

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);
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Test(org.junit.Test)

Example 48 with Fiber

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;
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Strand(co.paralleluniverse.strands.Strand)

Example 49 with Fiber

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));
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Test(org.junit.Test)

Example 50 with Fiber

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
}
Also used : IntChannel(co.paralleluniverse.strands.channels.IntChannel) SuspendExecution(co.paralleluniverse.fibers.SuspendExecution) Fiber(co.paralleluniverse.fibers.Fiber) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

Fiber (co.paralleluniverse.fibers.Fiber)105 Test (org.junit.Test)88 SuspendableRunnable (co.paralleluniverse.strands.SuspendableRunnable)73 SuspendExecution (co.paralleluniverse.fibers.SuspendExecution)20 Strand (co.paralleluniverse.strands.Strand)8 IntChannel (co.paralleluniverse.strands.channels.IntChannel)4 QueueCapacityExceededException (co.paralleluniverse.strands.queues.QueueCapacityExceededException)4 ExecutionException (java.util.concurrent.ExecutionException)3 Ignore (org.junit.Ignore)3 Timeout (co.paralleluniverse.strands.Timeout)2 Channel (co.paralleluniverse.strands.channels.Channel)2 ReceivePort (co.paralleluniverse.strands.channels.ReceivePort)2 TimeoutException (java.util.concurrent.TimeoutException)2 ActorRef (co.paralleluniverse.actors.ActorRef)1 AbstractServerHandler (co.paralleluniverse.actors.behaviors.AbstractServerHandler)1 ServerActor (co.paralleluniverse.actors.behaviors.ServerActor)1 Function2 (co.paralleluniverse.common.util.Function2)1 Pair (co.paralleluniverse.common.util.Pair)1 FiberScheduler (co.paralleluniverse.fibers.FiberScheduler)1 FiberWriter (co.paralleluniverse.fibers.FiberWriter)1