--- jsr166/src/test/tck/ForkJoinPoolTest.java 2009/08/04 00:23:18 1.7 +++ jsr166/src/test/tck/ForkJoinPoolTest.java 2009/11/26 15:42:15 1.13 @@ -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) {} } @@ -592,6 +590,7 @@ public class ForkJoinPoolTest extends JS Object result = future.get(); shouldThrow(); } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof IndexOutOfBoundsException); } finally { Policy.setPolicy(savedPolicy); } @@ -606,8 +605,7 @@ public class ForkJoinPoolTest extends JS TrackedShortRunnable task = null; Future future = e.submit(task); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} } @@ -620,8 +618,7 @@ public class ForkJoinPoolTest extends JS StringTask t = null; Future future = e.submit(t); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} } @@ -633,17 +630,23 @@ public class ForkJoinPoolTest extends JS final ForkJoinPool p = new ForkJoinPool(1); Thread t = new Thread(new CheckedInterruptedRunnable() { - void realRun() throws Throwable { + public 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(); }}); t.start(); + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); + t.join(); p.shutdownNow(); + joinPool(p); } /** @@ -652,21 +655,17 @@ 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) { + assertTrue(success.getCause() instanceof ArithmeticException); } + joinPool(p); } @@ -699,13 +698,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(); @@ -716,16 +714,40 @@ 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(); } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -734,7 +756,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>(); @@ -807,6 +829,7 @@ public class ForkJoinPoolTest extends JS future.get(); shouldThrow(); } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -904,6 +927,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); } @@ -1002,6 +1026,7 @@ public class ForkJoinPoolTest extends JS future.get(); shouldThrow(); } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); }