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

Comparing jsr166/src/test/tck/AbstractExecutorServiceTest.java (file contents):
Revision 1.22 by jsr166, Tue Dec 1 22:51:44 2009 UTC vs.
Revision 1.23 by jsr166, Tue Jan 5 02:08:37 2010 UTC

# Line 81 | Line 81 | public class AbstractExecutorServiceTest
81  
82  
83      /**
84 <     * A submitted privileged action to completion
84 >     * A submitted privileged action runs to completion
85       */
86      public void testSubmitPrivilegedAction() throws Exception {
87 <        Policy savedPolicy = null;
88 <        try {
89 <            savedPolicy = Policy.getPolicy();
90 <            AdjustablePolicy policy = new AdjustablePolicy();
91 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
92 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
93 <            Policy.setPolicy(policy);
94 <        } catch (AccessControlException ok) {
95 <            return;
96 <        }
97 <        try {
98 <            ExecutorService e = new DirectExecutorService();
99 <            Future future = e.submit(Executors.callable(new PrivilegedAction() {
87 >        Runnable r = new CheckedRunnable() {
88 >            public void realRun() throws Exception {
89 >                ExecutorService e = new DirectExecutorService();
90 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
91                      public Object run() {
92                          return TEST_STRING;
93                      }}));
94  
95 <            Object result = future.get();
96 <            assertSame(TEST_STRING, result);
97 <        }
98 <        finally {
99 <            try {
100 <                Policy.setPolicy(savedPolicy);
101 <            } catch (AccessControlException ok) {
111 <                return;
112 <            }
113 <        }
95 >                assertSame(TEST_STRING, future.get());
96 >            }};
97 >
98 >        runWithPermissions(r,
99 >                           new RuntimePermission("getClassLoader"),
100 >                           new RuntimePermission("setContextClassLoader"),
101 >                           new RuntimePermission("modifyThread"));
102      }
103  
104      /**
105 <     * A submitted a privileged exception action runs to completion
105 >     * A submitted privileged exception action runs to completion
106       */
107      public void testSubmitPrivilegedExceptionAction() throws Exception {
108 <        Policy savedPolicy = null;
109 <        try {
110 <            savedPolicy = Policy.getPolicy();
111 <            AdjustablePolicy policy = new AdjustablePolicy();
124 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
125 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
126 <            Policy.setPolicy(policy);
127 <        } catch (AccessControlException ok) {
128 <            return;
129 <        }
130 <
131 <        try {
132 <            ExecutorService e = new DirectExecutorService();
133 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
108 >        Runnable r = new CheckedRunnable() {
109 >            public void realRun() throws Exception {
110 >                ExecutorService e = new DirectExecutorService();
111 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
112                      public Object run() {
113                          return TEST_STRING;
114                      }}));
115  
116 <            Object result = future.get();
117 <            assertSame(TEST_STRING, result);
118 <        }
119 <        finally {
142 <            Policy.setPolicy(savedPolicy);
143 <        }
116 >                assertSame(TEST_STRING, future.get());
117 >            }};
118 >
119 >        runWithPermissions(r);
120      }
121  
122      /**
123       * A submitted failed privileged exception action reports exception
124       */
125      public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
126 <        Policy savedPolicy = null;
127 <        try {
128 <            savedPolicy = Policy.getPolicy();
129 <            AdjustablePolicy policy = new AdjustablePolicy();
154 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
155 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
156 <            Policy.setPolicy(policy);
157 <        } catch (AccessControlException ok) {
158 <            return;
159 <        }
160 <
161 <        try {
162 <            ExecutorService e = new DirectExecutorService();
163 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
126 >        Runnable r = new CheckedRunnable() {
127 >            public void realRun() throws Exception {
128 >                ExecutorService e = new DirectExecutorService();
129 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
130                      public Object run() throws Exception {
131                          throw new IndexOutOfBoundsException();
132                      }}));
133  
134 <            future.get();
135 <            shouldThrow();
136 <        } catch (ExecutionException success) {
137 <            assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
138 <        }
139 <        finally {
140 <            Policy.setPolicy(savedPolicy);
141 <        }
134 >                try {
135 >                    future.get();
136 >                    shouldThrow();
137 >                } catch (ExecutionException success) {
138 >                    assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
139 >                }}};
140 >
141 >        runWithPermissions(r);
142      }
143  
144      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines