ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ForkJoinPoolTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ForkJoinPoolTest.java (file contents):
Revision 1.7 by dl, Tue Aug 4 00:23:18 2009 UTC vs.
Revision 1.12 by jsr166, Sat Nov 21 20:10:48 2009 UTC

# Line 170 | Line 170 | public class ForkJoinPoolTest extends JS
170          try {
171              new ForkJoinPool(-1);
172              shouldThrow();
173 <        }
174 <        catch (IllegalArgumentException success) {}
173 >        } catch (IllegalArgumentException success) {}
174      }
175  
176      /**
# Line 181 | Line 180 | public class ForkJoinPoolTest extends JS
180          try {
181              new ForkJoinPool(1, null);
182              shouldThrow();
183 <        } catch (NullPointerException success) {
185 <        }
183 >        } catch (NullPointerException success) {}
184      }
185  
186  
# Line 592 | Line 590 | public class ForkJoinPoolTest extends JS
590              Object result = future.get();
591              shouldThrow();
592          } catch (ExecutionException success) {
593 +            assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
594          } finally {
595              Policy.setPolicy(savedPolicy);
596          }
# Line 606 | Line 605 | public class ForkJoinPoolTest extends JS
605              TrackedShortRunnable task = null;
606              Future<?> future = e.submit(task);
607              shouldThrow();
608 <        } catch (NullPointerException success) {
610 <        }
608 >        } catch (NullPointerException success) {}
609      }
610  
611  
# Line 620 | Line 618 | public class ForkJoinPoolTest extends JS
618              StringTask t = null;
619              Future<String> future = e.submit(t);
620              shouldThrow();
621 <        } catch (NullPointerException success) {
624 <        }
621 >        } catch (NullPointerException success) {}
622      }
623  
624  
# Line 636 | Line 633 | public class ForkJoinPoolTest extends JS
633              void realRun() throws Throwable {
634                  p.submit(new CheckedCallable<Object>() {
635                      public Object realCall() throws Throwable {
636 <                        Thread.sleep(MEDIUM_DELAY_MS);
636 >                        try {
637 >                            Thread.sleep(MEDIUM_DELAY_MS);
638 >                        } catch (InterruptedException ok) {
639 >                        }
640                          return null;
641                      }}).get();
642              }});
643  
644          t.start();
645 +        Thread.sleep(SHORT_DELAY_MS);
646          t.interrupt();
647 +        t.join();
648          p.shutdownNow();
649 +        joinPool(p);
650      }
651  
652      /**
# Line 652 | Line 655 | public class ForkJoinPoolTest extends JS
655       */
656      public void testSubmitEE() throws Throwable {
657          ForkJoinPool p = new ForkJoinPool(1);
655
658          try {
659 <            Callable c = new Callable() {
660 <                    public Object call() {
661 <                        int i = 5/0;
662 <                        return Boolean.TRUE;
663 <                    }
662 <                };
663 <
664 <            for (int i = 0; i < 5; i++) {
665 <                p.submit(c).get();
666 <            }
659 >            p.submit(new Callable() {
660 >                public Object call() {
661 >                    int i = 5/0;
662 >                    return Boolean.TRUE;
663 >                }}).get();
664              shouldThrow();
665          } catch (ExecutionException success) {
666 +            assertTrue(success.getCause() instanceof ArithmeticException);
667          }
668 +
669          joinPool(p);
670      }
671  
# Line 699 | Line 698 | public class ForkJoinPoolTest extends JS
698      }
699  
700      /**
701 <     * invokeAny(c) throws NullPointerException if c has null elements
701 >     * invokeAny(c) throws NullPointerException if c has a single null element
702       */
703      public void testInvokeAny3() throws Throwable {
704          ExecutorService e = new ForkJoinPool(1);
705          try {
706              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
708            l.add(new StringTask());
707              l.add(null);
708              e.invokeAny(l);
709              shouldThrow();
# Line 716 | Line 714 | public class ForkJoinPoolTest extends JS
714      }
715  
716      /**
717 <     * invokeAny(c) throws ExecutionException if no task in c completes
717 >     * invokeAny(c) throws NullPointerException if c has null elements
718       */
719      public void testInvokeAny4() throws Throwable {
720          ExecutorService e = new ForkJoinPool(1);
721          try {
722              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
723 +            l.add(new Callable<String>() {
724 +                public String call() {
725 +                    // The delay gives the pool a chance to notice
726 +                    // the null element.
727 +                    sleepTillInterrupted(SMALL_DELAY_MS);
728 +                    return "foo";
729 +                }});
730 +            l.add(null);
731 +            e.invokeAny(l);
732 +            shouldThrow();
733 +        } catch (NullPointerException success) {
734 +        } finally {
735 +            joinPool(e);
736 +        }
737 +    }
738 +
739 +    /**
740 +     * invokeAny(c) throws ExecutionException if no task in c completes
741 +     */
742 +    public void testInvokeAny5() throws Throwable {
743 +        ExecutorService e = new ForkJoinPool(1);
744 +        try {
745 +            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
746              l.add(new NPETask());
747              e.invokeAny(l);
748              shouldThrow();
749          } catch (ExecutionException success) {
750 +            assertTrue(success.getCause() instanceof NullPointerException);
751          } finally {
752              joinPool(e);
753          }
# Line 734 | Line 756 | public class ForkJoinPoolTest extends JS
756      /**
757       * invokeAny(c) returns result of some task in c if at least one completes
758       */
759 <    public void testInvokeAny5() throws Throwable {
759 >    public void testInvokeAny6() throws Throwable {
760          ExecutorService e = new ForkJoinPool(1);
761          try {
762              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 807 | Line 829 | public class ForkJoinPoolTest extends JS
829                  future.get();
830              shouldThrow();
831          } catch (ExecutionException success) {
832 +            assertTrue(success.getCause() instanceof NullPointerException);
833          } finally {
834              joinPool(e);
835          }
# Line 904 | Line 927 | public class ForkJoinPoolTest extends JS
927              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
928              shouldThrow();
929          } catch (ExecutionException success) {
930 +            assertTrue(success.getCause() instanceof NullPointerException);
931          } finally {
932              joinPool(e);
933          }
# Line 1002 | Line 1026 | public class ForkJoinPoolTest extends JS
1026                  future.get();
1027              shouldThrow();
1028          } catch (ExecutionException success) {
1029 +            assertTrue(success.getCause() instanceof NullPointerException);
1030          } finally {
1031              joinPool(e);
1032          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines