ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ScheduledExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.5 by dl, Sat Sep 20 18:20:08 2003 UTC vs.
Revision 1.6 by dl, Thu Sep 25 11:02:41 2003 UTC

# Line 41 | Line 41 | public class ScheduledExecutorTest exten
41      }
42  
43      /**
44 <     *
44 >     * execute successfully executes a runnable
45       */
46      public void testExecute() {
47          try {
# Line 66 | Line 66 | public class ScheduledExecutorTest exten
66          
67      }
68  
69 +
70      /**
71 <     *
71 >     * delayed schedule of callable successfully executes after delay
72       */
73      public void testSchedule1() {
74          try {
# Line 87 | Line 88 | public class ScheduledExecutorTest exten
88      }
89  
90      /**
91 <     *  
91 >     *  delayed schedule of runnable successfully executes after delay
92       */
93      public void testSchedule3() {
94          try {
# Line 106 | Line 107 | public class ScheduledExecutorTest exten
107      }
108      
109      /**
110 <     *
110 >     * scheduleAtFixedRate executes runnable after given initial delay
111       */
112      public void testSchedule4() {
113          try {
114              MyRunnable runnable = new MyRunnable();
115              ScheduledExecutor p1 = new ScheduledExecutor(1);
116 <            p1.schedule(runnable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
116 >            ScheduledCancellable h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
117 >            assertFalse(runnable.done);
118 >            Thread.sleep(MEDIUM_DELAY_MS);
119 >            assertTrue(runnable.done);
120 >            h.cancel(true);
121 >            p1.shutdown();
122 >            joinPool(p1);
123 >        } catch(Exception e){
124 >            unexpectedException();
125 >        }
126 >    }
127 >
128 >    /**
129 >     * scheduleWithFixedDelay executes runnable after given initial delay
130 >     */
131 >    public void testSchedule5() {
132 >        try {
133 >            MyRunnable runnable = new MyRunnable();
134 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
135 >            ScheduledCancellable h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
136              assertFalse(runnable.done);
137              Thread.sleep(MEDIUM_DELAY_MS);
138              assertTrue(runnable.done);
139 +            h.cancel(true);
140              p1.shutdown();
141              joinPool(p1);
142          } catch(Exception e){
# Line 123 | Line 144 | public class ScheduledExecutorTest exten
144          }
145      }
146      
147 <  
148 <    // exception tests
147 >    /**
148 >     *  execute (null) throws NPE
149 >     */
150 >    public void testExecuteNull() {
151 >        ScheduledExecutor se = null;
152 >        try {
153 >            se = new ScheduledExecutor(1);
154 >            se.execute(null);
155 >            shouldThrow();
156 >        } catch(NullPointerException success){}
157 >        catch(Exception e){
158 >            unexpectedException();
159 >        }
160 >        
161 >        joinPool(se);
162 >    }
163  
164      /**
165 <     *   schedule(Runnable, long) throws RejectedExecutionException
166 <     *  This occurs on an attempt to schedule a task on a shutdown executor
165 >     * schedule (null) throws NPE
166 >     */
167 >    public void testScheduleNull() {
168 >        ScheduledExecutor se = new ScheduledExecutor(1);
169 >        try {
170 >            MyCallable callable = null;
171 >            Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
172 >            shouldThrow();
173 >        } catch(NullPointerException success){}
174 >        catch(Exception e){
175 >            unexpectedException();
176 >        }
177 >        joinPool(se);
178 >    }
179 >  
180 >    /**
181 >     * execute throws RejectedExecutionException if shutdown
182       */
183      public void testSchedule1_RejectedExecutionException() {
184          ScheduledExecutor se = new ScheduledExecutor(1);
# Line 144 | Line 194 | public class ScheduledExecutorTest exten
194      }
195  
196      /**
197 <     *   schedule(Callable, long, TimeUnit) throws RejectedExecutionException
148 <     *  This occurs on an attempt to schedule a task on a shutdown executor
197 >     * schedule throws RejectedExecutionException if shutdown
198       */
199      public void testSchedule2_RejectedExecutionException() {
200          ScheduledExecutor se = new ScheduledExecutor(1);
# Line 160 | Line 209 | public class ScheduledExecutorTest exten
209      }
210  
211      /**
212 <     *   schedule(Callable, long) throws RejectedExecutionException
164 <     *  This occurs on an attempt to schedule a task on a shutdown executor
212 >     * schedule callable throws RejectedExecutionException if shutdown
213       */
214       public void testSchedule3_RejectedExecutionException() {
215           ScheduledExecutor se = new ScheduledExecutor(1);
# Line 176 | Line 224 | public class ScheduledExecutorTest exten
224      }
225  
226      /**
227 <     *   scheduleAtFixedRate(Runnable, long, long, TimeUnit) throws
180 <     *  RejectedExecutionException.
181 <     *  This occurs on an attempt to schedule a task on a shutdown executor
227 >     *  scheduleAtFixedRate throws RejectedExecutionException if shutdown
228       */
229      public void testScheduleAtFixedRate1_RejectedExecutionException() {
230          ScheduledExecutor se = new ScheduledExecutor(1);
# Line 193 | Line 239 | public class ScheduledExecutorTest exten
239      }
240      
241      /**
242 <     *   scheduleAtFixedRate(Runnable, long, long, TimeUnit) throws
197 <     *  RejectedExecutionException.
198 <     *  This occurs on an attempt to schedule a task on a shutdown executor
199 <     */
200 <    public void testScheduleAtFixedRate2_RejectedExecutionException() {
201 <        ScheduledExecutor se = new ScheduledExecutor(1);
202 <        try {
203 <            se.shutdown();
204 <            se.scheduleAtFixedRate(new NoOpRunnable(),
205 <                                   1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
206 <            shouldThrow();
207 <        } catch(RejectedExecutionException success){
208 <        }
209 <        joinPool(se);
210 <    }
211 <
212 <    /**
213 <     *   scheduleWithFixedDelay(Runnable, long, long, TimeUnit) throws
214 <     *  RejectedExecutionException.
215 <     *  This occurs on an attempt to schedule a task on a shutdown executor
242 >     * scheduleWithFixedDelay throws RejectedExecutionException if shutdown
243       */
244      public void testScheduleWithFixedDelay1_RejectedExecutionException() {
245          ScheduledExecutor se = new ScheduledExecutor(1);
# Line 227 | Line 254 | public class ScheduledExecutorTest exten
254      }
255  
256      /**
257 <     *   scheduleWithFixedDelay(Runnable, long, long, TimeUnit) throws
258 <     *  RejectedExecutionException.
232 <     *  This occurs on an attempt to schedule a task on a shutdown executor
233 <     */
234 <     public void testScheduleWithFixedDelay2_RejectedExecutionException() {
235 <         ScheduledExecutor se = new ScheduledExecutor(1);
236 <        try {
237 <            se.shutdown();
238 <            se.scheduleWithFixedDelay(new NoOpRunnable(),
239 <                                      1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
240 <            shouldThrow();
241 <        } catch(RejectedExecutionException success){
242 <        }
243 <        joinPool(se);
244 <    }
245 <
246 <    /**
247 <     *   execute throws RejectedExecutionException
248 <     *  This occurs on an attempt to schedule a task on a shutdown executor
249 <     */
250 <    public void testExecute_RejectedExecutionException() {
251 <        ScheduledExecutor se = new ScheduledExecutor(1);
252 <        try {
253 <            se.shutdown();
254 <            se.execute(new NoOpRunnable());
255 <            shouldThrow();
256 <        } catch(RejectedExecutionException success){
257 <        }
258 <        joinPool(se);
259 <    }
260 <
261 <    /**
262 <     *   getActiveCount gives correct values
257 >     *  getActiveCount increases but doesn't overestimate, when a
258 >     *  thread becomes active
259       */
260      public void testGetActiveCount() {
261          ScheduledExecutor p2 = new ScheduledExecutor(2);
# Line 275 | Line 271 | public class ScheduledExecutorTest exten
271      }
272      
273      /**
274 <     *   getCompleteTaskCount gives correct values
274 >     *    getCompletedTaskCount increases, but doesn't overestimate,
275 >     *   when tasks complete
276       */
277      public void testGetCompletedTaskCount() {
278          ScheduledExecutor p2 = new ScheduledExecutor(2);
# Line 291 | Line 288 | public class ScheduledExecutorTest exten
288      }
289      
290      /**
291 <     *   getCorePoolSize gives correct values
291 >     *  getCorePoolSize returns size given in constructor if not otherwise set
292       */
293      public void testGetCorePoolSize() {
294          ScheduledExecutor p1 = new ScheduledExecutor(1);
# Line 300 | Line 297 | public class ScheduledExecutorTest exten
297      }
298      
299      /**
300 <     *   getLargestPoolSize gives correct values
300 >     *    getLargestPoolSize increases, but doesn't overestimate, when
301 >     *   multiple threads active
302       */
303      public void testGetLargestPoolSize() {
304          ScheduledExecutor p2 = new ScheduledExecutor(2);
# Line 317 | Line 315 | public class ScheduledExecutorTest exten
315      }
316      
317      /**
318 <     *   getPoolSize gives correct values
318 >     *   getPoolSize increases, but doesn't overestimate, when threads
319 >     *   become active
320       */
321      public void testGetPoolSize() {
322          ScheduledExecutor p1 = new ScheduledExecutor(1);
# Line 328 | Line 327 | public class ScheduledExecutorTest exten
327      }
328      
329      /**
330 <     *   getTaskCount gives correct values
330 >     *    getTaskCount increases, but doesn't overestimate, when tasks
331 >     *    submitted
332       */
333      public void testGetTaskCount() {
334          ScheduledExecutor p1 = new ScheduledExecutor(1);
# Line 345 | Line 345 | public class ScheduledExecutorTest exten
345      }
346      
347      /**
348 <     *   isShutDown gives correct values
348 >     *   is isShutDown is false before shutdown, true after
349       */
350      public void testIsShutdown() {
351          
# Line 361 | Line 361 | public class ScheduledExecutorTest exten
361  
362          
363      /**
364 <     *  isTerminated gives correct values
364 >     *   isTerminated is false before termination, true after
365       */
366      public void testIsTerminated() {
367          ScheduledExecutor p1 = new ScheduledExecutor(1);
# Line 379 | Line 379 | public class ScheduledExecutorTest exten
379      }
380  
381      /**
382 <     *  isTerminating gives correct values
382 >     *  isTerminating is not true when running or when terminated
383       */
384      public void testIsTerminating() {
385          ScheduledExecutor p1 = new ScheduledExecutor(1);
# Line 400 | Line 400 | public class ScheduledExecutorTest exten
400      }
401  
402      /**
403 <     *   that purge correctly removes cancelled tasks
404 <     *  from the queue
403 >     *   purge removes cancelled tasks from the queue
404       */
405      public void testPurge() {
406          ScheduledExecutor p1 = new ScheduledExecutor(1);
# Line 419 | Line 418 | public class ScheduledExecutorTest exten
418      }
419  
420      /**
421 <     *   shutDownNow returns a list
423 <     *  containing the correct number of elements
421 >     *  shutDownNow returns a list containing tasks that were not run
422       */
423      public void testShutDownNow() {
424          ScheduledExecutor p1 = new ScheduledExecutor(1);
# Line 433 | Line 431 | public class ScheduledExecutorTest exten
431      }
432  
433      /**
434 <     *
434 >     * In default setting, shutdown cancels periodic but not delayed
435 >     * tasks at shutdown
436       */
437      public void testShutDown1() {
438          try {
# Line 465 | Line 464 | public class ScheduledExecutorTest exten
464  
465  
466      /**
467 <     *
467 >     * If setExecuteExistingDelayedTasksAfterShutdownPolicy is false,
468 >     * delayed tasks are cancelled at shutdown
469       */
470      public void testShutDown2() {
471          try {
# Line 488 | Line 488 | public class ScheduledExecutorTest exten
488  
489  
490      /**
491 <     *
491 >     * If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false,
492 >     * periodic tasks are not cancelled at shutdown
493       */
494      public void testShutDown3() {
495          try {
# Line 509 | Line 510 | public class ScheduledExecutorTest exten
510      }
511  
512      /**
513 <     *
513 >     * if setContinueExistingPeriodicTasksAfterShutdownPolicy is true,
514 >     * periodic tasks are cancelled at shutdown
515       */
516      public void testShutDown4() {
517          ScheduledExecutor p1 = new ScheduledExecutor(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines