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; |
28 |
|
import java.util.concurrent.atomic.AtomicInteger; |
29 |
|
import java.util.concurrent.locks.ReentrantLock; |
30 |
|
|
30 |
– |
import junit.framework.AssertionFailedError; |
31 |
|
import junit.framework.Test; |
32 |
|
import junit.framework.TestSuite; |
33 |
|
|
240 |
|
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); |
241 |
|
assertFalse(p.awaitTermination(-1L, NANOSECONDS)); |
242 |
|
assertFalse(p.awaitTermination(-1L, MILLISECONDS)); |
243 |
< |
assertFalse(p.awaitTermination(0L, NANOSECONDS)); |
244 |
< |
assertFalse(p.awaitTermination(0L, MILLISECONDS)); |
243 |
> |
assertFalse(p.awaitTermination(randomExpiredTimeout(), |
244 |
> |
randomTimeUnit())); |
245 |
|
long timeoutNanos = 999999L; |
246 |
|
long startTime = System.nanoTime(); |
247 |
|
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); |
303 |
|
p.getFactory()); |
304 |
|
while (! p.isQuiescent()) { |
305 |
|
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
306 |
< |
throw new AssertionFailedError("timed out"); |
306 |
> |
throw new AssertionError("timed out"); |
307 |
|
assertFalse(p.getAsyncMode()); |
308 |
|
assertFalse(p.isShutdown()); |
309 |
|
assertFalse(p.isTerminating()); |
422 |
|
done.set(true); |
423 |
|
}}); |
424 |
|
assertNull(future.get()); |
425 |
< |
assertNull(future.get(0, MILLISECONDS)); |
425 |
> |
assertNull(future.get(randomExpiredTimeout(), randomTimeUnit())); |
426 |
|
assertTrue(done.get()); |
427 |
|
assertTrue(future.isDone()); |
428 |
|
assertFalse(future.isCancelled()); |
703 |
|
} |
704 |
|
|
705 |
|
/** |
706 |
< |
* invokeAll(empty collection) returns empty collection |
706 |
> |
* invokeAll(empty collection) returns empty list |
707 |
|
*/ |
708 |
|
public void testInvokeAll2() throws InterruptedException { |
709 |
|
ExecutorService e = new ForkJoinPool(1); |
710 |
+ |
final Collection<Callable<String>> emptyCollection |
711 |
+ |
= Collections.emptyList(); |
712 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
713 |
< |
List<Future<String>> r |
712 |
< |
= e.invokeAll(new ArrayList<Callable<String>>()); |
713 |
> |
List<Future<String>> r = e.invokeAll(emptyCollection); |
714 |
|
assertTrue(r.isEmpty()); |
715 |
|
} |
716 |
|
} |
774 |
|
ExecutorService e = new ForkJoinPool(1); |
775 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
776 |
|
try { |
777 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
777 |
> |
e.invokeAny(null, randomTimeout(), randomTimeUnit()); |
778 |
|
shouldThrow(); |
779 |
|
} catch (NullPointerException success) {} |
780 |
|
} |
789 |
|
List<Callable<String>> l = new ArrayList<>(); |
790 |
|
l.add(new StringTask()); |
791 |
|
try { |
792 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
792 |
> |
e.invokeAny(l, randomTimeout(), null); |
793 |
|
shouldThrow(); |
794 |
|
} catch (NullPointerException success) {} |
795 |
|
} |
803 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
804 |
|
try { |
805 |
|
e.invokeAny(new ArrayList<Callable<String>>(), |
806 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
806 |
> |
randomTimeout(), randomTimeUnit()); |
807 |
|
shouldThrow(); |
808 |
|
} catch (IllegalArgumentException success) {} |
809 |
|
} |
820 |
|
l.add(latchAwaitingStringTask(latch)); |
821 |
|
l.add(null); |
822 |
|
try { |
823 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
823 |
> |
e.invokeAny(l, randomTimeout(), randomTimeUnit()); |
824 |
|
shouldThrow(); |
825 |
|
} catch (NullPointerException success) {} |
826 |
|
latch.countDown(); |
869 |
|
ExecutorService e = new ForkJoinPool(1); |
870 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
871 |
|
try { |
872 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
872 |
> |
e.invokeAll(null, randomTimeout(), randomTimeUnit()); |
873 |
|
shouldThrow(); |
874 |
|
} catch (NullPointerException success) {} |
875 |
|
} |
884 |
|
List<Callable<String>> l = new ArrayList<>(); |
885 |
|
l.add(new StringTask()); |
886 |
|
try { |
887 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
887 |
> |
e.invokeAll(l, randomTimeout(), null); |
888 |
|
shouldThrow(); |
889 |
|
} catch (NullPointerException success) {} |
890 |
|
} |
891 |
|
} |
892 |
|
|
893 |
|
/** |
894 |
< |
* timed invokeAll(empty collection) returns empty collection |
894 |
> |
* timed invokeAll(empty collection) returns empty list |
895 |
|
*/ |
896 |
|
public void testTimedInvokeAll2() throws InterruptedException { |
897 |
|
ExecutorService e = new ForkJoinPool(1); |
898 |
+ |
final Collection<Callable<String>> emptyCollection |
899 |
+ |
= Collections.emptyList(); |
900 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
901 |
|
List<Future<String>> r |
902 |
< |
= e.invokeAll(new ArrayList<Callable<String>>(), |
903 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
902 |
> |
= e.invokeAll(emptyCollection, |
903 |
> |
randomTimeout(), randomTimeUnit()); |
904 |
|
assertTrue(r.isEmpty()); |
905 |
|
} |
906 |
|
} |
915 |
|
l.add(new StringTask()); |
916 |
|
l.add(null); |
917 |
|
try { |
918 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
918 |
> |
e.invokeAll(l, randomTimeout(), randomTimeUnit()); |
919 |
|
shouldThrow(); |
920 |
|
} catch (NullPointerException success) {} |
921 |
|
} |