11 |
|
import java.security.PrivilegedAction; |
12 |
|
import java.security.PrivilegedExceptionAction; |
13 |
|
import java.util.ArrayList; |
14 |
+ |
import java.util.Collection; |
15 |
|
import java.util.Collections; |
16 |
|
import java.util.List; |
17 |
|
import java.util.concurrent.AbstractExecutorService; |
250 |
|
} |
251 |
|
|
252 |
|
/** |
253 |
< |
* invokeAny(empty collection) throws IAE |
253 |
> |
* invokeAny(empty collection) throws IllegalArgumentException |
254 |
|
*/ |
255 |
|
public void testInvokeAny2() throws Exception { |
256 |
|
final ExecutorService e = new DirectExecutorService(); |
257 |
+ |
final Collection<Callable<String>> emptyCollection |
258 |
+ |
= Collections.emptyList(); |
259 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
260 |
|
try { |
261 |
< |
e.invokeAny(new ArrayList<Callable<String>>()); |
261 |
> |
e.invokeAny(emptyCollection); |
262 |
|
shouldThrow(); |
263 |
|
} catch (IllegalArgumentException success) {} |
264 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
/** |
329 |
< |
* invokeAll(empty collection) returns empty collection |
329 |
> |
* invokeAll(empty collection) returns empty list |
330 |
|
*/ |
331 |
|
public void testInvokeAll2() throws InterruptedException { |
332 |
|
final ExecutorService e = new DirectExecutorService(); |
333 |
+ |
final Collection<Callable<String>> emptyCollection |
334 |
+ |
= Collections.emptyList(); |
335 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
336 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); |
336 |
> |
List<Future<String>> r = e.invokeAll(emptyCollection); |
337 |
|
assertTrue(r.isEmpty()); |
338 |
|
} |
339 |
|
} |
396 |
|
final ExecutorService e = new DirectExecutorService(); |
397 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
398 |
|
try { |
399 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
399 |
> |
e.invokeAny(null, randomTimeout(), randomTimeUnit()); |
400 |
|
shouldThrow(); |
401 |
|
} catch (NullPointerException success) {} |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
|
/** |
406 |
< |
* timed invokeAny(null time unit) throws NPE |
406 |
> |
* timed invokeAny(null time unit) throws NullPointerException |
407 |
|
*/ |
408 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
409 |
|
final ExecutorService e = new DirectExecutorService(); |
411 |
|
List<Callable<String>> l = new ArrayList<>(); |
412 |
|
l.add(new StringTask()); |
413 |
|
try { |
414 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
414 |
> |
e.invokeAny(l, randomTimeout(), null); |
415 |
|
shouldThrow(); |
416 |
|
} catch (NullPointerException success) {} |
417 |
|
} |
418 |
|
} |
419 |
|
|
420 |
|
/** |
421 |
< |
* timed invokeAny(empty collection) throws IAE |
421 |
> |
* timed invokeAny(empty collection) throws IllegalArgumentException |
422 |
|
*/ |
423 |
|
public void testTimedInvokeAny2() throws Exception { |
424 |
|
final ExecutorService e = new DirectExecutorService(); |
425 |
+ |
final Collection<Callable<String>> emptyCollection |
426 |
+ |
= Collections.emptyList(); |
427 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
428 |
|
try { |
429 |
< |
e.invokeAny(new ArrayList<Callable<String>>(), |
423 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
429 |
> |
e.invokeAny(emptyCollection, randomTimeout(), randomTimeUnit()); |
430 |
|
shouldThrow(); |
431 |
|
} catch (IllegalArgumentException success) {} |
432 |
|
} |
443 |
|
public Long call() { throw new ArithmeticException(); }}); |
444 |
|
l.add(null); |
445 |
|
try { |
446 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
446 |
> |
e.invokeAny(l, randomTimeout(), randomTimeUnit()); |
447 |
|
shouldThrow(); |
448 |
|
} catch (NullPointerException success) {} |
449 |
|
} |
485 |
|
} |
486 |
|
|
487 |
|
/** |
488 |
< |
* timed invokeAll(null) throws NPE |
488 |
> |
* timed invokeAll(null) throws NullPointerException |
489 |
|
*/ |
490 |
|
public void testTimedInvokeAll1() throws InterruptedException { |
491 |
|
final ExecutorService e = new DirectExecutorService(); |
492 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
493 |
|
try { |
494 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
494 |
> |
e.invokeAll(null, randomTimeout(), randomTimeUnit()); |
495 |
|
shouldThrow(); |
496 |
|
} catch (NullPointerException success) {} |
497 |
|
} |
506 |
|
List<Callable<String>> l = new ArrayList<>(); |
507 |
|
l.add(new StringTask()); |
508 |
|
try { |
509 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
509 |
> |
e.invokeAll(l, randomTimeout(), null); |
510 |
|
shouldThrow(); |
511 |
|
} catch (NullPointerException success) {} |
512 |
|
} |
513 |
|
} |
514 |
|
|
515 |
|
/** |
516 |
< |
* timed invokeAll(empty collection) returns empty collection |
516 |
> |
* timed invokeAll(empty collection) returns empty list |
517 |
|
*/ |
518 |
|
public void testTimedInvokeAll2() throws InterruptedException { |
519 |
|
final ExecutorService e = new DirectExecutorService(); |
520 |
+ |
final Collection<Callable<String>> emptyCollection |
521 |
+ |
= Collections.emptyList(); |
522 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
523 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
523 |
> |
List<Future<String>> r = |
524 |
> |
e.invokeAll(emptyCollection, randomTimeout(), randomTimeUnit()); |
525 |
|
assertTrue(r.isEmpty()); |
526 |
|
} |
527 |
|
} |
528 |
|
|
529 |
|
/** |
530 |
< |
* timed invokeAll(c) throws NPE if c has null elements |
530 |
> |
* timed invokeAll(c) throws NullPointerException if c has null elements |
531 |
|
*/ |
532 |
|
public void testTimedInvokeAll3() throws InterruptedException { |
533 |
|
final ExecutorService e = new DirectExecutorService(); |
536 |
|
l.add(new StringTask()); |
537 |
|
l.add(null); |
538 |
|
try { |
539 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
539 |
> |
e.invokeAll(l, randomTimeout(), randomTimeUnit()); |
540 |
|
shouldThrow(); |
541 |
|
} catch (NullPointerException success) {} |
542 |
|
} |