--- jsr166/src/test/tck/ForkJoinTaskTest.java 2010/09/01 06:41:55 1.10 +++ jsr166/src/test/tck/ForkJoinTaskTest.java 2010/09/13 23:23:44 1.16 @@ -3,38 +3,50 @@ * Expert Group and released to the public domain, as explained at * http://creativecommons.org/licenses/publicdomain */ -import java.util.*; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.AbstractExecutorService; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Callable; -import java.util.concurrent.Future; import java.util.concurrent.ExecutionException; import java.util.concurrent.CancellationException; -import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; import java.util.concurrent.ForkJoinWorkerThread; import java.util.concurrent.RecursiveAction; -import java.util.concurrent.RecursiveTask; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +import java.util.HashSet; import junit.framework.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.*; -import java.util.*; public class ForkJoinTaskTest extends JSR166TestCase { public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } + public static Test suite() { return new TestSuite(ForkJoinTaskTest.class); } - /** + private static ForkJoinPool mainPool() { + return new ForkJoinPool(); + } + + private static ForkJoinPool singletonPool() { + return new ForkJoinPool(1); + } + + private static ForkJoinPool asyncSingletonPool() { + return new ForkJoinPool(1, + ForkJoinPool.defaultForkJoinWorkerThreadFactory, + null, true); + } + + private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { + try { + assertTrue(pool.invoke(a) == null); + } finally { + joinPool(pool); + } + } + + /* * Testing coverage notes: * * To test extension methods and overrides, most tests use @@ -42,11 +54,6 @@ public class ForkJoinTaskTest extends JS * differently than supplied Recursive forms. */ - static final ForkJoinPool mainPool = new ForkJoinPool(); - static final ForkJoinPool singletonPool = new ForkJoinPool(1); - static final ForkJoinPool asyncSingletonPool = - new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, - null, true); static final class FJException extends RuntimeException { FJException() { super(); } } @@ -224,21 +231,19 @@ public class ForkJoinTaskTest extends JS * invoke returns when task completes normally. * isCompletedAbnormally and isCancelled return false for normally * completed tasks. getRawResult of a RecursiveAction returns null; - * */ public void testInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - f.invoke(); - threadAssertTrue(f.number == 21); - threadAssertTrue(f.isDone()); - threadAssertFalse(f.isCancelled()); - threadAssertFalse(f.isCompletedAbnormally()); - threadAssertTrue(f.getRawResult() == null); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + threadAssertNull(f.invoke()); + threadAssertTrue(f.number == 21); + threadAssertTrue(f.isDone()); + threadAssertFalse(f.isCancelled()); + threadAssertFalse(f.isCompletedAbnormally()); + threadAssertTrue(f.getRawResult() == null); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -248,17 +253,16 @@ public class ForkJoinTaskTest extends JS */ public void testQuietlyInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - f.quietlyInvoke(); - threadAssertTrue(f.number == 21); - threadAssertTrue(f.isDone()); - threadAssertFalse(f.isCancelled()); - threadAssertFalse(f.isCompletedAbnormally()); - threadAssertTrue(f.getRawResult() == null); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + f.quietlyInvoke(); + threadAssertTrue(f.number == 21); + threadAssertTrue(f.isDone()); + threadAssertFalse(f.isCancelled()); + threadAssertFalse(f.isCompletedAbnormally()); + threadAssertTrue(f.getRawResult() == null); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -266,16 +270,15 @@ public class ForkJoinTaskTest extends JS */ public void testForkJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - f.fork(); - f.join(); - threadAssertTrue(f.number == 21); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.getRawResult() == null); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertNull(f.join()); + threadAssertTrue(f.number == 21); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.getRawResult() == null); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -283,19 +286,18 @@ public class ForkJoinTaskTest extends JS */ public void testForkGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - f.fork(); - f.get(); - threadAssertTrue(f.number == 21); - threadAssertTrue(f.isDone()); - } catch (Exception ex) { - unexpectedException(ex); - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertNull(f.get()); + threadAssertTrue(f.number == 21); + threadAssertTrue(f.isDone()); + } catch (Exception ex) { + unexpectedException(ex); } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -303,19 +305,18 @@ public class ForkJoinTaskTest extends JS */ public void testForkTimedGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - f.fork(); - f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - threadAssertTrue(f.number == 21); - threadAssertTrue(f.isDone()); - } catch (Exception ex) { - unexpectedException(ex); - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertNull(f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); + threadAssertTrue(f.number == 21); + threadAssertTrue(f.isDone()); + } catch (Exception ex) { + unexpectedException(ex); } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -323,19 +324,18 @@ public class ForkJoinTaskTest extends JS */ public void testForkTimedGetNPE() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - f.fork(); - f.get(5L, null); - shouldThrow(); - } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + f.get(5L, null); + shouldThrow(); + } catch (NullPointerException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -343,15 +343,14 @@ public class ForkJoinTaskTest extends JS */ public void testForkQuietlyJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - f.fork(); - f.quietlyJoin(); - threadAssertTrue(f.number == 21); - threadAssertTrue(f.isDone()); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + f.quietlyJoin(); + threadAssertTrue(f.number == 21); + threadAssertTrue(f.isDone()); + }}; + testInvokeOnPool(mainPool(), a); } @@ -361,16 +360,15 @@ public class ForkJoinTaskTest extends JS */ public void testForkHelpQuiesce() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - f.fork(); - f.helpQuiesce(); - threadAssertTrue(f.number == 21); - threadAssertTrue(f.isDone()); - threadAssertTrue(getQueuedTaskCount() == 0); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + f.helpQuiesce(); + threadAssertTrue(f.number == 21); + threadAssertTrue(f.isDone()); + threadAssertTrue(getQueuedTaskCount() == 0); + }}; + testInvokeOnPool(mainPool(), a); } @@ -379,16 +377,15 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingAsyncFib f = new FailingAsyncFib(8); - f.invoke(); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingAsyncFib f = new FailingAsyncFib(8); + f.invoke(); + shouldThrow(); + } catch (FJException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -396,13 +393,12 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalQuietlyInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FailingAsyncFib f = new FailingAsyncFib(8); - f.quietlyInvoke(); - threadAssertTrue(f.isDone()); - } - }; - mainPool.invoke(a); + public void compute() { + FailingAsyncFib f = new FailingAsyncFib(8); + f.quietlyInvoke(); + threadAssertTrue(f.isDone()); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -410,17 +406,16 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalForkJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingAsyncFib f = new FailingAsyncFib(8); - f.fork(); - f.join(); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingAsyncFib f = new FailingAsyncFib(8); + threadAssertSame(f, f.fork()); + f.join(); + shouldThrow(); + } catch (FJException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -428,19 +423,18 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalForkGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingAsyncFib f = new FailingAsyncFib(8); - f.fork(); - f.get(); - shouldThrow(); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + public void compute() { + try { + FailingAsyncFib f = new FailingAsyncFib(8); + threadAssertSame(f, f.fork()); + f.get(); + shouldThrow(); + } catch (ExecutionException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -448,19 +442,18 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalForkTimedGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingAsyncFib f = new FailingAsyncFib(8); - f.fork(); - f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - shouldThrow(); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + public void compute() { + try { + FailingAsyncFib f = new FailingAsyncFib(8); + threadAssertSame(f, f.fork()); + f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); + shouldThrow(); + } catch (ExecutionException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -468,16 +461,15 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalForkQuietlyJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FailingAsyncFib f = new FailingAsyncFib(8); - f.fork(); - f.quietlyJoin(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.isCompletedAbnormally()); - threadAssertTrue(f.getException() instanceof FJException); - } - }; - mainPool.invoke(a); + public void compute() { + FailingAsyncFib f = new FailingAsyncFib(8); + threadAssertSame(f, f.fork()); + f.quietlyJoin(); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.isCompletedAbnormally()); + threadAssertTrue(f.getException() instanceof FJException); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -485,17 +477,16 @@ public class ForkJoinTaskTest extends JS */ public void testCancelledInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - f.cancel(true); - f.invoke(); - shouldThrow(); - } catch (CancellationException success) { - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + threadAssertTrue(f.cancel(true)); + f.invoke(); + shouldThrow(); + } catch (CancellationException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -503,18 +494,17 @@ public class ForkJoinTaskTest extends JS */ public void testCancelledForkJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - f.cancel(true); - f.fork(); - f.join(); - shouldThrow(); - } catch (CancellationException success) { - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + threadAssertTrue(f.cancel(true)); + threadAssertSame(f, f.fork()); + f.join(); + shouldThrow(); + } catch (CancellationException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -522,20 +512,19 @@ public class ForkJoinTaskTest extends JS */ public void testCancelledForkGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - f.cancel(true); - f.fork(); - f.get(); - shouldThrow(); - } catch (CancellationException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + threadAssertTrue(f.cancel(true)); + threadAssertSame(f, f.fork()); + f.get(); + shouldThrow(); + } catch (CancellationException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -543,20 +532,19 @@ public class ForkJoinTaskTest extends JS */ public void testCancelledForkTimedGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - f.cancel(true); - f.fork(); - f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); - shouldThrow(); - } catch (CancellationException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + threadAssertTrue(f.cancel(true)); + threadAssertSame(f, f.fork()); + f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); + shouldThrow(); + } catch (CancellationException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -564,29 +552,28 @@ public class ForkJoinTaskTest extends JS */ public void testCancelledForkQuietlyJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - f.cancel(true); - f.fork(); - f.quietlyJoin(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.isCompletedAbnormally()); - threadAssertTrue(f.getException() instanceof CancellationException); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + threadAssertTrue(f.cancel(true)); + threadAssertSame(f, f.fork()); + f.quietlyJoin(); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.isCompletedAbnormally()); + threadAssertTrue(f.getException() instanceof CancellationException); + }}; + testInvokeOnPool(mainPool(), a); } /** * getPool of executing task returns its pool */ public void testGetPool() { + final ForkJoinPool mainPool = mainPool(); RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(getPool() == mainPool); - } - }; - mainPool.invoke(a); + public void compute() { + threadAssertTrue(getPool() == mainPool); + }}; + testInvokeOnPool(mainPool, a); } /** @@ -594,11 +581,10 @@ public class ForkJoinTaskTest extends JS */ public void testGetPool2() { RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(getPool() == null); - } - }; - a.invoke(); + public void compute() { + threadAssertTrue(getPool() == null); + }}; + assertNull(a.invoke()); } /** @@ -606,11 +592,10 @@ public class ForkJoinTaskTest extends JS */ public void testInForkJoinPool() { RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(inForkJoinPool()); - } - }; - mainPool.invoke(a); + public void compute() { + threadAssertTrue(inForkJoinPool()); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -618,11 +603,10 @@ public class ForkJoinTaskTest extends JS */ public void testInForkJoinPool2() { RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(!inForkJoinPool()); - } - }; - a.invoke(); + public void compute() { + threadAssertTrue(!inForkJoinPool()); + }}; + assertNull(a.invoke()); } /** @@ -630,11 +614,10 @@ public class ForkJoinTaskTest extends JS */ public void testSetRawResult() { RecursiveAction a = new RecursiveAction() { - public void compute() { - setRawResult(null); - } - }; - a.invoke(); + public void compute() { + setRawResult(null); + }}; + assertNull(a.invoke()); } /** @@ -642,17 +625,16 @@ public class ForkJoinTaskTest extends JS */ public void testCompleteExceptionally() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - f.completeExceptionally(new FJException()); - f.invoke(); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + f.completeExceptionally(new FJException()); + f.invoke(); + shouldThrow(); + } catch (FJException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -660,17 +642,16 @@ public class ForkJoinTaskTest extends JS */ public void testInvokeAll2() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - AsyncFib g = new AsyncFib(9); - invokeAll(f, g); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.number == 21); - threadAssertTrue(g.isDone()); - threadAssertTrue(g.number == 34); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + AsyncFib g = new AsyncFib(9); + invokeAll(f, g); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.number == 21); + threadAssertTrue(g.isDone()); + threadAssertTrue(g.number == 34); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -678,14 +659,13 @@ public class ForkJoinTaskTest extends JS */ public void testInvokeAll1() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - invokeAll(f); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.number == 21); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + invokeAll(f); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.number == 21); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -693,20 +673,19 @@ public class ForkJoinTaskTest extends JS */ public void testInvokeAll3() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - AsyncFib g = new AsyncFib(9); - AsyncFib h = new AsyncFib(7); - invokeAll(f, g, h); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.number == 21); - threadAssertTrue(g.isDone()); - threadAssertTrue(g.number == 34); - threadAssertTrue(h.isDone()); - threadAssertTrue(h.number == 13); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + AsyncFib g = new AsyncFib(9); + AsyncFib h = new AsyncFib(7); + invokeAll(f, g, h); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.number == 21); + threadAssertTrue(g.isDone()); + threadAssertTrue(g.number == 34); + threadAssertTrue(h.isDone()); + threadAssertTrue(h.number == 13); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -714,24 +693,23 @@ public class ForkJoinTaskTest extends JS */ public void testInvokeAllCollection() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib f = new AsyncFib(8); - AsyncFib g = new AsyncFib(9); - AsyncFib h = new AsyncFib(7); - HashSet set = new HashSet(); - set.add(f); - set.add(g); - set.add(h); - invokeAll(set); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.number == 21); - threadAssertTrue(g.isDone()); - threadAssertTrue(g.number == 34); - threadAssertTrue(h.isDone()); - threadAssertTrue(h.number == 13); - } - }; - mainPool.invoke(a); + public void compute() { + AsyncFib f = new AsyncFib(8); + AsyncFib g = new AsyncFib(9); + AsyncFib h = new AsyncFib(7); + HashSet set = new HashSet(); + set.add(f); + set.add(g); + set.add(h); + invokeAll(set); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.number == 21); + threadAssertTrue(g.isDone()); + threadAssertTrue(g.number == 34); + threadAssertTrue(h.isDone()); + threadAssertTrue(h.number == 13); + }}; + testInvokeOnPool(mainPool(), a); } @@ -740,18 +718,17 @@ public class ForkJoinTaskTest extends JS */ public void testInvokeAllNPE() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - AsyncFib g = new AsyncFib(9); - AsyncFib h = null; - invokeAll(f, g, h); - shouldThrow(); - } catch (NullPointerException success) { - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + AsyncFib g = new AsyncFib(9); + AsyncFib h = null; + invokeAll(f, g, h); + shouldThrow(); + } catch (NullPointerException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -759,17 +736,16 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalInvokeAll2() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - FailingAsyncFib g = new FailingAsyncFib(9); - invokeAll(f, g); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + FailingAsyncFib g = new FailingAsyncFib(9); + invokeAll(f, g); + shouldThrow(); + } catch (FJException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -777,16 +753,15 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalInvokeAll1() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingAsyncFib g = new FailingAsyncFib(9); - invokeAll(g); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingAsyncFib g = new FailingAsyncFib(9); + invokeAll(g); + shouldThrow(); + } catch (FJException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -794,18 +769,17 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalInvokeAll3() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - AsyncFib f = new AsyncFib(8); - FailingAsyncFib g = new FailingAsyncFib(9); - AsyncFib h = new AsyncFib(7); - invokeAll(f, g, h); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + AsyncFib f = new AsyncFib(8); + FailingAsyncFib g = new FailingAsyncFib(9); + AsyncFib h = new AsyncFib(7); + invokeAll(f, g, h); + shouldThrow(); + } catch (FJException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -813,22 +787,21 @@ public class ForkJoinTaskTest extends JS */ public void testAbnormalInvokeAllCollection() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingAsyncFib f = new FailingAsyncFib(8); - AsyncFib g = new AsyncFib(9); - AsyncFib h = new AsyncFib(7); - HashSet set = new HashSet(); - set.add(f); - set.add(g); - set.add(h); - invokeAll(set); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingAsyncFib f = new FailingAsyncFib(8); + AsyncFib g = new AsyncFib(9); + AsyncFib h = new AsyncFib(7); + HashSet set = new HashSet(); + set.add(f); + set.add(g); + set.add(h); + invokeAll(set); + shouldThrow(); + } catch (FJException success) { } - }; - mainPool.invoke(a); + }}; + testInvokeOnPool(mainPool(), a); } /** @@ -837,18 +810,17 @@ public class ForkJoinTaskTest extends JS */ public void testTryUnfork() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib g = new AsyncFib(9); - g.fork(); - AsyncFib f = new AsyncFib(8); - f.fork(); - threadAssertTrue(f.tryUnfork()); - helpQuiesce(); - threadAssertFalse(f.isDone()); - threadAssertTrue(g.isDone()); - } - }; - singletonPool.invoke(a); + public void compute() { + AsyncFib g = new AsyncFib(9); + threadAssertSame(g, g.fork()); + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertTrue(f.tryUnfork()); + helpQuiesce(); + threadAssertFalse(f.isDone()); + threadAssertTrue(g.isDone()); + }}; + testInvokeOnPool(singletonPool(), a); } /** @@ -857,18 +829,17 @@ public class ForkJoinTaskTest extends JS */ public void testGetSurplusQueuedTaskCount() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib h = new AsyncFib(7); - h.fork(); - AsyncFib g = new AsyncFib(9); - g.fork(); - AsyncFib f = new AsyncFib(8); - f.fork(); - threadAssertTrue(getSurplusQueuedTaskCount() > 0); - helpQuiesce(); - } - }; - singletonPool.invoke(a); + public void compute() { + AsyncFib h = new AsyncFib(7); + threadAssertSame(h, h.fork()); + AsyncFib g = new AsyncFib(9); + threadAssertSame(g, g.fork()); + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertTrue(getSurplusQueuedTaskCount() > 0); + helpQuiesce(); + }}; + testInvokeOnPool(singletonPool(), a); } /** @@ -876,18 +847,17 @@ public class ForkJoinTaskTest extends JS */ public void testPeekNextLocalTask() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib g = new AsyncFib(9); - g.fork(); - AsyncFib f = new AsyncFib(8); - f.fork(); - threadAssertTrue(peekNextLocalTask() == f); - f.join(); - threadAssertTrue(f.isDone()); - helpQuiesce(); - } - }; - singletonPool.invoke(a); + public void compute() { + AsyncFib g = new AsyncFib(9); + threadAssertSame(g, g.fork()); + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertTrue(peekNextLocalTask() == f); + threadAssertNull(f.join()); + threadAssertTrue(f.isDone()); + helpQuiesce(); + }}; + testInvokeOnPool(singletonPool(), a); } /** @@ -896,17 +866,16 @@ public class ForkJoinTaskTest extends JS */ public void testPollNextLocalTask() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib g = new AsyncFib(9); - g.fork(); - AsyncFib f = new AsyncFib(8); - f.fork(); - threadAssertTrue(pollNextLocalTask() == f); - helpQuiesce(); - threadAssertFalse(f.isDone()); - } - }; - singletonPool.invoke(a); + public void compute() { + AsyncFib g = new AsyncFib(9); + threadAssertSame(g, g.fork()); + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertTrue(pollNextLocalTask() == f); + helpQuiesce(); + threadAssertFalse(f.isDone()); + }}; + testInvokeOnPool(singletonPool(), a); } /** @@ -915,18 +884,17 @@ public class ForkJoinTaskTest extends JS */ public void testPollTask() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib g = new AsyncFib(9); - g.fork(); - AsyncFib f = new AsyncFib(8); - f.fork(); - threadAssertTrue(pollTask() == f); - helpQuiesce(); - threadAssertFalse(f.isDone()); - threadAssertTrue(g.isDone()); - } - }; - singletonPool.invoke(a); + public void compute() { + AsyncFib g = new AsyncFib(9); + threadAssertSame(g, g.fork()); + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertTrue(pollTask() == f); + helpQuiesce(); + threadAssertFalse(f.isDone()); + threadAssertTrue(g.isDone()); + }}; + testInvokeOnPool(singletonPool(), a); } /** @@ -934,18 +902,17 @@ public class ForkJoinTaskTest extends JS */ public void testPeekNextLocalTaskAsync() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib g = new AsyncFib(9); - g.fork(); - AsyncFib f = new AsyncFib(8); - f.fork(); - threadAssertTrue(peekNextLocalTask() == g); - f.join(); - helpQuiesce(); - threadAssertTrue(f.isDone()); - } - }; - asyncSingletonPool.invoke(a); + public void compute() { + AsyncFib g = new AsyncFib(9); + threadAssertSame(g, g.fork()); + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertTrue(peekNextLocalTask() == g); + threadAssertNull(f.join()); + helpQuiesce(); + threadAssertTrue(f.isDone()); + }}; + testInvokeOnPool(asyncSingletonPool(), a); } /** @@ -954,18 +921,17 @@ public class ForkJoinTaskTest extends JS */ public void testPollNextLocalTaskAsync() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib g = new AsyncFib(9); - g.fork(); - AsyncFib f = new AsyncFib(8); - f.fork(); - threadAssertTrue(pollNextLocalTask() == g); - helpQuiesce(); - threadAssertTrue(f.isDone()); - threadAssertFalse(g.isDone()); - } - }; - asyncSingletonPool.invoke(a); + public void compute() { + AsyncFib g = new AsyncFib(9); + threadAssertSame(g, g.fork()); + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertTrue(pollNextLocalTask() == g); + helpQuiesce(); + threadAssertTrue(f.isDone()); + threadAssertFalse(g.isDone()); + }}; + testInvokeOnPool(asyncSingletonPool(), a); } /** @@ -974,17 +940,16 @@ public class ForkJoinTaskTest extends JS */ public void testPollTaskAsync() { RecursiveAction a = new RecursiveAction() { - public void compute() { - AsyncFib g = new AsyncFib(9); - g.fork(); - AsyncFib f = new AsyncFib(8); - f.fork(); - threadAssertTrue(pollTask() == g); - helpQuiesce(); - threadAssertTrue(f.isDone()); - threadAssertFalse(g.isDone()); - } - }; - asyncSingletonPool.invoke(a); + public void compute() { + AsyncFib g = new AsyncFib(9); + threadAssertSame(g, g.fork()); + AsyncFib f = new AsyncFib(8); + threadAssertSame(f, f.fork()); + threadAssertTrue(pollTask() == g); + helpQuiesce(); + threadAssertTrue(f.isDone()); + threadAssertFalse(g.isDone()); + }}; + testInvokeOnPool(asyncSingletonPool(), a); } }