12 |
|
|
13 |
|
public class ScheduledExecutorSubclassTest extends JSR166TestCase { |
14 |
|
public static void main(String[] args) { |
15 |
< |
junit.textui.TestRunner.run (suite()); |
15 |
> |
junit.textui.TestRunner.run (suite()); |
16 |
|
} |
17 |
|
public static Test suite() { |
18 |
< |
return new TestSuite(ScheduledExecutorSubclassTest.class); |
18 |
> |
return new TestSuite(ScheduledExecutorSubclassTest.class); |
19 |
|
} |
20 |
|
|
21 |
|
static class CustomTask<V> implements RunnableScheduledFuture<V> { |
196 |
|
public void testExecuteNull() throws InterruptedException { |
197 |
|
CustomExecutor se = new CustomExecutor(1); |
198 |
|
try { |
199 |
< |
se.execute(null); |
199 |
> |
se.execute(null); |
200 |
|
shouldThrow(); |
201 |
< |
} catch (NullPointerException success) {} |
202 |
< |
joinPool(se); |
201 |
> |
} catch (NullPointerException success) {} |
202 |
> |
joinPool(se); |
203 |
|
} |
204 |
|
|
205 |
|
/** |
207 |
|
*/ |
208 |
|
public void testScheduleNull() throws InterruptedException { |
209 |
|
CustomExecutor se = new CustomExecutor(1); |
210 |
< |
try { |
210 |
> |
try { |
211 |
|
TrackedCallable callable = null; |
212 |
< |
Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); |
212 |
> |
Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); |
213 |
|
shouldThrow(); |
214 |
< |
} catch (NullPointerException success) {} |
215 |
< |
joinPool(se); |
214 |
> |
} catch (NullPointerException success) {} |
215 |
> |
joinPool(se); |
216 |
|
} |
217 |
|
|
218 |
|
/** |
313 |
|
* getCompletedTaskCount increases, but doesn't overestimate, |
314 |
|
* when tasks complete |
315 |
|
*/ |
316 |
< |
public void testGetCompletedTaskCount()throws InterruptedException { |
316 |
> |
public void testGetCompletedTaskCount() throws InterruptedException { |
317 |
|
CustomExecutor p2 = new CustomExecutor(2); |
318 |
|
assertEquals(0, p2.getCompletedTaskCount()); |
319 |
|
p2.execute(new SmallRunnable()); |
376 |
|
*/ |
377 |
|
public void testGetThreadFactory() { |
378 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
379 |
< |
CustomExecutor p = new CustomExecutor(1, tf); |
379 |
> |
CustomExecutor p = new CustomExecutor(1, tf); |
380 |
|
assertSame(tf, p.getThreadFactory()); |
381 |
|
joinPool(p); |
382 |
|
} |
386 |
|
*/ |
387 |
|
public void testSetThreadFactory() { |
388 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
389 |
< |
CustomExecutor p = new CustomExecutor(1); |
389 |
> |
CustomExecutor p = new CustomExecutor(1); |
390 |
|
p.setThreadFactory(tf); |
391 |
|
assertSame(tf, p.getThreadFactory()); |
392 |
|
joinPool(p); |
396 |
|
* setThreadFactory(null) throws NPE |
397 |
|
*/ |
398 |
|
public void testSetThreadFactoryNull() { |
399 |
< |
CustomExecutor p = new CustomExecutor(1); |
399 |
> |
CustomExecutor p = new CustomExecutor(1); |
400 |
|
try { |
401 |
|
p.setThreadFactory(null); |
402 |
|
shouldThrow(); |
410 |
|
* is isShutDown is false before shutdown, true after |
411 |
|
*/ |
412 |
|
public void testIsShutdown() { |
413 |
< |
CustomExecutor p1 = new CustomExecutor(1); |
413 |
> |
CustomExecutor p1 = new CustomExecutor(1); |
414 |
|
try { |
415 |
|
assertFalse(p1.isShutdown()); |
416 |
|
} |
417 |
|
finally { |
418 |
|
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
419 |
|
} |
420 |
< |
assertTrue(p1.isShutdown()); |
420 |
> |
assertTrue(p1.isShutdown()); |
421 |
|
} |
422 |
|
|
423 |
|
|
425 |
|
* isTerminated is false before termination, true after |
426 |
|
*/ |
427 |
|
public void testIsTerminated() throws InterruptedException { |
428 |
< |
CustomExecutor p1 = new CustomExecutor(1); |
428 |
> |
CustomExecutor p1 = new CustomExecutor(1); |
429 |
|
try { |
430 |
|
p1.execute(new SmallRunnable()); |
431 |
|
} finally { |
439 |
|
* isTerminating is not true when running or when terminated |
440 |
|
*/ |
441 |
|
public void testIsTerminating() throws InterruptedException { |
442 |
< |
CustomExecutor p1 = new CustomExecutor(1); |
442 |
> |
CustomExecutor p1 = new CustomExecutor(1); |
443 |
|
assertFalse(p1.isTerminating()); |
444 |
|
try { |
445 |
|
p1.execute(new SmallRunnable()); |
530 |
|
* shutDownNow returns a list containing tasks that were not run |
531 |
|
*/ |
532 |
|
public void testShutDownNow() { |
533 |
< |
CustomExecutor p1 = new CustomExecutor(1); |
533 |
> |
CustomExecutor p1 = new CustomExecutor(1); |
534 |
|
for (int i = 0; i < 5; i++) |
535 |
|
p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS); |
536 |
|
List l; |
539 |
|
} catch (SecurityException ok) { |
540 |
|
return; |
541 |
|
} |
542 |
< |
assertTrue(p1.isShutdown()); |
543 |
< |
assertTrue(l.size() > 0 && l.size() <= 5); |
542 |
> |
assertTrue(p1.isShutdown()); |
543 |
> |
assertTrue(l.size() > 0 && l.size() <= 5); |
544 |
|
joinPool(p1); |
545 |
|
} |
546 |
|
|
716 |
|
public String call() { |
717 |
|
try { |
718 |
|
latch.await(); |
719 |
< |
} catch (InterruptedException ok) {} |
719 |
> |
} catch (InterruptedException quittingTime) {} |
720 |
|
return TEST_STRING; |
721 |
|
}}); |
722 |
|
l.add(null); |
900 |
|
public String call() { |
901 |
|
try { |
902 |
|
latch.await(); |
903 |
< |
} catch (InterruptedException ok) {} |
903 |
> |
} catch (InterruptedException quittingTime) {} |
904 |
|
return TEST_STRING; |
905 |
|
}}); |
906 |
|
l.add(null); |