10 |
|
import junit.framework.*; |
11 |
|
import java.util.*; |
12 |
|
import java.util.concurrent.*; |
13 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
14 |
|
import java.math.BigInteger; |
15 |
|
import java.security.*; |
16 |
|
|
488 |
|
public void testTimedInvokeAny1() throws Exception { |
489 |
|
ExecutorService e = new DirectExecutorService(); |
490 |
|
try { |
491 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
491 |
> |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
492 |
|
shouldThrow(); |
493 |
|
} catch (NullPointerException success) { |
494 |
|
} finally { |
518 |
|
public void testTimedInvokeAny2() throws Exception { |
519 |
|
ExecutorService e = new DirectExecutorService(); |
520 |
|
try { |
521 |
< |
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
521 |
> |
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
522 |
|
shouldThrow(); |
523 |
|
} catch (IllegalArgumentException success) { |
524 |
|
} finally { |
538 |
|
l.add(new Callable<Integer>() { |
539 |
|
public Integer call() { return 5/0; }}); |
540 |
|
l.add(null); |
541 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
541 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
542 |
|
shouldThrow(); |
543 |
|
} catch (NullPointerException success) { |
544 |
|
} finally { |
555 |
|
try { |
556 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
557 |
|
l.add(new NPETask()); |
558 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
558 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
559 |
|
shouldThrow(); |
560 |
|
} catch (ExecutionException success) { |
561 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
573 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
574 |
|
l.add(new StringTask()); |
575 |
|
l.add(new StringTask()); |
576 |
< |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
576 |
> |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
577 |
|
assertSame(TEST_STRING, result); |
578 |
|
} finally { |
579 |
|
joinPool(e); |
586 |
|
public void testTimedInvokeAll1() throws InterruptedException { |
587 |
|
ExecutorService e = new DirectExecutorService(); |
588 |
|
try { |
589 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
589 |
> |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
590 |
|
shouldThrow(); |
591 |
|
} catch (NullPointerException success) { |
592 |
|
} finally { |
616 |
|
public void testTimedInvokeAll2() throws InterruptedException { |
617 |
|
ExecutorService e = new DirectExecutorService(); |
618 |
|
try { |
619 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
619 |
> |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
620 |
|
assertTrue(r.isEmpty()); |
621 |
|
} finally { |
622 |
|
joinPool(e); |
632 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
633 |
|
l.add(new StringTask()); |
634 |
|
l.add(null); |
635 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
635 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
636 |
|
shouldThrow(); |
637 |
|
} catch (NullPointerException success) { |
638 |
|
} finally { |
648 |
|
try { |
649 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
650 |
|
l.add(new NPETask()); |
651 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
651 |
> |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
652 |
|
assertEquals(1, result.size()); |
653 |
|
for (Future<String> future : result) { |
654 |
|
try { |
671 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
672 |
|
l.add(new StringTask()); |
673 |
|
l.add(new StringTask()); |
674 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
674 |
> |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
675 |
|
assertEquals(2, result.size()); |
676 |
|
for (Future<String> future : result) |
677 |
|
assertSame(TEST_STRING, future.get()); |
690 |
|
l.add(new StringTask()); |
691 |
|
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
692 |
|
l.add(new StringTask()); |
693 |
< |
List<Future<String>> result = e.invokeAll(l, SMALL_DELAY_MS, TimeUnit.MILLISECONDS); |
693 |
> |
List<Future<String>> result = e.invokeAll(l, SMALL_DELAY_MS, MILLISECONDS); |
694 |
|
assertEquals(3, result.size()); |
695 |
|
Iterator<Future<String>> it = result.iterator(); |
696 |
|
Future<String> f1 = it.next(); |