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.42 by jsr166, Sun May 29 07:01:17 2011 UTC vs.
Revision 1.49 by jsr166, Sat Feb 16 20:50:29 2013 UTC

# Line 39 | Line 39 | public class ForkJoinPoolTest extends JS
39          return new TestSuite(ForkJoinPoolTest.class);
40      }
41  
42 <    /**
42 >    /*
43       * Testing coverage notes:
44       *
45       * 1. shutdown and related methods are tested via super.joinPool.
# Line 242 | Line 242 | public class ForkJoinPoolTest extends JS
242                                            eh, false);
243          try {
244              assertSame(eh, p.getUncaughtExceptionHandler());
245 <            p.execute(new FibTask(8));
246 <            assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS));
245 >            try {
246 >                p.execute(new FibTask(8));
247 >                assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS));
248 >            } catch (RejectedExecutionException ok) {
249 >            }
250          } finally {
251              p.shutdownNow(); // failure might have prevented processing task
252              joinPool(p);
# Line 256 | Line 259 | public class ForkJoinPoolTest extends JS
259       * the task has completed successfully, and construction
260       * parameters continue to hold
261       */
262 <    public void testisQuiescent() throws Exception {
262 >    public void testIsQuiescent() throws Exception {
263          ForkJoinPool p = new ForkJoinPool(2);
264          try {
265              assertTrue(p.isQuiescent());
# Line 452 | Line 455 | public class ForkJoinPoolTest extends JS
455       * A submitted privileged action runs to completion
456       */
457      public void testSubmitPrivilegedAction() throws Exception {
458 +        final Callable callable = Executors.callable(new PrivilegedAction() {
459 +                public Object run() { return TEST_STRING; }});
460          Runnable r = new CheckedRunnable() {
461 <            public void realRun() throws Exception {
462 <                ExecutorService e = new ForkJoinPool(1);
463 <                Future future = e.submit(Executors.callable(new PrivilegedAction() {
464 <                    public Object run() {
460 <                        return TEST_STRING;
461 <                    }}));
462 <
461 >        public void realRun() throws Exception {
462 >            ExecutorService e = new ForkJoinPool(1);
463 >            try {
464 >                Future future = e.submit(callable);
465                  assertSame(TEST_STRING, future.get());
466 <            }};
466 >            } finally {
467 >                joinPool(e);
468 >            }
469 >        }};
470  
471 <        runWithPermissions(r,
467 <                           new RuntimePermission("modifyThread"));
471 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
472      }
473  
474      /**
475       * A submitted privileged exception action runs to completion
476       */
477      public void testSubmitPrivilegedExceptionAction() throws Exception {
478 +        final Callable callable =
479 +            Executors.callable(new PrivilegedExceptionAction() {
480 +                public Object run() { return TEST_STRING; }});
481          Runnable r = new CheckedRunnable() {
482 <            public void realRun() throws Exception {
483 <                ExecutorService e = new ForkJoinPool(1);
484 <                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
485 <                    public Object run() {
479 <                        return TEST_STRING;
480 <                    }}));
481 <
482 >        public void realRun() throws Exception {
483 >            ExecutorService e = new ForkJoinPool(1);
484 >            try {
485 >                Future future = e.submit(callable);
486                  assertSame(TEST_STRING, future.get());
487 <            }};
487 >            } finally {
488 >                joinPool(e);
489 >            }
490 >        }};
491  
492          runWithPermissions(r, new RuntimePermission("modifyThread"));
493      }
# Line 489 | Line 496 | public class ForkJoinPoolTest extends JS
496       * A submitted failed privileged exception action reports exception
497       */
498      public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
499 +        final Callable callable =
500 +            Executors.callable(new PrivilegedExceptionAction() {
501 +                public Object run() { throw new IndexOutOfBoundsException(); }});
502          Runnable r = new CheckedRunnable() {
503 <            public void realRun() throws Exception {
504 <                ExecutorService e = new ForkJoinPool(1);
505 <                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
506 <                    public Object run() throws Exception {
497 <                        throw new IndexOutOfBoundsException();
498 <                    }}));
499 <
503 >        public void realRun() throws Exception {
504 >            ExecutorService e = new ForkJoinPool(1);
505 >            try {
506 >                Future future = e.submit(callable);
507                  try {
508                      future.get();
509                      shouldThrow();
510                  } catch (ExecutionException success) {
511                      assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
512 <                }}};
512 >                }
513 >            } finally {
514 >                joinPool(e);
515 >            }
516 >        }};
517  
518          runWithPermissions(r, new RuntimePermission("modifyThread"));
519      }
# Line 572 | Line 583 | public class ForkJoinPoolTest extends JS
583          ForkJoinPool p = new ForkJoinPool(1);
584          try {
585              p.submit(new Callable() {
586 <                public Object call() {
587 <                    int i = 5/0;
577 <                    return Boolean.TRUE;
578 <                }}).get();
586 >                public Object call() { throw new ArithmeticException(); }})
587 >                .get();
588              shouldThrow();
589          } catch (ExecutionException success) {
590              assertTrue(success.getCause() instanceof ArithmeticException);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines