16 |
|
|
17 |
|
public class ExecutorsTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
19 |
< |
junit.textui.TestRunner.run (suite()); |
19 |
> |
junit.textui.TestRunner.run(suite()); |
20 |
|
} |
21 |
|
public static Test suite() { |
22 |
|
return new TestSuite(ExecutorsTest.class); |
220 |
|
} |
221 |
|
|
222 |
|
/** |
223 |
< |
* Future.get on submitted tasks will time out if they compute too long. |
223 |
> |
* Future.get on submitted tasks will time out if they compute too long. |
224 |
|
*/ |
225 |
|
public void testTimedCallable() throws Exception { |
226 |
< |
final Runnable sleeper = |
227 |
< |
new RunnableShouldThrow(InterruptedException.class) { |
228 |
< |
public void realRun() throws InterruptedException { |
229 |
< |
Thread.sleep(LONG_DELAY_MS); |
230 |
< |
}}; |
226 |
> |
final Runnable sleeper = new CheckedInterruptedRunnable() { |
227 |
> |
public void realRun() throws InterruptedException { |
228 |
> |
Thread.sleep(LONG_DELAY_MS); |
229 |
> |
}}; |
230 |
|
for (ExecutorService executor : |
231 |
|
new ExecutorService[] { |
232 |
|
Executors.newSingleThreadExecutor(), |
257 |
|
*/ |
258 |
|
public void testDefaultThreadFactory() throws Exception { |
259 |
|
final ThreadGroup egroup = Thread.currentThread().getThreadGroup(); |
260 |
< |
Runnable r = new Runnable() { |
261 |
< |
public void run() { |
262 |
< |
try { |
263 |
< |
Thread current = Thread.currentThread(); |
264 |
< |
threadAssertTrue(!current.isDaemon()); |
265 |
< |
threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
266 |
< |
ThreadGroup g = current.getThreadGroup(); |
267 |
< |
SecurityManager s = System.getSecurityManager(); |
268 |
< |
if (s != null) |
269 |
< |
threadAssertTrue(g == s.getThreadGroup()); |
270 |
< |
else |
271 |
< |
threadAssertTrue(g == egroup); |
272 |
< |
String name = current.getName(); |
273 |
< |
threadAssertTrue(name.endsWith("thread-1")); |
274 |
< |
} catch (SecurityException ok) { |
275 |
< |
// Also pass if not allowed to change setting |
277 |
< |
} |
260 |
> |
Runnable r = new CheckedRunnable() { |
261 |
> |
public void realRun() { |
262 |
> |
try { |
263 |
> |
Thread current = Thread.currentThread(); |
264 |
> |
assertTrue(!current.isDaemon()); |
265 |
> |
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
266 |
> |
ThreadGroup g = current.getThreadGroup(); |
267 |
> |
SecurityManager s = System.getSecurityManager(); |
268 |
> |
if (s != null) |
269 |
> |
assertTrue(g == s.getThreadGroup()); |
270 |
> |
else |
271 |
> |
assertTrue(g == egroup); |
272 |
> |
String name = current.getName(); |
273 |
> |
assertTrue(name.endsWith("thread-1")); |
274 |
> |
} catch (SecurityException ok) { |
275 |
> |
// Also pass if not allowed to change setting |
276 |
|
} |
277 |
< |
}; |
277 |
> |
}}; |
278 |
|
ExecutorService e = Executors.newSingleThreadExecutor(Executors.defaultThreadFactory()); |
279 |
|
|
280 |
|
e.execute(r); |
314 |
|
assertTrue(g == egroup); |
315 |
|
String name = current.getName(); |
316 |
|
assertTrue(name.endsWith("thread-1")); |
317 |
< |
assertTrue(thisccl == current.getContextClassLoader()); |
318 |
< |
assertTrue(thisacc.equals(AccessController.getContext())); |
317 |
> |
assertSame(thisccl, current.getContextClassLoader()); |
318 |
> |
assertEquals(thisacc, AccessController.getContext()); |
319 |
|
}}; |
320 |
|
ExecutorService e = Executors.newSingleThreadExecutor(Executors.privilegedThreadFactory()); |
321 |
|
e.execute(r); |
398 |
|
* Without permissions, calling privilegedCallable throws ACE |
399 |
|
*/ |
400 |
|
public void testprivilegedCallableWithNoPrivs() throws Exception { |
401 |
+ |
// Avoid classloader-related SecurityExceptions in swingui.TestRunner |
402 |
+ |
Executors.privilegedCallable(new CheckCCL()); |
403 |
+ |
|
404 |
|
Runnable r = new CheckedRunnable() { |
405 |
|
public void realRun() throws Exception { |
406 |
|
if (System.getSecurityManager() == null) |