11 |
|
import java.security.PrivilegedExceptionAction; |
12 |
|
import java.util.ArrayList; |
13 |
|
import java.util.Collection; |
14 |
+ |
import java.util.Collections; |
15 |
|
import java.util.List; |
16 |
|
import java.util.concurrent.Callable; |
17 |
|
import java.util.concurrent.CountDownLatch; |
241 |
|
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); |
242 |
|
assertFalse(p.awaitTermination(-1L, NANOSECONDS)); |
243 |
|
assertFalse(p.awaitTermination(-1L, MILLISECONDS)); |
244 |
< |
assertFalse(p.awaitTermination(0L, NANOSECONDS)); |
245 |
< |
assertFalse(p.awaitTermination(0L, MILLISECONDS)); |
244 |
> |
assertFalse(p.awaitTermination(randomExpiredTimeout(), |
245 |
> |
randomTimeUnit())); |
246 |
|
long timeoutNanos = 999999L; |
247 |
|
long startTime = System.nanoTime(); |
248 |
|
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); |
423 |
|
done.set(true); |
424 |
|
}}); |
425 |
|
assertNull(future.get()); |
426 |
< |
assertNull(future.get(0, MILLISECONDS)); |
426 |
> |
assertNull(future.get(randomExpiredTimeout(), randomTimeUnit())); |
427 |
|
assertTrue(done.get()); |
428 |
|
assertTrue(future.isDone()); |
429 |
|
assertFalse(future.isCancelled()); |
704 |
|
} |
705 |
|
|
706 |
|
/** |
707 |
< |
* invokeAll(empty collection) returns empty collection |
707 |
> |
* invokeAll(empty collection) returns empty list |
708 |
|
*/ |
709 |
|
public void testInvokeAll2() throws InterruptedException { |
710 |
|
ExecutorService e = new ForkJoinPool(1); |
711 |
+ |
final Collection<Callable<String>> emptyCollection |
712 |
+ |
= Collections.emptyList(); |
713 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
714 |
< |
List<Future<String>> r |
712 |
< |
= e.invokeAll(new ArrayList<Callable<String>>()); |
714 |
> |
List<Future<String>> r = e.invokeAll(emptyCollection); |
715 |
|
assertTrue(r.isEmpty()); |
716 |
|
} |
717 |
|
} |
775 |
|
ExecutorService e = new ForkJoinPool(1); |
776 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
777 |
|
try { |
778 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
778 |
> |
e.invokeAny(null, randomTimeout(), randomTimeUnit()); |
779 |
|
shouldThrow(); |
780 |
|
} catch (NullPointerException success) {} |
781 |
|
} |
790 |
|
List<Callable<String>> l = new ArrayList<>(); |
791 |
|
l.add(new StringTask()); |
792 |
|
try { |
793 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
793 |
> |
e.invokeAny(l, randomTimeout(), null); |
794 |
|
shouldThrow(); |
795 |
|
} catch (NullPointerException success) {} |
796 |
|
} |
804 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
805 |
|
try { |
806 |
|
e.invokeAny(new ArrayList<Callable<String>>(), |
807 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
807 |
> |
randomTimeout(), randomTimeUnit()); |
808 |
|
shouldThrow(); |
809 |
|
} catch (IllegalArgumentException success) {} |
810 |
|
} |
821 |
|
l.add(latchAwaitingStringTask(latch)); |
822 |
|
l.add(null); |
823 |
|
try { |
824 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
824 |
> |
e.invokeAny(l, randomTimeout(), randomTimeUnit()); |
825 |
|
shouldThrow(); |
826 |
|
} catch (NullPointerException success) {} |
827 |
|
latch.countDown(); |
870 |
|
ExecutorService e = new ForkJoinPool(1); |
871 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
872 |
|
try { |
873 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
873 |
> |
e.invokeAll(null, randomTimeout(), randomTimeUnit()); |
874 |
|
shouldThrow(); |
875 |
|
} catch (NullPointerException success) {} |
876 |
|
} |
885 |
|
List<Callable<String>> l = new ArrayList<>(); |
886 |
|
l.add(new StringTask()); |
887 |
|
try { |
888 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
888 |
> |
e.invokeAll(l, randomTimeout(), null); |
889 |
|
shouldThrow(); |
890 |
|
} catch (NullPointerException success) {} |
891 |
|
} |
892 |
|
} |
893 |
|
|
894 |
|
/** |
895 |
< |
* timed invokeAll(empty collection) returns empty collection |
895 |
> |
* timed invokeAll(empty collection) returns empty list |
896 |
|
*/ |
897 |
|
public void testTimedInvokeAll2() throws InterruptedException { |
898 |
|
ExecutorService e = new ForkJoinPool(1); |
899 |
+ |
final Collection<Callable<String>> emptyCollection |
900 |
+ |
= Collections.emptyList(); |
901 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
902 |
|
List<Future<String>> r |
903 |
< |
= e.invokeAll(new ArrayList<Callable<String>>(), |
904 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
903 |
> |
= e.invokeAll(emptyCollection, |
904 |
> |
randomTimeout(), randomTimeUnit()); |
905 |
|
assertTrue(r.isEmpty()); |
906 |
|
} |
907 |
|
} |
916 |
|
l.add(new StringTask()); |
917 |
|
l.add(null); |
918 |
|
try { |
919 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
919 |
> |
e.invokeAll(l, randomTimeout(), randomTimeUnit()); |
920 |
|
shouldThrow(); |
921 |
|
} catch (NullPointerException success) {} |
922 |
|
} |