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.16 by jsr166, Tue Dec 1 22:51:44 2009 UTC vs.
Revision 1.17 by jsr166, Tue Jan 5 02:08:37 2010 UTC

# Line 504 | Line 504 | public class ForkJoinPoolTest extends JS
504          assertSame(TEST_STRING, result);
505      }
506  
507
507      /**
508 <     * A submitted privileged action to completion
508 >     * A submitted privileged action runs to completion
509       */
510      public void testSubmitPrivilegedAction() throws Throwable {
511 <        Policy savedPolicy = null;
512 <        try {
513 <            savedPolicy = Policy.getPolicy();
514 <            AdjustablePolicy policy = new AdjustablePolicy();
516 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
517 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
518 <            Policy.setPolicy(policy);
519 <        } catch (AccessControlException ok) {
520 <            return;
521 <        }
522 <        try {
523 <            ExecutorService e = new ForkJoinPool(1);
524 <            Future future = e.submit(Executors.callable(new PrivilegedAction() {
511 >        Runnable r = new CheckedRunnable() {
512 >            public void realRun() throws Exception {
513 >                ExecutorService e = new ForkJoinPool(1);
514 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
515                      public Object run() {
516                          return TEST_STRING;
517                      }}));
518  
519 <            Object result = future.get();
520 <            assertSame(TEST_STRING, result);
521 <        }
522 <        finally {
523 <            Policy.setPolicy(savedPolicy);
534 <        }
519 >                Object result = future.get();
520 >                assertSame(TEST_STRING, result);
521 >            }};
522 >
523 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
524      }
525  
526      /**
527 <     * A submitted a privileged exception action runs to completion
527 >     * A submitted privileged exception action runs to completion
528       */
529      public void testSubmitPrivilegedExceptionAction() throws Throwable {
530 <        Policy savedPolicy = null;
531 <        try {
532 <            savedPolicy = Policy.getPolicy();
533 <            AdjustablePolicy policy = new AdjustablePolicy();
545 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
546 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
547 <            Policy.setPolicy(policy);
548 <        } catch (AccessControlException ok) {
549 <            return;
550 <        }
551 <
552 <        try {
553 <            ExecutorService e = new ForkJoinPool(1);
554 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
530 >        Runnable r = new CheckedRunnable() {
531 >            public void realRun() throws Exception {
532 >                ExecutorService e = new ForkJoinPool(1);
533 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
534                      public Object run() {
535                          return TEST_STRING;
536                      }}));
537  
538 <            Object result = future.get();
539 <            assertSame(TEST_STRING, result);
540 <        }
541 <        finally {
542 <            Policy.setPolicy(savedPolicy);
564 <        }
538 >                Object result = future.get();
539 >                assertSame(TEST_STRING, result);
540 >            }};
541 >
542 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
543      }
544  
545      /**
546       * A submitted failed privileged exception action reports exception
547       */
548      public void testSubmitFailedPrivilegedExceptionAction() throws Throwable {
549 <        Policy savedPolicy = null;
550 <        try {
551 <            savedPolicy = Policy.getPolicy();
552 <            AdjustablePolicy policy = new AdjustablePolicy();
575 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
576 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
577 <            Policy.setPolicy(policy);
578 <        } catch (AccessControlException ok) {
579 <            return;
580 <        }
581 <
582 <
583 <        try {
584 <            ExecutorService e = new ForkJoinPool(1);
585 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
549 >        Runnable r = new CheckedRunnable() {
550 >            public void realRun() throws Exception {
551 >                ExecutorService e = new ForkJoinPool(1);
552 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
553                      public Object run() throws Exception {
554                          throw new IndexOutOfBoundsException();
555                      }}));
556  
557 <            Object result = future.get();
558 <            shouldThrow();
559 <        } catch (ExecutionException success) {
560 <            assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
561 <        } finally {
562 <            Policy.setPolicy(savedPolicy);
563 <        }
557 >                try {
558 >                    Object result = future.get();
559 >                    shouldThrow();
560 >                } catch (ExecutionException success) {
561 >                    assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
562 >                }}};
563 >
564 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
565      }
566  
567      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines