14 |
|
|
15 |
|
public class ScheduledExecutorTest 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(ScheduledExecutorTest.class); |
20 |
> |
return new TestSuite(ScheduledExecutorTest.class); |
21 |
|
} |
22 |
|
|
23 |
|
|
142 |
|
public void testExecuteNull() throws InterruptedException { |
143 |
|
ScheduledThreadPoolExecutor se = null; |
144 |
|
try { |
145 |
< |
se = new ScheduledThreadPoolExecutor(1); |
146 |
< |
se.execute(null); |
145 |
> |
se = new ScheduledThreadPoolExecutor(1); |
146 |
> |
se.execute(null); |
147 |
|
shouldThrow(); |
148 |
< |
} catch (NullPointerException success) {} |
148 |
> |
} catch (NullPointerException success) {} |
149 |
|
|
150 |
< |
joinPool(se); |
150 |
> |
joinPool(se); |
151 |
|
} |
152 |
|
|
153 |
|
/** |
155 |
|
*/ |
156 |
|
public void testScheduleNull() throws InterruptedException { |
157 |
|
ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1); |
158 |
< |
try { |
158 |
> |
try { |
159 |
|
TrackedCallable callable = null; |
160 |
< |
Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); |
160 |
> |
Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); |
161 |
|
shouldThrow(); |
162 |
< |
} catch (NullPointerException success) {} |
163 |
< |
joinPool(se); |
162 |
> |
} catch (NullPointerException success) {} |
163 |
> |
joinPool(se); |
164 |
|
} |
165 |
|
|
166 |
|
/** |
325 |
|
*/ |
326 |
|
public void testGetThreadFactory() throws InterruptedException { |
327 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
328 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf); |
328 |
> |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf); |
329 |
|
assertSame(tf, p.getThreadFactory()); |
330 |
|
joinPool(p); |
331 |
|
} |
335 |
|
*/ |
336 |
|
public void testSetThreadFactory() throws InterruptedException { |
337 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
338 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
338 |
> |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
339 |
|
p.setThreadFactory(tf); |
340 |
|
assertSame(tf, p.getThreadFactory()); |
341 |
|
joinPool(p); |
345 |
|
* setThreadFactory(null) throws NPE |
346 |
|
*/ |
347 |
|
public void testSetThreadFactoryNull() throws InterruptedException { |
348 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
348 |
> |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
349 |
|
try { |
350 |
|
p.setThreadFactory(null); |
351 |
|
shouldThrow(); |
360 |
|
*/ |
361 |
|
public void testIsShutdown() { |
362 |
|
|
363 |
< |
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
363 |
> |
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
364 |
|
try { |
365 |
|
assertFalse(p1.isShutdown()); |
366 |
|
} |
367 |
|
finally { |
368 |
|
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
369 |
|
} |
370 |
< |
assertTrue(p1.isShutdown()); |
370 |
> |
assertTrue(p1.isShutdown()); |
371 |
|
} |
372 |
|
|
373 |
|
|
375 |
|
* isTerminated is false before termination, true after |
376 |
|
*/ |
377 |
|
public void testIsTerminated() throws InterruptedException { |
378 |
< |
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
378 |
> |
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
379 |
|
try { |
380 |
|
p1.execute(new SmallRunnable()); |
381 |
|
} finally { |
389 |
|
* isTerminating is not true when running or when terminated |
390 |
|
*/ |
391 |
|
public void testIsTerminating() throws InterruptedException { |
392 |
< |
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
392 |
> |
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
393 |
|
assertFalse(p1.isTerminating()); |
394 |
|
try { |
395 |
|
p1.execute(new SmallRunnable()); |
481 |
|
* shutDownNow returns a list containing tasks that were not run |
482 |
|
*/ |
483 |
|
public void testShutDownNow() throws InterruptedException { |
484 |
< |
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
484 |
> |
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
485 |
|
for (int i = 0; i < 5; i++) |
486 |
|
p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS); |
487 |
|
List l; |
490 |
|
} catch (SecurityException ok) { |
491 |
|
return; |
492 |
|
} |
493 |
< |
assertTrue(p1.isShutdown()); |
494 |
< |
assertTrue(l.size() > 0 && l.size() <= 5); |
493 |
> |
assertTrue(p1.isShutdown()); |
494 |
> |
assertTrue(l.size() > 0 && l.size() <= 5); |
495 |
|
joinPool(p1); |
496 |
|
} |
497 |
|
|