--- jsr166/src/test/tck/ForkJoinPoolTest.java 2015/10/04 08:27:41 1.63 +++ jsr166/src/test/tck/ForkJoinPoolTest.java 2015/10/06 23:16:51 1.66 @@ -64,10 +64,12 @@ public class ForkJoinPoolTest extends JS } } + static class MyError extends Error {} + // to test handlers static class FailingFJWSubclass extends ForkJoinWorkerThread { public FailingFJWSubclass(ForkJoinPool p) { super(p) ; } - protected void onStart() { super.onStart(); throw new Error(); } + protected void onStart() { super.onStart(); throw new MyError(); } } static class FailingThreadFactory @@ -256,23 +258,23 @@ public class ForkJoinPoolTest extends JS */ public void testSetUncaughtExceptionHandler() throws InterruptedException { final CountDownLatch uehInvoked = new CountDownLatch(1); - final Thread.UncaughtExceptionHandler eh = + final Thread.UncaughtExceptionHandler ueh = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { + threadAssertTrue(e instanceof MyError); + threadAssertTrue(t instanceof FailingFJWSubclass); uehInvoked.countDown(); }}; ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), - eh, false); - try { - assertSame(eh, p.getUncaughtExceptionHandler()); + ueh, false); + try (PoolCleaner cleaner = cleaner(p)) { + assertSame(ueh, p.getUncaughtExceptionHandler()); try { p.execute(new FibTask(8)); - assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS)); - } catch (RejectedExecutionException ok) { + await(uehInvoked); + } finally { + p.shutdownNow(); // failure might have prevented processing task } - } finally { - p.shutdownNow(); // failure might have prevented processing task - joinPool(p); } } @@ -548,13 +550,13 @@ public class ForkJoinPoolTest extends JS public void testInterruptedSubmit() throws InterruptedException { final CountDownLatch submitted = new CountDownLatch(1); final CountDownLatch quittingTime = new CountDownLatch(1); - final ExecutorService p = new ForkJoinPool(1); final Callable awaiter = new CheckedCallable() { public Void realCall() throws InterruptedException { - assertTrue(quittingTime.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS)); return null; }}; - try { + final ExecutorService p = new ForkJoinPool(1); + try (PoolCleaner cleaner = cleaner(p, quittingTime)) { Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws Exception { Future future = p.submit(awaiter); @@ -562,12 +564,9 @@ public class ForkJoinPoolTest extends JS future.get(); }}); t.start(); - assertTrue(submitted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + await(submitted); t.interrupt(); - t.join(); - } finally { - quittingTime.countDown(); - joinPool(p); + awaitTermination(t); } }