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.26 by jsr166, Thu Sep 16 00:52:49 2010 UTC vs.
Revision 1.30 by jsr166, Fri Sep 17 17:07:47 2010 UTC

# Line 23 | Line 23 | import java.util.concurrent.ForkJoinWork
23   import java.util.concurrent.RecursiveTask;
24   import java.util.concurrent.TimeUnit;
25   import java.util.concurrent.locks.ReentrantLock;
26 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
27   import java.security.AccessControlException;
28   import java.security.Policy;
29   import java.security.PrivilegedAction;
# Line 232 | Line 233 | public class ForkJoinPoolTest extends JS
233       * performs its defined action
234       */
235      public void testSetUncaughtExceptionHandler() throws InterruptedException {
236 <        MyHandler eh = new MyHandler();
236 >        final CountDownLatch uehInvoked = new CountDownLatch(1);
237 >        final Thread.UncaughtExceptionHandler eh =
238 >            new Thread.UncaughtExceptionHandler() {
239 >                public void uncaughtException(Thread t, Throwable e) {
240 >                    uehInvoked.countDown();
241 >                }};
242          ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(),
243                                            eh, false);
244          try {
245              assertSame(eh, p.getUncaughtExceptionHandler());
246 <            p.execute(new FailingTask());
247 <            Thread.sleep(MEDIUM_DELAY_MS);
242 <            assertTrue(eh.catches > 0);
246 >            p.execute(new FibTask(8));
247 >            assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS));
248          } finally {
249 <            p.shutdownNow();
249 >            p.shutdownNow(); // failure might have prevented processing task
250              joinPool(p);
251          }
252      }
# Line 254 | Line 259 | public class ForkJoinPoolTest extends JS
259      public void testisQuiescent() throws InterruptedException {
260          ForkJoinPool p = new ForkJoinPool(2);
261          try {
262 +            assertTrue(p.isQuiescent());
263              p.invoke(new FibTask(20));
264              assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
265                         p.getFactory());
266 <            Thread.sleep(MEDIUM_DELAY_MS);
266 >            Thread.sleep(SMALL_DELAY_MS);
267              assertTrue(p.isQuiescent());
268              assertFalse(p.getAsyncMode());
269              assertEquals(0, p.getActiveThreadCount());
# Line 553 | Line 559 | public class ForkJoinPoolTest extends JS
559  
560  
561      /**
562 <     * Blocking on submit(callable) throws InterruptedException if
557 <     * caller interrupted.
562 >     * submit(callable).get() throws InterruptedException if interrupted
563       */
564      public void testInterruptedSubmit() throws InterruptedException {
565 <        final ForkJoinPool p = new ForkJoinPool(1);
566 <
567 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
568 <            public void realRun() throws Throwable {
569 <                p.submit(new CheckedCallable<Object>() {
570 <                    public Object realCall() throws Throwable {
571 <                        try {
572 <                            Thread.sleep(MEDIUM_DELAY_MS);
573 <                        } catch (InterruptedException ok) {
574 <                        }
575 <                        return null;
576 <                    }}).get();
577 <            }});
578 <
579 <        t.start();
580 <        Thread.sleep(SHORT_DELAY_MS);
581 <        t.interrupt();
582 <        t.join();
583 <        p.shutdownNow();
584 <        joinPool(p);
565 >        final CountDownLatch submitted    = new CountDownLatch(1);
566 >        final CountDownLatch quittingTime = new CountDownLatch(1);
567 >        final ExecutorService p = new ForkJoinPool(1);
568 >        final Callable<Void> awaiter = new CheckedCallable<Void>() {
569 >            public Void realCall() throws InterruptedException {
570 >                assertTrue(quittingTime.await(MEDIUM_DELAY_MS, MILLISECONDS));
571 >                return null;
572 >            }};
573 >        try {
574 >            Thread t = new Thread(new CheckedInterruptedRunnable() {
575 >                public void realRun() throws Exception {
576 >                    Future<Void> future = p.submit(awaiter);
577 >                    submitted.countDown();
578 >                    future.get();
579 >                }});
580 >            t.start();
581 >            assertTrue(submitted.await(MEDIUM_DELAY_MS, MILLISECONDS));
582 >            t.interrupt();
583 >            t.join();
584 >        } finally {
585 >            quittingTime.countDown();
586 >            joinPool(p);
587 >        }
588      }
589  
590      /**
# Line 785 | Line 793 | public class ForkJoinPoolTest extends JS
793      public void testTimedInvokeAny1() throws Throwable {
794          ExecutorService e = new ForkJoinPool(1);
795          try {
796 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
796 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
797              shouldThrow();
798          } catch (NullPointerException success) {
799          } finally {
# Line 816 | Line 824 | public class ForkJoinPoolTest extends JS
824          ExecutorService e = new ForkJoinPool(1);
825          try {
826              e.invokeAny(new ArrayList<Callable<String>>(),
827 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
827 >                        MEDIUM_DELAY_MS, MILLISECONDS);
828              shouldThrow();
829          } catch (IllegalArgumentException success) {
830          } finally {
# Line 834 | Line 842 | public class ForkJoinPoolTest extends JS
842          l.add(latchAwaitingStringTask(latch));
843          l.add(null);
844          try {
845 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
845 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
846              shouldThrow();
847          } catch (NullPointerException success) {
848          } finally {
# Line 851 | Line 859 | public class ForkJoinPoolTest extends JS
859          List<Callable<String>> l = new ArrayList<Callable<String>>();
860          l.add(new NPETask());
861          try {
862 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
862 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
863              shouldThrow();
864          } catch (ExecutionException success) {
865              assertTrue(success.getCause() instanceof NullPointerException);
# Line 869 | Line 877 | public class ForkJoinPoolTest extends JS
877              List<Callable<String>> l = new ArrayList<Callable<String>>();
878              l.add(new StringTask());
879              l.add(new StringTask());
880 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
880 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
881              assertSame(TEST_STRING, result);
882          } finally {
883              joinPool(e);
# Line 882 | Line 890 | public class ForkJoinPoolTest extends JS
890      public void testTimedInvokeAll1() throws Throwable {
891          ExecutorService e = new ForkJoinPool(1);
892          try {
893 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
893 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
894              shouldThrow();
895          } catch (NullPointerException success) {
896          } finally {
# Line 914 | Line 922 | public class ForkJoinPoolTest extends JS
922          try {
923              List<Future<String>> r
924                  = e.invokeAll(new ArrayList<Callable<String>>(),
925 <                              MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
925 >                              MEDIUM_DELAY_MS, MILLISECONDS);
926              assertTrue(r.isEmpty());
927          } finally {
928              joinPool(e);
# Line 930 | Line 938 | public class ForkJoinPoolTest extends JS
938          l.add(new StringTask());
939          l.add(null);
940          try {
941 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
941 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
942              shouldThrow();
943          } catch (NullPointerException success) {
944          } finally {
# Line 946 | Line 954 | public class ForkJoinPoolTest extends JS
954          List<Callable<String>> l = new ArrayList<Callable<String>>();
955          l.add(new NPETask());
956          List<Future<String>> futures
957 <            = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
957 >            = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
958          assertEquals(1, futures.size());
959          try {
960              futures.get(0).get();
# Line 968 | Line 976 | public class ForkJoinPoolTest extends JS
976              l.add(new StringTask());
977              l.add(new StringTask());
978              List<Future<String>> futures
979 <                = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
979 >                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
980              assertEquals(2, futures.size());
981              for (Future<String> future : futures)
982                  assertSame(TEST_STRING, future.get());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines