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.47 by jsr166, Mon Jan 14 22:05:39 2013 UTC vs.
Revision 1.48 by jsr166, Wed Feb 6 16:36:36 2013 UTC

# Line 455 | 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() {
463 <                        return TEST_STRING;
464 <                    }}));
465 <
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,
470 <                           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() {
482 <                        return TEST_STRING;
483 <                    }}));
484 <
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 492 | 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 {
500 <                        throw new IndexOutOfBoundsException();
501 <                    }}));
502 <
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      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines