Search in sources :

Example 81 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class CatchTest method testCatch2.

@Test
public void testCatch2() {
    results.clear();
    try {
        Fiber co = new Fiber((String) null, null, new Callable1());
        exec(co);
        results.add("B");
        exec(co);
        results.add("D");
        exec(co);
    } finally {
        System.out.println(results);
    }
    assertEquals(5, results.size());
    assertEquals(Arrays.asList("A", "B", "C", "D", "E"), results);
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Test(org.junit.Test)

Example 82 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class CatchTest method testCatch.

@Test
public void testCatch() {
    results.clear();
    try {
        Fiber co = new Fiber((String) null, null, new Runnable1());
        exec(co);
        results.add("B");
        exec(co);
        results.add("D");
        exec(co);
        results.add("E");
        exec(co);
        results.add("F");
        exec(co);
        results.add("G");
        exec(co);
        results.add("I");
    } finally {
        System.out.println(results);
    }
    assertEquals(13, results.size());
    assertEquals(Arrays.asList("A", "B", "C", "D", "cnt=0", "E", "not thrown", "F", "cnt=1", "G", "called second time", "H", "I"), results);
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Test(org.junit.Test)

Example 83 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class DoubleTest method testDouble.

@Test
public void testDouble() {
    Fiber co = new Fiber((String) null, null, this);
    TestsHelper.exec(co);
    assertEquals(0, result, 1e-8);
    boolean res = TestsHelper.exec(co);
    assertEquals(1, result, 1e-8);
    assertEquals(res, true);
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Test(org.junit.Test)

Example 84 with Fiber

use of co.paralleluniverse.fibers.Fiber in project quasar by puniverse.

the class FinallyTest method testFinally.

@Test
public void testFinally() {
    results.clear();
    try {
        Fiber co = new Fiber((String) null, null, this);
        exec(co);
        results.add("B");
        exec(co);
        results.add("D");
        exec(co);
        results.add("H");
        exec(co);
    } finally {
        System.out.println(results);
    }
    assertEquals(9, results.size());
    assertEquals("A", results.get(0));
    assertEquals("B", results.get(1));
    assertEquals("C", results.get(2));
    assertEquals("D", results.get(3));
    assertEquals("E", results.get(4));
    assertEquals("F", results.get(5));
    assertEquals("G", results.get(6));
    assertEquals("H", results.get(7));
    assertEquals("I", results.get(8));
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) Test(org.junit.Test)

Example 85 with Fiber

use of co.paralleluniverse.fibers.Fiber 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"));
}
Also used : SuspendExecution(co.paralleluniverse.fibers.SuspendExecution) SuspendableRunnable(co.paralleluniverse.strands.SuspendableRunnable) Fiber(co.paralleluniverse.fibers.Fiber) 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