--- jsr166/src/test/tck/RecursiveActionTest.java 2010/09/15 12:46:57 1.17 +++ jsr166/src/test/tck/RecursiveActionTest.java 2010/09/16 00:52:49 1.18 @@ -39,7 +39,19 @@ public class RecursiveActionTest extends private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { try { - assertTrue(pool.invoke(a) == null); + assertFalse(a.isDone()); + assertFalse(a.isCompletedNormally()); + assertFalse(a.isCompletedAbnormally()); + assertFalse(a.isCancelled()); + assertNull(a.getException()); + + assertNull(pool.invoke(a)); + + assertTrue(a.isDone()); + assertTrue(a.isCompletedNormally()); + assertFalse(a.isCompletedAbnormally()); + assertFalse(a.isCancelled()); + assertNull(a.getException()); } finally { joinPool(pool); } @@ -50,11 +62,11 @@ public class RecursiveActionTest extends } // A simple recursive action for testing - static final class FibAction extends RecursiveAction { + final class FibAction extends CheckedRecursiveAction { final int number; int result; FibAction(int n) { number = n; } - public void compute() { + public void realCompute() { int n = number; if (n <= 1) result = n; @@ -91,15 +103,15 @@ public class RecursiveActionTest extends * completed tasks. getRawResult of a RecursiveAction returns null; */ public void testInvoke() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); - threadAssertNull(f.invoke()); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertFalse(f.isCancelled()); - threadAssertFalse(f.isCompletedAbnormally()); - threadAssertTrue(f.getRawResult() == null); + assertNull(f.invoke()); + assertEquals(21, f.result); + assertTrue(f.isDone()); + assertFalse(f.isCancelled()); + assertFalse(f.isCompletedAbnormally()); + assertNull(f.getRawResult()); }}; testInvokeOnPool(mainPool(), a); } @@ -110,15 +122,15 @@ public class RecursiveActionTest extends * completed tasks */ public void testQuietlyInvoke() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); f.quietlyInvoke(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertFalse(f.isCancelled()); - threadAssertFalse(f.isCompletedAbnormally()); - threadAssertTrue(f.getRawResult() == null); + assertEquals(21, f.result); + assertTrue(f.isDone()); + assertFalse(f.isCancelled()); + assertFalse(f.isCompletedAbnormally()); + assertNull(f.getRawResult()); }}; testInvokeOnPool(mainPool(), a); } @@ -127,14 +139,14 @@ public class RecursiveActionTest extends * join of a forked task returns when task completes */ public void testForkJoin() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertNull(f.join()); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.getRawResult() == null); + assertSame(f, f.fork()); + assertNull(f.join()); + assertEquals(21, f.result); + assertTrue(f.isDone()); + assertNull(f.getRawResult()); }}; testInvokeOnPool(mainPool(), a); } @@ -143,17 +155,13 @@ public class RecursiveActionTest extends * get of a forked task returns when task completes */ public void testForkGet() { - RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertNull(f.get()); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - } catch (Exception ex) { - unexpectedException(ex); - } + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() throws Exception { + FibAction f = new FibAction(8); + assertSame(f, f.fork()); + assertNull(f.get()); + assertEquals(21, f.result); + assertTrue(f.isDone()); }}; testInvokeOnPool(mainPool(), a); } @@ -162,17 +170,13 @@ public class RecursiveActionTest extends * timed get of a forked task returns when task completes */ public void testForkTimedGet() { - RecursiveAction a = new RecursiveAction() { - public void compute() { - try { - FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertNull(f.get(5L, TimeUnit.SECONDS)); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - } catch (Exception ex) { - unexpectedException(ex); - } + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() throws Exception { + FibAction f = new FibAction(8); + assertSame(f, f.fork()); + assertNull(f.get(5L, TimeUnit.SECONDS)); + assertEquals(21, f.result); + assertTrue(f.isDone()); }}; testInvokeOnPool(mainPool(), a); } @@ -181,17 +185,14 @@ public class RecursiveActionTest extends * timed get with null time unit throws NPE */ public void testForkTimedGetNPE() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() throws Exception { + FibAction f = new FibAction(8); + assertSame(f, f.fork()); try { - FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); f.get(5L, null); shouldThrow(); - } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + } catch (NullPointerException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -200,13 +201,13 @@ public class RecursiveActionTest extends * quietlyJoin of a forked task returns when task completes */ public void testForkQuietlyJoin() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); + assertSame(f, f.fork()); f.quietlyJoin(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); + assertEquals(21, f.result); + assertTrue(f.isDone()); }}; testInvokeOnPool(mainPool(), a); } @@ -217,14 +218,14 @@ public class RecursiveActionTest extends * getQueuedTaskCount returns 0 when quiescent */ public void testForkHelpQuiesce() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); + assertSame(f, f.fork()); f.helpQuiesce(); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertTrue(getQueuedTaskCount() == 0); + assertEquals(21, f.result); + assertTrue(f.isDone()); + assertEquals(0, getQueuedTaskCount()); }}; testInvokeOnPool(mainPool(), a); } @@ -234,14 +235,13 @@ public class RecursiveActionTest extends * invoke task throws exception when task completes abnormally */ public void testAbnormalInvoke() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FailingFibAction f = new FailingFibAction(8); try { - FailingFibAction f = new FailingFibAction(8); f.invoke(); shouldThrow(); - } catch (FJException success) { - } + } catch (FJException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -250,11 +250,11 @@ public class RecursiveActionTest extends * quietlyInvoke task returns when task completes abnormally */ public void testAbnormalQuietlyInvoke() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FailingFibAction f = new FailingFibAction(8); f.quietlyInvoke(); - threadAssertTrue(f.isDone()); + assertTrue(f.isDone()); }}; testInvokeOnPool(mainPool(), a); } @@ -263,15 +263,14 @@ public class RecursiveActionTest extends * join of a forked task throws exception when task completes abnormally */ public void testAbnormalForkJoin() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FailingFibAction f = new FailingFibAction(8); + assertSame(f, f.fork()); try { - FailingFibAction f = new FailingFibAction(8); - threadAssertSame(f, f.fork()); f.join(); shouldThrow(); - } catch (FJException success) { - } + } catch (FJException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -280,17 +279,14 @@ public class RecursiveActionTest extends * get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkGet() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() throws Exception { + FailingFibAction f = new FailingFibAction(8); + assertSame(f, f.fork()); try { - FailingFibAction f = new FailingFibAction(8); - threadAssertSame(f, f.fork()); f.get(); shouldThrow(); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + } catch (ExecutionException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -299,17 +295,14 @@ public class RecursiveActionTest extends * timed get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkTimedGet() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() throws Exception { + FailingFibAction f = new FailingFibAction(8); + assertSame(f, f.fork()); try { - FailingFibAction f = new FailingFibAction(8); - threadAssertSame(f, f.fork()); f.get(5L, TimeUnit.SECONDS); shouldThrow(); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + } catch (ExecutionException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -318,14 +311,14 @@ public class RecursiveActionTest extends * quietlyJoin of a forked task returns when task completes abnormally */ public void testAbnormalForkQuietlyJoin() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FailingFibAction f = new FailingFibAction(8); - threadAssertSame(f, f.fork()); + assertSame(f, f.fork()); f.quietlyJoin(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.isCompletedAbnormally()); - threadAssertTrue(f.getException() instanceof FJException); + assertTrue(f.isDone()); + assertTrue(f.isCompletedAbnormally()); + assertTrue(f.getException() instanceof FJException); }}; testInvokeOnPool(mainPool(), a); } @@ -334,15 +327,14 @@ public class RecursiveActionTest extends * invoke task throws exception when task cancelled */ public void testCancelledInvoke() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FibAction f = new FibAction(8); + assertTrue(f.cancel(true)); try { - FibAction f = new FibAction(8); - threadAssertTrue(f.cancel(true)); f.invoke(); shouldThrow(); - } catch (CancellationException success) { - } + } catch (CancellationException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -351,16 +343,15 @@ public class RecursiveActionTest extends * join of a forked task throws exception when task cancelled */ public void testCancelledForkJoin() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FibAction f = new FibAction(8); + assertTrue(f.cancel(true)); + assertSame(f, f.fork()); try { - FibAction f = new FibAction(8); - threadAssertTrue(f.cancel(true)); - threadAssertSame(f, f.fork()); f.join(); shouldThrow(); - } catch (CancellationException success) { - } + } catch (CancellationException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -369,18 +360,15 @@ public class RecursiveActionTest extends * get of a forked task throws exception when task cancelled */ public void testCancelledForkGet() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() throws Exception { + FibAction f = new FibAction(8); + assertTrue(f.cancel(true)); + assertSame(f, f.fork()); try { - FibAction f = new FibAction(8); - threadAssertTrue(f.cancel(true)); - threadAssertSame(f, f.fork()); f.get(); shouldThrow(); - } catch (CancellationException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + } catch (CancellationException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -389,18 +377,15 @@ public class RecursiveActionTest extends * timed get of a forked task throws exception when task cancelled */ public void testCancelledForkTimedGet() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() throws Exception { + FibAction f = new FibAction(8); + assertTrue(f.cancel(true)); + assertSame(f, f.fork()); try { - FibAction f = new FibAction(8); - threadAssertTrue(f.cancel(true)); - threadAssertSame(f, f.fork()); f.get(5L, TimeUnit.SECONDS); shouldThrow(); - } catch (CancellationException success) { - } catch (Exception ex) { - unexpectedException(ex); - } + } catch (CancellationException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -409,15 +394,16 @@ public class RecursiveActionTest extends * quietlyJoin of a forked task returns when task cancelled */ public void testCancelledForkQuietlyJoin() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); - threadAssertTrue(f.cancel(true)); - threadAssertSame(f, f.fork()); + assertTrue(f.cancel(true)); + assertSame(f, f.fork()); f.quietlyJoin(); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.isCompletedAbnormally()); - threadAssertTrue(f.getException() instanceof CancellationException); + assertTrue(f.isDone()); + assertTrue(f.isCompletedAbnormally()); + assertTrue(f.isCancelled()); + assertTrue(f.getException() instanceof CancellationException); }}; testInvokeOnPool(mainPool(), a); } @@ -427,10 +413,9 @@ public class RecursiveActionTest extends */ public void testGetPool() { final ForkJoinPool mainPool = mainPool(); - RecursiveAction a = new RecursiveAction() { - final ForkJoinPool p = mainPool; - public void compute() { - threadAssertTrue(getPool() == p); + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + assertSame(mainPool, getPool()); }}; testInvokeOnPool(mainPool, a); } @@ -439,9 +424,9 @@ public class RecursiveActionTest extends * getPool of non-FJ task returns null */ public void testGetPool2() { - RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(getPool() == null); + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + assertNull(getPool()); }}; assertNull(a.invoke()); } @@ -450,9 +435,9 @@ public class RecursiveActionTest extends * inForkJoinPool of executing task returns true */ public void testInForkJoinPool() { - RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(inForkJoinPool()); + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + assertTrue(inForkJoinPool()); }}; testInvokeOnPool(mainPool(), a); } @@ -461,9 +446,9 @@ public class RecursiveActionTest extends * inForkJoinPool of non-FJ task returns false */ public void testInForkJoinPool2() { - RecursiveAction a = new RecursiveAction() { - public void compute() { - threadAssertTrue(!inForkJoinPool()); + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + assertFalse(inForkJoinPool()); }}; assertNull(a.invoke()); } @@ -473,11 +458,11 @@ public class RecursiveActionTest extends */ public void testWorkerGetPool() { final ForkJoinPool mainPool = mainPool(); - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { ForkJoinWorkerThread w = (ForkJoinWorkerThread) Thread.currentThread(); - threadAssertTrue(w.getPool() == mainPool); + assertSame(mainPool, w.getPool()); }}; testInvokeOnPool(mainPool, a); } @@ -487,13 +472,13 @@ public class RecursiveActionTest extends */ public void testWorkerGetPoolIndex() { final ForkJoinPool mainPool = mainPool(); - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { ForkJoinWorkerThread w = (ForkJoinWorkerThread)(Thread.currentThread()); int idx = w.getPoolIndex(); - threadAssertTrue(idx >= 0); - threadAssertTrue(idx < mainPool.getPoolSize()); + assertTrue(idx >= 0); + assertTrue(idx < mainPool.getPoolSize()); }}; testInvokeOnPool(mainPool, a); } @@ -503,8 +488,8 @@ public class RecursiveActionTest extends * setRawResult(null) succeeds */ public void testSetRawResult() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { setRawResult(null); }}; assertNull(a.invoke()); @@ -514,17 +499,17 @@ public class RecursiveActionTest extends * A reinitialized task may be re-invoked */ public void testReinitialize() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); - threadAssertNull(f.invoke()); - threadAssertTrue(f.result == 21); - threadAssertTrue(f.isDone()); - threadAssertFalse(f.isCancelled()); - threadAssertFalse(f.isCompletedAbnormally()); + assertNull(f.invoke()); + assertEquals(21, f.result); + assertTrue(f.isDone()); + assertFalse(f.isCancelled()); + assertFalse(f.isCompletedAbnormally()); f.reinitialize(); - threadAssertNull(f.invoke()); - threadAssertTrue(f.result == 21); + assertNull(f.invoke()); + assertEquals(21, f.result); }}; testInvokeOnPool(mainPool(), a); } @@ -533,15 +518,14 @@ public class RecursiveActionTest extends * invoke task throws exception after invoking completeExceptionally */ public void testCompleteExceptionally() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FibAction f = new FibAction(8); + f.completeExceptionally(new FJException()); try { - FibAction f = new FibAction(8); - f.completeExceptionally(new FJException()); f.invoke(); shouldThrow(); - } catch (FJException success) { - } + } catch (FJException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -550,13 +534,13 @@ public class RecursiveActionTest extends * invoke task suppresses execution invoking complete */ public void testComplete() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); f.complete(null); - threadAssertNull(f.invoke()); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.result == 0); + assertNull(f.invoke()); + assertTrue(f.isDone()); + assertEquals(0, f.result); }}; testInvokeOnPool(mainPool(), a); } @@ -565,15 +549,15 @@ public class RecursiveActionTest extends * invokeAll(t1, t2) invokes all task arguments */ public void testInvokeAll2() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { 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); + assertTrue(f.isDone()); + assertEquals(21, f.result); + assertTrue(g.isDone()); + assertEquals(34, g.result); }}; testInvokeOnPool(mainPool(), a); } @@ -582,12 +566,12 @@ public class RecursiveActionTest extends * invokeAll(tasks) with 1 argument invokes task */ public void testInvokeAll1() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); invokeAll(f); - threadAssertTrue(f.isDone()); - threadAssertTrue(f.result == 21); + assertTrue(f.isDone()); + assertEquals(21, f.result); }}; testInvokeOnPool(mainPool(), a); } @@ -596,18 +580,18 @@ public class RecursiveActionTest extends * invokeAll(tasks) with > 2 argument invokes tasks */ public void testInvokeAll3() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { 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); + assertTrue(f.isDone()); + assertEquals(21, f.result); + assertTrue(g.isDone()); + assertEquals(34, g.result); + assertTrue(h.isDone()); + assertEquals(13, h.result); }}; testInvokeOnPool(mainPool(), a); } @@ -616,8 +600,8 @@ public class RecursiveActionTest extends * invokeAll(collection) invokes all tasks in the collection */ public void testInvokeAllCollection() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction f = new FibAction(8); FibAction g = new FibAction(9); FibAction h = new FibAction(7); @@ -626,12 +610,12 @@ public class RecursiveActionTest extends 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); + assertTrue(f.isDone()); + assertEquals(21, f.result); + assertTrue(g.isDone()); + assertEquals(34, g.result); + assertTrue(h.isDone()); + assertEquals(13, h.result); }}; testInvokeOnPool(mainPool(), a); } @@ -641,16 +625,15 @@ public class RecursiveActionTest extends * invokeAll(tasks) with any null task throws NPE */ public void testInvokeAllNPE() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FibAction f = new FibAction(8); + FibAction g = new FibAction(9); + FibAction h = null; try { - FibAction f = new FibAction(8); - FibAction g = new FibAction(9); - FibAction h = null; invokeAll(f, g, h); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -659,15 +642,14 @@ public class RecursiveActionTest extends * invokeAll(t1, t2) throw exception if any task does */ public void testAbnormalInvokeAll2() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FibAction f = new FibAction(8); + FailingFibAction g = new FailingFibAction(9); try { - FibAction f = new FibAction(8); - FailingFibAction g = new FailingFibAction(9); invokeAll(f, g); shouldThrow(); - } catch (FJException success) { - } + } catch (FJException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -676,14 +658,13 @@ public class RecursiveActionTest extends * invokeAll(tasks) with 1 argument throws exception if task does */ public void testAbnormalInvokeAll1() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FailingFibAction g = new FailingFibAction(9); try { - FailingFibAction g = new FailingFibAction(9); invokeAll(g); shouldThrow(); - } catch (FJException success) { - } + } catch (FJException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -692,16 +673,15 @@ public class RecursiveActionTest extends * invokeAll(tasks) with > 2 argument throws exception if any task does */ public void testAbnormalInvokeAll3() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FibAction f = new FibAction(8); + FailingFibAction g = new FailingFibAction(9); + FibAction h = new FibAction(7); try { - FibAction f = new FibAction(8); - FailingFibAction g = new FailingFibAction(9); - FibAction h = new FibAction(7); invokeAll(f, g, h); shouldThrow(); - } catch (FJException success) { - } + } catch (FJException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -710,20 +690,19 @@ public class RecursiveActionTest extends * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollection() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + 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); 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) { - } + } catch (FJException success) {} }}; testInvokeOnPool(mainPool(), a); } @@ -733,16 +712,16 @@ public class RecursiveActionTest extends * and suppresses execution */ public void testTryUnfork() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction g = new FibAction(9); - threadAssertSame(g, g.fork()); + assertSame(g, g.fork()); FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertTrue(f.tryUnfork()); + assertSame(f, f.fork()); + assertTrue(f.tryUnfork()); helpQuiesce(); - threadAssertFalse(f.isDone()); - threadAssertTrue(g.isDone()); + assertFalse(f.isDone()); + assertTrue(g.isDone()); }}; testInvokeOnPool(singletonPool(), a); } @@ -752,15 +731,15 @@ public class RecursiveActionTest extends * there are more tasks than threads */ public void testGetSurplusQueuedTaskCount() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction h = new FibAction(7); - threadAssertSame(h, h.fork()); + assertSame(h, h.fork()); FibAction g = new FibAction(9); - threadAssertSame(g, g.fork()); + assertSame(g, g.fork()); FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertTrue(getSurplusQueuedTaskCount() > 0); + assertSame(f, f.fork()); + assertTrue(getSurplusQueuedTaskCount() > 0); helpQuiesce(); }}; testInvokeOnPool(singletonPool(), a); @@ -770,15 +749,15 @@ public class RecursiveActionTest extends * peekNextLocalTask returns most recent unexecuted task. */ public void testPeekNextLocalTask() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction g = new FibAction(9); - threadAssertSame(g, g.fork()); + assertSame(g, g.fork()); FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertTrue(peekNextLocalTask() == f); - threadAssertNull(f.join()); - threadAssertTrue(f.isDone()); + assertSame(f, f.fork()); + assertSame(f, peekNextLocalTask()); + assertNull(f.join()); + assertTrue(f.isDone()); helpQuiesce(); }}; testInvokeOnPool(singletonPool(), a); @@ -789,15 +768,15 @@ public class RecursiveActionTest extends * without executing it */ public void testPollNextLocalTask() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction g = new FibAction(9); - threadAssertSame(g, g.fork()); + assertSame(g, g.fork()); FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertTrue(pollNextLocalTask() == f); + assertSame(f, f.fork()); + assertSame(f, pollNextLocalTask()); helpQuiesce(); - threadAssertFalse(f.isDone()); + assertFalse(f.isDone()); }}; testInvokeOnPool(singletonPool(), a); } @@ -807,16 +786,16 @@ public class RecursiveActionTest extends * without executing it */ public void testPollTask() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction g = new FibAction(9); - threadAssertSame(g, g.fork()); + assertSame(g, g.fork()); FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertTrue(pollTask() == f); + assertSame(f, f.fork()); + assertSame(f, pollTask()); helpQuiesce(); - threadAssertFalse(f.isDone()); - threadAssertTrue(g.isDone()); + assertFalse(f.isDone()); + assertTrue(g.isDone()); }}; testInvokeOnPool(singletonPool(), a); } @@ -825,16 +804,16 @@ public class RecursiveActionTest extends * peekNextLocalTask returns least recent unexecuted task in async mode */ public void testPeekNextLocalTaskAsync() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction g = new FibAction(9); - threadAssertSame(g, g.fork()); + assertSame(g, g.fork()); FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertTrue(peekNextLocalTask() == g); - threadAssertNull(f.join()); + assertSame(f, f.fork()); + assertSame(g, peekNextLocalTask()); + assertNull(f.join()); helpQuiesce(); - threadAssertTrue(f.isDone()); + assertTrue(f.isDone()); }}; testInvokeOnPool(asyncSingletonPool(), a); } @@ -844,16 +823,16 @@ public class RecursiveActionTest extends * without executing it, in async mode */ public void testPollNextLocalTaskAsync() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction g = new FibAction(9); - threadAssertSame(g, g.fork()); + assertSame(g, g.fork()); FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertTrue(pollNextLocalTask() == g); + assertSame(f, f.fork()); + assertSame(g, pollNextLocalTask()); helpQuiesce(); - threadAssertTrue(f.isDone()); - threadAssertFalse(g.isDone()); + assertTrue(f.isDone()); + assertFalse(g.isDone()); }}; testInvokeOnPool(asyncSingletonPool(), a); } @@ -863,16 +842,16 @@ public class RecursiveActionTest extends * without executing it, in async mode */ public void testPollTaskAsync() { - RecursiveAction a = new RecursiveAction() { - public void compute() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { FibAction g = new FibAction(9); - threadAssertSame(g, g.fork()); + assertSame(g, g.fork()); FibAction f = new FibAction(8); - threadAssertSame(f, f.fork()); - threadAssertTrue(pollTask() == g); + assertSame(f, f.fork()); + assertSame(g, pollTask()); helpQuiesce(); - threadAssertTrue(f.isDone()); - threadAssertFalse(g.isDone()); + assertTrue(f.isDone()); + assertFalse(g.isDone()); }}; testInvokeOnPool(asyncSingletonPool(), a); }