140 |
|
} |
141 |
|
|
142 |
|
/** |
143 |
< |
* A new newFixedThreadPool with null ThreadFactory throws NPE |
143 |
> |
* A new newFixedThreadPool with null ThreadFactory throws |
144 |
> |
* NullPointerException |
145 |
|
*/ |
146 |
|
public void testNewFixedThreadPool3() { |
147 |
|
try { |
151 |
|
} |
152 |
|
|
153 |
|
/** |
154 |
< |
* A new newFixedThreadPool with 0 threads throws IAE |
154 |
> |
* A new newFixedThreadPool with 0 threads throws IllegalArgumentException |
155 |
|
*/ |
156 |
|
public void testNewFixedThreadPool4() { |
157 |
|
try { |
282 |
|
delay(LONG_DELAY_MS); |
283 |
|
}}; |
284 |
|
|
285 |
< |
List<Thread> threads = new ArrayList<Thread>(); |
285 |
> |
List<Thread> threads = new ArrayList<>(); |
286 |
|
for (final ExecutorService executor : executors) { |
287 |
|
threads.add(newStartedThread(new CheckedRunnable() { |
288 |
|
public void realRun() { |
307 |
|
public void realRun() { |
308 |
|
try { |
309 |
|
Thread current = Thread.currentThread(); |
310 |
< |
assertTrue(!current.isDaemon()); |
310 |
> |
assertFalse(current.isDaemon()); |
311 |
|
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
311 |
– |
ThreadGroup g = current.getThreadGroup(); |
312 |
|
SecurityManager s = System.getSecurityManager(); |
313 |
< |
if (s != null) |
314 |
< |
assertTrue(g == s.getThreadGroup()); |
315 |
< |
else |
316 |
< |
assertTrue(g == egroup); |
317 |
< |
String name = current.getName(); |
318 |
< |
assertTrue(name.endsWith("thread-1")); |
313 |
> |
assertSame(current.getThreadGroup(), |
314 |
> |
(s == null) ? egroup : s.getThreadGroup()); |
315 |
> |
assertTrue(current.getName().endsWith("thread-1")); |
316 |
|
} catch (SecurityException ok) { |
317 |
|
// Also pass if not allowed to change setting |
318 |
|
} |
340 |
|
Runnable r = new CheckedRunnable() { |
341 |
|
public void realRun() { |
342 |
|
Thread current = Thread.currentThread(); |
343 |
< |
assertTrue(!current.isDaemon()); |
343 |
> |
assertFalse(current.isDaemon()); |
344 |
|
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
348 |
– |
ThreadGroup g = current.getThreadGroup(); |
345 |
|
SecurityManager s = System.getSecurityManager(); |
346 |
< |
if (s != null) |
347 |
< |
assertTrue(g == s.getThreadGroup()); |
348 |
< |
else |
353 |
< |
assertTrue(g == egroup); |
354 |
< |
String name = current.getName(); |
355 |
< |
assertTrue(name.endsWith("thread-1")); |
346 |
> |
assertSame(current.getThreadGroup(), |
347 |
> |
(s == null) ? egroup : s.getThreadGroup()); |
348 |
> |
assertTrue(current.getName().endsWith("thread-1")); |
349 |
|
assertSame(thisccl, current.getContextClassLoader()); |
350 |
|
assertEquals(thisacc, AccessController.getContext()); |
351 |
|
done.countDown(); |
586 |
|
} catch (NullPointerException success) {} |
587 |
|
} |
588 |
|
|
589 |
+ |
/** |
590 |
+ |
* callable(runnable, x).toString() contains toString of wrapped task |
591 |
+ |
*/ |
592 |
+ |
public void testCallable_withResult_toString() { |
593 |
+ |
if (testImplementationDetails) { |
594 |
+ |
Runnable r = () -> {}; |
595 |
+ |
Callable<String> c = Executors.callable(r, ""); |
596 |
+ |
assertEquals( |
597 |
+ |
identityString(c) + "[Wrapped task = " + r.toString() + "]", |
598 |
+ |
c.toString()); |
599 |
+ |
} |
600 |
+ |
} |
601 |
+ |
|
602 |
+ |
/** |
603 |
+ |
* callable(runnable).toString() contains toString of wrapped task |
604 |
+ |
*/ |
605 |
+ |
public void testCallable_toString() { |
606 |
+ |
if (testImplementationDetails) { |
607 |
+ |
Runnable r = () -> {}; |
608 |
+ |
Callable<Object> c = Executors.callable(r); |
609 |
+ |
assertEquals( |
610 |
+ |
identityString(c) + "[Wrapped task = " + r.toString() + "]", |
611 |
+ |
c.toString()); |
612 |
+ |
} |
613 |
+ |
} |
614 |
+ |
|
615 |
+ |
/** |
616 |
+ |
* privilegedCallable(callable).toString() contains toString of wrapped task |
617 |
+ |
*/ |
618 |
+ |
public void testPrivilegedCallable_toString() { |
619 |
+ |
if (testImplementationDetails) { |
620 |
+ |
Callable<String> c = () -> ""; |
621 |
+ |
Callable<String> priv = Executors.privilegedCallable(c); |
622 |
+ |
assertEquals( |
623 |
+ |
identityString(priv) + "[Wrapped task = " + c.toString() + "]", |
624 |
+ |
priv.toString()); |
625 |
+ |
} |
626 |
+ |
} |
627 |
+ |
|
628 |
+ |
/** |
629 |
+ |
* privilegedCallableUsingCurrentClassLoader(callable).toString() |
630 |
+ |
* contains toString of wrapped task |
631 |
+ |
*/ |
632 |
+ |
public void testPrivilegedCallableUsingCurrentClassLoader_toString() { |
633 |
+ |
if (testImplementationDetails) { |
634 |
+ |
Callable<String> c = () -> ""; |
635 |
+ |
Callable<String> priv = Executors.privilegedCallableUsingCurrentClassLoader(c); |
636 |
+ |
assertEquals( |
637 |
+ |
identityString(priv) + "[Wrapped task = " + c.toString() + "]", |
638 |
+ |
priv.toString()); |
639 |
+ |
} |
640 |
+ |
} |
641 |
|
} |