--- jsr166/src/test/tck/RecursiveActionTest.java 2010/12/01 22:37:51 1.28 +++ jsr166/src/test/tck/RecursiveActionTest.java 2011/06/24 18:49:56 1.33 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ import junit.framework.*; @@ -134,7 +134,7 @@ public class RecursiveActionTest extends assertFalse(a.isCancelled()); assertFalse(a.isCompletedNormally()); assertTrue(a.isCompletedAbnormally()); - assertSame(t, a.getException()); + assertSame(t.getClass(), a.getException().getClass()); assertNull(a.getRawResult()); assertFalse(a.cancel(false)); assertFalse(a.cancel(true)); @@ -143,26 +143,27 @@ public class RecursiveActionTest extends a.join(); shouldThrow(); } catch (Throwable expected) { - assertSame(t, expected); + assertSame(expected.getClass(), t.getClass()); } try { a.get(); shouldThrow(); } catch (ExecutionException success) { - assertSame(t, success.getCause()); + assertSame(t.getClass(), success.getCause().getClass()); } catch (Throwable fail) { threadUnexpectedException(fail); } try { a.get(5L, SECONDS); shouldThrow(); } catch (ExecutionException success) { - assertSame(t, success.getCause()); + assertSame(t.getClass(), success.getCause().getClass()); } catch (Throwable fail) { threadUnexpectedException(fail); } } - static final class FJException extends RuntimeException { - FJException() { super(); } + public static final class FJException extends RuntimeException { + public FJException() { super(); } + public FJException(Throwable cause) { super(cause); } } // A simple recursive action for testing @@ -266,7 +267,7 @@ public class RecursiveActionTest extends assertEquals(21, f.result); checkCompletedNormally(f); - f.reinitialize(); + f = new FibAction(8); f.cancel(true); assertSame(f, f.fork()); myself.interrupt(); @@ -279,7 +280,7 @@ public class RecursiveActionTest extends checkCancelled(f); } - f.reinitialize(); + f = new FibAction(8); f.completeExceptionally(new FJException()); assertSame(f, f.fork()); myself.interrupt(); @@ -293,7 +294,7 @@ public class RecursiveActionTest extends } // test quietlyJoin() - f.reinitialize(); + f = new FibAction(8); assertSame(f, f.fork()); myself.interrupt(); assertTrue(myself.isInterrupted()); @@ -302,7 +303,7 @@ public class RecursiveActionTest extends assertEquals(21, f.result); checkCompletedNormally(f); - f.reinitialize(); + f = new FibAction(8); f.cancel(true); assertSame(f, f.fork()); myself.interrupt(); @@ -311,7 +312,7 @@ public class RecursiveActionTest extends Thread.interrupted(); checkCancelled(f); - f.reinitialize(); + f = new FibAction(8); f.completeExceptionally(new FJException()); assertSame(f, f.fork()); myself.interrupt(); @@ -489,7 +490,6 @@ public class RecursiveActionTest extends testInvokeOnPool(mainPool(), a); } - /** * helpQuiesce returns when tasks are complete. * getQueuedTaskCount returns 0 when quiescent @@ -499,7 +499,7 @@ public class RecursiveActionTest extends public void realCompute() { FibAction f = new FibAction(8); assertSame(f, f.fork()); - f.helpQuiesce(); + helpQuiesce(); assertEquals(21, f.result); assertEquals(0, getQueuedTaskCount()); checkCompletedNormally(f); @@ -507,7 +507,6 @@ public class RecursiveActionTest extends testInvokeOnPool(mainPool(), a); } - /** * invoke task throws exception when task completes abnormally */ @@ -771,12 +770,12 @@ public class RecursiveActionTest extends ForkJoinWorkerThread w = (ForkJoinWorkerThread) Thread.currentThread(); assertTrue(w.getPoolIndex() >= 0); - assertTrue(w.getPoolIndex() < mainPool.getPoolSize()); + // pool size can shrink after assigning index, so cannot check + // assertTrue(w.getPoolIndex() < mainPool.getPoolSize()); }}; testInvokeOnPool(mainPool, a); } - /** * setRawResult(null) succeeds */ @@ -790,7 +789,7 @@ public class RecursiveActionTest extends } /** - * A reinitialized task may be re-invoked + * A reinitialized normally completed task may be re-invoked */ public void testReinitialize() { RecursiveAction a = new CheckedRecursiveAction() { @@ -810,6 +809,29 @@ public class RecursiveActionTest extends } /** + * A reinitialized abnormally completed task may be re-invoked + */ + public void testReinitializeAbnormal() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FailingFibAction f = new FailingFibAction(8); + checkNotDone(f); + + for (int i = 0; i < 3; i++) { + try { + f.invoke(); + shouldThrow(); + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } + f.reinitialize(); + checkNotDone(f); + } + }}; + testInvokeOnPool(mainPool(), a); + } + + /** * invoke task throws exception after invoking completeExceptionally */ public void testCompleteExceptionally() { @@ -923,7 +945,6 @@ public class RecursiveActionTest extends testInvokeOnPool(mainPool(), a); } - /** * invokeAll(tasks) with any null task throws NPE */