10 |
|
import java.util.List; |
11 |
|
import java.util.concurrent.Executors; |
12 |
|
import java.util.concurrent.ExecutorService; |
13 |
– |
import java.util.concurrent.AbstractExecutorService; |
13 |
|
import java.util.concurrent.CountDownLatch; |
14 |
|
import java.util.concurrent.Callable; |
15 |
|
import java.util.concurrent.Future; |
16 |
|
import java.util.concurrent.ExecutionException; |
18 |
– |
import java.util.concurrent.CancellationException; |
17 |
|
import java.util.concurrent.RejectedExecutionException; |
18 |
|
import java.util.concurrent.ForkJoinPool; |
19 |
|
import java.util.concurrent.ForkJoinTask; |
20 |
|
import java.util.concurrent.ForkJoinWorkerThread; |
21 |
|
import java.util.concurrent.RecursiveTask; |
24 |
– |
import java.util.concurrent.TimeUnit; |
22 |
|
import java.util.concurrent.atomic.AtomicBoolean; |
23 |
|
import java.util.concurrent.locks.ReentrantLock; |
24 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
25 |
< |
import java.security.AccessControlException; |
29 |
< |
import java.security.Policy; |
25 |
> |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
26 |
|
import java.security.PrivilegedAction; |
27 |
|
import java.security.PrivilegedExceptionAction; |
28 |
|
|
35 |
|
return new TestSuite(ForkJoinPoolTest.class); |
36 |
|
} |
37 |
|
|
38 |
< |
/** |
38 |
> |
/* |
39 |
|
* Testing coverage notes: |
40 |
|
* |
41 |
|
* 1. shutdown and related methods are tested via super.joinPool. |
103 |
|
static final class FibTask extends RecursiveTask<Integer> { |
104 |
|
final int number; |
105 |
|
FibTask(int n) { number = n; } |
106 |
< |
public Integer compute() { |
106 |
> |
protected Integer compute() { |
107 |
|
int n = number; |
108 |
|
if (n <= 1) |
109 |
|
return n; |
131 |
|
this.locker = locker; |
132 |
|
this.lock = lock; |
133 |
|
} |
134 |
< |
public Integer compute() { |
134 |
> |
protected Integer compute() { |
135 |
|
int n; |
136 |
|
LockingFibTask f1 = null; |
137 |
|
LockingFibTask f2 = null; |
222 |
|
} |
223 |
|
|
224 |
|
/** |
225 |
+ |
* awaitTermination on a non-shutdown pool times out |
226 |
+ |
*/ |
227 |
+ |
public void testAwaitTermination_timesOut() throws InterruptedException { |
228 |
+ |
ForkJoinPool p = new ForkJoinPool(1); |
229 |
+ |
assertFalse(p.isTerminated()); |
230 |
+ |
assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS)); |
231 |
+ |
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); |
232 |
+ |
assertFalse(p.awaitTermination(-1L, NANOSECONDS)); |
233 |
+ |
assertFalse(p.awaitTermination(-1L, MILLISECONDS)); |
234 |
+ |
assertFalse(p.awaitTermination(0L, NANOSECONDS)); |
235 |
+ |
assertFalse(p.awaitTermination(0L, MILLISECONDS)); |
236 |
+ |
long timeoutNanos = 999999L; |
237 |
+ |
long startTime = System.nanoTime(); |
238 |
+ |
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); |
239 |
+ |
assertTrue(System.nanoTime() - startTime >= timeoutNanos); |
240 |
+ |
assertFalse(p.isTerminated()); |
241 |
+ |
startTime = System.nanoTime(); |
242 |
+ |
long timeoutMillis = timeoutMillis(); |
243 |
+ |
assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS)); |
244 |
+ |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
245 |
+ |
assertFalse(p.isTerminated()); |
246 |
+ |
p.shutdown(); |
247 |
+ |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
248 |
+ |
assertTrue(p.isTerminated()); |
249 |
+ |
} |
250 |
+ |
|
251 |
+ |
/** |
252 |
|
* setUncaughtExceptionHandler changes handler for uncaught exceptions. |
253 |
|
* |
254 |
|
* Additionally tests: Overriding ForkJoinWorkerThread.onStart |
414 |
|
ExecutorService e = new ForkJoinPool(1); |
415 |
|
try { |
416 |
|
final AtomicBoolean done = new AtomicBoolean(false); |
417 |
< |
CheckedRunnable task = new CheckedRunnable() { |
417 |
> |
Future<?> future = e.submit(new CheckedRunnable() { |
418 |
|
public void realRun() { |
419 |
|
done.set(true); |
420 |
< |
}}; |
398 |
< |
Future<?> future = e.submit(task); |
420 |
> |
}}); |
421 |
|
assertNull(future.get()); |
422 |
|
assertNull(future.get(0, MILLISECONDS)); |
423 |
|
assertTrue(done.get()); |