63 |
|
*/ |
64 |
|
public void testNewCachedThreadPool3() { |
65 |
|
try { |
66 |
< |
ExecutorService e = Executors.newCachedThreadPool(null); |
66 |
> |
ExecutorService unused = Executors.newCachedThreadPool(null); |
67 |
|
shouldThrow(); |
68 |
|
} catch (NullPointerException success) {} |
69 |
|
} |
97 |
|
*/ |
98 |
|
public void testNewSingleThreadExecutor3() { |
99 |
|
try { |
100 |
< |
ExecutorService e = Executors.newSingleThreadExecutor(null); |
100 |
> |
ExecutorService unused = Executors.newSingleThreadExecutor(null); |
101 |
|
shouldThrow(); |
102 |
|
} catch (NullPointerException success) {} |
103 |
|
} |
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 { |
148 |
< |
ExecutorService e = Executors.newFixedThreadPool(2, null); |
148 |
> |
ExecutorService unused = Executors.newFixedThreadPool(2, null); |
149 |
|
shouldThrow(); |
150 |
|
} catch (NullPointerException success) {} |
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 { |
158 |
< |
ExecutorService e = Executors.newFixedThreadPool(0); |
158 |
> |
ExecutorService unused = Executors.newFixedThreadPool(0); |
159 |
|
shouldThrow(); |
160 |
|
} catch (IllegalArgumentException success) {} |
161 |
|
} |
177 |
|
*/ |
178 |
|
public void testUnconfigurableExecutorServiceNPE() { |
179 |
|
try { |
180 |
< |
ExecutorService e = Executors.unconfigurableExecutorService(null); |
180 |
> |
ExecutorService unused = |
181 |
> |
Executors.unconfigurableExecutorService(null); |
182 |
|
shouldThrow(); |
183 |
|
} catch (NullPointerException success) {} |
184 |
|
} |
188 |
|
*/ |
189 |
|
public void testUnconfigurableScheduledExecutorServiceNPE() { |
190 |
|
try { |
191 |
< |
ExecutorService e = Executors.unconfigurableScheduledExecutorService(null); |
191 |
> |
ExecutorService unused = |
192 |
> |
Executors.unconfigurableScheduledExecutorService(null); |
193 |
|
shouldThrow(); |
194 |
|
} catch (NullPointerException success) {} |
195 |
|
} |
279 |
|
Executors.newScheduledThreadPool(2), |
280 |
|
}; |
281 |
|
|
282 |
< |
final Runnable sleeper = new CheckedInterruptedRunnable() { |
282 |
> |
final Runnable sleeper = new CheckedRunnable() { |
283 |
|
public void realRun() throws InterruptedException { |
284 |
< |
delay(LONG_DELAY_MS); |
284 |
> |
try { |
285 |
> |
delay(LONG_DELAY_MS); |
286 |
> |
} catch(InterruptedException OK) { |
287 |
> |
} |
288 |
|
}}; |
289 |
|
|
290 |
|
List<Thread> threads = new ArrayList<>(); |
298 |
|
for (Thread thread : threads) |
299 |
|
awaitTermination(thread); |
300 |
|
for (ExecutorService executor : executors) |
301 |
+ |
executor.shutdownNow(); // assumes shutdownNow interrupts threads |
302 |
+ |
for (ExecutorService executor : executors) |
303 |
|
joinPool(executor); |
304 |
|
} |
305 |
|
|
558 |
|
*/ |
559 |
|
public void testCallableNPE1() { |
560 |
|
try { |
561 |
< |
Callable c = Executors.callable((Runnable) null); |
561 |
> |
Callable unused = Executors.callable((Runnable) null); |
562 |
|
shouldThrow(); |
563 |
|
} catch (NullPointerException success) {} |
564 |
|
} |
568 |
|
*/ |
569 |
|
public void testCallableNPE2() { |
570 |
|
try { |
571 |
< |
Callable c = Executors.callable((Runnable) null, one); |
571 |
> |
Callable unused = Executors.callable((Runnable) null, one); |
572 |
|
shouldThrow(); |
573 |
|
} catch (NullPointerException success) {} |
574 |
|
} |
578 |
|
*/ |
579 |
|
public void testCallableNPE3() { |
580 |
|
try { |
581 |
< |
Callable c = Executors.callable((PrivilegedAction) null); |
581 |
> |
Callable unused = Executors.callable((PrivilegedAction) null); |
582 |
|
shouldThrow(); |
583 |
|
} catch (NullPointerException success) {} |
584 |
|
} |
588 |
|
*/ |
589 |
|
public void testCallableNPE4() { |
590 |
|
try { |
591 |
< |
Callable c = Executors.callable((PrivilegedExceptionAction) null); |
591 |
> |
Callable unused = Executors.callable((PrivilegedExceptionAction) null); |
592 |
|
shouldThrow(); |
593 |
|
} catch (NullPointerException success) {} |
594 |
|
} |
595 |
|
|
596 |
+ |
/** |
597 |
+ |
* callable(runnable, x).toString() contains toString of wrapped task |
598 |
+ |
*/ |
599 |
+ |
public void testCallable_withResult_toString() { |
600 |
+ |
if (testImplementationDetails) { |
601 |
+ |
Runnable r = () -> {}; |
602 |
+ |
Callable<String> c = Executors.callable(r, ""); |
603 |
+ |
assertEquals( |
604 |
+ |
identityString(c) + "[Wrapped task = " + r.toString() + "]", |
605 |
+ |
c.toString()); |
606 |
+ |
} |
607 |
+ |
} |
608 |
+ |
|
609 |
+ |
/** |
610 |
+ |
* callable(runnable).toString() contains toString of wrapped task |
611 |
+ |
*/ |
612 |
+ |
public void testCallable_toString() { |
613 |
+ |
if (testImplementationDetails) { |
614 |
+ |
Runnable r = () -> {}; |
615 |
+ |
Callable<Object> c = Executors.callable(r); |
616 |
+ |
assertEquals( |
617 |
+ |
identityString(c) + "[Wrapped task = " + r.toString() + "]", |
618 |
+ |
c.toString()); |
619 |
+ |
} |
620 |
+ |
} |
621 |
+ |
|
622 |
+ |
/** |
623 |
+ |
* privilegedCallable(callable).toString() contains toString of wrapped task |
624 |
+ |
*/ |
625 |
+ |
public void testPrivilegedCallable_toString() { |
626 |
+ |
if (testImplementationDetails) { |
627 |
+ |
Callable<String> c = () -> ""; |
628 |
+ |
Callable<String> priv = Executors.privilegedCallable(c); |
629 |
+ |
assertEquals( |
630 |
+ |
identityString(priv) + "[Wrapped task = " + c.toString() + "]", |
631 |
+ |
priv.toString()); |
632 |
+ |
} |
633 |
+ |
} |
634 |
+ |
|
635 |
+ |
/** |
636 |
+ |
* privilegedCallableUsingCurrentClassLoader(callable).toString() |
637 |
+ |
* contains toString of wrapped task |
638 |
+ |
*/ |
639 |
+ |
public void testPrivilegedCallableUsingCurrentClassLoader_toString() { |
640 |
+ |
if (testImplementationDetails) { |
641 |
+ |
Callable<String> c = () -> ""; |
642 |
+ |
Callable<String> priv = Executors.privilegedCallableUsingCurrentClassLoader(c); |
643 |
+ |
assertEquals( |
644 |
+ |
identityString(priv) + "[Wrapped task = " + c.toString() + "]", |
645 |
+ |
priv.toString()); |
646 |
+ |
} |
647 |
+ |
} |
648 |
|
} |