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); |
258 |
|
*/ |
259 |
|
public void testDefaultThreadFactory() throws Exception { |
260 |
|
final ThreadGroup egroup = Thread.currentThread().getThreadGroup(); |
261 |
< |
Runnable r = new Runnable() { |
262 |
< |
public void run() { |
263 |
< |
try { |
264 |
< |
Thread current = Thread.currentThread(); |
265 |
< |
threadAssertTrue(!current.isDaemon()); |
266 |
< |
threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
267 |
< |
ThreadGroup g = current.getThreadGroup(); |
268 |
< |
SecurityManager s = System.getSecurityManager(); |
269 |
< |
if (s != null) |
270 |
< |
threadAssertTrue(g == s.getThreadGroup()); |
271 |
< |
else |
272 |
< |
threadAssertTrue(g == egroup); |
273 |
< |
String name = current.getName(); |
274 |
< |
threadAssertTrue(name.endsWith("thread-1")); |
275 |
< |
} catch (SecurityException ok) { |
276 |
< |
// Also pass if not allowed to change setting |
277 |
< |
} |
261 |
> |
Runnable r = new CheckedRunnable() { |
262 |
> |
public void realRun() { |
263 |
> |
try { |
264 |
> |
Thread current = Thread.currentThread(); |
265 |
> |
assertTrue(!current.isDaemon()); |
266 |
> |
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
267 |
> |
ThreadGroup g = current.getThreadGroup(); |
268 |
> |
SecurityManager s = System.getSecurityManager(); |
269 |
> |
if (s != null) |
270 |
> |
assertTrue(g == s.getThreadGroup()); |
271 |
> |
else |
272 |
> |
assertTrue(g == egroup); |
273 |
> |
String name = current.getName(); |
274 |
> |
assertTrue(name.endsWith("thread-1")); |
275 |
> |
} catch (SecurityException ok) { |
276 |
> |
// Also pass if not allowed to change setting |
277 |
|
} |
278 |
< |
}; |
278 |
> |
}}; |
279 |
|
ExecutorService e = Executors.newSingleThreadExecutor(Executors.defaultThreadFactory()); |
280 |
|
|
281 |
|
e.execute(r); |
315 |
|
assertTrue(g == egroup); |
316 |
|
String name = current.getName(); |
317 |
|
assertTrue(name.endsWith("thread-1")); |
318 |
< |
assertTrue(thisccl == current.getContextClassLoader()); |
319 |
< |
assertTrue(thisacc.equals(AccessController.getContext())); |
318 |
> |
assertSame(thisccl, current.getContextClassLoader()); |
319 |
> |
assertEquals(thisacc, AccessController.getContext()); |
320 |
|
}}; |
321 |
|
ExecutorService e = Executors.newSingleThreadExecutor(Executors.privilegedThreadFactory()); |
322 |
|
e.execute(r); |
399 |
|
* Without permissions, calling privilegedCallable throws ACE |
400 |
|
*/ |
401 |
|
public void testprivilegedCallableWithNoPrivs() throws Exception { |
402 |
+ |
// Avoid classloader-related SecurityExceptions in swingui.TestRunner |
403 |
+ |
Executors.privilegedCallable(new CheckCCL()); |
404 |
+ |
|
405 |
|
Runnable r = new CheckedRunnable() { |
406 |
|
public void realRun() throws Exception { |
407 |
|
if (System.getSecurityManager() == null) |