--- jsr166/src/test/tck/ForkJoinPoolTest.java 2009/08/03 22:08:07 1.6 +++ jsr166/src/test/tck/ForkJoinPoolTest.java 2009/11/21 20:02:13 1.11 @@ -170,8 +170,7 @@ public class ForkJoinPoolTest extends JS try { new ForkJoinPool(-1); shouldThrow(); - } - catch (IllegalArgumentException success) {} + } catch (IllegalArgumentException success) {} } /** @@ -181,8 +180,7 @@ public class ForkJoinPoolTest extends JS try { new ForkJoinPool(1, null); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} } @@ -416,7 +414,7 @@ public class ForkJoinPoolTest extends JS int r = f.get(); assertTrue(r == 832040); } finally { - joinPool(p); + p.shutdownNow(); // don't wait out shutdown } } @@ -606,8 +604,7 @@ public class ForkJoinPoolTest extends JS TrackedShortRunnable task = null; Future future = e.submit(task); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} } @@ -620,8 +617,7 @@ public class ForkJoinPoolTest extends JS StringTask t = null; Future future = e.submit(t); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} } @@ -636,7 +632,10 @@ public class ForkJoinPoolTest extends JS void realRun() throws Throwable { p.submit(new CheckedCallable() { public Object realCall() throws Throwable { - Thread.sleep(MEDIUM_DELAY_MS); + try { + Thread.sleep(MEDIUM_DELAY_MS); + } catch (InterruptedException ok) { + } return null; }}).get(); }}); @@ -644,6 +643,8 @@ public class ForkJoinPoolTest extends JS t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); + t.join(); + p.shutdownNow(); joinPool(p); } @@ -653,21 +654,15 @@ public class ForkJoinPoolTest extends JS */ public void testSubmitEE() throws Throwable { ForkJoinPool p = new ForkJoinPool(1); - try { - Callable c = new Callable() { - public Object call() { - int i = 5/0; - return Boolean.TRUE; - } - }; - - for (int i = 0; i < 5; i++) { - p.submit(c).get(); - } + p.submit(new Callable() { + public Object call() { + int i = 5/0; + return Boolean.TRUE; + }}).get(); shouldThrow(); - } catch (ExecutionException success) { - } + } catch (ExecutionException success) {} + joinPool(p); } @@ -700,13 +695,12 @@ public class ForkJoinPoolTest extends JS } /** - * invokeAny(c) throws NullPointerException if c has null elements + * invokeAny(c) throws NullPointerException if c has a single null element */ public void testInvokeAny3() throws Throwable { ExecutorService e = new ForkJoinPool(1); try { ArrayList> l = new ArrayList>(); - l.add(new StringTask()); l.add(null); e.invokeAny(l); shouldThrow(); @@ -717,12 +711,35 @@ public class ForkJoinPoolTest extends JS } /** - * invokeAny(c) throws ExecutionException if no task in c completes + * invokeAny(c) throws NullPointerException if c has null elements */ public void testInvokeAny4() throws Throwable { ExecutorService e = new ForkJoinPool(1); try { ArrayList> l = new ArrayList>(); + l.add(new Callable() { + public String call() { + // The delay gives the pool a chance to notice + // the null element. + sleepTillInterrupted(SMALL_DELAY_MS); + return "foo"; + }}); + l.add(null); + e.invokeAny(l); + shouldThrow(); + } catch (NullPointerException success) { + } finally { + joinPool(e); + } + } + + /** + * invokeAny(c) throws ExecutionException if no task in c completes + */ + public void testInvokeAny5() throws Throwable { + ExecutorService e = new ForkJoinPool(1); + try { + ArrayList> l = new ArrayList>(); l.add(new NPETask()); e.invokeAny(l); shouldThrow(); @@ -735,7 +752,7 @@ public class ForkJoinPoolTest extends JS /** * invokeAny(c) returns result of some task in c if at least one completes */ - public void testInvokeAny5() throws Throwable { + public void testInvokeAny6() throws Throwable { ExecutorService e = new ForkJoinPool(1); try { ArrayList> l = new ArrayList>(); @@ -905,6 +922,7 @@ public class ForkJoinPoolTest extends JS e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); }