14 |
|
|
15 |
|
public class ThreadPoolExecutorSubclassTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run(suite()); |
17 |
> |
junit.textui.TestRunner.run(suite()); |
18 |
|
} |
19 |
|
public static Test suite() { |
20 |
|
return new TestSuite(ThreadPoolExecutorSubclassTest.class); |
197 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
198 |
|
try { |
199 |
|
p1.execute(new ShortRunnable()); |
200 |
< |
Thread.sleep(SMALL_DELAY_MS); |
200 |
> |
Thread.sleep(SMALL_DELAY_MS); |
201 |
|
} finally { |
202 |
|
joinPool(p1); |
203 |
|
} |
404 |
|
*/ |
405 |
|
public void testIsShutdown() { |
406 |
|
|
407 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
407 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
408 |
|
assertFalse(p1.isShutdown()); |
409 |
|
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
410 |
< |
assertTrue(p1.isShutdown()); |
410 |
> |
assertTrue(p1.isShutdown()); |
411 |
|
joinPool(p1); |
412 |
|
} |
413 |
|
|
416 |
|
* isTerminated is false before termination, true after |
417 |
|
*/ |
418 |
|
public void testIsTerminated() throws InterruptedException { |
419 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
419 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
420 |
|
assertFalse(p1.isTerminated()); |
421 |
|
try { |
422 |
|
p1.execute(new MediumRunnable()); |
431 |
|
* isTerminating is not true when running or when terminated |
432 |
|
*/ |
433 |
|
public void testIsTerminating() throws InterruptedException { |
434 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
434 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
435 |
|
assertFalse(p1.isTerminating()); |
436 |
|
try { |
437 |
|
p1.execute(new SmallRunnable()); |
518 |
|
* shutDownNow returns a list containing tasks that were not run |
519 |
|
*/ |
520 |
|
public void testShutDownNow() { |
521 |
< |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
521 |
> |
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
522 |
|
List l; |
523 |
|
try { |
524 |
|
for (int i = 0; i < 5; i++) |
530 |
|
} catch (SecurityException ok) { return; } |
531 |
|
|
532 |
|
} |
533 |
< |
assertTrue(p1.isShutdown()); |
534 |
< |
assertTrue(l.size() <= 4); |
533 |
> |
assertTrue(p1.isShutdown()); |
534 |
> |
assertTrue(l.size() <= 4); |
535 |
|
} |
536 |
|
|
537 |
|
// Exception Tests |
921 |
|
ThreadPoolExecutor tpe = |
922 |
|
new CustomTPE(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1)); |
923 |
|
try { tpe.shutdown(); } catch (SecurityException ok) { return; } |
924 |
< |
try { |
925 |
< |
tpe.execute(new NoOpRunnable()); |
926 |
< |
shouldThrow(); |
927 |
< |
} catch (RejectedExecutionException success) {} |
924 |
> |
try { |
925 |
> |
tpe.execute(new NoOpRunnable()); |
926 |
> |
shouldThrow(); |
927 |
> |
} catch (RejectedExecutionException success) {} |
928 |
|
|
929 |
< |
joinPool(tpe); |
929 |
> |
joinPool(tpe); |
930 |
|
} |
931 |
|
|
932 |
|
/** |
937 |
|
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
938 |
|
|
939 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
940 |
< |
try { |
940 |
> |
try { |
941 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
942 |
< |
p.execute(r); |
942 |
> |
p.execute(r); |
943 |
|
assertFalse(r.done); |
944 |
|
} finally { |
945 |
|
joinPool(p); |
954 |
|
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
955 |
|
|
956 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
957 |
< |
try { |
957 |
> |
try { |
958 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
959 |
< |
p.execute(r); |
959 |
> |
p.execute(r); |
960 |
|
assertFalse(r.done); |
961 |
|
} finally { |
962 |
|
joinPool(p); |
972 |
|
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
973 |
|
|
974 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
975 |
< |
try { |
975 |
> |
try { |
976 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
977 |
< |
p.execute(r); |
977 |
> |
p.execute(r); |
978 |
|
assertFalse(r.done); |
979 |
|
} finally { |
980 |
|
joinPool(p); |
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)); |
992 |
< |
tpe.execute(null); |
991 |
> |
tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
992 |
> |
tpe.execute(null); |
993 |
|
shouldThrow(); |
994 |
< |
} catch (NullPointerException success) {} |
994 |
> |
} catch (NullPointerException success) {} |
995 |
|
|
996 |
< |
joinPool(tpe); |
996 |
> |
joinPool(tpe); |
997 |
|
} |
998 |
|
|
999 |
|
/** |
1000 |
|
* setCorePoolSize of negative value throws IllegalArgumentException |
1001 |
|
*/ |
1002 |
|
public void testCorePoolSizeIllegalArgumentException() { |
1003 |
< |
ThreadPoolExecutor tpe = |
1003 |
> |
ThreadPoolExecutor tpe = |
1004 |
|
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1005 |
< |
try { |
1006 |
< |
tpe.setCorePoolSize(-1); |
1007 |
< |
shouldThrow(); |
1008 |
< |
} catch (IllegalArgumentException success) { |
1005 |
> |
try { |
1006 |
> |
tpe.setCorePoolSize(-1); |
1007 |
> |
shouldThrow(); |
1008 |
> |
} catch (IllegalArgumentException success) { |
1009 |
|
} finally { |
1010 |
|
try { tpe.shutdown(); } catch (SecurityException ok) { return; } |
1011 |
|
} |
1056 |
|
* when given a negative value |
1057 |
|
*/ |
1058 |
|
public void testKeepAliveTimeIllegalArgumentException() { |
1059 |
< |
ThreadPoolExecutor tpe = null; |
1059 |
> |
ThreadPoolExecutor tpe = null; |
1060 |
|
try { |
1061 |
|
tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1062 |
|
} catch (Exception e) {} |
1063 |
|
|
1064 |
< |
try { |
1064 |
> |
try { |
1065 |
|
tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS); |
1066 |
|
shouldThrow(); |
1067 |
|
} catch (IllegalArgumentException success) { |