17 |
|
return new TestSuite(ScheduledExecutorTest.class); |
18 |
|
} |
19 |
|
|
20 |
– |
static class MyRunnable implements Runnable { |
21 |
– |
volatile boolean done = false; |
22 |
– |
public void run() { |
23 |
– |
try { |
24 |
– |
Thread.sleep(SMALL_DELAY_MS); |
25 |
– |
done = true; |
26 |
– |
} catch(Exception e){ |
27 |
– |
} |
28 |
– |
} |
29 |
– |
} |
30 |
– |
|
31 |
– |
static class MyCallable implements Callable { |
32 |
– |
volatile boolean done = false; |
33 |
– |
public Object call() { |
34 |
– |
try { |
35 |
– |
Thread.sleep(SMALL_DELAY_MS); |
36 |
– |
done = true; |
37 |
– |
} catch(Exception e){ |
38 |
– |
} |
39 |
– |
return Boolean.TRUE; |
40 |
– |
} |
41 |
– |
} |
20 |
|
|
21 |
|
/** |
22 |
|
* execute successfully executes a runnable |
23 |
|
*/ |
24 |
|
public void testExecute() { |
25 |
|
try { |
26 |
< |
MyRunnable runnable =new MyRunnable(); |
26 |
> |
TrackedRunnable runnable =new TrackedRunnable(); |
27 |
|
ScheduledExecutor p1 = new ScheduledExecutor(1); |
28 |
|
p1.execute(runnable); |
29 |
|
assertFalse(runnable.done); |
50 |
|
*/ |
51 |
|
public void testSchedule1() { |
52 |
|
try { |
53 |
< |
MyCallable callable = new MyCallable(); |
53 |
> |
TrackedCallable callable = new TrackedCallable(); |
54 |
|
ScheduledExecutor p1 = new ScheduledExecutor(1); |
55 |
|
Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
56 |
|
assertFalse(callable.done); |
70 |
|
*/ |
71 |
|
public void testSchedule3() { |
72 |
|
try { |
73 |
< |
MyRunnable runnable = new MyRunnable(); |
73 |
> |
TrackedRunnable runnable = new TrackedRunnable(); |
74 |
|
ScheduledExecutor p1 = new ScheduledExecutor(1); |
75 |
|
p1.schedule(runnable, SMALL_DELAY_MS, TimeUnit.MILLISECONDS); |
76 |
|
Thread.sleep(SHORT_DELAY_MS); |
89 |
|
*/ |
90 |
|
public void testSchedule4() { |
91 |
|
try { |
92 |
< |
MyRunnable runnable = new MyRunnable(); |
92 |
> |
TrackedRunnable runnable = new TrackedRunnable(); |
93 |
|
ScheduledExecutor p1 = new ScheduledExecutor(1); |
94 |
|
ScheduledCancellable h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
95 |
|
assertFalse(runnable.done); |
108 |
|
*/ |
109 |
|
public void testSchedule5() { |
110 |
|
try { |
111 |
< |
MyRunnable runnable = new MyRunnable(); |
111 |
> |
TrackedRunnable runnable = new TrackedRunnable(); |
112 |
|
ScheduledExecutor p1 = new ScheduledExecutor(1); |
113 |
|
ScheduledCancellable h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
114 |
|
assertFalse(runnable.done); |
145 |
|
public void testScheduleNull() { |
146 |
|
ScheduledExecutor se = new ScheduledExecutor(1); |
147 |
|
try { |
148 |
< |
MyCallable callable = null; |
148 |
> |
TrackedCallable callable = null; |
149 |
|
Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
150 |
|
shouldThrow(); |
151 |
|
} catch(NullPointerException success){} |