2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
< |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
< |
* Pat Fisher, Mike Judd. |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
13 |
|
|
14 |
|
public class ScheduledExecutorTest extends JSR166TestCase { |
15 |
|
public static void main(String[] args) { |
16 |
< |
junit.textui.TestRunner.run (suite()); |
16 |
> |
junit.textui.TestRunner.run (suite()); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
|
return new TestSuite(ScheduledExecutorTest.class); |
30 |
|
p1.execute(runnable); |
31 |
|
assertFalse(runnable.done); |
32 |
|
Thread.sleep(SHORT_DELAY_MS); |
33 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
33 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
34 |
|
try { |
35 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
36 |
< |
} catch(InterruptedException e){ |
36 |
> |
} catch (InterruptedException e){ |
37 |
|
unexpectedException(); |
38 |
|
} |
39 |
|
assertTrue(runnable.done); |
40 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
40 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
41 |
|
joinPool(p1); |
42 |
|
} |
43 |
< |
catch(Exception e){ |
43 |
> |
catch (Exception e){ |
44 |
|
unexpectedException(); |
45 |
|
} |
46 |
< |
|
46 |
> |
|
47 |
|
} |
48 |
|
|
49 |
|
|
59 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
60 |
|
assertTrue(callable.done); |
61 |
|
assertEquals(Boolean.TRUE, f.get()); |
62 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
62 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
63 |
|
joinPool(p1); |
64 |
< |
} catch(RejectedExecutionException e){} |
65 |
< |
catch(Exception e){ |
64 |
> |
} catch (RejectedExecutionException e){} |
65 |
> |
catch (Exception e){ |
66 |
|
e.printStackTrace(); |
67 |
|
unexpectedException(); |
68 |
|
} |
80 |
|
assertFalse(runnable.done); |
81 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
82 |
|
assertTrue(runnable.done); |
83 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
83 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
84 |
|
joinPool(p1); |
85 |
< |
} catch(Exception e){ |
85 |
> |
} catch (Exception e){ |
86 |
|
unexpectedException(); |
87 |
|
} |
88 |
|
} |
89 |
< |
|
89 |
> |
|
90 |
|
/** |
91 |
|
* scheduleAtFixedRate executes runnable after given initial delay |
92 |
|
*/ |
100 |
|
assertTrue(runnable.done); |
101 |
|
h.cancel(true); |
102 |
|
joinPool(p1); |
103 |
< |
} catch(Exception e){ |
103 |
> |
} catch (Exception e){ |
104 |
|
unexpectedException(); |
105 |
|
} |
106 |
|
} |
123 |
|
assertTrue(runnable.done); |
124 |
|
h.cancel(true); |
125 |
|
joinPool(p1); |
126 |
< |
} catch(Exception e){ |
126 |
> |
} catch (Exception e){ |
127 |
|
unexpectedException(); |
128 |
|
} |
129 |
|
} |
130 |
< |
|
130 |
> |
|
131 |
|
/** |
132 |
|
* scheduleAtFixedRate executes series of tasks at given rate |
133 |
|
*/ |
135 |
|
try { |
136 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
137 |
|
RunnableCounter counter = new RunnableCounter(); |
138 |
< |
ScheduledFuture h = |
138 |
> |
ScheduledFuture h = |
139 |
|
p1.scheduleAtFixedRate(counter, 0, 1, TimeUnit.MILLISECONDS); |
140 |
|
Thread.sleep(SMALL_DELAY_MS); |
141 |
|
h.cancel(true); |
144 |
|
// an execution per SHORT delay, but no more than one SHORT more |
145 |
|
assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS); |
146 |
|
assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS); |
147 |
– |
assertTrue(h.isDone()); |
147 |
|
joinPool(p1); |
148 |
< |
} catch(Exception e){ |
148 |
> |
} catch (Exception e){ |
149 |
|
unexpectedException(); |
150 |
|
} |
151 |
|
} |
157 |
|
try { |
158 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
159 |
|
RunnableCounter counter = new RunnableCounter(); |
160 |
< |
ScheduledFuture h = |
160 |
> |
ScheduledFuture h = |
161 |
|
p1.scheduleWithFixedDelay(counter, 0, 1, TimeUnit.MILLISECONDS); |
162 |
|
Thread.sleep(SMALL_DELAY_MS); |
163 |
|
h.cancel(true); |
164 |
|
int c = counter.count.get(); |
165 |
|
assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS); |
166 |
|
assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS); |
168 |
– |
assertTrue(h.isDone()); |
167 |
|
joinPool(p1); |
168 |
< |
} catch(Exception e){ |
168 |
> |
} catch (Exception e){ |
169 |
|
unexpectedException(); |
170 |
|
} |
171 |
|
} |
180 |
|
se = new ScheduledThreadPoolExecutor(1); |
181 |
|
se.execute(null); |
182 |
|
shouldThrow(); |
183 |
< |
} catch(NullPointerException success){} |
184 |
< |
catch(Exception e){ |
183 |
> |
} catch (NullPointerException success){} |
184 |
> |
catch (Exception e){ |
185 |
|
unexpectedException(); |
186 |
|
} |
187 |
< |
|
187 |
> |
|
188 |
|
joinPool(se); |
189 |
|
} |
190 |
|
|
197 |
|
TrackedCallable callable = null; |
198 |
|
Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
199 |
|
shouldThrow(); |
200 |
< |
} catch(NullPointerException success){} |
201 |
< |
catch(Exception e){ |
200 |
> |
} catch (NullPointerException success){} |
201 |
> |
catch (Exception e){ |
202 |
|
unexpectedException(); |
203 |
|
} |
204 |
|
joinPool(se); |
205 |
|
} |
206 |
< |
|
206 |
> |
|
207 |
|
/** |
208 |
|
* execute throws RejectedExecutionException if shutdown |
209 |
|
*/ |
214 |
|
se.schedule(new NoOpRunnable(), |
215 |
|
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
216 |
|
shouldThrow(); |
217 |
< |
} catch(RejectedExecutionException success){ |
217 |
> |
} catch (RejectedExecutionException success){ |
218 |
|
} catch (SecurityException ok) { |
219 |
|
} |
220 |
< |
|
220 |
> |
|
221 |
|
joinPool(se); |
222 |
|
|
223 |
|
} |
232 |
|
se.schedule(new NoOpCallable(), |
233 |
|
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
234 |
|
shouldThrow(); |
235 |
< |
} catch(RejectedExecutionException success){ |
235 |
> |
} catch (RejectedExecutionException success){ |
236 |
|
} catch (SecurityException ok) { |
237 |
|
} |
238 |
|
joinPool(se); |
248 |
|
se.schedule(new NoOpCallable(), |
249 |
|
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
250 |
|
shouldThrow(); |
251 |
< |
} catch(RejectedExecutionException success){ |
251 |
> |
} catch (RejectedExecutionException success){ |
252 |
|
} catch (SecurityException ok) { |
253 |
|
} |
254 |
|
joinPool(se); |
264 |
|
se.scheduleAtFixedRate(new NoOpRunnable(), |
265 |
|
MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
266 |
|
shouldThrow(); |
267 |
< |
} catch(RejectedExecutionException success){ |
267 |
> |
} catch (RejectedExecutionException success){ |
268 |
|
} catch (SecurityException ok) { |
269 |
< |
} |
269 |
> |
} |
270 |
|
joinPool(se); |
271 |
|
} |
272 |
< |
|
272 |
> |
|
273 |
|
/** |
274 |
|
* scheduleWithFixedDelay throws RejectedExecutionException if shutdown |
275 |
|
*/ |
280 |
|
se.scheduleWithFixedDelay(new NoOpRunnable(), |
281 |
|
MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
282 |
|
shouldThrow(); |
283 |
< |
} catch(RejectedExecutionException success){ |
283 |
> |
} catch (RejectedExecutionException success){ |
284 |
|
} catch (SecurityException ok) { |
285 |
< |
} |
285 |
> |
} |
286 |
|
joinPool(se); |
287 |
|
} |
288 |
|
|
296 |
|
p2.execute(new SmallRunnable()); |
297 |
|
try { |
298 |
|
Thread.sleep(SHORT_DELAY_MS); |
299 |
< |
} catch(Exception e){ |
299 |
> |
} catch (Exception e){ |
300 |
|
unexpectedException(); |
301 |
|
} |
302 |
|
assertEquals(1, p2.getActiveCount()); |
303 |
|
joinPool(p2); |
304 |
|
} |
305 |
< |
|
305 |
> |
|
306 |
|
/** |
307 |
|
* getCompletedTaskCount increases, but doesn't overestimate, |
308 |
|
* when tasks complete |
313 |
|
p2.execute(new SmallRunnable()); |
314 |
|
try { |
315 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
316 |
< |
} catch(Exception e){ |
316 |
> |
} catch (Exception e){ |
317 |
|
unexpectedException(); |
318 |
|
} |
319 |
|
assertEquals(1, p2.getCompletedTaskCount()); |
320 |
|
joinPool(p2); |
321 |
|
} |
322 |
< |
|
322 |
> |
|
323 |
|
/** |
324 |
< |
* getCorePoolSize returns size given in constructor if not otherwise set |
324 |
> |
* getCorePoolSize returns size given in constructor if not otherwise set |
325 |
|
*/ |
326 |
|
public void testGetCorePoolSize() { |
327 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
328 |
|
assertEquals(1, p1.getCorePoolSize()); |
329 |
|
joinPool(p1); |
330 |
|
} |
331 |
< |
|
331 |
> |
|
332 |
|
/** |
333 |
|
* getLargestPoolSize increases, but doesn't overestimate, when |
334 |
|
* multiple threads active |
340 |
|
p2.execute(new SmallRunnable()); |
341 |
|
try { |
342 |
|
Thread.sleep(SHORT_DELAY_MS); |
343 |
< |
} catch(Exception e){ |
343 |
> |
} catch (Exception e){ |
344 |
|
unexpectedException(); |
345 |
|
} |
346 |
|
assertEquals(2, p2.getLargestPoolSize()); |
347 |
|
joinPool(p2); |
348 |
|
} |
349 |
< |
|
349 |
> |
|
350 |
|
/** |
351 |
|
* getPoolSize increases, but doesn't overestimate, when threads |
352 |
|
* become active |
358 |
|
assertEquals(1, p1.getPoolSize()); |
359 |
|
joinPool(p1); |
360 |
|
} |
361 |
< |
|
361 |
> |
|
362 |
|
/** |
363 |
|
* getTaskCount increases, but doesn't overestimate, when tasks |
364 |
|
* submitted |
366 |
|
public void testGetTaskCount() { |
367 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
368 |
|
assertEquals(0, p1.getTaskCount()); |
369 |
< |
for(int i = 0; i < 5; i++) |
369 |
> |
for (int i = 0; i < 5; i++) |
370 |
|
p1.execute(new SmallRunnable()); |
371 |
|
try { |
372 |
|
Thread.sleep(SHORT_DELAY_MS); |
373 |
< |
} catch(Exception e){ |
373 |
> |
} catch (Exception e){ |
374 |
|
unexpectedException(); |
375 |
|
} |
376 |
|
assertEquals(5, p1.getTaskCount()); |
377 |
|
joinPool(p1); |
378 |
|
} |
379 |
|
|
380 |
< |
/** |
380 |
> |
/** |
381 |
|
* getThreadFactory returns factory in constructor if not set |
382 |
|
*/ |
383 |
|
public void testGetThreadFactory() { |
387 |
|
joinPool(p); |
388 |
|
} |
389 |
|
|
390 |
< |
/** |
390 |
> |
/** |
391 |
|
* setThreadFactory sets the thread factory returned by getThreadFactory |
392 |
|
*/ |
393 |
|
public void testSetThreadFactory() { |
398 |
|
joinPool(p); |
399 |
|
} |
400 |
|
|
401 |
< |
/** |
401 |
> |
/** |
402 |
|
* setThreadFactory(null) throws NPE |
403 |
|
*/ |
404 |
|
public void testSetThreadFactoryNull() { |
411 |
|
joinPool(p); |
412 |
|
} |
413 |
|
} |
414 |
< |
|
414 |
> |
|
415 |
|
/** |
416 |
|
* is isShutDown is false before shutdown, true after |
417 |
|
*/ |
418 |
|
public void testIsShutdown() { |
419 |
< |
|
419 |
> |
|
420 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
421 |
|
try { |
422 |
|
assertFalse(p1.isShutdown()); |
423 |
|
} |
424 |
|
finally { |
425 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
425 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
426 |
|
} |
427 |
|
assertTrue(p1.isShutdown()); |
428 |
|
} |
429 |
|
|
430 |
< |
|
430 |
> |
|
431 |
|
/** |
432 |
|
* isTerminated is false before termination, true after |
433 |
|
*/ |
436 |
|
try { |
437 |
|
p1.execute(new SmallRunnable()); |
438 |
|
} finally { |
439 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
439 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
440 |
|
} |
441 |
|
try { |
442 |
|
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
443 |
|
assertTrue(p1.isTerminated()); |
444 |
< |
} catch(Exception e){ |
444 |
> |
} catch (Exception e){ |
445 |
|
unexpectedException(); |
446 |
< |
} |
446 |
> |
} |
447 |
|
} |
448 |
|
|
449 |
|
/** |
456 |
|
p1.execute(new SmallRunnable()); |
457 |
|
assertFalse(p1.isTerminating()); |
458 |
|
} finally { |
459 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
459 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
460 |
|
} |
461 |
|
try { |
462 |
|
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
463 |
|
assertTrue(p1.isTerminated()); |
464 |
|
assertFalse(p1.isTerminating()); |
465 |
< |
} catch(Exception e){ |
465 |
> |
} catch (Exception e){ |
466 |
|
unexpectedException(); |
467 |
< |
} |
467 |
> |
} |
468 |
|
} |
469 |
|
|
470 |
|
/** |
473 |
|
public void testGetQueue() { |
474 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
475 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
476 |
< |
for(int i = 0; i < 5; i++){ |
476 |
> |
for (int i = 0; i < 5; i++){ |
477 |
|
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); |
478 |
|
} |
479 |
|
try { |
481 |
|
BlockingQueue<Runnable> q = p1.getQueue(); |
482 |
|
assertTrue(q.contains(tasks[4])); |
483 |
|
assertFalse(q.contains(tasks[0])); |
484 |
< |
} catch(Exception e) { |
484 |
> |
} catch (Exception e) { |
485 |
|
unexpectedException(); |
486 |
|
} finally { |
487 |
|
joinPool(p1); |
494 |
|
public void testRemove() { |
495 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
496 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
497 |
< |
for(int i = 0; i < 5; i++){ |
497 |
> |
for (int i = 0; i < 5; i++){ |
498 |
|
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); |
499 |
|
} |
500 |
|
try { |
509 |
|
assertTrue(q.contains((Runnable)tasks[3])); |
510 |
|
assertTrue(p1.remove((Runnable)tasks[3])); |
511 |
|
assertFalse(q.contains((Runnable)tasks[3])); |
512 |
< |
} catch(Exception e) { |
512 |
> |
} catch (Exception e) { |
513 |
|
unexpectedException(); |
514 |
|
} finally { |
515 |
|
joinPool(p1); |
522 |
|
public void testPurge() { |
523 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
524 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
525 |
< |
for(int i = 0; i < 5; i++){ |
526 |
< |
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); |
525 |
> |
for (int i = 0; i < 5; i++){ |
526 |
> |
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
527 |
> |
} |
528 |
> |
try { |
529 |
> |
int max = 5; |
530 |
> |
if (tasks[4].cancel(true)) --max; |
531 |
> |
if (tasks[3].cancel(true)) --max; |
532 |
> |
// There must eventually be an interference-free point at |
533 |
> |
// which purge will not fail. (At worst, when queue is empty.) |
534 |
> |
int k; |
535 |
> |
for (k = 0; k < SMALL_DELAY_MS; ++k) { |
536 |
> |
p1.purge(); |
537 |
> |
long count = p1.getTaskCount(); |
538 |
> |
if (count >= 0 && count <= max) |
539 |
> |
break; |
540 |
> |
Thread.sleep(1); |
541 |
> |
} |
542 |
> |
assertTrue(k < SMALL_DELAY_MS); |
543 |
> |
} catch (Exception e) { |
544 |
> |
unexpectedException(); |
545 |
> |
} finally { |
546 |
> |
joinPool(p1); |
547 |
|
} |
530 |
– |
int max = 5; |
531 |
– |
if (tasks[4].cancel(true)) --max; |
532 |
– |
if (tasks[3].cancel(true)) --max; |
533 |
– |
p1.purge(); |
534 |
– |
long count = p1.getTaskCount(); |
535 |
– |
assertTrue(count > 0 && count <= max); |
536 |
– |
joinPool(p1); |
548 |
|
} |
549 |
|
|
550 |
|
/** |
552 |
|
*/ |
553 |
|
public void testShutDownNow() { |
554 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
555 |
< |
for(int i = 0; i < 5; i++) |
555 |
> |
for (int i = 0; i < 5; i++) |
556 |
|
p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
557 |
|
List l; |
558 |
|
try { |
559 |
|
l = p1.shutdownNow(); |
560 |
< |
} catch (SecurityException ok) { |
560 |
> |
} catch (SecurityException ok) { |
561 |
|
return; |
562 |
|
} |
563 |
|
assertTrue(p1.isShutdown()); |
576 |
|
assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
577 |
|
|
578 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
579 |
< |
for(int i = 0; i < 5; i++) |
579 |
> |
for (int i = 0; i < 5; i++) |
580 |
|
tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
581 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
581 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
582 |
|
BlockingQueue q = p1.getQueue(); |
583 |
|
for (Iterator it = q.iterator(); it.hasNext();) { |
584 |
|
ScheduledFuture t = (ScheduledFuture)it.next(); |
590 |
|
assertTrue(tasks[i].isDone()); |
591 |
|
assertFalse(tasks[i].isCancelled()); |
592 |
|
} |
593 |
< |
|
593 |
> |
|
594 |
|
} |
595 |
< |
catch(Exception ex) { |
595 |
> |
catch (Exception ex) { |
596 |
|
unexpectedException(); |
597 |
|
} |
598 |
|
} |
607 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
608 |
|
p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); |
609 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
610 |
< |
for(int i = 0; i < 5; i++) |
610 |
> |
for (int i = 0; i < 5; i++) |
611 |
|
tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
612 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
612 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
613 |
|
assertTrue(p1.isShutdown()); |
614 |
|
BlockingQueue q = p1.getQueue(); |
615 |
|
assertTrue(q.isEmpty()); |
616 |
|
Thread.sleep(SMALL_DELAY_MS); |
617 |
|
assertTrue(p1.isTerminated()); |
618 |
|
} |
619 |
< |
catch(Exception ex) { |
619 |
> |
catch (Exception ex) { |
620 |
|
unexpectedException(); |
621 |
|
} |
622 |
|
} |
632 |
|
p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); |
633 |
|
ScheduledFuture task = |
634 |
|
p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS); |
635 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
635 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
636 |
|
assertTrue(p1.isShutdown()); |
637 |
|
BlockingQueue q = p1.getQueue(); |
638 |
|
assertTrue(q.isEmpty()); |
639 |
|
Thread.sleep(SHORT_DELAY_MS); |
640 |
|
assertTrue(p1.isTerminated()); |
641 |
|
} |
642 |
< |
catch(Exception ex) { |
642 |
> |
catch (Exception ex) { |
643 |
|
unexpectedException(); |
644 |
|
} |
645 |
|
} |
655 |
|
ScheduledFuture task = |
656 |
|
p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, TimeUnit.MILLISECONDS); |
657 |
|
assertFalse(task.isCancelled()); |
658 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
658 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
659 |
|
assertFalse(task.isCancelled()); |
660 |
|
assertFalse(p1.isTerminated()); |
661 |
|
assertTrue(p1.isShutdown()); |
666 |
|
Thread.sleep(SHORT_DELAY_MS); |
667 |
|
assertTrue(p1.isTerminated()); |
668 |
|
} |
669 |
< |
catch(Exception ex) { |
669 |
> |
catch (Exception ex) { |
670 |
|
unexpectedException(); |
671 |
|
} |
672 |
< |
finally { |
672 |
> |
finally { |
673 |
|
joinPool(p1); |
674 |
|
} |
675 |
|
} |
742 |
|
try { |
743 |
|
e.invokeAny(null); |
744 |
|
} catch (NullPointerException success) { |
745 |
< |
} catch(Exception ex) { |
745 |
> |
} catch (Exception ex) { |
746 |
|
unexpectedException(); |
747 |
|
} finally { |
748 |
|
joinPool(e); |
757 |
|
try { |
758 |
|
e.invokeAny(new ArrayList<Callable<String>>()); |
759 |
|
} catch (IllegalArgumentException success) { |
760 |
< |
} catch(Exception ex) { |
760 |
> |
} catch (Exception ex) { |
761 |
|
unexpectedException(); |
762 |
|
} finally { |
763 |
|
joinPool(e); |
775 |
|
l.add(null); |
776 |
|
e.invokeAny(l); |
777 |
|
} catch (NullPointerException success) { |
778 |
< |
} catch(Exception ex) { |
778 |
> |
} catch (Exception ex) { |
779 |
|
unexpectedException(); |
780 |
|
} finally { |
781 |
|
joinPool(e); |
792 |
|
l.add(new NPETask()); |
793 |
|
e.invokeAny(l); |
794 |
|
} catch (ExecutionException success) { |
795 |
< |
} catch(Exception ex) { |
795 |
> |
} catch (Exception ex) { |
796 |
|
unexpectedException(); |
797 |
|
} finally { |
798 |
|
joinPool(e); |
811 |
|
String result = e.invokeAny(l); |
812 |
|
assertSame(TEST_STRING, result); |
813 |
|
} catch (ExecutionException success) { |
814 |
< |
} catch(Exception ex) { |
814 |
> |
} catch (Exception ex) { |
815 |
|
unexpectedException(); |
816 |
|
} finally { |
817 |
|
joinPool(e); |
826 |
|
try { |
827 |
|
e.invokeAll(null); |
828 |
|
} catch (NullPointerException success) { |
829 |
< |
} catch(Exception ex) { |
829 |
> |
} catch (Exception ex) { |
830 |
|
unexpectedException(); |
831 |
|
} finally { |
832 |
|
joinPool(e); |
841 |
|
try { |
842 |
|
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); |
843 |
|
assertTrue(r.isEmpty()); |
844 |
< |
} catch(Exception ex) { |
844 |
> |
} catch (Exception ex) { |
845 |
|
unexpectedException(); |
846 |
|
} finally { |
847 |
|
joinPool(e); |
859 |
|
l.add(null); |
860 |
|
e.invokeAll(l); |
861 |
|
} catch (NullPointerException success) { |
862 |
< |
} catch(Exception ex) { |
862 |
> |
} catch (Exception ex) { |
863 |
|
unexpectedException(); |
864 |
|
} finally { |
865 |
|
joinPool(e); |
876 |
|
l.add(new NPETask()); |
877 |
|
List<Future<String>> result = e.invokeAll(l); |
878 |
|
assertEquals(1, result.size()); |
879 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
879 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
880 |
|
it.next().get(); |
881 |
< |
} catch(ExecutionException success) { |
882 |
< |
} catch(Exception ex) { |
881 |
> |
} catch (ExecutionException success) { |
882 |
> |
} catch (Exception ex) { |
883 |
|
unexpectedException(); |
884 |
|
} finally { |
885 |
|
joinPool(e); |
897 |
|
l.add(new StringTask()); |
898 |
|
List<Future<String>> result = e.invokeAll(l); |
899 |
|
assertEquals(2, result.size()); |
900 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
900 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
901 |
|
assertSame(TEST_STRING, it.next().get()); |
902 |
|
} catch (ExecutionException success) { |
903 |
< |
} catch(Exception ex) { |
903 |
> |
} catch (Exception ex) { |
904 |
|
unexpectedException(); |
905 |
|
} finally { |
906 |
|
joinPool(e); |
915 |
|
try { |
916 |
|
e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
917 |
|
} catch (NullPointerException success) { |
918 |
< |
} catch(Exception ex) { |
918 |
> |
} catch (Exception ex) { |
919 |
|
unexpectedException(); |
920 |
|
} finally { |
921 |
|
joinPool(e); |
932 |
|
l.add(new StringTask()); |
933 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
934 |
|
} catch (NullPointerException success) { |
935 |
< |
} catch(Exception ex) { |
935 |
> |
} catch (Exception ex) { |
936 |
|
unexpectedException(); |
937 |
|
} finally { |
938 |
|
joinPool(e); |
947 |
|
try { |
948 |
|
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
949 |
|
} catch (IllegalArgumentException success) { |
950 |
< |
} catch(Exception ex) { |
950 |
> |
} catch (Exception ex) { |
951 |
|
unexpectedException(); |
952 |
|
} finally { |
953 |
|
joinPool(e); |
965 |
|
l.add(null); |
966 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
967 |
|
} catch (NullPointerException success) { |
968 |
< |
} catch(Exception ex) { |
968 |
> |
} catch (Exception ex) { |
969 |
|
ex.printStackTrace(); |
970 |
|
unexpectedException(); |
971 |
|
} finally { |
982 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
983 |
|
l.add(new NPETask()); |
984 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
985 |
< |
} catch(ExecutionException success) { |
986 |
< |
} catch(Exception ex) { |
985 |
> |
} catch (ExecutionException success) { |
986 |
> |
} catch (Exception ex) { |
987 |
|
unexpectedException(); |
988 |
|
} finally { |
989 |
|
joinPool(e); |
1002 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1003 |
|
assertSame(TEST_STRING, result); |
1004 |
|
} catch (ExecutionException success) { |
1005 |
< |
} catch(Exception ex) { |
1005 |
> |
} catch (Exception ex) { |
1006 |
|
unexpectedException(); |
1007 |
|
} finally { |
1008 |
|
joinPool(e); |
1017 |
|
try { |
1018 |
|
e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1019 |
|
} catch (NullPointerException success) { |
1020 |
< |
} catch(Exception ex) { |
1020 |
> |
} catch (Exception ex) { |
1021 |
|
unexpectedException(); |
1022 |
|
} finally { |
1023 |
|
joinPool(e); |
1034 |
|
l.add(new StringTask()); |
1035 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1036 |
|
} catch (NullPointerException success) { |
1037 |
< |
} catch(Exception ex) { |
1037 |
> |
} catch (Exception ex) { |
1038 |
|
unexpectedException(); |
1039 |
|
} finally { |
1040 |
|
joinPool(e); |
1049 |
|
try { |
1050 |
|
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1051 |
|
assertTrue(r.isEmpty()); |
1052 |
< |
} catch(Exception ex) { |
1052 |
> |
} catch (Exception ex) { |
1053 |
|
unexpectedException(); |
1054 |
|
} finally { |
1055 |
|
joinPool(e); |
1067 |
|
l.add(null); |
1068 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1069 |
|
} catch (NullPointerException success) { |
1070 |
< |
} catch(Exception ex) { |
1070 |
> |
} catch (Exception ex) { |
1071 |
|
unexpectedException(); |
1072 |
|
} finally { |
1073 |
|
joinPool(e); |
1084 |
|
l.add(new NPETask()); |
1085 |
|
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1086 |
|
assertEquals(1, result.size()); |
1087 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1087 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1088 |
|
it.next().get(); |
1089 |
< |
} catch(ExecutionException success) { |
1090 |
< |
} catch(Exception ex) { |
1089 |
> |
} catch (ExecutionException success) { |
1090 |
> |
} catch (Exception ex) { |
1091 |
|
unexpectedException(); |
1092 |
|
} finally { |
1093 |
|
joinPool(e); |
1105 |
|
l.add(new StringTask()); |
1106 |
|
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1107 |
|
assertEquals(2, result.size()); |
1108 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1108 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1109 |
|
assertSame(TEST_STRING, it.next().get()); |
1110 |
|
} catch (ExecutionException success) { |
1111 |
< |
} catch(Exception ex) { |
1111 |
> |
} catch (Exception ex) { |
1112 |
|
unexpectedException(); |
1113 |
|
} finally { |
1114 |
|
joinPool(e); |
1127 |
|
l.add(new StringTask()); |
1128 |
|
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
1129 |
|
assertEquals(3, result.size()); |
1130 |
< |
Iterator<Future<String>> it = result.iterator(); |
1130 |
> |
Iterator<Future<String>> it = result.iterator(); |
1131 |
|
Future<String> f1 = it.next(); |
1132 |
|
Future<String> f2 = it.next(); |
1133 |
|
Future<String> f3 = it.next(); |
1136 |
|
assertTrue(f3.isDone()); |
1137 |
|
assertFalse(f1.isCancelled()); |
1138 |
|
assertTrue(f2.isCancelled()); |
1139 |
< |
} catch(Exception ex) { |
1139 |
> |
} catch (Exception ex) { |
1140 |
|
unexpectedException(); |
1141 |
|
} finally { |
1142 |
|
joinPool(e); |