--- jsr166/src/test/tck/RecursiveActionTest.java 2009/07/31 23:37:31 1.2 +++ jsr166/src/test/tck/RecursiveActionTest.java 2009/11/21 02:07:27 1.9 @@ -11,10 +11,10 @@ import java.util.*; public class RecursiveActionTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run (suite()); } public static Test suite() { - return new TestSuite(RecursiveActionTest.class); + return new TestSuite(RecursiveActionTest.class); } static final ForkJoinPool mainPool = new ForkJoinPool(); @@ -72,16 +72,15 @@ public class RecursiveActionTest extends */ public void testInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.invoke(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertFalse(f.isCancelled()); - threadAssertFalse(f.isCompletedAbnormally()); - threadAssertTrue(f.getRawResult() == null); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.invoke(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + threadAssertFalse(f.isCancelled()); + threadAssertFalse(f.isCompletedAbnormally()); + threadAssertTrue(f.getRawResult() == null); + }}; mainPool.invoke(a); } @@ -92,16 +91,15 @@ public class RecursiveActionTest extends */ public void testQuietlyInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.quietlyInvoke(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertFalse(f.isCancelled()); - threadAssertFalse(f.isCompletedAbnormally()); - threadAssertTrue(f.getRawResult() == null); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.quietlyInvoke(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + threadAssertFalse(f.isCancelled()); + threadAssertFalse(f.isCompletedAbnormally()); + threadAssertTrue(f.getRawResult() == null); + }}; mainPool.invoke(a); } @@ -110,15 +108,14 @@ public class RecursiveActionTest extends */ public void testForkJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.fork(); - f.join(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.getRawResult() == null); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.fork(); + f.join(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.getRawResult() == null); + }}; mainPool.invoke(a); } @@ -127,18 +124,17 @@ public class RecursiveActionTest extends */ public void testForkGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.fork(); - f.get(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - } catch (Exception ex) { - unexpectedException(); - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.fork(); + f.get(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + } catch (Exception ex) { + unexpectedException(ex); } - }; + }}; mainPool.invoke(a); } @@ -147,18 +143,17 @@ public class RecursiveActionTest extends */ public void testForkTimedGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.fork(); - f.get(5L, TimeUnit.SECONDS); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - } catch (Exception ex) { - unexpectedException(); - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.fork(); + f.get(5L, TimeUnit.SECONDS); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + } catch (Exception ex) { + unexpectedException(ex); } - }; + }}; mainPool.invoke(a); } @@ -167,17 +162,17 @@ public class RecursiveActionTest extends */ public void testForkTimedGetNPE() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.fork(); - f.get(5L, null); - } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.fork(); + f.get(5L, null); + shouldThrow(); + } catch (NullPointerException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; + }}; mainPool.invoke(a); } @@ -186,14 +181,13 @@ public class RecursiveActionTest extends */ public void testForkHelpJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.fork(); - f.helpJoin(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.fork(); + f.helpJoin(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + }}; mainPool.invoke(a); } @@ -202,14 +196,13 @@ public class RecursiveActionTest extends */ public void testForkQuietlyJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.fork(); - f.quietlyJoin(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.fork(); + f.quietlyJoin(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + }}; mainPool.invoke(a); } @@ -219,14 +212,13 @@ public class RecursiveActionTest extends */ public void testForkQuietlyHelpJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.fork(); - f.quietlyHelpJoin(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.fork(); + f.quietlyHelpJoin(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + }}; mainPool.invoke(a); } @@ -237,15 +229,14 @@ public class RecursiveActionTest extends */ public void testForkHelpQuiesce() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.fork(); - f.helpQuiesce(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertTrue(getQueuedTaskCount() == 0); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.fork(); + f.helpQuiesce(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + threadAssertTrue(getQueuedTaskCount() == 0); + }}; mainPool.invoke(a); } @@ -255,29 +246,27 @@ public class RecursiveActionTest extends */ public void testAbnormalInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingFibAction f = new FailingFibAction(8); - f.invoke(); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingFibAction f = new FailingFibAction(8); + f.invoke(); + shouldThrow(); + } catch (FJException success) { } - }; + }}; mainPool.invoke(a); } /** - * quietelyInvoke task returns when task completes abnormally + * quietlyInvoke task returns when task completes abnormally */ public void testAbnormalQuietlyInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FailingFibAction f = new FailingFibAction(8); - f.quietlyInvoke(); - threadAssertTrue(f.isDone()); - } - }; + public void compute() { + FailingFibAction f = new FailingFibAction(8); + f.quietlyInvoke(); + threadAssertTrue(f.isDone()); + }}; mainPool.invoke(a); } @@ -286,16 +275,15 @@ public class RecursiveActionTest extends */ public void testAbnormalForkJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingFibAction f = new FailingFibAction(8); - f.fork(); - f.join(); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingFibAction f = new FailingFibAction(8); + f.fork(); + f.join(); + shouldThrow(); + } catch (FJException success) { } - }; + }}; mainPool.invoke(a); } @@ -304,16 +292,17 @@ public class RecursiveActionTest extends */ public void testAbnormalForkGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingFibAction f = new FailingFibAction(8); - f.fork(); - f.get(); - shouldThrow(); - } catch (Exception success) { - } + public void compute() { + try { + FailingFibAction f = new FailingFibAction(8); + f.fork(); + f.get(); + shouldThrow(); + } catch (ExecutionException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; + }}; mainPool.invoke(a); } @@ -322,16 +311,17 @@ public class RecursiveActionTest extends */ public void testAbnormalForkTimedGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingFibAction f = new FailingFibAction(8); - f.fork(); - f.get(5L, TimeUnit.SECONDS); - shouldThrow(); - } catch (Exception success) { - } + public void compute() { + try { + FailingFibAction f = new FailingFibAction(8); + f.fork(); + f.get(5L, TimeUnit.SECONDS); + shouldThrow(); + } catch (ExecutionException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; + }}; mainPool.invoke(a); } @@ -340,16 +330,15 @@ public class RecursiveActionTest extends */ public void testAbnormalForkHelpJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingFibAction f = new FailingFibAction(8); - f.fork(); - f.helpJoin(); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingFibAction f = new FailingFibAction(8); + f.fork(); + f.helpJoin(); + shouldThrow(); + } catch (FJException success) { } - }; + }}; mainPool.invoke(a); } @@ -361,16 +350,15 @@ public class RecursiveActionTest extends */ public void testAbnormalForkQuietlyHelpJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FailingFibAction f = new FailingFibAction(8); - f.fork(); - f.quietlyHelpJoin(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.isCompletedAbnormally()); - threadAssertFalse(f.isCancelled()); - threadAssertTrue(f.getException() instanceof FJException); - } - }; + public void compute() { + FailingFibAction f = new FailingFibAction(8); + f.fork(); + f.quietlyHelpJoin(); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.isCompletedAbnormally()); + threadAssertFalse(f.isCancelled()); + threadAssertTrue(f.getException() instanceof FJException); + }}; mainPool.invoke(a); } @@ -379,15 +367,14 @@ public class RecursiveActionTest extends */ public void testAbnormalForkQuietlyJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FailingFibAction f = new FailingFibAction(8); - f.fork(); - f.quietlyJoin(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.isCompletedAbnormally()); - threadAssertTrue(f.getException() instanceof FJException); - } - }; + public void compute() { + FailingFibAction f = new FailingFibAction(8); + f.fork(); + f.quietlyJoin(); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.isCompletedAbnormally()); + threadAssertTrue(f.getException() instanceof FJException); + }}; mainPool.invoke(a); } @@ -396,16 +383,15 @@ public class RecursiveActionTest extends */ public void testCancelledInvoke() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.cancel(true); - f.invoke(); - shouldThrow(); - } catch (CancellationException success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.cancel(true); + f.invoke(); + shouldThrow(); + } catch (CancellationException success) { } - }; + }}; mainPool.invoke(a); } @@ -414,17 +400,16 @@ public class RecursiveActionTest extends */ public void testCancelledForkJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.cancel(true); - f.fork(); - f.join(); - shouldThrow(); - } catch (CancellationException success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.cancel(true); + f.fork(); + f.join(); + shouldThrow(); + } catch (CancellationException success) { } - }; + }}; mainPool.invoke(a); } @@ -433,17 +418,18 @@ public class RecursiveActionTest extends */ public void testCancelledForkGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.cancel(true); - f.fork(); - f.get(); - shouldThrow(); - } catch (Exception success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.cancel(true); + f.fork(); + f.get(); + shouldThrow(); + } catch (CancellationException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; + }}; mainPool.invoke(a); } @@ -452,17 +438,18 @@ public class RecursiveActionTest extends */ public void testCancelledForkTimedGet() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.cancel(true); - f.fork(); - f.get(5L, TimeUnit.SECONDS); - shouldThrow(); - } catch (Exception success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.cancel(true); + f.fork(); + f.get(5L, TimeUnit.SECONDS); + shouldThrow(); + } catch (CancellationException success) { + } catch (Exception ex) { + unexpectedException(ex); } - }; + }}; mainPool.invoke(a); } @@ -471,17 +458,16 @@ public class RecursiveActionTest extends */ public void testCancelledForkHelpJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.cancel(true); - f.fork(); - f.helpJoin(); - shouldThrow(); - } catch (CancellationException success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.cancel(true); + f.fork(); + f.helpJoin(); + shouldThrow(); + } catch (CancellationException success) { } - }; + }}; mainPool.invoke(a); } @@ -493,17 +479,16 @@ public class RecursiveActionTest extends */ public void testCancelledForkQuietlyHelpJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.cancel(true); - f.fork(); - f.quietlyHelpJoin(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.isCompletedAbnormally()); - threadAssertTrue(f.isCancelled()); - threadAssertTrue(f.getException() instanceof CancellationException); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.cancel(true); + f.fork(); + f.quietlyHelpJoin(); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.isCompletedAbnormally()); + threadAssertTrue(f.isCancelled()); + threadAssertTrue(f.getException() instanceof CancellationException); + }}; mainPool.invoke(a); } @@ -512,16 +497,15 @@ public class RecursiveActionTest extends */ public void testCancelledForkQuietlyJoin() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.cancel(true); - f.fork(); - f.quietlyJoin(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.isCompletedAbnormally()); - threadAssertTrue(f.getException() instanceof CancellationException); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.cancel(true); + f.fork(); + f.quietlyJoin(); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.isCompletedAbnormally()); + threadAssertTrue(f.getException() instanceof CancellationException); + }}; mainPool.invoke(a); } @@ -530,10 +514,9 @@ public class RecursiveActionTest extends */ public void testGetPool() { RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(getPool() == mainPool); - } - }; + public void compute() { + threadAssertTrue(getPool() == mainPool); + }}; mainPool.invoke(a); } @@ -542,10 +525,9 @@ public class RecursiveActionTest extends */ public void testGetPool2() { RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(getPool() == null); - } - }; + public void compute() { + threadAssertTrue(getPool() == null); + }}; a.invoke(); } @@ -554,10 +536,9 @@ public class RecursiveActionTest extends */ public void testInForkJoinPool() { RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(inForkJoinPool()); - } - }; + public void compute() { + threadAssertTrue(inForkJoinPool()); + }}; mainPool.invoke(a); } @@ -566,10 +547,9 @@ public class RecursiveActionTest extends */ public void testInForkJoinPool2() { RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(!inForkJoinPool()); - } - }; + public void compute() { + threadAssertTrue(!inForkJoinPool()); + }}; a.invoke(); } @@ -578,12 +558,11 @@ public class RecursiveActionTest extends */ public void testWorkerGetPool() { RecursiveAction a = new RecursiveAction() { - public void compute() { - ForkJoinWorkerThread w = - (ForkJoinWorkerThread)(Thread.currentThread()); - threadAssertTrue(w.getPool() == mainPool); - } - }; + public void compute() { + ForkJoinWorkerThread w = + (ForkJoinWorkerThread)(Thread.currentThread()); + threadAssertTrue(w.getPool() == mainPool); + }}; mainPool.invoke(a); } @@ -593,14 +572,13 @@ public class RecursiveActionTest extends */ public void testWorkerGetPoolIndex() { RecursiveAction a = new RecursiveAction() { - public void compute() { - ForkJoinWorkerThread w = - (ForkJoinWorkerThread)(Thread.currentThread()); - int idx = w.getPoolIndex(); - threadAssertTrue(idx >= 0); - threadAssertTrue(idx < mainPool.getPoolSize()); - } - }; + public void compute() { + ForkJoinWorkerThread w = + (ForkJoinWorkerThread)(Thread.currentThread()); + int idx = w.getPoolIndex(); + threadAssertTrue(idx >= 0); + threadAssertTrue(idx < mainPool.getPoolSize()); + }}; mainPool.invoke(a); } @@ -610,10 +588,9 @@ public class RecursiveActionTest extends */ public void testSetRawResult() { RecursiveAction a = new RecursiveAction() { - public void compute() { - setRawResult(null); - } - }; + public void compute() { + setRawResult(null); + }}; a.invoke(); } @@ -622,18 +599,17 @@ public class RecursiveActionTest extends */ public void testReinitialize() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.invoke(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertFalse(f.isCancelled()); - threadAssertFalse(f.isCompletedAbnormally()); - f.reinitialize(); - f.invoke(); - threadAssertTrue(f.result == 21); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.invoke(); + threadAssertTrue(f.result == 21); + threadAssertTrue(f.isDone()); + threadAssertFalse(f.isCancelled()); + threadAssertFalse(f.isCompletedAbnormally()); + f.reinitialize(); + f.invoke(); + threadAssertTrue(f.result == 21); + }}; mainPool.invoke(a); } @@ -642,16 +618,15 @@ public class RecursiveActionTest extends */ public void testCompleteExceptionally() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - f.completeExceptionally(new FJException()); - f.invoke(); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + f.completeExceptionally(new FJException()); + f.invoke(); + shouldThrow(); + } catch (FJException success) { } - }; + }}; mainPool.invoke(a); } @@ -660,14 +635,13 @@ public class RecursiveActionTest extends */ public void testComplete() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - f.complete(null); - f.invoke(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.result == 0); - } - }; + public void compute() { + FibAction f = new FibAction(8); + f.complete(null); + f.invoke(); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.result == 0); + }}; mainPool.invoke(a); } @@ -676,16 +650,15 @@ public class RecursiveActionTest extends */ public void testInvokeAll2() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - FibAction g = new FibAction(9); - invokeAll(f, g); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.result == 21); - threadAssertTrue(g.isDone()); - threadAssertTrue(g.result == 34); - } - }; + public void compute() { + FibAction f = new FibAction(8); + FibAction g = new FibAction(9); + invokeAll(f, g); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.result == 21); + threadAssertTrue(g.isDone()); + threadAssertTrue(g.result == 34); + }}; mainPool.invoke(a); } @@ -694,13 +667,12 @@ public class RecursiveActionTest extends */ public void testInvokeAll1() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - invokeAll(f); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.result == 21); - } - }; + public void compute() { + FibAction f = new FibAction(8); + invokeAll(f); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.result == 21); + }}; mainPool.invoke(a); } @@ -709,19 +681,18 @@ public class RecursiveActionTest extends */ public void testInvokeAll3() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - FibAction g = new FibAction(9); - FibAction h = new FibAction(7); - invokeAll(f, g, h); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.result == 21); - threadAssertTrue(g.isDone()); - threadAssertTrue(g.result == 34); - threadAssertTrue(h.isDone()); - threadAssertTrue(h.result == 13); - } - }; + public void compute() { + FibAction f = new FibAction(8); + FibAction g = new FibAction(9); + FibAction h = new FibAction(7); + invokeAll(f, g, h); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.result == 21); + threadAssertTrue(g.isDone()); + threadAssertTrue(g.result == 34); + threadAssertTrue(h.isDone()); + threadAssertTrue(h.result == 13); + }}; mainPool.invoke(a); } @@ -730,23 +701,22 @@ public class RecursiveActionTest extends */ public void testInvokeAllCollection() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction f = new FibAction(8); - FibAction g = new FibAction(9); - FibAction h = new FibAction(7); - HashSet set = new HashSet(); - set.add(f); - set.add(g); - set.add(h); - invokeAll(set); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.result == 21); - threadAssertTrue(g.isDone()); - threadAssertTrue(g.result == 34); - threadAssertTrue(h.isDone()); - threadAssertTrue(h.result == 13); - } - }; + public void compute() { + FibAction f = new FibAction(8); + FibAction g = new FibAction(9); + FibAction h = new FibAction(7); + HashSet set = new HashSet(); + set.add(f); + set.add(g); + set.add(h); + invokeAll(set); + threadAssertTrue(f.isDone()); + threadAssertTrue(f.result == 21); + threadAssertTrue(g.isDone()); + threadAssertTrue(g.result == 34); + threadAssertTrue(h.isDone()); + threadAssertTrue(h.result == 13); + }}; mainPool.invoke(a); } @@ -756,17 +726,16 @@ public class RecursiveActionTest extends */ public void testInvokeAllNPE() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - FibAction g = new FibAction(9); - FibAction h = null; - invokeAll(f, g, h); - shouldThrow(); - } catch (NullPointerException success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + FibAction g = new FibAction(9); + FibAction h = null; + invokeAll(f, g, h); + shouldThrow(); + } catch (NullPointerException success) { } - }; + }}; mainPool.invoke(a); } @@ -775,16 +744,15 @@ public class RecursiveActionTest extends */ public void testAbnormalInvokeAll2() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - FailingFibAction g = new FailingFibAction(9); - invokeAll(f, g); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + FailingFibAction g = new FailingFibAction(9); + invokeAll(f, g); + shouldThrow(); + } catch (FJException success) { } - }; + }}; mainPool.invoke(a); } @@ -793,15 +761,14 @@ public class RecursiveActionTest extends */ public void testAbnormalInvokeAll1() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingFibAction g = new FailingFibAction(9); - invokeAll(g); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingFibAction g = new FailingFibAction(9); + invokeAll(g); + shouldThrow(); + } catch (FJException success) { } - }; + }}; mainPool.invoke(a); } @@ -810,40 +777,38 @@ public class RecursiveActionTest extends */ public void testAbnormalInvokeAll3() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - FailingFibAction g = new FailingFibAction(9); - FibAction h = new FibAction(7); - invokeAll(f, g, h); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FibAction f = new FibAction(8); + FailingFibAction g = new FailingFibAction(9); + FibAction h = new FibAction(7); + invokeAll(f, g, h); + shouldThrow(); + } catch (FJException success) { } - }; + }}; mainPool.invoke(a); } /** - * invokeAll(collection) throws exception if any task does + * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollection() { RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FailingFibAction f = new FailingFibAction(8); - FibAction g = new FibAction(9); - FibAction h = new FibAction(7); - HashSet set = new HashSet(); - set.add(f); - set.add(g); - set.add(h); - invokeAll(set); - shouldThrow(); - } catch (FJException success) { - } + public void compute() { + try { + FailingFibAction f = new FailingFibAction(8); + FibAction g = new FibAction(9); + FibAction h = new FibAction(7); + HashSet set = new HashSet(); + set.add(f); + set.add(g); + set.add(h); + invokeAll(set); + shouldThrow(); + } catch (FJException success) { } - }; + }}; mainPool.invoke(a); } @@ -853,17 +818,16 @@ public class RecursiveActionTest extends */ public void testTryUnfork() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction g = new FibAction(9); - g.fork(); - FibAction f = new FibAction(8); - f.fork(); - threadAssertTrue(f.tryUnfork()); - helpQuiesce(); - threadAssertFalse(f.isDone()); - threadAssertTrue(g.isDone()); - } - }; + public void compute() { + FibAction g = new FibAction(9); + g.fork(); + FibAction f = new FibAction(8); + f.fork(); + threadAssertTrue(f.tryUnfork()); + helpQuiesce(); + threadAssertFalse(f.isDone()); + threadAssertTrue(g.isDone()); + }}; singletonPool.invoke(a); } @@ -873,17 +837,16 @@ public class RecursiveActionTest extends */ public void testGetSurplusQueuedTaskCount() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction h = new FibAction(7); - h.fork(); - FibAction g = new FibAction(9); - g.fork(); - FibAction f = new FibAction(8); - f.fork(); - threadAssertTrue(getSurplusQueuedTaskCount() > 0); - helpQuiesce(); - } - }; + public void compute() { + FibAction h = new FibAction(7); + h.fork(); + FibAction g = new FibAction(9); + g.fork(); + FibAction f = new FibAction(8); + f.fork(); + threadAssertTrue(getSurplusQueuedTaskCount() > 0); + helpQuiesce(); + }}; singletonPool.invoke(a); } @@ -892,17 +855,16 @@ public class RecursiveActionTest extends */ public void testPeekNextLocalTask() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction g = new FibAction(9); - g.fork(); - FibAction f = new FibAction(8); - f.fork(); - threadAssertTrue(peekNextLocalTask() == f); - f.join(); - threadAssertTrue(f.isDone()); - helpQuiesce(); - } - }; + public void compute() { + FibAction g = new FibAction(9); + g.fork(); + FibAction f = new FibAction(8); + f.fork(); + threadAssertTrue(peekNextLocalTask() == f); + f.join(); + threadAssertTrue(f.isDone()); + helpQuiesce(); + }}; singletonPool.invoke(a); } @@ -912,16 +874,15 @@ public class RecursiveActionTest extends */ public void testPollNextLocalTask() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction g = new FibAction(9); - g.fork(); - FibAction f = new FibAction(8); - f.fork(); - threadAssertTrue(pollNextLocalTask() == f); - helpQuiesce(); - threadAssertFalse(f.isDone()); - } - }; + public void compute() { + FibAction g = new FibAction(9); + g.fork(); + FibAction f = new FibAction(8); + f.fork(); + threadAssertTrue(pollNextLocalTask() == f); + helpQuiesce(); + threadAssertFalse(f.isDone()); + }}; singletonPool.invoke(a); } @@ -931,17 +892,16 @@ public class RecursiveActionTest extends */ public void testPollTask() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction g = new FibAction(9); - g.fork(); - FibAction f = new FibAction(8); - f.fork(); - threadAssertTrue(pollTask() == f); - helpQuiesce(); - threadAssertFalse(f.isDone()); - threadAssertTrue(g.isDone()); - } - }; + public void compute() { + FibAction g = new FibAction(9); + g.fork(); + FibAction f = new FibAction(8); + f.fork(); + threadAssertTrue(pollTask() == f); + helpQuiesce(); + threadAssertFalse(f.isDone()); + threadAssertTrue(g.isDone()); + }}; singletonPool.invoke(a); } @@ -950,17 +910,16 @@ public class RecursiveActionTest extends */ public void testPeekNextLocalTaskAsync() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction g = new FibAction(9); - g.fork(); - FibAction f = new FibAction(8); - f.fork(); - threadAssertTrue(peekNextLocalTask() == g); - f.join(); - helpQuiesce(); - threadAssertTrue(f.isDone()); - } - }; + public void compute() { + FibAction g = new FibAction(9); + g.fork(); + FibAction f = new FibAction(8); + f.fork(); + threadAssertTrue(peekNextLocalTask() == g); + f.join(); + helpQuiesce(); + threadAssertTrue(f.isDone()); + }}; asyncSingletonPool.invoke(a); } @@ -970,17 +929,16 @@ public class RecursiveActionTest extends */ public void testPollNextLocalTaskAsync() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction g = new FibAction(9); - g.fork(); - FibAction f = new FibAction(8); - f.fork(); - threadAssertTrue(pollNextLocalTask() == g); - helpQuiesce(); - threadAssertTrue(f.isDone()); - threadAssertFalse(g.isDone()); - } - }; + public void compute() { + FibAction g = new FibAction(9); + g.fork(); + FibAction f = new FibAction(8); + f.fork(); + threadAssertTrue(pollNextLocalTask() == g); + helpQuiesce(); + threadAssertTrue(f.isDone()); + threadAssertFalse(g.isDone()); + }}; asyncSingletonPool.invoke(a); } @@ -990,17 +948,16 @@ public class RecursiveActionTest extends */ public void testPollTaskAsync() { RecursiveAction a = new RecursiveAction() { - public void compute() { - FibAction g = new FibAction(9); - g.fork(); - FibAction f = new FibAction(8); - f.fork(); - threadAssertTrue(pollTask() == g); - helpQuiesce(); - threadAssertTrue(f.isDone()); - threadAssertFalse(g.isDone()); - } - }; + public void compute() { + FibAction g = new FibAction(9); + g.fork(); + FibAction f = new FibAction(8); + f.fork(); + threadAssertTrue(pollTask() == g); + helpQuiesce(); + threadAssertTrue(f.isDone()); + threadAssertFalse(g.isDone()); + }}; asyncSingletonPool.invoke(a); }