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 java.util.concurrent.*; |
13 |
|
|
14 |
|
public class ThreadPoolExecutorTest 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(ThreadPoolExecutorTest.class); |
20 |
|
} |
21 |
< |
|
21 |
> |
|
22 |
|
static class ExtendedTPE extends ThreadPoolExecutor { |
23 |
|
volatile boolean beforeCalled = false; |
24 |
|
volatile boolean afterCalled = false; |
42 |
|
public Thread newThread(Runnable r){ |
43 |
|
if (++calls > 1) return null; |
44 |
|
return new Thread(r); |
45 |
< |
} |
45 |
> |
} |
46 |
|
} |
47 |
< |
|
47 |
> |
|
48 |
|
|
49 |
|
/** |
50 |
|
* execute successfully executes a runnable |
64 |
|
Thread.sleep(SMALL_DELAY_MS); |
65 |
|
} catch(InterruptedException e){ |
66 |
|
unexpectedException(); |
67 |
< |
} |
67 |
> |
} |
68 |
|
joinPool(p1); |
69 |
|
} |
70 |
|
|
112 |
|
assertEquals(2, p2.getPoolSize()); |
113 |
|
joinPool(p2); |
114 |
|
} |
115 |
< |
|
115 |
> |
|
116 |
|
/** |
117 |
|
* getCompletedTaskCount increases, but doesn't overestimate, |
118 |
|
* when tasks complete |
130 |
|
try { p2.shutdown(); } catch(SecurityException ok) { return; } |
131 |
|
joinPool(p2); |
132 |
|
} |
133 |
< |
|
133 |
> |
|
134 |
|
/** |
135 |
|
* getCorePoolSize returns size given in constructor if not otherwise set |
136 |
|
*/ |
139 |
|
assertEquals(1, p1.getCorePoolSize()); |
140 |
|
joinPool(p1); |
141 |
|
} |
142 |
< |
|
142 |
> |
|
143 |
|
/** |
144 |
|
* getKeepAliveTime returns value given in constructor if not otherwise set |
145 |
|
*/ |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
< |
/** |
153 |
> |
/** |
154 |
|
* getThreadFactory returns factory in constructor if not set |
155 |
|
*/ |
156 |
|
public void testGetThreadFactory() { |
160 |
|
joinPool(p); |
161 |
|
} |
162 |
|
|
163 |
< |
/** |
163 |
> |
/** |
164 |
|
* setThreadFactory sets the thread factory returned by getThreadFactory |
165 |
|
*/ |
166 |
|
public void testSetThreadFactory() { |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
< |
/** |
175 |
> |
/** |
176 |
|
* setThreadFactory(null) throws NPE |
177 |
|
*/ |
178 |
|
public void testSetThreadFactoryNull() { |
186 |
|
} |
187 |
|
} |
188 |
|
|
189 |
< |
/** |
189 |
> |
/** |
190 |
|
* getRejectedExecutionHandler returns handler in constructor if not set |
191 |
|
*/ |
192 |
|
public void testGetRejectedExecutionHandler() { |
196 |
|
joinPool(p); |
197 |
|
} |
198 |
|
|
199 |
< |
/** |
199 |
> |
/** |
200 |
|
* setRejectedExecutionHandler sets the handler returned by |
201 |
|
* getRejectedExecutionHandler |
202 |
|
*/ |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
< |
/** |
212 |
> |
/** |
213 |
|
* setRejectedExecutionHandler(null) throws NPE |
214 |
|
*/ |
215 |
|
public void testSetRejectedExecutionHandlerNull() { |
223 |
|
} |
224 |
|
} |
225 |
|
|
226 |
< |
|
226 |
> |
|
227 |
|
/** |
228 |
|
* getLargestPoolSize increases, but doesn't overestimate, when |
229 |
|
* multiple threads active |
238 |
|
assertEquals(2, p2.getLargestPoolSize()); |
239 |
|
} catch(Exception e){ |
240 |
|
unexpectedException(); |
241 |
< |
} |
241 |
> |
} |
242 |
|
joinPool(p2); |
243 |
|
} |
244 |
< |
|
244 |
> |
|
245 |
|
/** |
246 |
|
* getMaximumPoolSize returns value given in constructor if not |
247 |
|
* otherwise set |
251 |
|
assertEquals(2, p2.getMaximumPoolSize()); |
252 |
|
joinPool(p2); |
253 |
|
} |
254 |
< |
|
254 |
> |
|
255 |
|
/** |
256 |
|
* getPoolSize increases, but doesn't overestimate, when threads |
257 |
|
* become active |
263 |
|
assertEquals(1, p1.getPoolSize()); |
264 |
|
joinPool(p1); |
265 |
|
} |
266 |
< |
|
266 |
> |
|
267 |
|
/** |
268 |
|
* getTaskCount increases, but doesn't overestimate, when tasks submitted |
269 |
|
*/ |
276 |
|
assertEquals(1, p1.getTaskCount()); |
277 |
|
} catch(Exception e){ |
278 |
|
unexpectedException(); |
279 |
< |
} |
279 |
> |
} |
280 |
|
joinPool(p1); |
281 |
|
} |
282 |
< |
|
282 |
> |
|
283 |
|
/** |
284 |
|
* isShutDown is false before shutdown, true after |
285 |
|
*/ |
286 |
|
public void testIsShutdown() { |
287 |
< |
|
287 |
> |
|
288 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
289 |
|
assertFalse(p1.isShutdown()); |
290 |
|
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
292 |
|
joinPool(p1); |
293 |
|
} |
294 |
|
|
295 |
< |
|
295 |
> |
|
296 |
|
/** |
297 |
|
* isTerminated is false before termination, true after |
298 |
|
*/ |
309 |
|
assertTrue(p1.isTerminated()); |
310 |
|
} catch(Exception e){ |
311 |
|
unexpectedException(); |
312 |
< |
} |
312 |
> |
} |
313 |
|
} |
314 |
|
|
315 |
|
/** |
330 |
|
assertFalse(p1.isTerminating()); |
331 |
|
} catch(Exception e){ |
332 |
|
unexpectedException(); |
333 |
< |
} |
333 |
> |
} |
334 |
|
} |
335 |
|
|
336 |
|
/** |
421 |
|
try { |
422 |
|
l = p1.shutdownNow(); |
423 |
|
} catch (SecurityException ok) { return; } |
424 |
< |
|
424 |
> |
|
425 |
|
} |
426 |
|
assertTrue(p1.isShutdown()); |
427 |
|
assertTrue(l.size() <= 4); |
428 |
|
} |
429 |
|
|
430 |
|
// Exception Tests |
431 |
– |
|
431 |
|
|
432 |
< |
/** |
433 |
< |
* Constructor throws if corePoolSize argument is less than zero |
432 |
> |
|
433 |
> |
/** |
434 |
> |
* Constructor throws if corePoolSize argument is less than zero |
435 |
|
*/ |
436 |
|
public void testConstructor1() { |
437 |
|
try { |
440 |
|
} |
441 |
|
catch (IllegalArgumentException success){} |
442 |
|
} |
443 |
< |
|
444 |
< |
/** |
445 |
< |
* Constructor throws if maximumPoolSize is less than zero |
443 |
> |
|
444 |
> |
/** |
445 |
> |
* Constructor throws if maximumPoolSize is less than zero |
446 |
|
*/ |
447 |
|
public void testConstructor2() { |
448 |
|
try { |
451 |
|
} |
452 |
|
catch (IllegalArgumentException success){} |
453 |
|
} |
454 |
< |
|
455 |
< |
/** |
456 |
< |
* Constructor throws if maximumPoolSize is equal to zero |
454 |
> |
|
455 |
> |
/** |
456 |
> |
* Constructor throws if maximumPoolSize is equal to zero |
457 |
|
*/ |
458 |
|
public void testConstructor3() { |
459 |
|
try { |
463 |
|
catch (IllegalArgumentException success){} |
464 |
|
} |
465 |
|
|
466 |
< |
/** |
467 |
< |
* Constructor throws if keepAliveTime is less than zero |
466 |
> |
/** |
467 |
> |
* Constructor throws if keepAliveTime is less than zero |
468 |
|
*/ |
469 |
|
public void testConstructor4() { |
470 |
|
try { |
474 |
|
catch (IllegalArgumentException success){} |
475 |
|
} |
476 |
|
|
477 |
< |
/** |
478 |
< |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
477 |
> |
/** |
478 |
> |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
479 |
|
*/ |
480 |
|
public void testConstructor5() { |
481 |
|
try { |
484 |
|
} |
485 |
|
catch (IllegalArgumentException success){} |
486 |
|
} |
487 |
< |
|
488 |
< |
/** |
489 |
< |
* Constructor throws if workQueue is set to null |
487 |
> |
|
488 |
> |
/** |
489 |
> |
* Constructor throws if workQueue is set to null |
490 |
|
*/ |
491 |
|
public void testConstructorNullPointerException() { |
492 |
|
try { |
493 |
|
new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null); |
494 |
|
shouldThrow(); |
495 |
|
} |
496 |
< |
catch (NullPointerException success){} |
496 |
> |
catch (NullPointerException success){} |
497 |
|
} |
498 |
– |
|
498 |
|
|
499 |
< |
|
500 |
< |
/** |
501 |
< |
* Constructor throws if corePoolSize argument is less than zero |
499 |
> |
|
500 |
> |
|
501 |
> |
/** |
502 |
> |
* Constructor throws if corePoolSize argument is less than zero |
503 |
|
*/ |
504 |
|
public void testConstructor6() { |
505 |
|
try { |
507 |
|
shouldThrow(); |
508 |
|
} catch (IllegalArgumentException success){} |
509 |
|
} |
510 |
< |
|
511 |
< |
/** |
512 |
< |
* Constructor throws if maximumPoolSize is less than zero |
510 |
> |
|
511 |
> |
/** |
512 |
> |
* Constructor throws if maximumPoolSize is less than zero |
513 |
|
*/ |
514 |
|
public void testConstructor7() { |
515 |
|
try { |
519 |
|
catch (IllegalArgumentException success){} |
520 |
|
} |
521 |
|
|
522 |
< |
/** |
523 |
< |
* Constructor throws if maximumPoolSize is equal to zero |
522 |
> |
/** |
523 |
> |
* Constructor throws if maximumPoolSize is equal to zero |
524 |
|
*/ |
525 |
|
public void testConstructor8() { |
526 |
|
try { |
530 |
|
catch (IllegalArgumentException success){} |
531 |
|
} |
532 |
|
|
533 |
< |
/** |
534 |
< |
* Constructor throws if keepAliveTime is less than zero |
533 |
> |
/** |
534 |
> |
* Constructor throws if keepAliveTime is less than zero |
535 |
|
*/ |
536 |
|
public void testConstructor9() { |
537 |
|
try { |
541 |
|
catch (IllegalArgumentException success){} |
542 |
|
} |
543 |
|
|
544 |
< |
/** |
545 |
< |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
544 |
> |
/** |
545 |
> |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
546 |
|
*/ |
547 |
|
public void testConstructor10() { |
548 |
|
try { |
552 |
|
catch (IllegalArgumentException success){} |
553 |
|
} |
554 |
|
|
555 |
< |
/** |
556 |
< |
* Constructor throws if workQueue is set to null |
555 |
> |
/** |
556 |
> |
* Constructor throws if workQueue is set to null |
557 |
|
*/ |
558 |
|
public void testConstructorNullPointerException2() { |
559 |
|
try { |
560 |
|
new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory()); |
561 |
|
shouldThrow(); |
562 |
|
} |
563 |
< |
catch (NullPointerException success){} |
563 |
> |
catch (NullPointerException success){} |
564 |
|
} |
565 |
|
|
566 |
< |
/** |
567 |
< |
* Constructor throws if threadFactory is set to null |
566 |
> |
/** |
567 |
> |
* Constructor throws if threadFactory is set to null |
568 |
|
*/ |
569 |
|
public void testConstructorNullPointerException3() { |
570 |
|
try { |
572 |
|
new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f); |
573 |
|
shouldThrow(); |
574 |
|
} |
575 |
< |
catch (NullPointerException success){} |
575 |
> |
catch (NullPointerException success){} |
576 |
|
} |
577 |
< |
|
578 |
< |
|
579 |
< |
/** |
580 |
< |
* Constructor throws if corePoolSize argument is less than zero |
577 |
> |
|
578 |
> |
|
579 |
> |
/** |
580 |
> |
* Constructor throws if corePoolSize argument is less than zero |
581 |
|
*/ |
582 |
|
public void testConstructor11() { |
583 |
|
try { |
587 |
|
catch (IllegalArgumentException success){} |
588 |
|
} |
589 |
|
|
590 |
< |
/** |
591 |
< |
* Constructor throws if maximumPoolSize is less than zero |
590 |
> |
/** |
591 |
> |
* Constructor throws if maximumPoolSize is less than zero |
592 |
|
*/ |
593 |
|
public void testConstructor12() { |
594 |
|
try { |
598 |
|
catch (IllegalArgumentException success){} |
599 |
|
} |
600 |
|
|
601 |
< |
/** |
602 |
< |
* Constructor throws if maximumPoolSize is equal to zero |
601 |
> |
/** |
602 |
> |
* Constructor throws if maximumPoolSize is equal to zero |
603 |
|
*/ |
604 |
|
public void testConstructor13() { |
605 |
|
try { |
609 |
|
catch (IllegalArgumentException success){} |
610 |
|
} |
611 |
|
|
612 |
< |
/** |
613 |
< |
* Constructor throws if keepAliveTime is less than zero |
612 |
> |
/** |
613 |
> |
* Constructor throws if keepAliveTime is less than zero |
614 |
|
*/ |
615 |
|
public void testConstructor14() { |
616 |
|
try { |
620 |
|
catch (IllegalArgumentException success){} |
621 |
|
} |
622 |
|
|
623 |
< |
/** |
624 |
< |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
623 |
> |
/** |
624 |
> |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
625 |
|
*/ |
626 |
|
public void testConstructor15() { |
627 |
|
try { |
631 |
|
catch (IllegalArgumentException success){} |
632 |
|
} |
633 |
|
|
634 |
< |
/** |
635 |
< |
* Constructor throws if workQueue is set to null |
634 |
> |
/** |
635 |
> |
* Constructor throws if workQueue is set to null |
636 |
|
*/ |
637 |
|
public void testConstructorNullPointerException4() { |
638 |
|
try { |
639 |
|
new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler()); |
640 |
|
shouldThrow(); |
641 |
|
} |
642 |
< |
catch (NullPointerException success){} |
642 |
> |
catch (NullPointerException success){} |
643 |
|
} |
644 |
|
|
645 |
< |
/** |
646 |
< |
* Constructor throws if handler is set to null |
645 |
> |
/** |
646 |
> |
* Constructor throws if handler is set to null |
647 |
|
*/ |
648 |
|
public void testConstructorNullPointerException5() { |
649 |
|
try { |
651 |
|
new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r); |
652 |
|
shouldThrow(); |
653 |
|
} |
654 |
< |
catch (NullPointerException success){} |
654 |
> |
catch (NullPointerException success){} |
655 |
|
} |
656 |
|
|
657 |
< |
|
658 |
< |
/** |
659 |
< |
* Constructor throws if corePoolSize argument is less than zero |
657 |
> |
|
658 |
> |
/** |
659 |
> |
* Constructor throws if corePoolSize argument is less than zero |
660 |
|
*/ |
661 |
|
public void testConstructor16() { |
662 |
|
try { |
666 |
|
catch (IllegalArgumentException success){} |
667 |
|
} |
668 |
|
|
669 |
< |
/** |
670 |
< |
* Constructor throws if maximumPoolSize is less than zero |
669 |
> |
/** |
670 |
> |
* Constructor throws if maximumPoolSize is less than zero |
671 |
|
*/ |
672 |
|
public void testConstructor17() { |
673 |
|
try { |
677 |
|
catch (IllegalArgumentException success){} |
678 |
|
} |
679 |
|
|
680 |
< |
/** |
681 |
< |
* Constructor throws if maximumPoolSize is equal to zero |
680 |
> |
/** |
681 |
> |
* Constructor throws if maximumPoolSize is equal to zero |
682 |
|
*/ |
683 |
|
public void testConstructor18() { |
684 |
|
try { |
688 |
|
catch (IllegalArgumentException success){} |
689 |
|
} |
690 |
|
|
691 |
< |
/** |
692 |
< |
* Constructor throws if keepAliveTime is less than zero |
691 |
> |
/** |
692 |
> |
* Constructor throws if keepAliveTime is less than zero |
693 |
|
*/ |
694 |
|
public void testConstructor19() { |
695 |
|
try { |
699 |
|
catch (IllegalArgumentException success){} |
700 |
|
} |
701 |
|
|
702 |
< |
/** |
703 |
< |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
702 |
> |
/** |
703 |
> |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
704 |
|
*/ |
705 |
|
public void testConstructor20() { |
706 |
|
try { |
710 |
|
catch (IllegalArgumentException success){} |
711 |
|
} |
712 |
|
|
713 |
< |
/** |
714 |
< |
* Constructor throws if workQueue is set to null |
713 |
> |
/** |
714 |
> |
* Constructor throws if workQueue is set to null |
715 |
|
*/ |
716 |
|
public void testConstructorNullPointerException6() { |
717 |
|
try { |
718 |
|
new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); |
719 |
|
shouldThrow(); |
720 |
|
} |
721 |
< |
catch (NullPointerException success){} |
721 |
> |
catch (NullPointerException success){} |
722 |
|
} |
723 |
|
|
724 |
< |
/** |
725 |
< |
* Constructor throws if handler is set to null |
724 |
> |
/** |
725 |
> |
* Constructor throws if handler is set to null |
726 |
|
*/ |
727 |
|
public void testConstructorNullPointerException7() { |
728 |
|
try { |
730 |
|
new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r); |
731 |
|
shouldThrow(); |
732 |
|
} |
733 |
< |
catch (NullPointerException success){} |
733 |
> |
catch (NullPointerException success){} |
734 |
|
} |
735 |
|
|
736 |
< |
/** |
737 |
< |
* Constructor throws if ThreadFactory is set top null |
736 |
> |
/** |
737 |
> |
* Constructor throws if ThreadFactory is set top null |
738 |
|
*/ |
739 |
|
public void testConstructorNullPointerException8() { |
740 |
|
try { |
742 |
|
new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler()); |
743 |
|
shouldThrow(); |
744 |
|
} |
745 |
< |
catch (NullPointerException successdn8){} |
745 |
> |
catch (NullPointerException successdn8){} |
746 |
|
} |
747 |
< |
|
747 |
> |
|
748 |
|
|
749 |
|
/** |
750 |
|
* execute throws RejectedExecutionException |
753 |
|
public void testSaturatedExecute() { |
754 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); |
755 |
|
try { |
756 |
< |
|
756 |
> |
|
757 |
|
for(int i = 0; i < 5; ++i){ |
758 |
|
p.execute(new MediumRunnable()); |
759 |
|
} |
769 |
|
RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy(); |
770 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
771 |
|
try { |
772 |
< |
|
772 |
> |
|
773 |
|
TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; |
774 |
|
for(int i = 0; i < 5; ++i){ |
775 |
|
tasks[i] = new TrackedNoOpRunnable(); |
797 |
|
RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy(); |
798 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
799 |
|
try { |
800 |
< |
|
800 |
> |
|
801 |
|
TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; |
802 |
|
for(int i = 0; i < 5; ++i){ |
803 |
|
tasks[i] = new TrackedNoOpRunnable(); |
844 |
|
* execute throws RejectedExecutionException if shutdown |
845 |
|
*/ |
846 |
|
public void testRejectedExecutionExceptionOnShutdown() { |
847 |
< |
ThreadPoolExecutor tpe = |
847 |
> |
ThreadPoolExecutor tpe = |
848 |
|
new ThreadPoolExecutor(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1)); |
849 |
|
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
850 |
|
try { |
851 |
|
tpe.execute(new NoOpRunnable()); |
852 |
|
shouldThrow(); |
853 |
|
} catch(RejectedExecutionException success){} |
854 |
< |
|
854 |
> |
|
855 |
|
joinPool(tpe); |
856 |
|
} |
857 |
|
|
924 |
|
tpe.execute(null); |
925 |
|
shouldThrow(); |
926 |
|
} catch(NullPointerException success){} |
927 |
< |
|
927 |
> |
|
928 |
|
joinPool(tpe); |
929 |
|
} |
930 |
< |
|
930 |
> |
|
931 |
|
/** |
932 |
|
* setCorePoolSize of negative value throws IllegalArgumentException |
933 |
|
*/ |
944 |
|
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
945 |
|
} |
946 |
|
joinPool(tpe); |
947 |
< |
} |
947 |
> |
} |
948 |
|
|
949 |
|
/** |
950 |
|
* setMaximumPoolSize(int) throws IllegalArgumentException if |
951 |
|
* given a value less the core pool size |
952 |
< |
*/ |
952 |
> |
*/ |
953 |
|
public void testMaximumPoolSizeIllegalArgumentException() { |
954 |
|
ThreadPoolExecutor tpe = null; |
955 |
|
try { |
964 |
|
} |
965 |
|
joinPool(tpe); |
966 |
|
} |
967 |
< |
|
967 |
> |
|
968 |
|
/** |
969 |
|
* setMaximumPoolSize throws IllegalArgumentException |
970 |
|
* if given a negative value |
983 |
|
} |
984 |
|
joinPool(tpe); |
985 |
|
} |
986 |
< |
|
986 |
> |
|
987 |
|
|
988 |
|
/** |
989 |
|
* setKeepAliveTime throws IllegalArgumentException |
994 |
|
try { |
995 |
|
tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
996 |
|
} catch(Exception e){} |
997 |
< |
|
997 |
> |
|
998 |
|
try { |
999 |
|
tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS); |
1000 |
|
shouldThrow(); |
1242 |
|
l.add(new NPETask()); |
1243 |
|
List<Future<String>> result = e.invokeAll(l); |
1244 |
|
assertEquals(1, result.size()); |
1245 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1245 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1246 |
|
it.next().get(); |
1247 |
|
} catch(ExecutionException success) { |
1248 |
|
} catch(Exception ex) { |
1263 |
|
l.add(new StringTask()); |
1264 |
|
List<Future<String>> result = e.invokeAll(l); |
1265 |
|
assertEquals(2, result.size()); |
1266 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1266 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1267 |
|
assertSame(TEST_STRING, it.next().get()); |
1268 |
|
} catch (ExecutionException success) { |
1269 |
|
} catch(Exception ex) { |
1452 |
|
l.add(new NPETask()); |
1453 |
|
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1454 |
|
assertEquals(1, result.size()); |
1455 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1455 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1456 |
|
it.next().get(); |
1457 |
|
} catch(ExecutionException success) { |
1458 |
|
} catch(Exception ex) { |
1473 |
|
l.add(new StringTask()); |
1474 |
|
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1475 |
|
assertEquals(2, result.size()); |
1476 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1476 |
> |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1477 |
|
assertSame(TEST_STRING, it.next().get()); |
1478 |
|
} catch (ExecutionException success) { |
1479 |
|
} catch(Exception ex) { |
1495 |
|
l.add(new StringTask()); |
1496 |
|
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
1497 |
|
assertEquals(3, result.size()); |
1498 |
< |
Iterator<Future<String>> it = result.iterator(); |
1498 |
> |
Iterator<Future<String>> it = result.iterator(); |
1499 |
|
Future<String> f1 = it.next(); |
1500 |
|
Future<String> f2 = it.next(); |
1501 |
|
Future<String> f3 = it.next(); |
1584 |
|
public void run() { |
1585 |
|
nRun.getAndIncrement(); |
1586 |
|
} }; |
1587 |
< |
final ThreadPoolExecutor p = |
1588 |
< |
new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS, |
1587 |
> |
final ThreadPoolExecutor p = |
1588 |
> |
new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS, |
1589 |
|
new ArrayBlockingQueue(30)); |
1590 |
|
try { |
1591 |
|
for (int i = 0; i < nTasks; ++i) { |
1607 |
|
p.shutdown(); |
1608 |
|
} |
1609 |
|
} |
1610 |
< |
|
1610 |
> |
|
1611 |
|
} |