11 |
|
|
12 |
|
public class ScheduledExecutorSubclassTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run (suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
|
return new TestSuite(ScheduledExecutorTest.class); |
18 |
|
} |
19 |
|
|
20 |
< |
static class CustomTask<V> implements RunnableScheduledFuture<V> { |
20 |
> |
static class CustomTask<V> implements RunnableScheduledFuture<V> { |
21 |
|
RunnableScheduledFuture<V> task; |
22 |
|
volatile boolean ran; |
23 |
|
CustomTask(RunnableScheduledFuture<V> t) { task = t; } |
24 |
|
public boolean isPeriodic() { return task.isPeriodic(); } |
25 |
< |
public void run() { |
25 |
> |
public void run() { |
26 |
|
ran = true; |
27 |
< |
task.run(); |
27 |
> |
task.run(); |
28 |
|
} |
29 |
|
public long getDelay(TimeUnit unit) { return task.getDelay(unit); } |
30 |
|
public int compareTo(Delayed t) { |
31 |
< |
return task.compareTo(((CustomTask)t).task); |
31 |
> |
return task.compareTo(((CustomTask)t).task); |
32 |
|
} |
33 |
|
public boolean cancel(boolean mayInterruptIfRunning) { |
34 |
|
return task.cancel(mayInterruptIfRunning); |
46 |
|
return v; |
47 |
|
} |
48 |
|
} |
49 |
< |
|
49 |
> |
|
50 |
|
|
51 |
|
public class CustomExecutor extends ScheduledThreadPoolExecutor { |
52 |
|
|
65 |
|
CustomExecutor(int corePoolSize, ThreadFactory threadFactory) { |
66 |
|
super(corePoolSize, threadFactory); |
67 |
|
} |
68 |
< |
CustomExecutor(int corePoolSize, ThreadFactory threadFactory, |
68 |
> |
CustomExecutor(int corePoolSize, ThreadFactory threadFactory, |
69 |
|
RejectedExecutionHandler handler) { |
70 |
|
super(corePoolSize, threadFactory, handler); |
71 |
|
} |
72 |
< |
|
72 |
> |
|
73 |
|
} |
74 |
< |
|
74 |
> |
|
75 |
|
|
76 |
|
|
77 |
|
/** |
84 |
|
p1.execute(runnable); |
85 |
|
assertFalse(runnable.done); |
86 |
|
Thread.sleep(SHORT_DELAY_MS); |
87 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
87 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
88 |
|
try { |
89 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
90 |
< |
} catch(InterruptedException e){ |
90 |
> |
} catch (InterruptedException e) { |
91 |
|
unexpectedException(); |
92 |
|
} |
93 |
|
assertTrue(runnable.done); |
94 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
94 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
95 |
|
joinPool(p1); |
96 |
|
} |
97 |
< |
catch(Exception e){ |
97 |
> |
catch (Exception e) { |
98 |
|
unexpectedException(); |
99 |
|
} |
100 |
< |
|
100 |
> |
|
101 |
|
} |
102 |
|
|
103 |
|
|
113 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
114 |
|
assertTrue(callable.done); |
115 |
|
assertEquals(Boolean.TRUE, f.get()); |
116 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
116 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
117 |
|
joinPool(p1); |
118 |
< |
} catch(RejectedExecutionException e){} |
119 |
< |
catch(Exception e){ |
118 |
> |
} catch (RejectedExecutionException e) {} |
119 |
> |
catch (Exception e) { |
120 |
|
e.printStackTrace(); |
121 |
|
unexpectedException(); |
122 |
|
} |
134 |
|
assertFalse(runnable.done); |
135 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
136 |
|
assertTrue(runnable.done); |
137 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
137 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
138 |
|
joinPool(p1); |
139 |
< |
} catch(Exception e){ |
139 |
> |
} catch (Exception e) { |
140 |
|
unexpectedException(); |
141 |
|
} |
142 |
|
} |
143 |
< |
|
143 |
> |
|
144 |
|
/** |
145 |
|
* scheduleAtFixedRate executes runnable after given initial delay |
146 |
|
*/ |
154 |
|
assertTrue(runnable.done); |
155 |
|
h.cancel(true); |
156 |
|
joinPool(p1); |
157 |
< |
} catch(Exception e){ |
157 |
> |
} catch (Exception e) { |
158 |
|
unexpectedException(); |
159 |
|
} |
160 |
|
} |
177 |
|
assertTrue(runnable.done); |
178 |
|
h.cancel(true); |
179 |
|
joinPool(p1); |
180 |
< |
} catch(Exception e){ |
180 |
> |
} catch (Exception e) { |
181 |
|
unexpectedException(); |
182 |
|
} |
183 |
|
} |
184 |
< |
|
184 |
> |
|
185 |
|
/** |
186 |
|
* scheduleAtFixedRate executes series of tasks at given rate |
187 |
|
*/ |
189 |
|
try { |
190 |
|
CustomExecutor p1 = new CustomExecutor(1); |
191 |
|
RunnableCounter counter = new RunnableCounter(); |
192 |
< |
ScheduledFuture h = |
192 |
> |
ScheduledFuture h = |
193 |
|
p1.scheduleAtFixedRate(counter, 0, 1, TimeUnit.MILLISECONDS); |
194 |
|
Thread.sleep(SMALL_DELAY_MS); |
195 |
|
h.cancel(true); |
199 |
|
assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS); |
200 |
|
assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS); |
201 |
|
joinPool(p1); |
202 |
< |
} catch(Exception e){ |
202 |
> |
} catch (Exception e) { |
203 |
|
unexpectedException(); |
204 |
|
} |
205 |
|
} |
211 |
|
try { |
212 |
|
CustomExecutor p1 = new CustomExecutor(1); |
213 |
|
RunnableCounter counter = new RunnableCounter(); |
214 |
< |
ScheduledFuture h = |
214 |
> |
ScheduledFuture h = |
215 |
|
p1.scheduleWithFixedDelay(counter, 0, 1, TimeUnit.MILLISECONDS); |
216 |
|
Thread.sleep(SMALL_DELAY_MS); |
217 |
|
h.cancel(true); |
219 |
|
assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS); |
220 |
|
assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS); |
221 |
|
joinPool(p1); |
222 |
< |
} catch(Exception e){ |
222 |
> |
} catch (Exception e) { |
223 |
|
unexpectedException(); |
224 |
|
} |
225 |
|
} |
234 |
|
se = new CustomExecutor(1); |
235 |
|
se.execute(null); |
236 |
|
shouldThrow(); |
237 |
< |
} catch(NullPointerException success){} |
238 |
< |
catch(Exception e){ |
237 |
> |
} catch (NullPointerException success) {} |
238 |
> |
catch (Exception e) { |
239 |
|
unexpectedException(); |
240 |
|
} |
241 |
< |
|
241 |
> |
|
242 |
|
joinPool(se); |
243 |
|
} |
244 |
|
|
251 |
|
TrackedCallable callable = null; |
252 |
|
Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
253 |
|
shouldThrow(); |
254 |
< |
} catch(NullPointerException success){} |
255 |
< |
catch(Exception e){ |
254 |
> |
} catch (NullPointerException success) {} |
255 |
> |
catch (Exception e) { |
256 |
|
unexpectedException(); |
257 |
|
} |
258 |
|
joinPool(se); |
259 |
|
} |
260 |
< |
|
260 |
> |
|
261 |
|
/** |
262 |
|
* execute throws RejectedExecutionException if shutdown |
263 |
|
*/ |
268 |
|
se.schedule(new NoOpRunnable(), |
269 |
|
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
270 |
|
shouldThrow(); |
271 |
< |
} catch(RejectedExecutionException success){ |
271 |
> |
} catch (RejectedExecutionException success) { |
272 |
|
} catch (SecurityException ok) { |
273 |
|
} |
274 |
< |
|
274 |
> |
|
275 |
|
joinPool(se); |
276 |
|
|
277 |
|
} |
286 |
|
se.schedule(new NoOpCallable(), |
287 |
|
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
288 |
|
shouldThrow(); |
289 |
< |
} catch(RejectedExecutionException success){ |
289 |
> |
} catch (RejectedExecutionException success) { |
290 |
|
} catch (SecurityException ok) { |
291 |
|
} |
292 |
|
joinPool(se); |
302 |
|
se.schedule(new NoOpCallable(), |
303 |
|
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
304 |
|
shouldThrow(); |
305 |
< |
} catch(RejectedExecutionException success){ |
305 |
> |
} catch (RejectedExecutionException success) { |
306 |
|
} catch (SecurityException ok) { |
307 |
|
} |
308 |
|
joinPool(se); |
318 |
|
se.scheduleAtFixedRate(new NoOpRunnable(), |
319 |
|
MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
320 |
|
shouldThrow(); |
321 |
< |
} catch(RejectedExecutionException success){ |
321 |
> |
} catch (RejectedExecutionException success) { |
322 |
|
} catch (SecurityException ok) { |
323 |
< |
} |
323 |
> |
} |
324 |
|
joinPool(se); |
325 |
|
} |
326 |
< |
|
326 |
> |
|
327 |
|
/** |
328 |
|
* scheduleWithFixedDelay throws RejectedExecutionException if shutdown |
329 |
|
*/ |
334 |
|
se.scheduleWithFixedDelay(new NoOpRunnable(), |
335 |
|
MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
336 |
|
shouldThrow(); |
337 |
< |
} catch(RejectedExecutionException success){ |
337 |
> |
} catch (RejectedExecutionException success) { |
338 |
|
} catch (SecurityException ok) { |
339 |
< |
} |
339 |
> |
} |
340 |
|
joinPool(se); |
341 |
|
} |
342 |
|
|
350 |
|
p2.execute(new SmallRunnable()); |
351 |
|
try { |
352 |
|
Thread.sleep(SHORT_DELAY_MS); |
353 |
< |
} catch(Exception e){ |
353 |
> |
} catch (Exception e) { |
354 |
|
unexpectedException(); |
355 |
|
} |
356 |
|
assertEquals(1, p2.getActiveCount()); |
357 |
|
joinPool(p2); |
358 |
|
} |
359 |
< |
|
359 |
> |
|
360 |
|
/** |
361 |
|
* getCompletedTaskCount increases, but doesn't overestimate, |
362 |
|
* when tasks complete |
367 |
|
p2.execute(new SmallRunnable()); |
368 |
|
try { |
369 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
370 |
< |
} catch(Exception e){ |
370 |
> |
} catch (Exception e) { |
371 |
|
unexpectedException(); |
372 |
|
} |
373 |
|
assertEquals(1, p2.getCompletedTaskCount()); |
374 |
|
joinPool(p2); |
375 |
|
} |
376 |
< |
|
376 |
> |
|
377 |
|
/** |
378 |
< |
* getCorePoolSize returns size given in constructor if not otherwise set |
378 |
> |
* getCorePoolSize returns size given in constructor if not otherwise set |
379 |
|
*/ |
380 |
|
public void testGetCorePoolSize() { |
381 |
|
CustomExecutor p1 = new CustomExecutor(1); |
382 |
|
assertEquals(1, p1.getCorePoolSize()); |
383 |
|
joinPool(p1); |
384 |
|
} |
385 |
< |
|
385 |
> |
|
386 |
|
/** |
387 |
|
* getLargestPoolSize increases, but doesn't overestimate, when |
388 |
|
* multiple threads active |
394 |
|
p2.execute(new SmallRunnable()); |
395 |
|
try { |
396 |
|
Thread.sleep(SHORT_DELAY_MS); |
397 |
< |
} catch(Exception e){ |
397 |
> |
} catch (Exception e) { |
398 |
|
unexpectedException(); |
399 |
|
} |
400 |
|
assertEquals(2, p2.getLargestPoolSize()); |
401 |
|
joinPool(p2); |
402 |
|
} |
403 |
< |
|
403 |
> |
|
404 |
|
/** |
405 |
|
* getPoolSize increases, but doesn't overestimate, when threads |
406 |
|
* become active |
412 |
|
assertEquals(1, p1.getPoolSize()); |
413 |
|
joinPool(p1); |
414 |
|
} |
415 |
< |
|
415 |
> |
|
416 |
|
/** |
417 |
|
* getTaskCount increases, but doesn't overestimate, when tasks |
418 |
|
* submitted |
420 |
|
public void testGetTaskCount() { |
421 |
|
CustomExecutor p1 = new CustomExecutor(1); |
422 |
|
assertEquals(0, p1.getTaskCount()); |
423 |
< |
for(int i = 0; i < 5; i++) |
423 |
> |
for (int i = 0; i < 5; i++) |
424 |
|
p1.execute(new SmallRunnable()); |
425 |
|
try { |
426 |
|
Thread.sleep(SHORT_DELAY_MS); |
427 |
< |
} catch(Exception e){ |
427 |
> |
} catch (Exception e) { |
428 |
|
unexpectedException(); |
429 |
|
} |
430 |
|
assertEquals(5, p1.getTaskCount()); |
431 |
|
joinPool(p1); |
432 |
|
} |
433 |
|
|
434 |
< |
/** |
434 |
> |
/** |
435 |
|
* getThreadFactory returns factory in constructor if not set |
436 |
|
*/ |
437 |
|
public void testGetThreadFactory() { |
441 |
|
joinPool(p); |
442 |
|
} |
443 |
|
|
444 |
< |
/** |
444 |
> |
/** |
445 |
|
* setThreadFactory sets the thread factory returned by getThreadFactory |
446 |
|
*/ |
447 |
|
public void testSetThreadFactory() { |
452 |
|
joinPool(p); |
453 |
|
} |
454 |
|
|
455 |
< |
/** |
455 |
> |
/** |
456 |
|
* setThreadFactory(null) throws NPE |
457 |
|
*/ |
458 |
|
public void testSetThreadFactoryNull() { |
465 |
|
joinPool(p); |
466 |
|
} |
467 |
|
} |
468 |
< |
|
468 |
> |
|
469 |
|
/** |
470 |
|
* is isShutDown is false before shutdown, true after |
471 |
|
*/ |
472 |
|
public void testIsShutdown() { |
473 |
< |
|
473 |
> |
|
474 |
|
CustomExecutor p1 = new CustomExecutor(1); |
475 |
|
try { |
476 |
|
assertFalse(p1.isShutdown()); |
477 |
|
} |
478 |
|
finally { |
479 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
479 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
480 |
|
} |
481 |
|
assertTrue(p1.isShutdown()); |
482 |
|
} |
483 |
|
|
484 |
< |
|
484 |
> |
|
485 |
|
/** |
486 |
|
* isTerminated is false before termination, true after |
487 |
|
*/ |
490 |
|
try { |
491 |
|
p1.execute(new SmallRunnable()); |
492 |
|
} finally { |
493 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
493 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
494 |
|
} |
495 |
|
try { |
496 |
|
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
497 |
|
assertTrue(p1.isTerminated()); |
498 |
< |
} catch(Exception e){ |
498 |
> |
} catch (Exception e) { |
499 |
|
unexpectedException(); |
500 |
< |
} |
500 |
> |
} |
501 |
|
} |
502 |
|
|
503 |
|
/** |
510 |
|
p1.execute(new SmallRunnable()); |
511 |
|
assertFalse(p1.isTerminating()); |
512 |
|
} finally { |
513 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
513 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
514 |
|
} |
515 |
|
try { |
516 |
|
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
517 |
|
assertTrue(p1.isTerminated()); |
518 |
|
assertFalse(p1.isTerminating()); |
519 |
< |
} catch(Exception e){ |
519 |
> |
} catch (Exception e) { |
520 |
|
unexpectedException(); |
521 |
< |
} |
521 |
> |
} |
522 |
|
} |
523 |
|
|
524 |
|
/** |
527 |
|
public void testGetQueue() { |
528 |
|
CustomExecutor p1 = new CustomExecutor(1); |
529 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
530 |
< |
for(int i = 0; i < 5; i++){ |
530 |
> |
for (int i = 0; i < 5; i++) { |
531 |
|
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); |
532 |
|
} |
533 |
|
try { |
535 |
|
BlockingQueue<Runnable> q = p1.getQueue(); |
536 |
|
assertTrue(q.contains(tasks[4])); |
537 |
|
assertFalse(q.contains(tasks[0])); |
538 |
< |
} catch(Exception e) { |
538 |
> |
} catch (Exception e) { |
539 |
|
unexpectedException(); |
540 |
|
} finally { |
541 |
|
joinPool(p1); |
548 |
|
public void testRemove() { |
549 |
|
CustomExecutor p1 = new CustomExecutor(1); |
550 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
551 |
< |
for(int i = 0; i < 5; i++){ |
551 |
> |
for (int i = 0; i < 5; i++) { |
552 |
|
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); |
553 |
|
} |
554 |
|
try { |
563 |
|
assertTrue(q.contains((Runnable)tasks[3])); |
564 |
|
assertTrue(p1.remove((Runnable)tasks[3])); |
565 |
|
assertFalse(q.contains((Runnable)tasks[3])); |
566 |
< |
} catch(Exception e) { |
566 |
> |
} catch (Exception e) { |
567 |
|
unexpectedException(); |
568 |
|
} finally { |
569 |
|
joinPool(p1); |
576 |
|
public void testPurge() { |
577 |
|
CustomExecutor p1 = new CustomExecutor(1); |
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 SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
581 |
|
} |
582 |
|
try { |
594 |
|
Thread.sleep(1); |
595 |
|
} |
596 |
|
assertTrue(k < SMALL_DELAY_MS); |
597 |
< |
} catch(Exception e) { |
597 |
> |
} catch (Exception e) { |
598 |
|
unexpectedException(); |
599 |
|
} finally { |
600 |
|
joinPool(p1); |
606 |
|
*/ |
607 |
|
public void testShutDownNow() { |
608 |
|
CustomExecutor p1 = new CustomExecutor(1); |
609 |
< |
for(int i = 0; i < 5; i++) |
609 |
> |
for (int i = 0; i < 5; i++) |
610 |
|
p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
611 |
|
List l; |
612 |
|
try { |
613 |
|
l = p1.shutdownNow(); |
614 |
< |
} catch (SecurityException ok) { |
614 |
> |
} catch (SecurityException ok) { |
615 |
|
return; |
616 |
|
} |
617 |
|
assertTrue(p1.isShutdown()); |
630 |
|
assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
631 |
|
|
632 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
633 |
< |
for(int i = 0; i < 5; i++) |
633 |
> |
for (int i = 0; i < 5; i++) |
634 |
|
tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
635 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
635 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
636 |
|
BlockingQueue q = p1.getQueue(); |
637 |
|
for (Iterator it = q.iterator(); it.hasNext();) { |
638 |
|
ScheduledFuture t = (ScheduledFuture)it.next(); |
644 |
|
assertTrue(tasks[i].isDone()); |
645 |
|
assertFalse(tasks[i].isCancelled()); |
646 |
|
} |
647 |
< |
|
647 |
> |
|
648 |
|
} |
649 |
< |
catch(Exception ex) { |
649 |
> |
catch (Exception ex) { |
650 |
|
unexpectedException(); |
651 |
|
} |
652 |
|
} |
661 |
|
CustomExecutor p1 = new CustomExecutor(1); |
662 |
|
p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); |
663 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
664 |
< |
for(int i = 0; i < 5; i++) |
664 |
> |
for (int i = 0; i < 5; i++) |
665 |
|
tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
666 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
666 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
667 |
|
assertTrue(p1.isShutdown()); |
668 |
|
BlockingQueue q = p1.getQueue(); |
669 |
|
assertTrue(q.isEmpty()); |
670 |
|
Thread.sleep(SMALL_DELAY_MS); |
671 |
|
assertTrue(p1.isTerminated()); |
672 |
|
} |
673 |
< |
catch(Exception ex) { |
673 |
> |
catch (Exception ex) { |
674 |
|
unexpectedException(); |
675 |
|
} |
676 |
|
} |
686 |
|
p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); |
687 |
|
ScheduledFuture task = |
688 |
|
p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS); |
689 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
689 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
690 |
|
assertTrue(p1.isShutdown()); |
691 |
|
BlockingQueue q = p1.getQueue(); |
692 |
|
assertTrue(q.isEmpty()); |
693 |
|
Thread.sleep(SHORT_DELAY_MS); |
694 |
|
assertTrue(p1.isTerminated()); |
695 |
|
} |
696 |
< |
catch(Exception ex) { |
696 |
> |
catch (Exception ex) { |
697 |
|
unexpectedException(); |
698 |
|
} |
699 |
|
} |
709 |
|
ScheduledFuture task = |
710 |
|
p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, TimeUnit.MILLISECONDS); |
711 |
|
assertFalse(task.isCancelled()); |
712 |
< |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
712 |
> |
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
713 |
|
assertFalse(task.isCancelled()); |
714 |
|
assertFalse(p1.isTerminated()); |
715 |
|
assertTrue(p1.isShutdown()); |
720 |
|
Thread.sleep(SHORT_DELAY_MS); |
721 |
|
assertTrue(p1.isTerminated()); |
722 |
|
} |
723 |
< |
catch(Exception ex) { |
723 |
> |
catch (Exception ex) { |
724 |
|
unexpectedException(); |
725 |
|
} |
726 |
< |
finally { |
726 |
> |
finally { |
727 |
|
joinPool(p1); |
728 |
|
} |
729 |
|
} |
796 |
|
try { |
797 |
|
e.invokeAny(null); |
798 |
|
} catch (NullPointerException success) { |
799 |
< |
} catch(Exception ex) { |
799 |
> |
} catch (Exception ex) { |
800 |
|
unexpectedException(); |
801 |
|
} finally { |
802 |
|
joinPool(e); |
811 |
|
try { |
812 |
|
e.invokeAny(new ArrayList<Callable<String>>()); |
813 |
|
} catch (IllegalArgumentException success) { |
814 |
< |
} catch(Exception ex) { |
814 |
> |
} catch (Exception ex) { |
815 |
|
unexpectedException(); |
816 |
|
} finally { |
817 |
|
joinPool(e); |
829 |
|
l.add(null); |
830 |
|
e.invokeAny(l); |
831 |
|
} catch (NullPointerException success) { |
832 |
< |
} catch(Exception ex) { |
832 |
> |
} catch (Exception ex) { |
833 |
|
unexpectedException(); |
834 |
|
} finally { |
835 |
|
joinPool(e); |
846 |
|
l.add(new NPETask()); |
847 |
|
e.invokeAny(l); |
848 |
|
} catch (ExecutionException success) { |
849 |
< |
} catch(Exception ex) { |
849 |
> |
} catch (Exception ex) { |
850 |
|
unexpectedException(); |
851 |
|
} finally { |
852 |
|
joinPool(e); |
865 |
|
String result = e.invokeAny(l); |
866 |
|
assertSame(TEST_STRING, result); |
867 |
|
} catch (ExecutionException success) { |
868 |
< |
} catch(Exception ex) { |
868 |
> |
} catch (Exception ex) { |
869 |
|
unexpectedException(); |
870 |
|
} finally { |
871 |
|
joinPool(e); |
880 |
|
try { |
881 |
|
e.invokeAll(null); |
882 |
|
} catch (NullPointerException success) { |
883 |
< |
} catch(Exception ex) { |
883 |
> |
} catch (Exception ex) { |
884 |
|
unexpectedException(); |
885 |
|
} finally { |
886 |
|
joinPool(e); |
895 |
|
try { |
896 |
|
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); |
897 |
|
assertTrue(r.isEmpty()); |
898 |
< |
} catch(Exception ex) { |
898 |
> |
} catch (Exception ex) { |
899 |
|
unexpectedException(); |
900 |
|
} finally { |
901 |
|
joinPool(e); |
913 |
|
l.add(null); |
914 |
|
e.invokeAll(l); |
915 |
|
} catch (NullPointerException success) { |
916 |
< |
} catch(Exception ex) { |
916 |
> |
} catch (Exception ex) { |
917 |
|
unexpectedException(); |
918 |
|
} finally { |
919 |
|
joinPool(e); |
930 |
|
l.add(new NPETask()); |
931 |
|
List<Future<String>> result = e.invokeAll(l); |
932 |
|
assertEquals(1, result.size()); |
933 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
933 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
934 |
|
it.next().get(); |
935 |
< |
} catch(ExecutionException success) { |
936 |
< |
} catch(Exception ex) { |
935 |
> |
} catch (ExecutionException success) { |
936 |
> |
} catch (Exception ex) { |
937 |
|
unexpectedException(); |
938 |
|
} finally { |
939 |
|
joinPool(e); |
951 |
|
l.add(new StringTask()); |
952 |
|
List<Future<String>> result = e.invokeAll(l); |
953 |
|
assertEquals(2, result.size()); |
954 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
954 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
955 |
|
assertSame(TEST_STRING, it.next().get()); |
956 |
|
} catch (ExecutionException success) { |
957 |
< |
} catch(Exception ex) { |
957 |
> |
} catch (Exception ex) { |
958 |
|
unexpectedException(); |
959 |
|
} finally { |
960 |
|
joinPool(e); |
969 |
|
try { |
970 |
|
e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
971 |
|
} catch (NullPointerException success) { |
972 |
< |
} catch(Exception ex) { |
972 |
> |
} catch (Exception ex) { |
973 |
|
unexpectedException(); |
974 |
|
} finally { |
975 |
|
joinPool(e); |
986 |
|
l.add(new StringTask()); |
987 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
988 |
|
} catch (NullPointerException success) { |
989 |
< |
} catch(Exception ex) { |
989 |
> |
} catch (Exception ex) { |
990 |
|
unexpectedException(); |
991 |
|
} finally { |
992 |
|
joinPool(e); |
1001 |
|
try { |
1002 |
|
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1003 |
|
} catch (IllegalArgumentException success) { |
1004 |
< |
} catch(Exception ex) { |
1004 |
> |
} catch (Exception ex) { |
1005 |
|
unexpectedException(); |
1006 |
|
} finally { |
1007 |
|
joinPool(e); |
1019 |
|
l.add(null); |
1020 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1021 |
|
} catch (NullPointerException success) { |
1022 |
< |
} catch(Exception ex) { |
1022 |
> |
} catch (Exception ex) { |
1023 |
|
ex.printStackTrace(); |
1024 |
|
unexpectedException(); |
1025 |
|
} finally { |
1036 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1037 |
|
l.add(new NPETask()); |
1038 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1039 |
< |
} catch(ExecutionException success) { |
1040 |
< |
} catch(Exception ex) { |
1039 |
> |
} catch (ExecutionException success) { |
1040 |
> |
} catch (Exception ex) { |
1041 |
|
unexpectedException(); |
1042 |
|
} finally { |
1043 |
|
joinPool(e); |
1056 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1057 |
|
assertSame(TEST_STRING, result); |
1058 |
|
} catch (ExecutionException success) { |
1059 |
< |
} catch(Exception ex) { |
1059 |
> |
} catch (Exception ex) { |
1060 |
|
unexpectedException(); |
1061 |
|
} finally { |
1062 |
|
joinPool(e); |
1071 |
|
try { |
1072 |
|
e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1073 |
|
} catch (NullPointerException success) { |
1074 |
< |
} catch(Exception ex) { |
1074 |
> |
} catch (Exception ex) { |
1075 |
|
unexpectedException(); |
1076 |
|
} finally { |
1077 |
|
joinPool(e); |
1088 |
|
l.add(new StringTask()); |
1089 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1090 |
|
} catch (NullPointerException success) { |
1091 |
< |
} catch(Exception ex) { |
1091 |
> |
} catch (Exception ex) { |
1092 |
|
unexpectedException(); |
1093 |
|
} finally { |
1094 |
|
joinPool(e); |
1103 |
|
try { |
1104 |
|
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1105 |
|
assertTrue(r.isEmpty()); |
1106 |
< |
} catch(Exception ex) { |
1106 |
> |
} catch (Exception ex) { |
1107 |
|
unexpectedException(); |
1108 |
|
} finally { |
1109 |
|
joinPool(e); |
1121 |
|
l.add(null); |
1122 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1123 |
|
} catch (NullPointerException success) { |
1124 |
< |
} catch(Exception ex) { |
1124 |
> |
} catch (Exception ex) { |
1125 |
|
unexpectedException(); |
1126 |
|
} finally { |
1127 |
|
joinPool(e); |
1138 |
|
l.add(new NPETask()); |
1139 |
|
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1140 |
|
assertEquals(1, result.size()); |
1141 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1141 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1142 |
|
it.next().get(); |
1143 |
< |
} catch(ExecutionException success) { |
1144 |
< |
} catch(Exception ex) { |
1143 |
> |
} catch (ExecutionException success) { |
1144 |
> |
} catch (Exception ex) { |
1145 |
|
unexpectedException(); |
1146 |
|
} finally { |
1147 |
|
joinPool(e); |
1159 |
|
l.add(new StringTask()); |
1160 |
|
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1161 |
|
assertEquals(2, result.size()); |
1162 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1162 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1163 |
|
assertSame(TEST_STRING, it.next().get()); |
1164 |
|
} catch (ExecutionException success) { |
1165 |
< |
} catch(Exception ex) { |
1165 |
> |
} catch (Exception ex) { |
1166 |
|
unexpectedException(); |
1167 |
|
} finally { |
1168 |
|
joinPool(e); |
1181 |
|
l.add(new StringTask()); |
1182 |
|
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
1183 |
|
assertEquals(3, result.size()); |
1184 |
< |
Iterator<Future<String>> it = result.iterator(); |
1184 |
> |
Iterator<Future<String>> it = result.iterator(); |
1185 |
|
Future<String> f1 = it.next(); |
1186 |
|
Future<String> f2 = it.next(); |
1187 |
|
Future<String> f3 = it.next(); |
1190 |
|
assertTrue(f3.isDone()); |
1191 |
|
assertFalse(f1.isCancelled()); |
1192 |
|
assertTrue(f2.isCancelled()); |
1193 |
< |
} catch(Exception ex) { |
1193 |
> |
} catch (Exception ex) { |
1194 |
|
unexpectedException(); |
1195 |
|
} finally { |
1196 |
|
joinPool(e); |