4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
|
*/ |
6 |
|
|
7 |
– |
|
7 |
|
import junit.framework.*; |
8 |
|
import java.util.*; |
9 |
< |
import java.util.concurrent.*; |
10 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
11 |
< |
import java.util.concurrent.locks.*; |
12 |
< |
import java.security.*; |
9 |
> |
import java.util.concurrent.Executors; |
10 |
> |
import java.util.concurrent.ExecutorService; |
11 |
> |
import java.util.concurrent.AbstractExecutorService; |
12 |
> |
import java.util.concurrent.CountDownLatch; |
13 |
> |
import java.util.concurrent.Callable; |
14 |
> |
import java.util.concurrent.Future; |
15 |
> |
import java.util.concurrent.ExecutionException; |
16 |
> |
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; |
22 |
> |
import java.util.concurrent.TimeUnit; |
23 |
> |
import java.util.concurrent.locks.ReentrantLock; |
24 |
> |
import java.security.AccessControlException; |
25 |
> |
import java.security.Policy; |
26 |
> |
import java.security.PrivilegedAction; |
27 |
> |
import java.security.PrivilegedExceptionAction; |
28 |
|
|
29 |
|
public class ForkJoinPoolTest extends JSR166TestCase { |
30 |
|
public static void main(String[] args) { |
31 |
< |
junit.textui.TestRunner.run (suite()); |
31 |
> |
junit.textui.TestRunner.run(suite()); |
32 |
|
} |
33 |
+ |
|
34 |
|
public static Test suite() { |
35 |
|
return new TestSuite(ForkJoinPoolTest.class); |
36 |
|
} |
54 |
|
// Some classes to test extension and factory methods |
55 |
|
|
56 |
|
static class MyHandler implements Thread.UncaughtExceptionHandler { |
57 |
< |
int catches = 0; |
57 |
> |
volatile int catches = 0; |
58 |
|
public void uncaughtException(Thread t, Throwable e) { |
59 |
|
++catches; |
60 |
|
} |
63 |
|
// to test handlers |
64 |
|
static class FailingFJWSubclass extends ForkJoinWorkerThread { |
65 |
|
public FailingFJWSubclass(ForkJoinPool p) { super(p) ; } |
66 |
< |
protected void onStart() { throw new Error(); } |
66 |
> |
protected void onStart() { super.onStart(); throw new Error(); } |
67 |
|
} |
68 |
|
|
69 |
|
static class FailingThreadFactory |
70 |
|
implements ForkJoinPool.ForkJoinWorkerThreadFactory { |
71 |
< |
int calls = 0; |
71 |
> |
volatile int calls = 0; |
72 |
|
public ForkJoinWorkerThread newThread(ForkJoinPool p) { |
73 |
|
if (++calls > 1) return null; |
74 |
|
return new FailingFJWSubclass(p); |
157 |
|
* tasks, and quiescent running state. |
158 |
|
*/ |
159 |
|
public void testDefaultInitialState() { |
160 |
< |
ForkJoinPool p = null; |
160 |
> |
ForkJoinPool p = new ForkJoinPool(1); |
161 |
|
try { |
147 |
– |
p = new ForkJoinPool(1); |
162 |
|
assertTrue(p.getFactory() == |
163 |
|
ForkJoinPool.defaultForkJoinWorkerThreadFactory); |
164 |
|
assertTrue(p.isQuiescent()); |
151 |
– |
assertTrue(p.getMaintainsParallelism()); |
165 |
|
assertFalse(p.getAsyncMode()); |
166 |
|
assertTrue(p.getActiveThreadCount() == 0); |
167 |
|
assertTrue(p.getStealCount() == 0); |
191 |
|
*/ |
192 |
|
public void testConstructor2() { |
193 |
|
try { |
194 |
< |
new ForkJoinPool(1, null); |
194 |
> |
new ForkJoinPool(1, null, null, false); |
195 |
|
shouldThrow(); |
196 |
|
} catch (NullPointerException success) {} |
197 |
|
} |
201 |
|
* getParallelism returns size set in constructor |
202 |
|
*/ |
203 |
|
public void testGetParallelism() { |
204 |
< |
ForkJoinPool p = null; |
192 |
< |
try { |
193 |
< |
p = new ForkJoinPool(1); |
194 |
< |
assertTrue(p.getParallelism() == 1); |
195 |
< |
} finally { |
196 |
< |
joinPool(p); |
197 |
< |
} |
198 |
< |
} |
199 |
< |
|
200 |
< |
/** |
201 |
< |
* setParallelism changes reported parallelism level. |
202 |
< |
*/ |
203 |
< |
public void testSetParallelism() { |
204 |
< |
ForkJoinPool p = null; |
205 |
< |
try { |
206 |
< |
p = new ForkJoinPool(1); |
207 |
< |
assertTrue(p.getParallelism() == 1); |
208 |
< |
p.setParallelism(2); |
209 |
< |
assertTrue(p.getParallelism() == 2); |
210 |
< |
} finally { |
211 |
< |
joinPool(p); |
212 |
< |
} |
213 |
< |
} |
214 |
< |
|
215 |
< |
/** |
216 |
< |
* setParallelism with argument <= 0 throws exception |
217 |
< |
*/ |
218 |
< |
public void testSetParallelism2() { |
219 |
< |
ForkJoinPool p = null; |
204 |
> |
ForkJoinPool p = new ForkJoinPool(1); |
205 |
|
try { |
221 |
– |
p = new ForkJoinPool(1); |
206 |
|
assertTrue(p.getParallelism() == 1); |
223 |
– |
p.setParallelism(-2); |
224 |
– |
shouldThrow(); |
225 |
– |
} catch (IllegalArgumentException success) { |
207 |
|
} finally { |
208 |
|
joinPool(p); |
209 |
|
} |
213 |
|
* getPoolSize returns number of started workers. |
214 |
|
*/ |
215 |
|
public void testGetPoolSize() { |
216 |
< |
ForkJoinPool p = null; |
216 |
> |
ForkJoinPool p = new ForkJoinPool(1); |
217 |
|
try { |
237 |
– |
p = new ForkJoinPool(1); |
218 |
|
assertTrue(p.getActiveThreadCount() == 0); |
219 |
|
Future<String> future = p.submit(new StringTask()); |
220 |
|
assertTrue(p.getPoolSize() == 1); |
241 |
– |
|
242 |
– |
} finally { |
243 |
– |
joinPool(p); |
244 |
– |
} |
245 |
– |
} |
246 |
– |
|
247 |
– |
/** |
248 |
– |
* setMaximumPoolSize changes size reported by getMaximumPoolSize. |
249 |
– |
*/ |
250 |
– |
public void testSetMaximumPoolSize() { |
251 |
– |
ForkJoinPool p = null; |
252 |
– |
try { |
253 |
– |
p = new ForkJoinPool(1); |
254 |
– |
p.setMaximumPoolSize(2); |
255 |
– |
assertTrue(p.getMaximumPoolSize() == 2); |
256 |
– |
} finally { |
257 |
– |
joinPool(p); |
258 |
– |
} |
259 |
– |
} |
260 |
– |
|
261 |
– |
/** |
262 |
– |
* setMaximumPoolSize with argument <= 0 throws exception |
263 |
– |
*/ |
264 |
– |
public void testSetMaximumPoolSize2() { |
265 |
– |
ForkJoinPool p = null; |
266 |
– |
try { |
267 |
– |
p = new ForkJoinPool(1); |
268 |
– |
p.setMaximumPoolSize(-2); |
269 |
– |
shouldThrow(); |
270 |
– |
} catch (IllegalArgumentException success) { |
271 |
– |
} finally { |
272 |
– |
joinPool(p); |
273 |
– |
} |
274 |
– |
} |
275 |
– |
|
276 |
– |
/** |
277 |
– |
* setMaintainsParallelism changes policy reported by |
278 |
– |
* getMaintainsParallelism. |
279 |
– |
*/ |
280 |
– |
public void testSetMaintainsParallelism() { |
281 |
– |
ForkJoinPool p = null; |
282 |
– |
try { |
283 |
– |
p = new ForkJoinPool(1); |
284 |
– |
p.setMaintainsParallelism(false); |
285 |
– |
assertFalse(p.getMaintainsParallelism()); |
286 |
– |
} finally { |
287 |
– |
joinPool(p); |
288 |
– |
} |
289 |
– |
} |
290 |
– |
|
291 |
– |
/** |
292 |
– |
* setAsyncMode changes policy reported by |
293 |
– |
* getAsyncMode. |
294 |
– |
*/ |
295 |
– |
public void testSetAsyncMode() { |
296 |
– |
ForkJoinPool p = null; |
297 |
– |
try { |
298 |
– |
p = new ForkJoinPool(1); |
299 |
– |
p.setAsyncMode(true); |
300 |
– |
assertTrue(p.getAsyncMode()); |
221 |
|
} finally { |
222 |
|
joinPool(p); |
223 |
|
} |
230 |
|
* performs its defined action |
231 |
|
*/ |
232 |
|
public void testSetUncaughtExceptionHandler() throws InterruptedException { |
233 |
< |
ForkJoinPool p = null; |
233 |
> |
MyHandler eh = new MyHandler(); |
234 |
> |
ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), eh, false); |
235 |
|
try { |
236 |
< |
p = new ForkJoinPool(1, new FailingThreadFactory()); |
316 |
< |
MyHandler eh = new MyHandler(); |
317 |
< |
p.setUncaughtExceptionHandler(eh); |
318 |
< |
assertEquals(eh, p.getUncaughtExceptionHandler()); |
236 |
> |
assert(eh == p.getUncaughtExceptionHandler()); |
237 |
|
p.execute(new FailingTask()); |
238 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
239 |
|
assertTrue(eh.catches > 0); |
244 |
|
} |
245 |
|
|
246 |
|
/** |
329 |
– |
* setUncaughtExceptionHandler of null removes handler |
330 |
– |
*/ |
331 |
– |
public void testSetUncaughtExceptionHandler2() { |
332 |
– |
ForkJoinPool p = null; |
333 |
– |
try { |
334 |
– |
p = new ForkJoinPool(1); |
335 |
– |
p.setUncaughtExceptionHandler(null); |
336 |
– |
assertNull(p.getUncaughtExceptionHandler()); |
337 |
– |
} finally { |
338 |
– |
joinPool(p); |
339 |
– |
} |
340 |
– |
} |
341 |
– |
|
342 |
– |
|
343 |
– |
/** |
247 |
|
* After invoking a single task, isQuiescent is true, |
248 |
|
* queues are empty, threads are not active, and |
249 |
|
* construction parameters continue to hold |
250 |
|
*/ |
251 |
|
public void testisQuiescent() throws InterruptedException { |
252 |
< |
ForkJoinPool p = null; |
252 |
> |
ForkJoinPool p = new ForkJoinPool(2); |
253 |
|
try { |
351 |
– |
p = new ForkJoinPool(2); |
254 |
|
p.invoke(new FibTask(20)); |
255 |
|
assertTrue(p.getFactory() == |
256 |
|
ForkJoinPool.defaultForkJoinWorkerThreadFactory); |
257 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
258 |
|
assertTrue(p.isQuiescent()); |
357 |
– |
assertTrue(p.getMaintainsParallelism()); |
259 |
|
assertFalse(p.getAsyncMode()); |
260 |
|
assertTrue(p.getActiveThreadCount() == 0); |
261 |
|
assertTrue(p.getQueuedTaskCount() == 0); |
273 |
|
* Completed submit(ForkJoinTask) returns result |
274 |
|
*/ |
275 |
|
public void testSubmitForkJoinTask() throws Throwable { |
276 |
< |
ForkJoinPool p = null; |
276 |
> |
ForkJoinPool p = new ForkJoinPool(1); |
277 |
|
try { |
377 |
– |
p = new ForkJoinPool(1); |
278 |
|
ForkJoinTask<Integer> f = p.submit(new FibTask(8)); |
279 |
|
int r = f.get(); |
280 |
|
assertTrue(r == 21); |
287 |
|
* A task submitted after shutdown is rejected |
288 |
|
*/ |
289 |
|
public void testSubmitAfterShutdown() { |
290 |
< |
ForkJoinPool p = null; |
290 |
> |
ForkJoinPool p = new ForkJoinPool(1); |
291 |
|
try { |
392 |
– |
p = new ForkJoinPool(1); |
292 |
|
p.shutdown(); |
293 |
|
assertTrue(p.isShutdown()); |
294 |
|
ForkJoinTask<Integer> f = p.submit(new FibTask(8)); |
303 |
|
* Pool maintains parallelism when using ManagedBlocker |
304 |
|
*/ |
305 |
|
public void testBlockingForkJoinTask() throws Throwable { |
306 |
< |
ForkJoinPool p = null; |
306 |
> |
ForkJoinPool p = new ForkJoinPool(4); |
307 |
|
try { |
409 |
– |
p = new ForkJoinPool(4); |
308 |
|
ReentrantLock lock = new ReentrantLock(); |
309 |
|
ManagedLocker locker = new ManagedLocker(lock); |
310 |
|
ForkJoinTask<Integer> f = new LockingFibTask(30, locker, lock); |
311 |
|
p.execute(f); |
414 |
– |
assertTrue(p.getPoolSize() >= 4); |
312 |
|
int r = f.get(); |
313 |
|
assertTrue(r == 832040); |
314 |
|
} finally { |
320 |
|
* pollSubmission returns unexecuted submitted task, if present |
321 |
|
*/ |
322 |
|
public void testPollSubmission() { |
323 |
< |
SubFJP p = null; |
323 |
> |
SubFJP p = new SubFJP(); |
324 |
|
try { |
428 |
– |
p = new SubFJP(); |
325 |
|
ForkJoinTask a = p.submit(new MediumRunnable()); |
326 |
|
ForkJoinTask b = p.submit(new MediumRunnable()); |
327 |
|
ForkJoinTask c = p.submit(new MediumRunnable()); |
337 |
|
* drainTasksTo transfers unexecuted submitted tasks, if present |
338 |
|
*/ |
339 |
|
public void testDrainTasksTo() { |
340 |
< |
SubFJP p = null; |
340 |
> |
SubFJP p = new SubFJP(); |
341 |
|
try { |
446 |
– |
p = new SubFJP(); |
342 |
|
ForkJoinTask a = p.submit(new MediumRunnable()); |
343 |
|
ForkJoinTask b = p.submit(new MediumRunnable()); |
344 |
|
ForkJoinTask c = p.submit(new MediumRunnable()); |
362 |
|
*/ |
363 |
|
public void testExecuteRunnable() throws Throwable { |
364 |
|
ExecutorService e = new ForkJoinPool(1); |
365 |
< |
TrackedShortRunnable task = new TrackedShortRunnable(); |
366 |
< |
assertFalse(task.done); |
367 |
< |
Future<?> future = e.submit(task); |
368 |
< |
future.get(); |
369 |
< |
assertTrue(task.done); |
365 |
> |
try { |
366 |
> |
TrackedShortRunnable task = new TrackedShortRunnable(); |
367 |
> |
assertFalse(task.done); |
368 |
> |
Future<?> future = e.submit(task); |
369 |
> |
future.get(); |
370 |
> |
assertTrue(task.done); |
371 |
> |
} finally { |
372 |
> |
joinPool(e); |
373 |
> |
} |
374 |
|
} |
375 |
|
|
376 |
|
|
379 |
|
*/ |
380 |
|
public void testSubmitCallable() throws Throwable { |
381 |
|
ExecutorService e = new ForkJoinPool(1); |
382 |
< |
Future<String> future = e.submit(new StringTask()); |
383 |
< |
String result = future.get(); |
384 |
< |
assertSame(TEST_STRING, result); |
382 |
> |
try { |
383 |
> |
Future<String> future = e.submit(new StringTask()); |
384 |
> |
String result = future.get(); |
385 |
> |
assertSame(TEST_STRING, result); |
386 |
> |
} finally { |
387 |
> |
joinPool(e); |
388 |
> |
} |
389 |
|
} |
390 |
|
|
391 |
|
/** |
393 |
|
*/ |
394 |
|
public void testSubmitRunnable() throws Throwable { |
395 |
|
ExecutorService e = new ForkJoinPool(1); |
396 |
< |
Future<?> future = e.submit(new NoOpRunnable()); |
397 |
< |
future.get(); |
398 |
< |
assertTrue(future.isDone()); |
396 |
> |
try { |
397 |
> |
Future<?> future = e.submit(new NoOpRunnable()); |
398 |
> |
future.get(); |
399 |
> |
assertTrue(future.isDone()); |
400 |
> |
} finally { |
401 |
> |
joinPool(e); |
402 |
> |
} |
403 |
|
} |
404 |
|
|
405 |
|
/** |
407 |
|
*/ |
408 |
|
public void testSubmitRunnable2() throws Throwable { |
409 |
|
ExecutorService e = new ForkJoinPool(1); |
410 |
< |
Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING); |
411 |
< |
String result = future.get(); |
412 |
< |
assertSame(TEST_STRING, result); |
410 |
> |
try { |
411 |
> |
Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING); |
412 |
> |
String result = future.get(); |
413 |
> |
assertSame(TEST_STRING, result); |
414 |
> |
} finally { |
415 |
> |
joinPool(e); |
416 |
> |
} |
417 |
|
} |
418 |
|
|
419 |
+ |
|
420 |
|
/** |
421 |
< |
* A submitted privileged action runs to completion |
421 |
> |
* A submitted privileged action to completion |
422 |
|
*/ |
423 |
|
public void testSubmitPrivilegedAction() throws Throwable { |
424 |
< |
Runnable r = new CheckedRunnable() { |
425 |
< |
public void realRun() throws Exception { |
426 |
< |
ExecutorService e = new ForkJoinPool(1); |
424 |
> |
Policy savedPolicy = null; |
425 |
> |
try { |
426 |
> |
savedPolicy = Policy.getPolicy(); |
427 |
> |
AdjustablePolicy policy = new AdjustablePolicy(); |
428 |
> |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
429 |
> |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
430 |
> |
Policy.setPolicy(policy); |
431 |
> |
} catch (AccessControlException ok) { |
432 |
> |
return; |
433 |
> |
} |
434 |
> |
|
435 |
> |
try { |
436 |
> |
ExecutorService e = new ForkJoinPool(1); |
437 |
> |
try { |
438 |
|
Future future = e.submit(Executors.callable(new PrivilegedAction() { |
439 |
|
public Object run() { |
440 |
|
return TEST_STRING; |
442 |
|
|
443 |
|
Object result = future.get(); |
444 |
|
assertSame(TEST_STRING, result); |
445 |
< |
}}; |
446 |
< |
|
447 |
< |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
445 |
> |
} finally { |
446 |
> |
joinPool(e); |
447 |
> |
} |
448 |
> |
} finally { |
449 |
> |
Policy.setPolicy(savedPolicy); |
450 |
> |
} |
451 |
|
} |
452 |
|
|
453 |
|
/** |
454 |
< |
* A submitted privileged exception action runs to completion |
454 |
> |
* A submitted a privileged exception action runs to completion |
455 |
|
*/ |
456 |
|
public void testSubmitPrivilegedExceptionAction() throws Throwable { |
457 |
< |
Runnable r = new CheckedRunnable() { |
458 |
< |
public void realRun() throws Exception { |
459 |
< |
ExecutorService e = new ForkJoinPool(1); |
457 |
> |
Policy savedPolicy = null; |
458 |
> |
try { |
459 |
> |
savedPolicy = Policy.getPolicy(); |
460 |
> |
AdjustablePolicy policy = new AdjustablePolicy(); |
461 |
> |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
462 |
> |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
463 |
> |
Policy.setPolicy(policy); |
464 |
> |
} catch (AccessControlException ok) { |
465 |
> |
return; |
466 |
> |
} |
467 |
> |
|
468 |
> |
try { |
469 |
> |
ExecutorService e = new ForkJoinPool(1); |
470 |
> |
try { |
471 |
|
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
472 |
|
public Object run() { |
473 |
|
return TEST_STRING; |
475 |
|
|
476 |
|
Object result = future.get(); |
477 |
|
assertSame(TEST_STRING, result); |
478 |
< |
}}; |
479 |
< |
|
480 |
< |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
478 |
> |
} finally { |
479 |
> |
joinPool(e); |
480 |
> |
} |
481 |
> |
} finally { |
482 |
> |
Policy.setPolicy(savedPolicy); |
483 |
> |
} |
484 |
|
} |
485 |
|
|
486 |
|
/** |
487 |
|
* A submitted failed privileged exception action reports exception |
488 |
|
*/ |
489 |
|
public void testSubmitFailedPrivilegedExceptionAction() throws Throwable { |
490 |
< |
Runnable r = new CheckedRunnable() { |
491 |
< |
public void realRun() throws Exception { |
492 |
< |
ExecutorService e = new ForkJoinPool(1); |
490 |
> |
Policy savedPolicy = null; |
491 |
> |
try { |
492 |
> |
savedPolicy = Policy.getPolicy(); |
493 |
> |
AdjustablePolicy policy = new AdjustablePolicy(); |
494 |
> |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
495 |
> |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
496 |
> |
Policy.setPolicy(policy); |
497 |
> |
} catch (AccessControlException ok) { |
498 |
> |
return; |
499 |
> |
} |
500 |
> |
|
501 |
> |
try { |
502 |
> |
ExecutorService e = new ForkJoinPool(1); |
503 |
> |
try { |
504 |
|
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
505 |
|
public Object run() throws Exception { |
506 |
|
throw new IndexOutOfBoundsException(); |
507 |
|
}})); |
508 |
|
|
509 |
< |
try { |
510 |
< |
Object result = future.get(); |
511 |
< |
shouldThrow(); |
512 |
< |
} catch (ExecutionException success) { |
513 |
< |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
514 |
< |
}}}; |
515 |
< |
|
516 |
< |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
509 |
> |
Object result = future.get(); |
510 |
> |
shouldThrow(); |
511 |
> |
} catch (ExecutionException success) { |
512 |
> |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
513 |
> |
} finally { |
514 |
> |
joinPool(e); |
515 |
> |
} |
516 |
> |
} finally { |
517 |
> |
Policy.setPolicy(savedPolicy); |
518 |
> |
} |
519 |
|
} |
520 |
|
|
521 |
|
/** |
522 |
|
* execute(null runnable) throws NullPointerException |
523 |
|
*/ |
524 |
|
public void testExecuteNullRunnable() { |
525 |
+ |
ExecutorService e = new ForkJoinPool(1); |
526 |
|
try { |
573 |
– |
ExecutorService e = new ForkJoinPool(1); |
527 |
|
TrackedShortRunnable task = null; |
528 |
|
Future<?> future = e.submit(task); |
529 |
|
shouldThrow(); |
530 |
< |
} catch (NullPointerException success) {} |
530 |
> |
} catch (NullPointerException success) { |
531 |
> |
} finally { |
532 |
> |
joinPool(e); |
533 |
> |
} |
534 |
|
} |
535 |
|
|
536 |
|
|
538 |
|
* submit(null callable) throws NullPointerException |
539 |
|
*/ |
540 |
|
public void testSubmitNullCallable() { |
541 |
+ |
ExecutorService e = new ForkJoinPool(1); |
542 |
|
try { |
586 |
– |
ExecutorService e = new ForkJoinPool(1); |
543 |
|
StringTask t = null; |
544 |
|
Future<String> future = e.submit(t); |
545 |
|
shouldThrow(); |
546 |
< |
} catch (NullPointerException success) {} |
546 |
> |
} catch (NullPointerException success) { |
547 |
> |
} finally { |
548 |
> |
joinPool(e); |
549 |
> |
} |
550 |
|
} |
551 |
|
|
552 |
|
|
592 |
|
shouldThrow(); |
593 |
|
} catch (ExecutionException success) { |
594 |
|
assertTrue(success.getCause() instanceof ArithmeticException); |
595 |
+ |
} finally { |
596 |
+ |
joinPool(p); |
597 |
|
} |
637 |
– |
|
638 |
– |
joinPool(p); |
598 |
|
} |
599 |
|
|
600 |
|
/** |
783 |
|
public void testTimedInvokeAny1() throws Throwable { |
784 |
|
ExecutorService e = new ForkJoinPool(1); |
785 |
|
try { |
786 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
786 |
> |
e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
787 |
|
shouldThrow(); |
788 |
|
} catch (NullPointerException success) { |
789 |
|
} finally { |
814 |
|
ExecutorService e = new ForkJoinPool(1); |
815 |
|
try { |
816 |
|
e.invokeAny(new ArrayList<Callable<String>>(), |
817 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
817 |
> |
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
818 |
|
shouldThrow(); |
819 |
|
} catch (IllegalArgumentException success) { |
820 |
|
} finally { |
832 |
|
l.add(latchAwaitingStringTask(latch)); |
833 |
|
l.add(null); |
834 |
|
try { |
835 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
835 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
836 |
|
shouldThrow(); |
837 |
|
} catch (NullPointerException success) { |
838 |
|
} finally { |
849 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
850 |
|
l.add(new NPETask()); |
851 |
|
try { |
852 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
852 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
853 |
|
shouldThrow(); |
854 |
|
} catch (ExecutionException success) { |
855 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
867 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
868 |
|
l.add(new StringTask()); |
869 |
|
l.add(new StringTask()); |
870 |
< |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
870 |
> |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
871 |
|
assertSame(TEST_STRING, result); |
872 |
|
} finally { |
873 |
|
joinPool(e); |
880 |
|
public void testTimedInvokeAll1() throws Throwable { |
881 |
|
ExecutorService e = new ForkJoinPool(1); |
882 |
|
try { |
883 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
883 |
> |
e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
884 |
|
shouldThrow(); |
885 |
|
} catch (NullPointerException success) { |
886 |
|
} finally { |
912 |
|
try { |
913 |
|
List<Future<String>> r |
914 |
|
= e.invokeAll(new ArrayList<Callable<String>>(), |
915 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
915 |
> |
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
916 |
|
assertTrue(r.isEmpty()); |
917 |
|
} finally { |
918 |
|
joinPool(e); |
928 |
|
l.add(new StringTask()); |
929 |
|
l.add(null); |
930 |
|
try { |
931 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
931 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
932 |
|
shouldThrow(); |
933 |
|
} catch (NullPointerException success) { |
934 |
|
} finally { |
944 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
945 |
|
l.add(new NPETask()); |
946 |
|
List<Future<String>> futures |
947 |
< |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
947 |
> |
= e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
948 |
|
assertEquals(1, futures.size()); |
949 |
|
try { |
950 |
|
futures.get(0).get(); |
966 |
|
l.add(new StringTask()); |
967 |
|
l.add(new StringTask()); |
968 |
|
List<Future<String>> futures |
969 |
< |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
969 |
> |
= e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
970 |
|
assertEquals(2, futures.size()); |
971 |
|
for (Future<String> future : futures) |
972 |
|
assertSame(TEST_STRING, future.get()); |