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> { |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
– |
|
77 |
|
/** |
78 |
|
* execute successfully executes a runnable |
79 |
|
*/ |
195 |
|
public void testExecuteNull() throws InterruptedException { |
196 |
|
CustomExecutor se = new CustomExecutor(1); |
197 |
|
try { |
198 |
< |
se.execute(null); |
198 |
> |
se.execute(null); |
199 |
|
shouldThrow(); |
200 |
< |
} catch (NullPointerException success) {} |
201 |
< |
joinPool(se); |
200 |
> |
} catch (NullPointerException success) {} |
201 |
> |
joinPool(se); |
202 |
|
} |
203 |
|
|
204 |
|
/** |
206 |
|
*/ |
207 |
|
public void testScheduleNull() throws InterruptedException { |
208 |
|
CustomExecutor se = new CustomExecutor(1); |
209 |
< |
try { |
209 |
> |
try { |
210 |
|
TrackedCallable callable = null; |
211 |
< |
Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); |
211 |
> |
Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); |
212 |
|
shouldThrow(); |
213 |
< |
} catch (NullPointerException success) {} |
214 |
< |
joinPool(se); |
213 |
> |
} catch (NullPointerException success) {} |
214 |
> |
joinPool(se); |
215 |
|
} |
216 |
|
|
217 |
|
/** |
312 |
|
* getCompletedTaskCount increases, but doesn't overestimate, |
313 |
|
* when tasks complete |
314 |
|
*/ |
315 |
< |
public void testGetCompletedTaskCount()throws InterruptedException { |
315 |
> |
public void testGetCompletedTaskCount() throws InterruptedException { |
316 |
|
CustomExecutor p2 = new CustomExecutor(2); |
317 |
|
assertEquals(0, p2.getCompletedTaskCount()); |
318 |
|
p2.execute(new SmallRunnable()); |
375 |
|
*/ |
376 |
|
public void testGetThreadFactory() { |
377 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
378 |
< |
CustomExecutor p = new CustomExecutor(1, tf); |
378 |
> |
CustomExecutor p = new CustomExecutor(1, tf); |
379 |
|
assertSame(tf, p.getThreadFactory()); |
380 |
|
joinPool(p); |
381 |
|
} |
385 |
|
*/ |
386 |
|
public void testSetThreadFactory() { |
387 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
388 |
< |
CustomExecutor p = new CustomExecutor(1); |
388 |
> |
CustomExecutor p = new CustomExecutor(1); |
389 |
|
p.setThreadFactory(tf); |
390 |
|
assertSame(tf, p.getThreadFactory()); |
391 |
|
joinPool(p); |
395 |
|
* setThreadFactory(null) throws NPE |
396 |
|
*/ |
397 |
|
public void testSetThreadFactoryNull() { |
398 |
< |
CustomExecutor p = new CustomExecutor(1); |
398 |
> |
CustomExecutor p = new CustomExecutor(1); |
399 |
|
try { |
400 |
|
p.setThreadFactory(null); |
401 |
|
shouldThrow(); |
409 |
|
* is isShutDown is false before shutdown, true after |
410 |
|
*/ |
411 |
|
public void testIsShutdown() { |
412 |
< |
CustomExecutor p1 = new CustomExecutor(1); |
412 |
> |
CustomExecutor p1 = new CustomExecutor(1); |
413 |
|
try { |
414 |
|
assertFalse(p1.isShutdown()); |
415 |
|
} |
416 |
|
finally { |
417 |
|
try { p1.shutdown(); } catch (SecurityException ok) { return; } |
418 |
|
} |
419 |
< |
assertTrue(p1.isShutdown()); |
419 |
> |
assertTrue(p1.isShutdown()); |
420 |
|
} |
421 |
|
|
422 |
|
|
424 |
|
* isTerminated is false before termination, true after |
425 |
|
*/ |
426 |
|
public void testIsTerminated() throws InterruptedException { |
427 |
< |
CustomExecutor p1 = new CustomExecutor(1); |
427 |
> |
CustomExecutor p1 = new CustomExecutor(1); |
428 |
|
try { |
429 |
|
p1.execute(new SmallRunnable()); |
430 |
|
} finally { |
438 |
|
* isTerminating is not true when running or when terminated |
439 |
|
*/ |
440 |
|
public void testIsTerminating() throws InterruptedException { |
441 |
< |
CustomExecutor p1 = new CustomExecutor(1); |
441 |
> |
CustomExecutor p1 = new CustomExecutor(1); |
442 |
|
assertFalse(p1.isTerminating()); |
443 |
|
try { |
444 |
|
p1.execute(new SmallRunnable()); |
529 |
|
* shutDownNow returns a list containing tasks that were not run |
530 |
|
*/ |
531 |
|
public void testShutDownNow() { |
532 |
< |
CustomExecutor p1 = new CustomExecutor(1); |
532 |
> |
CustomExecutor p1 = new CustomExecutor(1); |
533 |
|
for (int i = 0; i < 5; i++) |
534 |
|
p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS); |
535 |
|
List l; |
538 |
|
} catch (SecurityException ok) { |
539 |
|
return; |
540 |
|
} |
541 |
< |
assertTrue(p1.isShutdown()); |
542 |
< |
assertTrue(l.size() > 0 && l.size() <= 5); |
541 |
> |
assertTrue(p1.isShutdown()); |
542 |
> |
assertTrue(l.size() > 0 && l.size() <= 5); |
543 |
|
joinPool(p1); |
544 |
|
} |
545 |
|
|
715 |
|
public String call() { |
716 |
|
try { |
717 |
|
latch.await(); |
718 |
< |
} catch (InterruptedException ok) {} |
718 |
> |
} catch (InterruptedException quittingTime) {} |
719 |
|
return TEST_STRING; |
720 |
|
}}); |
721 |
|
l.add(null); |
899 |
|
public String call() { |
900 |
|
try { |
901 |
|
latch.await(); |
902 |
< |
} catch (InterruptedException ok) {} |
902 |
> |
} catch (InterruptedException quittingTime) {} |
903 |
|
return TEST_STRING; |
904 |
|
}}); |
905 |
|
l.add(null); |