14 |
|
|
15 |
|
public class ThreadPoolExecutorTest 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(ThreadPoolExecutorTest.class); |
54 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
55 |
|
try { |
56 |
|
p1.execute(new ShortRunnable()); |
57 |
< |
Thread.sleep(SMALL_DELAY_MS); |
57 |
> |
Thread.sleep(SMALL_DELAY_MS); |
58 |
|
} finally { |
59 |
|
joinPool(p1); |
60 |
|
} |
261 |
|
*/ |
262 |
|
public void testIsShutdown() { |
263 |
|
|
264 |
< |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
264 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
265 |
|
assertFalse(p1.isShutdown()); |
266 |
|
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
267 |
< |
assertTrue(p1.isShutdown()); |
267 |
> |
assertTrue(p1.isShutdown()); |
268 |
|
joinPool(p1); |
269 |
|
} |
270 |
|
|
273 |
|
* isTerminated is false before termination, true after |
274 |
|
*/ |
275 |
|
public void testIsTerminated() throws InterruptedException { |
276 |
< |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
276 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
277 |
|
assertFalse(p1.isTerminated()); |
278 |
|
try { |
279 |
|
p1.execute(new MediumRunnable()); |
288 |
|
* isTerminating is not true when running or when terminated |
289 |
|
*/ |
290 |
|
public void testIsTerminating() throws InterruptedException { |
291 |
< |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
291 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
292 |
|
assertFalse(p1.isTerminating()); |
293 |
|
try { |
294 |
|
p1.execute(new SmallRunnable()); |
375 |
|
* shutDownNow returns a list containing tasks that were not run |
376 |
|
*/ |
377 |
|
public void testShutDownNow() { |
378 |
< |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
378 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
379 |
|
List l; |
380 |
|
try { |
381 |
|
for (int i = 0; i < 5; i++) |
387 |
|
} catch (SecurityException ok) { return; } |
388 |
|
|
389 |
|
} |
390 |
< |
assertTrue(p1.isShutdown()); |
391 |
< |
assertTrue(l.size() <= 4); |
390 |
> |
assertTrue(p1.isShutdown()); |
391 |
> |
assertTrue(l.size() <= 4); |
392 |
|
} |
393 |
|
|
394 |
|
// Exception Tests |
785 |
|
ThreadPoolExecutor tpe = |
786 |
|
new ThreadPoolExecutor(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(1)); |
787 |
|
try { tpe.shutdown(); } catch (SecurityException ok) { return; } |
788 |
< |
try { |
789 |
< |
tpe.execute(new NoOpRunnable()); |
790 |
< |
shouldThrow(); |
791 |
< |
} catch (RejectedExecutionException success) {} |
788 |
> |
try { |
789 |
> |
tpe.execute(new NoOpRunnable()); |
790 |
> |
shouldThrow(); |
791 |
> |
} catch (RejectedExecutionException success) {} |
792 |
|
|
793 |
< |
joinPool(tpe); |
793 |
> |
joinPool(tpe); |
794 |
|
} |
795 |
|
|
796 |
|
/** |
801 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
802 |
|
|
803 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
804 |
< |
try { |
804 |
> |
try { |
805 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
806 |
< |
p.execute(r); |
806 |
> |
p.execute(r); |
807 |
|
assertFalse(r.done); |
808 |
|
} finally { |
809 |
|
joinPool(p); |
818 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
819 |
|
|
820 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
821 |
< |
try { |
821 |
> |
try { |
822 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
823 |
< |
p.execute(r); |
823 |
> |
p.execute(r); |
824 |
|
assertFalse(r.done); |
825 |
|
} finally { |
826 |
|
joinPool(p); |
836 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
837 |
|
|
838 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
839 |
< |
try { |
839 |
> |
try { |
840 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
841 |
< |
p.execute(r); |
841 |
> |
p.execute(r); |
842 |
|
assertFalse(r.done); |
843 |
|
} finally { |
844 |
|
joinPool(p); |
852 |
|
public void testExecuteNull() { |
853 |
|
ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
854 |
|
try { |
855 |
< |
tpe.execute(null); |
855 |
> |
tpe.execute(null); |
856 |
|
shouldThrow(); |
857 |
< |
} catch (NullPointerException success) {} |
857 |
> |
} catch (NullPointerException success) {} |
858 |
|
|
859 |
< |
joinPool(tpe); |
859 |
> |
joinPool(tpe); |
860 |
|
} |
861 |
|
|
862 |
|
/** |
863 |
|
* setCorePoolSize of negative value throws IllegalArgumentException |
864 |
|
*/ |
865 |
|
public void testCorePoolSizeIllegalArgumentException() { |
866 |
< |
ThreadPoolExecutor tpe = |
866 |
> |
ThreadPoolExecutor tpe = |
867 |
|
new ThreadPoolExecutor(1, 2, |
868 |
|
LONG_DELAY_MS, MILLISECONDS, |
869 |
|
new ArrayBlockingQueue<Runnable>(10)); |
870 |
< |
try { |
871 |
< |
tpe.setCorePoolSize(-1); |
872 |
< |
shouldThrow(); |
873 |
< |
} catch (IllegalArgumentException success) { |
870 |
> |
try { |
871 |
> |
tpe.setCorePoolSize(-1); |
872 |
> |
shouldThrow(); |
873 |
> |
} catch (IllegalArgumentException success) { |
874 |
|
} finally { |
875 |
|
try { tpe.shutdown(); } catch (SecurityException ok) { return; } |
876 |
|
} |
921 |
|
* when given a negative value |
922 |
|
*/ |
923 |
|
public void testKeepAliveTimeIllegalArgumentException() { |
924 |
< |
ThreadPoolExecutor tpe = |
924 |
> |
ThreadPoolExecutor tpe = |
925 |
|
new ThreadPoolExecutor(2, 3, |
926 |
|
LONG_DELAY_MS, MILLISECONDS, |
927 |
|
new ArrayBlockingQueue<Runnable>(10)); |
928 |
< |
try { |
928 |
> |
try { |
929 |
|
tpe.setKeepAliveTime(-1,MILLISECONDS); |
930 |
|
shouldThrow(); |
931 |
|
} catch (IllegalArgumentException success) { |