7 |
|
*/ |
8 |
|
|
9 |
|
import java.util.concurrent.*; |
10 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
11 |
|
import java.util.concurrent.locks.*; |
12 |
|
|
13 |
|
import junit.framework.*; |
168 |
|
volatile boolean afterCalled = false; |
169 |
|
volatile boolean terminatedCalled = false; |
170 |
|
public CustomTPE() { |
171 |
< |
super(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>()); |
171 |
> |
super(1, 1, LONG_DELAY_MS, MILLISECONDS, new SynchronousQueue<Runnable>()); |
172 |
|
} |
173 |
|
protected void beforeExecute(Thread t, Runnable r) { |
174 |
|
beforeCalled = true; |
195 |
|
* execute successfully executes a runnable |
196 |
|
*/ |
197 |
|
public void testExecute() throws InterruptedException { |
198 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
198 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
199 |
|
try { |
200 |
|
p1.execute(new ShortRunnable()); |
201 |
|
Thread.sleep(SMALL_DELAY_MS); |
209 |
|
* thread becomes active |
210 |
|
*/ |
211 |
|
public void testGetActiveCount() throws InterruptedException { |
212 |
< |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
212 |
> |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
213 |
|
assertEquals(0, p2.getActiveCount()); |
214 |
|
p2.execute(new MediumRunnable()); |
215 |
|
Thread.sleep(SHORT_DELAY_MS); |
221 |
|
* prestartCoreThread starts a thread if under corePoolSize, else doesn't |
222 |
|
*/ |
223 |
|
public void testPrestartCoreThread() { |
224 |
< |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
224 |
> |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
225 |
|
assertEquals(0, p2.getPoolSize()); |
226 |
|
assertTrue(p2.prestartCoreThread()); |
227 |
|
assertEquals(1, p2.getPoolSize()); |
236 |
|
* prestartAllCoreThreads starts all corePoolSize threads |
237 |
|
*/ |
238 |
|
public void testPrestartAllCoreThreads() { |
239 |
< |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
239 |
> |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
240 |
|
assertEquals(0, p2.getPoolSize()); |
241 |
|
p2.prestartAllCoreThreads(); |
242 |
|
assertEquals(2, p2.getPoolSize()); |
250 |
|
* when tasks complete |
251 |
|
*/ |
252 |
|
public void testGetCompletedTaskCount() throws InterruptedException { |
253 |
< |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
253 |
> |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
254 |
|
assertEquals(0, p2.getCompletedTaskCount()); |
255 |
|
p2.execute(new ShortRunnable()); |
256 |
|
Thread.sleep(SMALL_DELAY_MS); |
263 |
|
* getCorePoolSize returns size given in constructor if not otherwise set |
264 |
|
*/ |
265 |
|
public void testGetCorePoolSize() { |
266 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
266 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
267 |
|
assertEquals(1, p1.getCorePoolSize()); |
268 |
|
joinPool(p1); |
269 |
|
} |
272 |
|
* getKeepAliveTime returns value given in constructor if not otherwise set |
273 |
|
*/ |
274 |
|
public void testGetKeepAliveTime() { |
275 |
< |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
275 |
> |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
276 |
|
assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS)); |
277 |
|
joinPool(p2); |
278 |
|
} |
283 |
|
*/ |
284 |
|
public void testGetThreadFactory() { |
285 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
286 |
< |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler()); |
286 |
> |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler()); |
287 |
|
assertSame(tf, p.getThreadFactory()); |
288 |
|
joinPool(p); |
289 |
|
} |
292 |
|
* setThreadFactory sets the thread factory returned by getThreadFactory |
293 |
|
*/ |
294 |
|
public void testSetThreadFactory() { |
295 |
< |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
295 |
> |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
296 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
297 |
|
p.setThreadFactory(tf); |
298 |
|
assertSame(tf, p.getThreadFactory()); |
304 |
|
* setThreadFactory(null) throws NPE |
305 |
|
*/ |
306 |
|
public void testSetThreadFactoryNull() { |
307 |
< |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
307 |
> |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
308 |
|
try { |
309 |
|
p.setThreadFactory(null); |
310 |
|
shouldThrow(); |
319 |
|
*/ |
320 |
|
public void testGetRejectedExecutionHandler() { |
321 |
|
RejectedExecutionHandler h = new NoOpREHandler(); |
322 |
< |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h); |
322 |
> |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h); |
323 |
|
assertSame(h, p.getRejectedExecutionHandler()); |
324 |
|
joinPool(p); |
325 |
|
} |
329 |
|
* getRejectedExecutionHandler |
330 |
|
*/ |
331 |
|
public void testSetRejectedExecutionHandler() { |
332 |
< |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
332 |
> |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
333 |
|
RejectedExecutionHandler h = new NoOpREHandler(); |
334 |
|
p.setRejectedExecutionHandler(h); |
335 |
|
assertSame(h, p.getRejectedExecutionHandler()); |
341 |
|
* setRejectedExecutionHandler(null) throws NPE |
342 |
|
*/ |
343 |
|
public void testSetRejectedExecutionHandlerNull() { |
344 |
< |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
344 |
> |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
345 |
|
try { |
346 |
|
p.setRejectedExecutionHandler(null); |
347 |
|
shouldThrow(); |
357 |
|
* multiple threads active |
358 |
|
*/ |
359 |
|
public void testGetLargestPoolSize() throws InterruptedException { |
360 |
< |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
360 |
> |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
361 |
|
assertEquals(0, p2.getLargestPoolSize()); |
362 |
|
p2.execute(new MediumRunnable()); |
363 |
|
p2.execute(new MediumRunnable()); |
371 |
|
* otherwise set |
372 |
|
*/ |
373 |
|
public void testGetMaximumPoolSize() { |
374 |
< |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
374 |
> |
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
375 |
|
assertEquals(2, p2.getMaximumPoolSize()); |
376 |
|
joinPool(p2); |
377 |
|
} |
381 |
|
* become active |
382 |
|
*/ |
383 |
|
public void testGetPoolSize() { |
384 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
384 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
385 |
|
assertEquals(0, p1.getPoolSize()); |
386 |
|
p1.execute(new MediumRunnable()); |
387 |
|
assertEquals(1, p1.getPoolSize()); |
392 |
|
* getTaskCount increases, but doesn't overestimate, when tasks submitted |
393 |
|
*/ |
394 |
|
public void testGetTaskCount() throws InterruptedException { |
395 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
395 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
396 |
|
assertEquals(0, p1.getTaskCount()); |
397 |
|
p1.execute(new MediumRunnable()); |
398 |
|
Thread.sleep(SHORT_DELAY_MS); |
405 |
|
*/ |
406 |
|
public void testIsShutdown() { |
407 |
|
|
408 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
408 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
409 |
|
assertFalse(p1.isShutdown()); |
410 |
|
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
411 |
|
assertTrue(p1.isShutdown()); |
417 |
|
* isTerminated is false before termination, true after |
418 |
|
*/ |
419 |
|
public void testIsTerminated() throws InterruptedException { |
420 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
420 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
421 |
|
assertFalse(p1.isTerminated()); |
422 |
|
try { |
423 |
|
p1.execute(new MediumRunnable()); |
424 |
|
} finally { |
425 |
|
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
426 |
|
} |
427 |
< |
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
427 |
> |
assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
428 |
|
assertTrue(p1.isTerminated()); |
429 |
|
} |
430 |
|
|
432 |
|
* isTerminating is not true when running or when terminated |
433 |
|
*/ |
434 |
|
public void testIsTerminating() throws InterruptedException { |
435 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
435 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
436 |
|
assertFalse(p1.isTerminating()); |
437 |
|
try { |
438 |
|
p1.execute(new SmallRunnable()); |
440 |
|
} finally { |
441 |
|
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
442 |
|
} |
443 |
< |
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
443 |
> |
assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
444 |
|
assertTrue(p1.isTerminated()); |
445 |
|
assertFalse(p1.isTerminating()); |
446 |
|
} |
450 |
|
*/ |
451 |
|
public void testGetQueue() throws InterruptedException { |
452 |
|
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10); |
453 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q); |
453 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, q); |
454 |
|
FutureTask[] tasks = new FutureTask[5]; |
455 |
|
for (int i = 0; i < 5; i++) { |
456 |
|
tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE); |
475 |
|
*/ |
476 |
|
public void testRemove() throws InterruptedException { |
477 |
|
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10); |
478 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q); |
478 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, q); |
479 |
|
FutureTask[] tasks = new FutureTask[5]; |
480 |
|
for (int i = 0; i < 5; i++) { |
481 |
|
tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE); |
501 |
|
* purge removes cancelled tasks from the queue |
502 |
|
*/ |
503 |
|
public void testPurge() { |
504 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
504 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
505 |
|
FutureTask[] tasks = new FutureTask[5]; |
506 |
|
for (int i = 0; i < 5; i++) { |
507 |
|
tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE); |
519 |
|
* shutDownNow returns a list containing tasks that were not run |
520 |
|
*/ |
521 |
|
public void testShutDownNow() { |
522 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
522 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
523 |
|
List l; |
524 |
|
try { |
525 |
|
for (int i = 0; i < 5; i++) |
529 |
|
try { |
530 |
|
l = p1.shutdownNow(); |
531 |
|
} catch (SecurityException ok) { return; } |
531 |
– |
|
532 |
|
} |
533 |
|
assertTrue(p1.isShutdown()); |
534 |
|
assertTrue(l.size() <= 4); |
542 |
|
*/ |
543 |
|
public void testConstructor1() { |
544 |
|
try { |
545 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
545 |
> |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
546 |
|
shouldThrow(); |
547 |
|
} catch (IllegalArgumentException success) {} |
548 |
|
} |
552 |
|
*/ |
553 |
|
public void testConstructor2() { |
554 |
|
try { |
555 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
555 |
> |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
556 |
|
shouldThrow(); |
557 |
|
} catch (IllegalArgumentException success) {} |
558 |
|
} |
562 |
|
*/ |
563 |
|
public void testConstructor3() { |
564 |
|
try { |
565 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
565 |
> |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
566 |
|
shouldThrow(); |
567 |
|
} catch (IllegalArgumentException success) {} |
568 |
|
} |
572 |
|
*/ |
573 |
|
public void testConstructor4() { |
574 |
|
try { |
575 |
< |
new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
575 |
> |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
576 |
|
shouldThrow(); |
577 |
|
} catch (IllegalArgumentException success) {} |
578 |
|
} |
582 |
|
*/ |
583 |
|
public void testConstructor5() { |
584 |
|
try { |
585 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
585 |
> |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
586 |
|
shouldThrow(); |
587 |
|
} catch (IllegalArgumentException success) {} |
588 |
|
} |
592 |
|
*/ |
593 |
|
public void testConstructorNullPointerException() { |
594 |
|
try { |
595 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null); |
595 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null); |
596 |
|
shouldThrow(); |
597 |
|
} catch (NullPointerException success) {} |
598 |
|
} |
604 |
|
*/ |
605 |
|
public void testConstructor6() { |
606 |
|
try { |
607 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
607 |
> |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
608 |
|
shouldThrow(); |
609 |
|
} catch (IllegalArgumentException success) {} |
610 |
|
} |
614 |
|
*/ |
615 |
|
public void testConstructor7() { |
616 |
|
try { |
617 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
617 |
> |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
618 |
|
shouldThrow(); |
619 |
|
} catch (IllegalArgumentException success) {} |
620 |
|
} |
624 |
|
*/ |
625 |
|
public void testConstructor8() { |
626 |
|
try { |
627 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
627 |
> |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
628 |
|
shouldThrow(); |
629 |
|
} catch (IllegalArgumentException success) {} |
630 |
|
} |
634 |
|
*/ |
635 |
|
public void testConstructor9() { |
636 |
|
try { |
637 |
< |
new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
637 |
> |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
638 |
|
shouldThrow(); |
639 |
|
} catch (IllegalArgumentException success) {} |
640 |
|
} |
644 |
|
*/ |
645 |
|
public void testConstructor10() { |
646 |
|
try { |
647 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
647 |
> |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
648 |
|
shouldThrow(); |
649 |
|
} catch (IllegalArgumentException success) {} |
650 |
|
} |
654 |
|
*/ |
655 |
|
public void testConstructorNullPointerException2() { |
656 |
|
try { |
657 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory()); |
657 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory()); |
658 |
|
shouldThrow(); |
659 |
|
} catch (NullPointerException success) {} |
660 |
|
} |
665 |
|
public void testConstructorNullPointerException3() { |
666 |
|
try { |
667 |
|
ThreadFactory f = null; |
668 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f); |
668 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f); |
669 |
|
shouldThrow(); |
670 |
|
} catch (NullPointerException success) {} |
671 |
|
} |
676 |
|
*/ |
677 |
|
public void testConstructor11() { |
678 |
|
try { |
679 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
679 |
> |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
680 |
|
shouldThrow(); |
681 |
|
} catch (IllegalArgumentException success) {} |
682 |
|
} |
686 |
|
*/ |
687 |
|
public void testConstructor12() { |
688 |
|
try { |
689 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
689 |
> |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
690 |
|
shouldThrow(); |
691 |
|
} catch (IllegalArgumentException success) {} |
692 |
|
} |
696 |
|
*/ |
697 |
|
public void testConstructor13() { |
698 |
|
try { |
699 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
699 |
> |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
700 |
|
shouldThrow(); |
701 |
|
} catch (IllegalArgumentException success) {} |
702 |
|
} |
706 |
|
*/ |
707 |
|
public void testConstructor14() { |
708 |
|
try { |
709 |
< |
new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
709 |
> |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
710 |
|
shouldThrow(); |
711 |
|
} catch (IllegalArgumentException success) {} |
712 |
|
} |
716 |
|
*/ |
717 |
|
public void testConstructor15() { |
718 |
|
try { |
719 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
719 |
> |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
720 |
|
shouldThrow(); |
721 |
|
} catch (IllegalArgumentException success) {} |
722 |
|
} |
726 |
|
*/ |
727 |
|
public void testConstructorNullPointerException4() { |
728 |
|
try { |
729 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler()); |
729 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler()); |
730 |
|
shouldThrow(); |
731 |
|
} catch (NullPointerException success) {} |
732 |
|
} |
737 |
|
public void testConstructorNullPointerException5() { |
738 |
|
try { |
739 |
|
RejectedExecutionHandler r = null; |
740 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r); |
740 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r); |
741 |
|
shouldThrow(); |
742 |
|
} catch (NullPointerException success) {} |
743 |
|
} |
748 |
|
*/ |
749 |
|
public void testConstructor16() { |
750 |
|
try { |
751 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
751 |
> |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
752 |
|
shouldThrow(); |
753 |
|
} catch (IllegalArgumentException success) {} |
754 |
|
} |
758 |
|
*/ |
759 |
|
public void testConstructor17() { |
760 |
|
try { |
761 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
761 |
> |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
762 |
|
shouldThrow(); |
763 |
|
} catch (IllegalArgumentException success) {} |
764 |
|
} |
768 |
|
*/ |
769 |
|
public void testConstructor18() { |
770 |
|
try { |
771 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
771 |
> |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
772 |
|
shouldThrow(); |
773 |
|
} catch (IllegalArgumentException success) {} |
774 |
|
} |
778 |
|
*/ |
779 |
|
public void testConstructor19() { |
780 |
|
try { |
781 |
< |
new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
781 |
> |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
782 |
|
shouldThrow(); |
783 |
|
} catch (IllegalArgumentException success) {} |
784 |
|
} |
788 |
|
*/ |
789 |
|
public void testConstructor20() { |
790 |
|
try { |
791 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
791 |
> |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
792 |
|
shouldThrow(); |
793 |
|
} catch (IllegalArgumentException success) {} |
794 |
|
} |
798 |
|
*/ |
799 |
|
public void testConstructorNullPointerException6() { |
800 |
|
try { |
801 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); |
801 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); |
802 |
|
shouldThrow(); |
803 |
|
} catch (NullPointerException success) {} |
804 |
|
} |
809 |
|
public void testConstructorNullPointerException7() { |
810 |
|
try { |
811 |
|
RejectedExecutionHandler r = null; |
812 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r); |
812 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r); |
813 |
|
shouldThrow(); |
814 |
|
} catch (NullPointerException success) {} |
815 |
|
} |
820 |
|
public void testConstructorNullPointerException8() { |
821 |
|
try { |
822 |
|
ThreadFactory f = null; |
823 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler()); |
823 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler()); |
824 |
|
shouldThrow(); |
825 |
|
} catch (NullPointerException success) {} |
826 |
|
} |
831 |
|
* if saturated. |
832 |
|
*/ |
833 |
|
public void testSaturatedExecute() { |
834 |
< |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); |
834 |
> |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); |
835 |
|
try { |
836 |
|
|
837 |
|
for (int i = 0; i < 5; ++i) { |
847 |
|
*/ |
848 |
|
public void testSaturatedExecute2() { |
849 |
|
RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); |
850 |
< |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
850 |
> |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
851 |
|
try { |
852 |
|
|
853 |
|
TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; |
873 |
|
*/ |
874 |
|
public void testSaturatedExecute3() { |
875 |
|
RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); |
876 |
< |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
876 |
> |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
877 |
|
try { |
878 |
|
|
879 |
|
TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; |
898 |
|
*/ |
899 |
|
public void testSaturatedExecute4() { |
900 |
|
RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); |
901 |
< |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
901 |
> |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
902 |
|
try { |
903 |
|
p.execute(new TrackedLongRunnable()); |
904 |
|
TrackedLongRunnable r2 = new TrackedLongRunnable(); |
919 |
|
*/ |
920 |
|
public void testRejectedExecutionExceptionOnShutdown() { |
921 |
|
ThreadPoolExecutor tpe = |
922 |
< |
new CustomTPE(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1)); |
922 |
> |
new CustomTPE(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1)); |
923 |
|
try { tpe.shutdown(); } catch (SecurityException ok) { return; } |
924 |
|
try { |
925 |
|
tpe.execute(new NoOpRunnable()); |
934 |
|
*/ |
935 |
|
public void testCallerRunsOnShutdown() { |
936 |
|
RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); |
937 |
< |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
937 |
> |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
938 |
|
|
939 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
940 |
|
try { |
951 |
|
*/ |
952 |
|
public void testDiscardOnShutdown() { |
953 |
|
RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); |
954 |
< |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
954 |
> |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
955 |
|
|
956 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
957 |
|
try { |
969 |
|
*/ |
970 |
|
public void testDiscardOldestOnShutdown() { |
971 |
|
RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); |
972 |
< |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
972 |
> |
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
973 |
|
|
974 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
975 |
|
try { |
983 |
|
|
984 |
|
|
985 |
|
/** |
986 |
< |
* execute (null) throws NPE |
986 |
> |
* execute(null) throws NPE |
987 |
|
*/ |
988 |
|
public void testExecuteNull() { |
989 |
|
ThreadPoolExecutor tpe = null; |
990 |
|
try { |
991 |
< |
tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
991 |
> |
tpe = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
992 |
|
tpe.execute(null); |
993 |
|
shouldThrow(); |
994 |
|
} catch (NullPointerException success) {} |
1001 |
|
*/ |
1002 |
|
public void testCorePoolSizeIllegalArgumentException() { |
1003 |
|
ThreadPoolExecutor tpe = |
1004 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1004 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1005 |
|
try { |
1006 |
|
tpe.setCorePoolSize(-1); |
1007 |
|
shouldThrow(); |
1017 |
|
* given a value less the core pool size |
1018 |
|
*/ |
1019 |
|
public void testMaximumPoolSizeIllegalArgumentException() { |
1020 |
< |
ThreadPoolExecutor tpe = null; |
1021 |
< |
try { |
1022 |
< |
tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1023 |
< |
} catch (Exception e) {} |
1020 |
> |
ThreadPoolExecutor tpe = |
1021 |
> |
new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1022 |
|
try { |
1023 |
|
tpe.setMaximumPoolSize(1); |
1024 |
|
shouldThrow(); |
1034 |
|
* if given a negative value |
1035 |
|
*/ |
1036 |
|
public void testMaximumPoolSizeIllegalArgumentException2() { |
1037 |
< |
ThreadPoolExecutor tpe = null; |
1038 |
< |
try { |
1041 |
< |
tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1042 |
< |
} catch (Exception e) {} |
1037 |
> |
ThreadPoolExecutor tpe = |
1038 |
> |
new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1039 |
|
try { |
1040 |
|
tpe.setMaximumPoolSize(-1); |
1041 |
|
shouldThrow(); |
1052 |
|
* when given a negative value |
1053 |
|
*/ |
1054 |
|
public void testKeepAliveTimeIllegalArgumentException() { |
1055 |
< |
ThreadPoolExecutor tpe = null; |
1056 |
< |
try { |
1061 |
< |
tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1062 |
< |
} catch (Exception e) {} |
1055 |
> |
ThreadPoolExecutor tpe = |
1056 |
> |
new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1057 |
|
|
1058 |
|
try { |
1059 |
< |
tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS); |
1059 |
> |
tpe.setKeepAliveTime(-1,MILLISECONDS); |
1060 |
|
shouldThrow(); |
1061 |
|
} catch (IllegalArgumentException success) { |
1062 |
|
} finally { |
1097 |
|
* completed submit of callable returns result |
1098 |
|
*/ |
1099 |
|
public void testSubmitCallable() throws Exception { |
1100 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1100 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1101 |
|
try { |
1102 |
|
Future<String> future = e.submit(new StringTask()); |
1103 |
|
String result = future.get(); |
1111 |
|
* completed submit of runnable returns successfully |
1112 |
|
*/ |
1113 |
|
public void testSubmitRunnable() throws Exception { |
1114 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1114 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1115 |
|
try { |
1116 |
|
Future<?> future = e.submit(new NoOpRunnable()); |
1117 |
|
future.get(); |
1125 |
|
* completed submit of (runnable, result) returns result |
1126 |
|
*/ |
1127 |
|
public void testSubmitRunnable2() throws Exception { |
1128 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1128 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1129 |
|
try { |
1130 |
|
Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING); |
1131 |
|
String result = future.get(); |
1140 |
|
* invokeAny(null) throws NPE |
1141 |
|
*/ |
1142 |
|
public void testInvokeAny1() throws Exception { |
1143 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1143 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1144 |
|
try { |
1145 |
|
e.invokeAny(null); |
1146 |
|
shouldThrow(); |
1154 |
|
* invokeAny(empty collection) throws IAE |
1155 |
|
*/ |
1156 |
|
public void testInvokeAny2() throws Exception { |
1157 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1157 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1158 |
|
try { |
1159 |
|
e.invokeAny(new ArrayList<Callable<String>>()); |
1160 |
|
shouldThrow(); |
1168 |
|
* invokeAny(c) throws NPE if c has null elements |
1169 |
|
*/ |
1170 |
|
public void testInvokeAny3() throws Exception { |
1171 |
< |
final CountDownLatch latch = new CountDownLatch(1); |
1172 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1171 |
> |
CountDownLatch latch = new CountDownLatch(1); |
1172 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1173 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1174 |
> |
l.add(latchAwaitingStringTask(latch)); |
1175 |
> |
l.add(null); |
1176 |
|
try { |
1180 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1181 |
– |
l.add(new Callable<String>() { |
1182 |
– |
public String call() { |
1183 |
– |
try { |
1184 |
– |
latch.await(); |
1185 |
– |
} catch (InterruptedException ok) {} |
1186 |
– |
return TEST_STRING; |
1187 |
– |
}}); |
1188 |
– |
l.add(null); |
1177 |
|
e.invokeAny(l); |
1178 |
|
shouldThrow(); |
1179 |
|
} catch (NullPointerException success) { |
1187 |
|
* invokeAny(c) throws ExecutionException if no task completes |
1188 |
|
*/ |
1189 |
|
public void testInvokeAny4() throws Exception { |
1190 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1190 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1191 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1192 |
> |
l.add(new NPETask()); |
1193 |
|
try { |
1204 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1205 |
– |
l.add(new NPETask()); |
1194 |
|
e.invokeAny(l); |
1195 |
|
shouldThrow(); |
1196 |
|
} catch (ExecutionException success) { |
1197 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1198 |
|
} finally { |
1199 |
|
joinPool(e); |
1200 |
|
} |
1204 |
|
* invokeAny(c) returns result of some task |
1205 |
|
*/ |
1206 |
|
public void testInvokeAny5() throws Exception { |
1207 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1207 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1208 |
|
try { |
1209 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1209 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1210 |
|
l.add(new StringTask()); |
1211 |
|
l.add(new StringTask()); |
1212 |
|
String result = e.invokeAny(l); |
1220 |
|
* invokeAll(null) throws NPE |
1221 |
|
*/ |
1222 |
|
public void testInvokeAll1() throws Exception { |
1223 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1223 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1224 |
|
try { |
1225 |
|
e.invokeAll(null); |
1226 |
|
shouldThrow(); |
1234 |
|
* invokeAll(empty collection) returns empty collection |
1235 |
|
*/ |
1236 |
|
public void testInvokeAll2() throws Exception { |
1237 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1237 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1238 |
|
try { |
1239 |
|
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); |
1240 |
|
assertTrue(r.isEmpty()); |
1247 |
|
* invokeAll(c) throws NPE if c has null elements |
1248 |
|
*/ |
1249 |
|
public void testInvokeAll3() throws Exception { |
1250 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1250 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1251 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1252 |
> |
l.add(new StringTask()); |
1253 |
> |
l.add(null); |
1254 |
|
try { |
1263 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1264 |
– |
l.add(new StringTask()); |
1265 |
– |
l.add(null); |
1255 |
|
e.invokeAll(l); |
1256 |
|
shouldThrow(); |
1257 |
|
} catch (NullPointerException success) { |
1264 |
|
* get of element of invokeAll(c) throws exception on failed task |
1265 |
|
*/ |
1266 |
|
public void testInvokeAll4() throws Exception { |
1267 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1267 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1268 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1269 |
> |
l.add(new NPETask()); |
1270 |
> |
List<Future<String>> futures = e.invokeAll(l); |
1271 |
> |
assertEquals(1, futures.size()); |
1272 |
|
try { |
1273 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1281 |
< |
l.add(new NPETask()); |
1282 |
< |
List<Future<String>> result = e.invokeAll(l); |
1283 |
< |
assertEquals(1, result.size()); |
1284 |
< |
for (Future<String> future : result) |
1285 |
< |
future.get(); |
1273 |
> |
futures.get(0).get(); |
1274 |
|
shouldThrow(); |
1275 |
|
} catch (ExecutionException success) { |
1276 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1277 |
|
} finally { |
1278 |
|
joinPool(e); |
1279 |
|
} |
1283 |
|
* invokeAll(c) returns results of all completed tasks |
1284 |
|
*/ |
1285 |
|
public void testInvokeAll5() throws Exception { |
1286 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1286 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1287 |
|
try { |
1288 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1288 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1289 |
|
l.add(new StringTask()); |
1290 |
|
l.add(new StringTask()); |
1291 |
< |
List<Future<String>> result = e.invokeAll(l); |
1292 |
< |
assertEquals(2, result.size()); |
1293 |
< |
for (Future<String> future : result) |
1291 |
> |
List<Future<String>> futures = e.invokeAll(l); |
1292 |
> |
assertEquals(2, futures.size()); |
1293 |
> |
for (Future<String> future : futures) |
1294 |
|
assertSame(TEST_STRING, future.get()); |
1295 |
|
} finally { |
1296 |
|
joinPool(e); |
1303 |
|
* timed invokeAny(null) throws NPE |
1304 |
|
*/ |
1305 |
|
public void testTimedInvokeAny1() throws Exception { |
1306 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1306 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1307 |
|
try { |
1308 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1308 |
> |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
1309 |
|
shouldThrow(); |
1310 |
|
} catch (NullPointerException success) { |
1311 |
|
} finally { |
1317 |
|
* timed invokeAny(,,null) throws NPE |
1318 |
|
*/ |
1319 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
1320 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1320 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1321 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1322 |
> |
l.add(new StringTask()); |
1323 |
|
try { |
1333 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1334 |
– |
l.add(new StringTask()); |
1324 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
1325 |
|
shouldThrow(); |
1326 |
|
} catch (NullPointerException success) { |
1333 |
|
* timed invokeAny(empty collection) throws IAE |
1334 |
|
*/ |
1335 |
|
public void testTimedInvokeAny2() throws Exception { |
1336 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1336 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1337 |
|
try { |
1338 |
< |
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1338 |
> |
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
1339 |
|
shouldThrow(); |
1340 |
|
} catch (IllegalArgumentException success) { |
1341 |
|
} finally { |
1347 |
|
* timed invokeAny(c) throws NPE if c has null elements |
1348 |
|
*/ |
1349 |
|
public void testTimedInvokeAny3() throws Exception { |
1350 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1350 |
> |
CountDownLatch latch = new CountDownLatch(1); |
1351 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1352 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1353 |
> |
l.add(latchAwaitingStringTask(latch)); |
1354 |
> |
l.add(null); |
1355 |
|
try { |
1356 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1364 |
< |
l.add(new StringTask()); |
1365 |
< |
l.add(null); |
1366 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1356 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1357 |
|
shouldThrow(); |
1358 |
|
} catch (NullPointerException success) { |
1359 |
|
} finally { |
1360 |
+ |
latch.countDown(); |
1361 |
|
joinPool(e); |
1362 |
|
} |
1363 |
|
} |
1366 |
|
* timed invokeAny(c) throws ExecutionException if no task completes |
1367 |
|
*/ |
1368 |
|
public void testTimedInvokeAny4() throws Exception { |
1369 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1369 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1370 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1371 |
> |
l.add(new NPETask()); |
1372 |
|
try { |
1373 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1381 |
< |
l.add(new NPETask()); |
1382 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1373 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1374 |
|
shouldThrow(); |
1375 |
|
} catch (ExecutionException success) { |
1376 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1377 |
|
} finally { |
1378 |
|
joinPool(e); |
1379 |
|
} |
1383 |
|
* timed invokeAny(c) returns result of some task |
1384 |
|
*/ |
1385 |
|
public void testTimedInvokeAny5() throws Exception { |
1386 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1386 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1387 |
|
try { |
1388 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1388 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1389 |
|
l.add(new StringTask()); |
1390 |
|
l.add(new StringTask()); |
1391 |
< |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1391 |
> |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1392 |
|
assertSame(TEST_STRING, result); |
1393 |
|
} finally { |
1394 |
|
joinPool(e); |
1399 |
|
* timed invokeAll(null) throws NPE |
1400 |
|
*/ |
1401 |
|
public void testTimedInvokeAll1() throws Exception { |
1402 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1402 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1403 |
|
try { |
1404 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1404 |
> |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
1405 |
|
shouldThrow(); |
1406 |
|
} catch (NullPointerException success) { |
1407 |
|
} finally { |
1413 |
|
* timed invokeAll(,,null) throws NPE |
1414 |
|
*/ |
1415 |
|
public void testTimedInvokeAllNullTimeUnit() throws Exception { |
1416 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1416 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1417 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1418 |
> |
l.add(new StringTask()); |
1419 |
|
try { |
1426 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1427 |
– |
l.add(new StringTask()); |
1420 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1421 |
|
shouldThrow(); |
1422 |
|
} catch (NullPointerException success) { |
1429 |
|
* timed invokeAll(empty collection) returns empty collection |
1430 |
|
*/ |
1431 |
|
public void testTimedInvokeAll2() throws Exception { |
1432 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1432 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1433 |
|
try { |
1434 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1434 |
> |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
1435 |
|
assertTrue(r.isEmpty()); |
1436 |
|
} finally { |
1437 |
|
joinPool(e); |
1442 |
|
* timed invokeAll(c) throws NPE if c has null elements |
1443 |
|
*/ |
1444 |
|
public void testTimedInvokeAll3() throws Exception { |
1445 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1445 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1446 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1447 |
> |
l.add(new StringTask()); |
1448 |
> |
l.add(null); |
1449 |
|
try { |
1450 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1456 |
< |
l.add(new StringTask()); |
1457 |
< |
l.add(null); |
1458 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1450 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1451 |
|
shouldThrow(); |
1452 |
|
} catch (NullPointerException success) { |
1453 |
|
} finally { |
1459 |
|
* get of element of invokeAll(c) throws exception on failed task |
1460 |
|
*/ |
1461 |
|
public void testTimedInvokeAll4() throws Exception { |
1462 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1462 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1463 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1464 |
> |
l.add(new NPETask()); |
1465 |
> |
List<Future<String>> futures = |
1466 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1467 |
> |
assertEquals(1, futures.size()); |
1468 |
|
try { |
1469 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1473 |
< |
l.add(new NPETask()); |
1474 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1475 |
< |
assertEquals(1, result.size()); |
1476 |
< |
for (Future<String> future : result) |
1477 |
< |
future.get(); |
1469 |
> |
futures.get(0).get(); |
1470 |
|
shouldThrow(); |
1471 |
|
} catch (ExecutionException success) { |
1472 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
1479 |
|
* timed invokeAll(c) returns results of all completed tasks |
1480 |
|
*/ |
1481 |
|
public void testTimedInvokeAll5() throws Exception { |
1482 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1482 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1483 |
|
try { |
1484 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1484 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1485 |
|
l.add(new StringTask()); |
1486 |
|
l.add(new StringTask()); |
1487 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1488 |
< |
assertEquals(2, result.size()); |
1489 |
< |
for (Future<String> future : result) |
1487 |
> |
List<Future<String>> futures = |
1488 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1489 |
> |
assertEquals(2, futures.size()); |
1490 |
> |
for (Future<String> future : futures) |
1491 |
|
assertSame(TEST_STRING, future.get()); |
1499 |
– |
} catch (ExecutionException success) { |
1492 |
|
} finally { |
1493 |
|
joinPool(e); |
1494 |
|
} |
1498 |
|
* timed invokeAll(c) cancels tasks not completed by timeout |
1499 |
|
*/ |
1500 |
|
public void testTimedInvokeAll6() throws Exception { |
1501 |
< |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1501 |
> |
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1502 |
|
try { |
1503 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1503 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1504 |
|
l.add(new StringTask()); |
1505 |
|
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
1506 |
|
l.add(new StringTask()); |
1507 |
< |
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
1508 |
< |
assertEquals(3, result.size()); |
1509 |
< |
Iterator<Future<String>> it = result.iterator(); |
1507 |
> |
List<Future<String>> futures = |
1508 |
> |
e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
1509 |
> |
assertEquals(3, futures.size()); |
1510 |
> |
Iterator<Future<String>> it = futures.iterator(); |
1511 |
|
Future<String> f1 = it.next(); |
1512 |
|
Future<String> f2 = it.next(); |
1513 |
|
Future<String> f3 = it.next(); |
1526 |
|
* thread factory fails to create more |
1527 |
|
*/ |
1528 |
|
public void testFailingThreadFactory() throws InterruptedException { |
1529 |
< |
ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory()); |
1529 |
> |
ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory()); |
1530 |
|
try { |
1531 |
|
for (int k = 0; k < 100; ++k) { |
1532 |
|
e.execute(new NoOpRunnable()); |
1541 |
|
* allowsCoreThreadTimeOut is by default false. |
1542 |
|
*/ |
1543 |
|
public void testAllowsCoreThreadTimeOut() { |
1544 |
< |
ThreadPoolExecutor tpe = new CustomTPE(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1544 |
> |
ThreadPoolExecutor tpe = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1545 |
|
assertFalse(tpe.allowsCoreThreadTimeOut()); |
1546 |
|
joinPool(tpe); |
1547 |
|
} |
1550 |
|
* allowCoreThreadTimeOut(true) causes idle threads to time out |
1551 |
|
*/ |
1552 |
|
public void testAllowCoreThreadTimeOut_true() throws InterruptedException { |
1553 |
< |
ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1553 |
> |
ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1554 |
|
tpe.allowCoreThreadTimeOut(true); |
1555 |
|
tpe.execute(new NoOpRunnable()); |
1556 |
|
try { |
1565 |
|
* allowCoreThreadTimeOut(false) causes idle threads not to time out |
1566 |
|
*/ |
1567 |
|
public void testAllowCoreThreadTimeOut_false() throws InterruptedException { |
1568 |
< |
ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1568 |
> |
ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1569 |
|
tpe.allowCoreThreadTimeOut(false); |
1570 |
|
tpe.execute(new NoOpRunnable()); |
1571 |
|
try { |