35394
|
1 |
/*
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
*
|
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
|
6 |
* published by the Free Software Foundation.
|
|
7 |
*
|
|
8 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
9 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
10 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
11 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
12 |
* accompanied this code).
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License version
|
|
15 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
16 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
17 |
*
|
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
19 |
* or visit www.oracle.com if you need additional information or have any
|
|
20 |
* questions.
|
|
21 |
*/
|
|
22 |
|
|
23 |
/*
|
|
24 |
* This file is available under and governed by the GNU General Public
|
|
25 |
* License version 2 only, as published by the Free Software Foundation.
|
|
26 |
* However, the following notice accompanied the original version of this
|
|
27 |
* file:
|
|
28 |
*
|
|
29 |
* Written by Doug Lea with assistance from members of JCP JSR-166
|
|
30 |
* Expert Group and released to the public domain, as explained at
|
|
31 |
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
32 |
*/
|
|
33 |
|
|
34 |
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
|
35 |
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
|
36 |
|
|
37 |
import java.security.PrivilegedAction;
|
|
38 |
import java.security.PrivilegedExceptionAction;
|
|
39 |
import java.util.ArrayList;
|
|
40 |
import java.util.Collection;
|
|
41 |
import java.util.List;
|
|
42 |
import java.util.concurrent.Callable;
|
|
43 |
import java.util.concurrent.CountDownLatch;
|
|
44 |
import java.util.concurrent.ExecutionException;
|
|
45 |
import java.util.concurrent.Executors;
|
|
46 |
import java.util.concurrent.ExecutorService;
|
|
47 |
import java.util.concurrent.ForkJoinPool;
|
|
48 |
import java.util.concurrent.ForkJoinTask;
|
|
49 |
import java.util.concurrent.ForkJoinWorkerThread;
|
|
50 |
import java.util.concurrent.Future;
|
|
51 |
import java.util.concurrent.RecursiveTask;
|
|
52 |
import java.util.concurrent.RejectedExecutionException;
|
|
53 |
import java.util.concurrent.atomic.AtomicBoolean;
|
|
54 |
import java.util.concurrent.locks.ReentrantLock;
|
|
55 |
|
|
56 |
import junit.framework.AssertionFailedError;
|
|
57 |
import junit.framework.Test;
|
|
58 |
import junit.framework.TestSuite;
|
|
59 |
|
|
60 |
public class ForkJoinPoolTest extends JSR166TestCase {
|
|
61 |
public static void main(String[] args) {
|
|
62 |
main(suite(), args);
|
|
63 |
}
|
|
64 |
|
|
65 |
public static Test suite() {
|
|
66 |
return new TestSuite(ForkJoinPoolTest.class);
|
|
67 |
}
|
|
68 |
|
|
69 |
/*
|
|
70 |
* Testing coverage notes:
|
|
71 |
*
|
|
72 |
* 1. shutdown and related methods are tested via super.joinPool.
|
|
73 |
*
|
|
74 |
* 2. newTaskFor and adapters are tested in submit/invoke tests
|
|
75 |
*
|
|
76 |
* 3. We cannot portably test monitoring methods such as
|
|
77 |
* getStealCount() since they rely ultimately on random task
|
|
78 |
* stealing that may cause tasks not to be stolen/propagated
|
|
79 |
* across threads, especially on uniprocessors.
|
|
80 |
*
|
|
81 |
* 4. There are no independently testable ForkJoinWorkerThread
|
|
82 |
* methods, but they are covered here and in task tests.
|
|
83 |
*/
|
|
84 |
|
|
85 |
// Some classes to test extension and factory methods
|
|
86 |
|
|
87 |
static class MyHandler implements Thread.UncaughtExceptionHandler {
|
|
88 |
volatile int catches = 0;
|
|
89 |
public void uncaughtException(Thread t, Throwable e) {
|
|
90 |
++catches;
|
|
91 |
}
|
|
92 |
}
|
|
93 |
|
|
94 |
static class MyError extends Error {}
|
|
95 |
|
|
96 |
// to test handlers
|
|
97 |
static class FailingFJWSubclass extends ForkJoinWorkerThread {
|
|
98 |
public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
|
|
99 |
protected void onStart() { super.onStart(); throw new MyError(); }
|
|
100 |
}
|
|
101 |
|
|
102 |
static class FailingThreadFactory
|
|
103 |
implements ForkJoinPool.ForkJoinWorkerThreadFactory {
|
|
104 |
volatile int calls = 0;
|
|
105 |
public ForkJoinWorkerThread newThread(ForkJoinPool p) {
|
|
106 |
if (++calls > 1) return null;
|
|
107 |
return new FailingFJWSubclass(p);
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
static class SubFJP extends ForkJoinPool { // to expose protected
|
|
112 |
SubFJP() { super(1); }
|
|
113 |
public int drainTasksTo(Collection<? super ForkJoinTask<?>> c) {
|
|
114 |
return super.drainTasksTo(c);
|
|
115 |
}
|
|
116 |
public ForkJoinTask<?> pollSubmission() {
|
|
117 |
return super.pollSubmission();
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
static class ManagedLocker implements ForkJoinPool.ManagedBlocker {
|
|
122 |
final ReentrantLock lock;
|
|
123 |
boolean hasLock = false;
|
|
124 |
ManagedLocker(ReentrantLock lock) { this.lock = lock; }
|
|
125 |
public boolean block() {
|
|
126 |
if (!hasLock)
|
|
127 |
lock.lock();
|
|
128 |
return true;
|
|
129 |
}
|
|
130 |
public boolean isReleasable() {
|
|
131 |
return hasLock || (hasLock = lock.tryLock());
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
|
135 |
// A simple recursive task for testing
|
|
136 |
static final class FibTask extends RecursiveTask<Integer> {
|
|
137 |
final int number;
|
|
138 |
FibTask(int n) { number = n; }
|
|
139 |
protected Integer compute() {
|
|
140 |
int n = number;
|
|
141 |
if (n <= 1)
|
|
142 |
return n;
|
|
143 |
FibTask f1 = new FibTask(n - 1);
|
|
144 |
f1.fork();
|
|
145 |
return (new FibTask(n - 2)).compute() + f1.join();
|
|
146 |
}
|
|
147 |
}
|
|
148 |
|
|
149 |
// A failing task for testing
|
|
150 |
static final class FailingTask extends ForkJoinTask<Void> {
|
|
151 |
public final Void getRawResult() { return null; }
|
|
152 |
protected final void setRawResult(Void mustBeNull) { }
|
|
153 |
protected final boolean exec() { throw new Error(); }
|
|
154 |
FailingTask() {}
|
|
155 |
}
|
|
156 |
|
|
157 |
// Fib needlessly using locking to test ManagedBlockers
|
|
158 |
static final class LockingFibTask extends RecursiveTask<Integer> {
|
|
159 |
final int number;
|
|
160 |
final ManagedLocker locker;
|
|
161 |
final ReentrantLock lock;
|
|
162 |
LockingFibTask(int n, ManagedLocker locker, ReentrantLock lock) {
|
|
163 |
number = n;
|
|
164 |
this.locker = locker;
|
|
165 |
this.lock = lock;
|
|
166 |
}
|
|
167 |
protected Integer compute() {
|
|
168 |
int n;
|
|
169 |
LockingFibTask f1 = null;
|
|
170 |
LockingFibTask f2 = null;
|
|
171 |
locker.block();
|
|
172 |
n = number;
|
|
173 |
if (n > 1) {
|
|
174 |
f1 = new LockingFibTask(n - 1, locker, lock);
|
|
175 |
f2 = new LockingFibTask(n - 2, locker, lock);
|
|
176 |
}
|
|
177 |
lock.unlock();
|
|
178 |
if (n <= 1)
|
|
179 |
return n;
|
|
180 |
else {
|
|
181 |
f1.fork();
|
|
182 |
return f2.compute() + f1.join();
|
|
183 |
}
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Successfully constructed pool reports default factory,
|
|
189 |
* parallelism and async mode policies, no active threads or
|
|
190 |
* tasks, and quiescent running state.
|
|
191 |
*/
|
|
192 |
public void testDefaultInitialState() {
|
|
193 |
ForkJoinPool p = new ForkJoinPool(1);
|
|
194 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
195 |
assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
|
|
196 |
p.getFactory());
|
|
197 |
assertFalse(p.getAsyncMode());
|
|
198 |
assertEquals(0, p.getActiveThreadCount());
|
|
199 |
assertEquals(0, p.getStealCount());
|
|
200 |
assertEquals(0, p.getQueuedTaskCount());
|
|
201 |
assertEquals(0, p.getQueuedSubmissionCount());
|
|
202 |
assertFalse(p.hasQueuedSubmissions());
|
|
203 |
assertFalse(p.isShutdown());
|
|
204 |
assertFalse(p.isTerminating());
|
|
205 |
assertFalse(p.isTerminated());
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
/**
|
|
210 |
* Constructor throws if size argument is less than zero
|
|
211 |
*/
|
|
212 |
public void testConstructor1() {
|
|
213 |
try {
|
|
214 |
new ForkJoinPool(-1);
|
|
215 |
shouldThrow();
|
|
216 |
} catch (IllegalArgumentException success) {}
|
|
217 |
}
|
|
218 |
|
|
219 |
/**
|
|
220 |
* Constructor throws if factory argument is null
|
|
221 |
*/
|
|
222 |
public void testConstructor2() {
|
|
223 |
try {
|
|
224 |
new ForkJoinPool(1, null, null, false);
|
|
225 |
shouldThrow();
|
|
226 |
} catch (NullPointerException success) {}
|
|
227 |
}
|
|
228 |
|
|
229 |
/**
|
|
230 |
* getParallelism returns size set in constructor
|
|
231 |
*/
|
|
232 |
public void testGetParallelism() {
|
|
233 |
ForkJoinPool p = new ForkJoinPool(1);
|
|
234 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
235 |
assertEquals(1, p.getParallelism());
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
/**
|
|
240 |
* getPoolSize returns number of started workers.
|
|
241 |
*/
|
|
242 |
public void testGetPoolSize() {
|
|
243 |
final CountDownLatch taskStarted = new CountDownLatch(1);
|
|
244 |
final CountDownLatch done = new CountDownLatch(1);
|
|
245 |
final ForkJoinPool p = new ForkJoinPool(1);
|
|
246 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
247 |
assertEquals(0, p.getActiveThreadCount());
|
|
248 |
final Runnable task = new CheckedRunnable() {
|
|
249 |
public void realRun() throws InterruptedException {
|
|
250 |
taskStarted.countDown();
|
|
251 |
assertEquals(1, p.getPoolSize());
|
|
252 |
assertEquals(1, p.getActiveThreadCount());
|
|
253 |
done.await();
|
|
254 |
}};
|
|
255 |
Future<?> future = p.submit(task);
|
|
256 |
await(taskStarted);
|
|
257 |
assertEquals(1, p.getPoolSize());
|
|
258 |
assertEquals(1, p.getActiveThreadCount());
|
|
259 |
done.countDown();
|
|
260 |
}
|
|
261 |
assertEquals(0, p.getPoolSize());
|
|
262 |
assertEquals(0, p.getActiveThreadCount());
|
|
263 |
}
|
|
264 |
|
|
265 |
/**
|
|
266 |
* awaitTermination on a non-shutdown pool times out
|
|
267 |
*/
|
|
268 |
public void testAwaitTermination_timesOut() throws InterruptedException {
|
|
269 |
ForkJoinPool p = new ForkJoinPool(1);
|
|
270 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
271 |
assertFalse(p.isTerminated());
|
|
272 |
assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
|
|
273 |
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
|
|
274 |
assertFalse(p.awaitTermination(-1L, NANOSECONDS));
|
|
275 |
assertFalse(p.awaitTermination(-1L, MILLISECONDS));
|
|
276 |
assertFalse(p.awaitTermination(0L, NANOSECONDS));
|
|
277 |
assertFalse(p.awaitTermination(0L, MILLISECONDS));
|
|
278 |
long timeoutNanos = 999999L;
|
|
279 |
long startTime = System.nanoTime();
|
|
280 |
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
|
|
281 |
assertTrue(System.nanoTime() - startTime >= timeoutNanos);
|
|
282 |
assertFalse(p.isTerminated());
|
|
283 |
startTime = System.nanoTime();
|
|
284 |
long timeoutMillis = timeoutMillis();
|
|
285 |
assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
|
|
286 |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
|
|
287 |
assertFalse(p.isTerminated());
|
|
288 |
p.shutdown();
|
|
289 |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
|
|
290 |
assertTrue(p.isTerminated());
|
|
291 |
}
|
|
292 |
}
|
|
293 |
|
|
294 |
/**
|
|
295 |
* setUncaughtExceptionHandler changes handler for uncaught exceptions.
|
|
296 |
*
|
|
297 |
* Additionally tests: Overriding ForkJoinWorkerThread.onStart
|
|
298 |
* performs its defined action
|
|
299 |
*/
|
|
300 |
public void testSetUncaughtExceptionHandler() throws InterruptedException {
|
|
301 |
final CountDownLatch uehInvoked = new CountDownLatch(1);
|
|
302 |
final Thread.UncaughtExceptionHandler ueh =
|
|
303 |
new Thread.UncaughtExceptionHandler() {
|
|
304 |
public void uncaughtException(Thread t, Throwable e) {
|
|
305 |
threadAssertTrue(e instanceof MyError);
|
|
306 |
threadAssertTrue(t instanceof FailingFJWSubclass);
|
|
307 |
uehInvoked.countDown();
|
|
308 |
}};
|
|
309 |
ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(),
|
|
310 |
ueh, false);
|
|
311 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
312 |
assertSame(ueh, p.getUncaughtExceptionHandler());
|
|
313 |
try {
|
|
314 |
p.execute(new FibTask(8));
|
|
315 |
await(uehInvoked);
|
|
316 |
} finally {
|
|
317 |
p.shutdownNow(); // failure might have prevented processing task
|
|
318 |
}
|
|
319 |
}
|
|
320 |
}
|
|
321 |
|
|
322 |
/**
|
|
323 |
* After invoking a single task, isQuiescent eventually becomes
|
|
324 |
* true, at which time queues are empty, threads are not active,
|
|
325 |
* the task has completed successfully, and construction
|
|
326 |
* parameters continue to hold
|
|
327 |
*/
|
|
328 |
public void testIsQuiescent() throws Exception {
|
|
329 |
ForkJoinPool p = new ForkJoinPool(2);
|
|
330 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
331 |
assertTrue(p.isQuiescent());
|
|
332 |
long startTime = System.nanoTime();
|
|
333 |
FibTask f = new FibTask(20);
|
|
334 |
p.invoke(f);
|
|
335 |
assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
|
|
336 |
p.getFactory());
|
|
337 |
while (! p.isQuiescent()) {
|
|
338 |
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
|
|
339 |
throw new AssertionFailedError("timed out");
|
|
340 |
assertFalse(p.getAsyncMode());
|
|
341 |
assertFalse(p.isShutdown());
|
|
342 |
assertFalse(p.isTerminating());
|
|
343 |
assertFalse(p.isTerminated());
|
|
344 |
Thread.yield();
|
|
345 |
}
|
|
346 |
|
|
347 |
assertTrue(p.isQuiescent());
|
|
348 |
assertFalse(p.getAsyncMode());
|
|
349 |
assertEquals(0, p.getQueuedTaskCount());
|
|
350 |
assertEquals(0, p.getQueuedSubmissionCount());
|
|
351 |
assertFalse(p.hasQueuedSubmissions());
|
|
352 |
while (p.getActiveThreadCount() != 0
|
|
353 |
&& millisElapsedSince(startTime) < LONG_DELAY_MS)
|
|
354 |
Thread.yield();
|
|
355 |
assertFalse(p.isShutdown());
|
|
356 |
assertFalse(p.isTerminating());
|
|
357 |
assertFalse(p.isTerminated());
|
|
358 |
assertTrue(f.isDone());
|
|
359 |
assertEquals(6765, (int) f.get());
|
|
360 |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|
|
364 |
/**
|
|
365 |
* Completed submit(ForkJoinTask) returns result
|
|
366 |
*/
|
|
367 |
public void testSubmitForkJoinTask() throws Throwable {
|
|
368 |
ForkJoinPool p = new ForkJoinPool(1);
|
|
369 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
370 |
ForkJoinTask<Integer> f = p.submit(new FibTask(8));
|
|
371 |
assertEquals(21, (int) f.get());
|
|
372 |
}
|
|
373 |
}
|
|
374 |
|
|
375 |
/**
|
|
376 |
* A task submitted after shutdown is rejected
|
|
377 |
*/
|
|
378 |
public void testSubmitAfterShutdown() {
|
|
379 |
ForkJoinPool p = new ForkJoinPool(1);
|
|
380 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
381 |
p.shutdown();
|
|
382 |
assertTrue(p.isShutdown());
|
|
383 |
try {
|
|
384 |
ForkJoinTask<Integer> f = p.submit(new FibTask(8));
|
|
385 |
shouldThrow();
|
|
386 |
} catch (RejectedExecutionException success) {}
|
|
387 |
}
|
|
388 |
}
|
|
389 |
|
|
390 |
/**
|
|
391 |
* Pool maintains parallelism when using ManagedBlocker
|
|
392 |
*/
|
|
393 |
public void testBlockingForkJoinTask() throws Throwable {
|
|
394 |
ForkJoinPool p = new ForkJoinPool(4);
|
|
395 |
try {
|
|
396 |
ReentrantLock lock = new ReentrantLock();
|
|
397 |
ManagedLocker locker = new ManagedLocker(lock);
|
|
398 |
ForkJoinTask<Integer> f = new LockingFibTask(20, locker, lock);
|
|
399 |
p.execute(f);
|
|
400 |
assertEquals(6765, (int) f.get());
|
|
401 |
} finally {
|
|
402 |
p.shutdownNow(); // don't wait out shutdown
|
|
403 |
}
|
|
404 |
}
|
|
405 |
|
|
406 |
/**
|
|
407 |
* pollSubmission returns unexecuted submitted task, if present
|
|
408 |
*/
|
|
409 |
public void testPollSubmission() {
|
|
410 |
final CountDownLatch done = new CountDownLatch(1);
|
|
411 |
SubFJP p = new SubFJP();
|
|
412 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
413 |
ForkJoinTask a = p.submit(awaiter(done));
|
|
414 |
ForkJoinTask b = p.submit(awaiter(done));
|
|
415 |
ForkJoinTask c = p.submit(awaiter(done));
|
|
416 |
ForkJoinTask r = p.pollSubmission();
|
|
417 |
assertTrue(r == a || r == b || r == c);
|
|
418 |
assertFalse(r.isDone());
|
|
419 |
done.countDown();
|
|
420 |
}
|
|
421 |
}
|
|
422 |
|
|
423 |
/**
|
|
424 |
* drainTasksTo transfers unexecuted submitted tasks, if present
|
|
425 |
*/
|
|
426 |
public void testDrainTasksTo() {
|
|
427 |
final CountDownLatch done = new CountDownLatch(1);
|
|
428 |
SubFJP p = new SubFJP();
|
|
429 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
430 |
ForkJoinTask a = p.submit(awaiter(done));
|
|
431 |
ForkJoinTask b = p.submit(awaiter(done));
|
|
432 |
ForkJoinTask c = p.submit(awaiter(done));
|
|
433 |
ArrayList<ForkJoinTask> al = new ArrayList();
|
|
434 |
p.drainTasksTo(al);
|
|
435 |
assertTrue(al.size() > 0);
|
|
436 |
for (ForkJoinTask r : al) {
|
|
437 |
assertTrue(r == a || r == b || r == c);
|
|
438 |
assertFalse(r.isDone());
|
|
439 |
}
|
|
440 |
done.countDown();
|
|
441 |
}
|
|
442 |
}
|
|
443 |
|
|
444 |
// FJ Versions of AbstractExecutorService tests
|
|
445 |
|
|
446 |
/**
|
|
447 |
* execute(runnable) runs it to completion
|
|
448 |
*/
|
|
449 |
public void testExecuteRunnable() throws Throwable {
|
|
450 |
ExecutorService e = new ForkJoinPool(1);
|
|
451 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
452 |
final AtomicBoolean done = new AtomicBoolean(false);
|
|
453 |
Future<?> future = e.submit(new CheckedRunnable() {
|
|
454 |
public void realRun() {
|
|
455 |
done.set(true);
|
|
456 |
}});
|
|
457 |
assertNull(future.get());
|
|
458 |
assertNull(future.get(0, MILLISECONDS));
|
|
459 |
assertTrue(done.get());
|
|
460 |
assertTrue(future.isDone());
|
|
461 |
assertFalse(future.isCancelled());
|
|
462 |
}
|
|
463 |
}
|
|
464 |
|
|
465 |
/**
|
|
466 |
* Completed submit(callable) returns result
|
|
467 |
*/
|
|
468 |
public void testSubmitCallable() throws Throwable {
|
|
469 |
ExecutorService e = new ForkJoinPool(1);
|
|
470 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
471 |
Future<String> future = e.submit(new StringTask());
|
|
472 |
assertSame(TEST_STRING, future.get());
|
|
473 |
assertTrue(future.isDone());
|
|
474 |
assertFalse(future.isCancelled());
|
|
475 |
}
|
|
476 |
}
|
|
477 |
|
|
478 |
/**
|
|
479 |
* Completed submit(runnable) returns successfully
|
|
480 |
*/
|
|
481 |
public void testSubmitRunnable() throws Throwable {
|
|
482 |
ExecutorService e = new ForkJoinPool(1);
|
|
483 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
484 |
Future<?> future = e.submit(new NoOpRunnable());
|
|
485 |
assertNull(future.get());
|
|
486 |
assertTrue(future.isDone());
|
|
487 |
assertFalse(future.isCancelled());
|
|
488 |
}
|
|
489 |
}
|
|
490 |
|
|
491 |
/**
|
|
492 |
* Completed submit(runnable, result) returns result
|
|
493 |
*/
|
|
494 |
public void testSubmitRunnable2() throws Throwable {
|
|
495 |
ExecutorService e = new ForkJoinPool(1);
|
|
496 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
497 |
Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
|
|
498 |
assertSame(TEST_STRING, future.get());
|
|
499 |
assertTrue(future.isDone());
|
|
500 |
assertFalse(future.isCancelled());
|
|
501 |
}
|
|
502 |
}
|
|
503 |
|
|
504 |
/**
|
|
505 |
* A submitted privileged action runs to completion
|
|
506 |
*/
|
|
507 |
public void testSubmitPrivilegedAction() throws Exception {
|
|
508 |
final Callable callable = Executors.callable(new PrivilegedAction() {
|
|
509 |
public Object run() { return TEST_STRING; }});
|
|
510 |
Runnable r = new CheckedRunnable() {
|
|
511 |
public void realRun() throws Exception {
|
|
512 |
ExecutorService e = new ForkJoinPool(1);
|
|
513 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
514 |
Future future = e.submit(callable);
|
|
515 |
assertSame(TEST_STRING, future.get());
|
|
516 |
}
|
|
517 |
}};
|
|
518 |
|
|
519 |
runWithPermissions(r, new RuntimePermission("modifyThread"));
|
|
520 |
}
|
|
521 |
|
|
522 |
/**
|
|
523 |
* A submitted privileged exception action runs to completion
|
|
524 |
*/
|
|
525 |
public void testSubmitPrivilegedExceptionAction() throws Exception {
|
|
526 |
final Callable callable =
|
|
527 |
Executors.callable(new PrivilegedExceptionAction() {
|
|
528 |
public Object run() { return TEST_STRING; }});
|
|
529 |
Runnable r = new CheckedRunnable() {
|
|
530 |
public void realRun() throws Exception {
|
|
531 |
ExecutorService e = new ForkJoinPool(1);
|
|
532 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
533 |
Future future = e.submit(callable);
|
|
534 |
assertSame(TEST_STRING, future.get());
|
|
535 |
}
|
|
536 |
}};
|
|
537 |
|
|
538 |
runWithPermissions(r, new RuntimePermission("modifyThread"));
|
|
539 |
}
|
|
540 |
|
|
541 |
/**
|
|
542 |
* A submitted failed privileged exception action reports exception
|
|
543 |
*/
|
|
544 |
public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
|
|
545 |
final Callable callable =
|
|
546 |
Executors.callable(new PrivilegedExceptionAction() {
|
|
547 |
public Object run() { throw new IndexOutOfBoundsException(); }});
|
|
548 |
Runnable r = new CheckedRunnable() {
|
|
549 |
public void realRun() throws Exception {
|
|
550 |
ExecutorService e = new ForkJoinPool(1);
|
|
551 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
552 |
Future future = e.submit(callable);
|
|
553 |
try {
|
|
554 |
future.get();
|
|
555 |
shouldThrow();
|
|
556 |
} catch (ExecutionException success) {
|
|
557 |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
|
|
558 |
}
|
|
559 |
}
|
|
560 |
}};
|
|
561 |
|
|
562 |
runWithPermissions(r, new RuntimePermission("modifyThread"));
|
|
563 |
}
|
|
564 |
|
|
565 |
/**
|
|
566 |
* execute(null runnable) throws NullPointerException
|
|
567 |
*/
|
|
568 |
public void testExecuteNullRunnable() {
|
|
569 |
ExecutorService e = new ForkJoinPool(1);
|
|
570 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
571 |
try {
|
|
572 |
Future<?> future = e.submit((Runnable) null);
|
|
573 |
shouldThrow();
|
|
574 |
} catch (NullPointerException success) {}
|
|
575 |
}
|
|
576 |
}
|
|
577 |
|
|
578 |
/**
|
|
579 |
* submit(null callable) throws NullPointerException
|
|
580 |
*/
|
|
581 |
public void testSubmitNullCallable() {
|
|
582 |
ExecutorService e = new ForkJoinPool(1);
|
|
583 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
584 |
try {
|
|
585 |
Future<String> future = e.submit((Callable) null);
|
|
586 |
shouldThrow();
|
|
587 |
} catch (NullPointerException success) {}
|
|
588 |
}
|
|
589 |
}
|
|
590 |
|
|
591 |
/**
|
|
592 |
* submit(callable).get() throws InterruptedException if interrupted
|
|
593 |
*/
|
|
594 |
public void testInterruptedSubmit() throws InterruptedException {
|
|
595 |
final CountDownLatch submitted = new CountDownLatch(1);
|
|
596 |
final CountDownLatch quittingTime = new CountDownLatch(1);
|
|
597 |
final Callable<Void> awaiter = new CheckedCallable<Void>() {
|
|
598 |
public Void realCall() throws InterruptedException {
|
|
599 |
assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS));
|
|
600 |
return null;
|
|
601 |
}};
|
|
602 |
final ExecutorService p = new ForkJoinPool(1);
|
|
603 |
try (PoolCleaner cleaner = cleaner(p, quittingTime)) {
|
|
604 |
Thread t = new Thread(new CheckedInterruptedRunnable() {
|
|
605 |
public void realRun() throws Exception {
|
|
606 |
Future<Void> future = p.submit(awaiter);
|
|
607 |
submitted.countDown();
|
|
608 |
future.get();
|
|
609 |
}});
|
|
610 |
t.start();
|
|
611 |
await(submitted);
|
|
612 |
t.interrupt();
|
|
613 |
awaitTermination(t);
|
|
614 |
}
|
|
615 |
}
|
|
616 |
|
|
617 |
/**
|
|
618 |
* get of submit(callable) throws ExecutionException if callable
|
|
619 |
* throws exception
|
|
620 |
*/
|
|
621 |
public void testSubmitEE() throws Throwable {
|
|
622 |
ForkJoinPool p = new ForkJoinPool(1);
|
|
623 |
try (PoolCleaner cleaner = cleaner(p)) {
|
|
624 |
try {
|
|
625 |
p.submit(new Callable() {
|
|
626 |
public Object call() { throw new ArithmeticException(); }})
|
|
627 |
.get();
|
|
628 |
shouldThrow();
|
|
629 |
} catch (ExecutionException success) {
|
|
630 |
assertTrue(success.getCause() instanceof ArithmeticException);
|
|
631 |
}
|
|
632 |
}
|
|
633 |
}
|
|
634 |
|
|
635 |
/**
|
|
636 |
* invokeAny(null) throws NullPointerException
|
|
637 |
*/
|
|
638 |
public void testInvokeAny1() throws Throwable {
|
|
639 |
ExecutorService e = new ForkJoinPool(1);
|
|
640 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
641 |
try {
|
|
642 |
e.invokeAny(null);
|
|
643 |
shouldThrow();
|
|
644 |
} catch (NullPointerException success) {}
|
|
645 |
}
|
|
646 |
}
|
|
647 |
|
|
648 |
/**
|
|
649 |
* invokeAny(empty collection) throws IllegalArgumentException
|
|
650 |
*/
|
|
651 |
public void testInvokeAny2() throws Throwable {
|
|
652 |
ExecutorService e = new ForkJoinPool(1);
|
|
653 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
654 |
try {
|
|
655 |
e.invokeAny(new ArrayList<Callable<String>>());
|
|
656 |
shouldThrow();
|
|
657 |
} catch (IllegalArgumentException success) {}
|
|
658 |
}
|
|
659 |
}
|
|
660 |
|
|
661 |
/**
|
|
662 |
* invokeAny(c) throws NullPointerException if c has a single null element
|
|
663 |
*/
|
|
664 |
public void testInvokeAny3() throws Throwable {
|
|
665 |
ExecutorService e = new ForkJoinPool(1);
|
|
666 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
667 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
668 |
l.add(null);
|
|
669 |
try {
|
|
670 |
e.invokeAny(l);
|
|
671 |
shouldThrow();
|
|
672 |
} catch (NullPointerException success) {}
|
|
673 |
}
|
|
674 |
}
|
|
675 |
|
|
676 |
/**
|
|
677 |
* invokeAny(c) throws NullPointerException if c has null elements
|
|
678 |
*/
|
|
679 |
public void testInvokeAny4() throws Throwable {
|
|
680 |
CountDownLatch latch = new CountDownLatch(1);
|
|
681 |
ExecutorService e = new ForkJoinPool(1);
|
|
682 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
683 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
684 |
l.add(latchAwaitingStringTask(latch));
|
|
685 |
l.add(null);
|
|
686 |
try {
|
|
687 |
e.invokeAny(l);
|
|
688 |
shouldThrow();
|
|
689 |
} catch (NullPointerException success) {}
|
|
690 |
latch.countDown();
|
|
691 |
}
|
|
692 |
}
|
|
693 |
|
|
694 |
/**
|
|
695 |
* invokeAny(c) throws ExecutionException if no task in c completes
|
|
696 |
*/
|
|
697 |
public void testInvokeAny5() throws Throwable {
|
|
698 |
ExecutorService e = new ForkJoinPool(1);
|
|
699 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
700 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
701 |
l.add(new NPETask());
|
|
702 |
try {
|
|
703 |
e.invokeAny(l);
|
|
704 |
shouldThrow();
|
|
705 |
} catch (ExecutionException success) {
|
|
706 |
assertTrue(success.getCause() instanceof NullPointerException);
|
|
707 |
}
|
|
708 |
}
|
|
709 |
}
|
|
710 |
|
|
711 |
/**
|
|
712 |
* invokeAny(c) returns result of some task in c if at least one completes
|
|
713 |
*/
|
|
714 |
public void testInvokeAny6() throws Throwable {
|
|
715 |
ExecutorService e = new ForkJoinPool(1);
|
|
716 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
717 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
718 |
l.add(new StringTask());
|
|
719 |
l.add(new StringTask());
|
|
720 |
String result = e.invokeAny(l);
|
|
721 |
assertSame(TEST_STRING, result);
|
|
722 |
}
|
|
723 |
}
|
|
724 |
|
|
725 |
/**
|
|
726 |
* invokeAll(null) throws NullPointerException
|
|
727 |
*/
|
|
728 |
public void testInvokeAll1() throws Throwable {
|
|
729 |
ExecutorService e = new ForkJoinPool(1);
|
|
730 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
731 |
try {
|
|
732 |
e.invokeAll(null);
|
|
733 |
shouldThrow();
|
|
734 |
} catch (NullPointerException success) {}
|
|
735 |
}
|
|
736 |
}
|
|
737 |
|
|
738 |
/**
|
|
739 |
* invokeAll(empty collection) returns empty collection
|
|
740 |
*/
|
|
741 |
public void testInvokeAll2() throws InterruptedException {
|
|
742 |
ExecutorService e = new ForkJoinPool(1);
|
|
743 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
744 |
List<Future<String>> r
|
|
745 |
= e.invokeAll(new ArrayList<Callable<String>>());
|
|
746 |
assertTrue(r.isEmpty());
|
|
747 |
}
|
|
748 |
}
|
|
749 |
|
|
750 |
/**
|
|
751 |
* invokeAll(c) throws NullPointerException if c has null elements
|
|
752 |
*/
|
|
753 |
public void testInvokeAll3() throws InterruptedException {
|
|
754 |
ExecutorService e = new ForkJoinPool(1);
|
|
755 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
756 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
757 |
l.add(new StringTask());
|
|
758 |
l.add(null);
|
|
759 |
try {
|
|
760 |
e.invokeAll(l);
|
|
761 |
shouldThrow();
|
|
762 |
} catch (NullPointerException success) {}
|
|
763 |
}
|
|
764 |
}
|
|
765 |
|
|
766 |
/**
|
|
767 |
* get of returned element of invokeAll(c) throws
|
|
768 |
* ExecutionException on failed task
|
|
769 |
*/
|
|
770 |
public void testInvokeAll4() throws Throwable {
|
|
771 |
ExecutorService e = new ForkJoinPool(1);
|
|
772 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
773 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
774 |
l.add(new NPETask());
|
|
775 |
List<Future<String>> futures = e.invokeAll(l);
|
|
776 |
assertEquals(1, futures.size());
|
|
777 |
try {
|
|
778 |
futures.get(0).get();
|
|
779 |
shouldThrow();
|
|
780 |
} catch (ExecutionException success) {
|
|
781 |
assertTrue(success.getCause() instanceof NullPointerException);
|
|
782 |
}
|
|
783 |
}
|
|
784 |
}
|
|
785 |
|
|
786 |
/**
|
|
787 |
* invokeAll(c) returns results of all completed tasks in c
|
|
788 |
*/
|
|
789 |
public void testInvokeAll5() throws Throwable {
|
|
790 |
ExecutorService e = new ForkJoinPool(1);
|
|
791 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
792 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
793 |
l.add(new StringTask());
|
|
794 |
l.add(new StringTask());
|
|
795 |
List<Future<String>> futures = e.invokeAll(l);
|
|
796 |
assertEquals(2, futures.size());
|
|
797 |
for (Future<String> future : futures)
|
|
798 |
assertSame(TEST_STRING, future.get());
|
|
799 |
}
|
|
800 |
}
|
|
801 |
|
|
802 |
/**
|
|
803 |
* timed invokeAny(null) throws NullPointerException
|
|
804 |
*/
|
|
805 |
public void testTimedInvokeAny1() throws Throwable {
|
|
806 |
ExecutorService e = new ForkJoinPool(1);
|
|
807 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
808 |
try {
|
|
809 |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
|
|
810 |
shouldThrow();
|
|
811 |
} catch (NullPointerException success) {}
|
|
812 |
}
|
|
813 |
}
|
|
814 |
|
|
815 |
/**
|
|
816 |
* timed invokeAny(null time unit) throws NullPointerException
|
|
817 |
*/
|
|
818 |
public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
|
|
819 |
ExecutorService e = new ForkJoinPool(1);
|
|
820 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
821 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
822 |
l.add(new StringTask());
|
|
823 |
try {
|
|
824 |
e.invokeAny(l, MEDIUM_DELAY_MS, null);
|
|
825 |
shouldThrow();
|
|
826 |
} catch (NullPointerException success) {}
|
|
827 |
}
|
|
828 |
}
|
|
829 |
|
|
830 |
/**
|
|
831 |
* timed invokeAny(empty collection) throws IllegalArgumentException
|
|
832 |
*/
|
|
833 |
public void testTimedInvokeAny2() throws Throwable {
|
|
834 |
ExecutorService e = new ForkJoinPool(1);
|
|
835 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
836 |
try {
|
|
837 |
e.invokeAny(new ArrayList<Callable<String>>(),
|
|
838 |
MEDIUM_DELAY_MS, MILLISECONDS);
|
|
839 |
shouldThrow();
|
|
840 |
} catch (IllegalArgumentException success) {}
|
|
841 |
}
|
|
842 |
}
|
|
843 |
|
|
844 |
/**
|
|
845 |
* timed invokeAny(c) throws NullPointerException if c has null elements
|
|
846 |
*/
|
|
847 |
public void testTimedInvokeAny3() throws Throwable {
|
|
848 |
CountDownLatch latch = new CountDownLatch(1);
|
|
849 |
ExecutorService e = new ForkJoinPool(1);
|
|
850 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
851 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
852 |
l.add(latchAwaitingStringTask(latch));
|
|
853 |
l.add(null);
|
|
854 |
try {
|
|
855 |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
|
|
856 |
shouldThrow();
|
|
857 |
} catch (NullPointerException success) {}
|
|
858 |
latch.countDown();
|
|
859 |
}
|
|
860 |
}
|
|
861 |
|
|
862 |
/**
|
|
863 |
* timed invokeAny(c) throws ExecutionException if no task completes
|
|
864 |
*/
|
|
865 |
public void testTimedInvokeAny4() throws Throwable {
|
|
866 |
ExecutorService e = new ForkJoinPool(1);
|
|
867 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
868 |
long startTime = System.nanoTime();
|
|
869 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
870 |
l.add(new NPETask());
|
|
871 |
try {
|
|
872 |
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
|
|
873 |
shouldThrow();
|
|
874 |
} catch (ExecutionException success) {
|
|
875 |
assertTrue(success.getCause() instanceof NullPointerException);
|
|
876 |
}
|
|
877 |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
|
|
878 |
}
|
|
879 |
}
|
|
880 |
|
|
881 |
/**
|
|
882 |
* timed invokeAny(c) returns result of some task in c
|
|
883 |
*/
|
|
884 |
public void testTimedInvokeAny5() throws Throwable {
|
|
885 |
ExecutorService e = new ForkJoinPool(1);
|
|
886 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
887 |
long startTime = System.nanoTime();
|
|
888 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
889 |
l.add(new StringTask());
|
|
890 |
l.add(new StringTask());
|
|
891 |
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
|
|
892 |
assertSame(TEST_STRING, result);
|
|
893 |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
|
|
894 |
}
|
|
895 |
}
|
|
896 |
|
|
897 |
/**
|
|
898 |
* timed invokeAll(null) throws NullPointerException
|
|
899 |
*/
|
|
900 |
public void testTimedInvokeAll1() throws Throwable {
|
|
901 |
ExecutorService e = new ForkJoinPool(1);
|
|
902 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
903 |
try {
|
|
904 |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
|
|
905 |
shouldThrow();
|
|
906 |
} catch (NullPointerException success) {}
|
|
907 |
}
|
|
908 |
}
|
|
909 |
|
|
910 |
/**
|
|
911 |
* timed invokeAll(null time unit) throws NullPointerException
|
|
912 |
*/
|
|
913 |
public void testTimedInvokeAllNullTimeUnit() throws Throwable {
|
|
914 |
ExecutorService e = new ForkJoinPool(1);
|
|
915 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
916 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
917 |
l.add(new StringTask());
|
|
918 |
try {
|
|
919 |
e.invokeAll(l, MEDIUM_DELAY_MS, null);
|
|
920 |
shouldThrow();
|
|
921 |
} catch (NullPointerException success) {}
|
|
922 |
}
|
|
923 |
}
|
|
924 |
|
|
925 |
/**
|
|
926 |
* timed invokeAll(empty collection) returns empty collection
|
|
927 |
*/
|
|
928 |
public void testTimedInvokeAll2() throws InterruptedException {
|
|
929 |
ExecutorService e = new ForkJoinPool(1);
|
|
930 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
931 |
List<Future<String>> r
|
|
932 |
= e.invokeAll(new ArrayList<Callable<String>>(),
|
|
933 |
MEDIUM_DELAY_MS, MILLISECONDS);
|
|
934 |
assertTrue(r.isEmpty());
|
|
935 |
}
|
|
936 |
}
|
|
937 |
|
|
938 |
/**
|
|
939 |
* timed invokeAll(c) throws NullPointerException if c has null elements
|
|
940 |
*/
|
|
941 |
public void testTimedInvokeAll3() throws InterruptedException {
|
|
942 |
ExecutorService e = new ForkJoinPool(1);
|
|
943 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
944 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
945 |
l.add(new StringTask());
|
|
946 |
l.add(null);
|
|
947 |
try {
|
|
948 |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
|
|
949 |
shouldThrow();
|
|
950 |
} catch (NullPointerException success) {}
|
|
951 |
}
|
|
952 |
}
|
|
953 |
|
|
954 |
/**
|
|
955 |
* get of returned element of invokeAll(c) throws exception on failed task
|
|
956 |
*/
|
|
957 |
public void testTimedInvokeAll4() throws Throwable {
|
|
958 |
ExecutorService e = new ForkJoinPool(1);
|
|
959 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
960 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
961 |
l.add(new NPETask());
|
|
962 |
List<Future<String>> futures
|
|
963 |
= e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
|
|
964 |
assertEquals(1, futures.size());
|
|
965 |
try {
|
|
966 |
futures.get(0).get();
|
|
967 |
shouldThrow();
|
|
968 |
} catch (ExecutionException success) {
|
|
969 |
assertTrue(success.getCause() instanceof NullPointerException);
|
|
970 |
}
|
|
971 |
}
|
|
972 |
}
|
|
973 |
|
|
974 |
/**
|
|
975 |
* timed invokeAll(c) returns results of all completed tasks in c
|
|
976 |
*/
|
|
977 |
public void testTimedInvokeAll5() throws Throwable {
|
|
978 |
ForkJoinPool e = new ForkJoinPool(1);
|
|
979 |
try (PoolCleaner cleaner = cleaner(e)) {
|
|
980 |
List<Callable<String>> l = new ArrayList<Callable<String>>();
|
|
981 |
l.add(new StringTask());
|
|
982 |
l.add(new StringTask());
|
|
983 |
List<Future<String>> futures
|
|
984 |
= e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
|
|
985 |
assertEquals(2, futures.size());
|
|
986 |
for (Future<String> future : futures)
|
|
987 |
assertSame(TEST_STRING, future.get());
|
|
988 |
}
|
|
989 |
}
|
|
990 |
|
|
991 |
}
|