1 package org.apache.commons.javaflow.bytecode.transformation.tests; 2 3 import org.apache.commons.javaflow.Continuation; 4 import org.apache.commons.javaflow.bytecode.transformation.AbstractTransformerTestCase; 5 import org.apache.commons.javaflow.bytecode.transformation.rewrite.SimpleSerializable; 6 7 public abstract class AbstractResumeTestCase extends AbstractTransformerTestCase { 8 9 public void testSimpleSuspendResume() throws Exception { 10 final SimpleSerializable r = new SimpleSerializable(); 11 assertTrue(r.g == -1); 12 assertTrue(r.l == -1); 13 Continuation c1 = Continuation.startWith(r); 14 assertNotNull(c1); 15 assertTrue(r.g == 0); 16 assertTrue(r.l == 0); 17 Continuation c2 = Continuation.continueWith(c1); 18 assertNotNull(c2); 19 assertTrue(r.g == 1); 20 assertTrue(r.l == 1); 21 Continuation c3 = Continuation.continueWith(c2); 22 assertNotNull(c3); 23 assertTrue(r.g == 2); 24 assertTrue(r.l == 2); 25 } 26 27 28 public void testContinuationBranching() throws Exception { 29 final SimpleSerializable r = new SimpleSerializable(); 30 assertTrue(r.g == -1); 31 assertTrue(r.l == -1); 32 Continuation c1 = Continuation.startWith(r); 33 assertNotNull(c1); 34 assertTrue(r.g == 0); 35 assertTrue(r.l == 0); 36 Continuation c2 = Continuation.continueWith(c1); 37 assertNotNull(c2); 38 assertTrue(r.g == 1); 39 assertTrue(r.l == 1); 40 Continuation c31 = Continuation.continueWith(c2); 41 assertNotNull(c31); 42 assertTrue(r.g == 2); 43 assertTrue(r.l == 2); 44 Continuation c32 = Continuation.continueWith(c2); 45 assertNotNull(c32); 46 assertTrue(r.g == 3); 47 assertTrue(r.l == 2); 48 } 49 }