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.1 by dl, Sun Aug 31 19:24:55 2003 UTC vs.
Revision 1.5 by dl, Sat Sep 20 18:20:08 2003 UTC

# Line 9 | Line 9 | import junit.framework.*;
9   import java.util.*;
10   import java.util.concurrent.*;
11  
12 < public class ScheduledExecutorTest extends TestCase{
13 <    
14 <    boolean flag = false;
15 <
12 > public class ScheduledExecutorTest extends JSR166TestCase {
13      public static void main(String[] args) {
14          junit.textui.TestRunner.run (suite());  
15      }
19    
20
16      public static Test suite() {
17          return new TestSuite(ScheduledExecutorTest.class);
18      }
19  
25    private static long SHORT_DELAY_MS = 100;
26    private static long MEDIUM_DELAY_MS = 1000;
27    private static long LONG_DELAY_MS = 10000;
28
20      static class MyRunnable implements Runnable {
30        volatile boolean waiting = true;
21          volatile boolean done = false;
22 <        public void run(){
23 <            try{
24 <                Thread.sleep(MEDIUM_DELAY_MS);
35 <                waiting = false;
22 >        public void run() {
23 >            try {
24 >                Thread.sleep(SMALL_DELAY_MS);
25                  done = true;
26 <            } catch(Exception e){}
26 >            } catch(Exception e){
27 >            }
28          }
29      }
30  
31      static class MyCallable implements Callable {
42        volatile boolean waiting = true;
32          volatile boolean done = false;
33 <        public Object call(){
34 <            try{
35 <                Thread.sleep(MEDIUM_DELAY_MS);
47 <                waiting = false;
33 >        public Object call() {
34 >            try {
35 >                Thread.sleep(SMALL_DELAY_MS);
36                  done = true;
37 <            }catch(Exception e){}
37 >            } catch(Exception e){
38 >            }
39              return Boolean.TRUE;
40          }
41      }
42  
43      /**
44 <     *  Test to verify execute successfully runs the given Runnable
44 >     *
45       */
46 <    public void testExecute(){
47 <        try{
46 >    public void testExecute() {
47 >        try {
48              MyRunnable runnable =new MyRunnable();
49 <            ScheduledExecutor one = new ScheduledExecutor(1);
50 <            one.execute(runnable);
51 <            Thread.sleep(100);
52 <            assertTrue(runnable.waiting);
53 <            one.shutdown();
54 <            // make sure the Runnable has time to complete
55 <            try{Thread.sleep(1010);}catch(InterruptedException e){}
56 <            assertFalse(runnable.waiting);
49 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
50 >            p1.execute(runnable);
51 >            assertFalse(runnable.done);
52 >            Thread.sleep(SHORT_DELAY_MS);
53 >            p1.shutdown();
54 >            try {
55 >                Thread.sleep(MEDIUM_DELAY_MS);
56 >            } catch(InterruptedException e){
57 >                unexpectedException();
58 >            }
59              assertTrue(runnable.done);
60 <            one.shutdown();
60 >            p1.shutdown();
61 >            joinPool(p1);
62          }
63          catch(Exception e){
64 <            fail("unexpected exception");
64 >            unexpectedException();
65          }
66 +        
67      }
68  
69      /**
70 <     *  Test to verify schedule successfully runs the given Callable.
78 <     *  The waiting flag shows that the Callable is not started until
79 <     *  immediately.
70 >     *
71       */
72 <    public void testSchedule1(){
73 <        try{
72 >    public void testSchedule1() {
73 >        try {
74              MyCallable callable = new MyCallable();
75 <            ScheduledExecutor one = new ScheduledExecutor(1);
76 <            Future f = one.schedule(callable, 500, TimeUnit.MILLISECONDS);
77 <            //      Thread.sleep(505);
78 <            assertTrue(callable.waiting);
88 <            Thread.sleep(2000);
75 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
76 >            Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
77 >            assertFalse(callable.done);
78 >            Thread.sleep(MEDIUM_DELAY_MS);
79              assertTrue(callable.done);
80              assertEquals(Boolean.TRUE, f.get());
81 <            one.shutdown();
82 <        }catch(RejectedExecutionException e){}
83 <        catch(Exception e){}
81 >            p1.shutdown();
82 >            joinPool(p1);
83 >        } catch(RejectedExecutionException e){}
84 >        catch(Exception e){
85 >            unexpectedException();
86 >        }
87      }
88  
89      /**
90 <     *  Another version of schedule, only using Runnable instead of Callable
90 >     *  
91       */
92 <    public void testSchedule3(){
93 <        try{
92 >    public void testSchedule3() {
93 >        try {
94              MyRunnable runnable = new MyRunnable();
95 <            ScheduledExecutor one = new ScheduledExecutor(1);
96 <            one.schedule(runnable, 500, TimeUnit.MILLISECONDS);
97 <            Thread.sleep(50);
98 <            assertTrue(runnable.waiting);
99 <            Thread.sleep(2000);
95 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
96 >            p1.schedule(runnable, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
97 >            Thread.sleep(SHORT_DELAY_MS);
98 >            assertFalse(runnable.done);
99 >            Thread.sleep(MEDIUM_DELAY_MS);
100              assertTrue(runnable.done);
101 <            one.shutdown();
101 >            p1.shutdown();
102 >            joinPool(p1);
103          } catch(Exception e){
104 <            fail("unexpected exception");
104 >            unexpectedException();
105          }
106      }
107      
108      /**
109 <     *  The final version of schedule, using both long, TimeUnit and Runnable
109 >     *
110       */
111 <    public void testSchedule4(){
112 <        try{
111 >    public void testSchedule4() {
112 >        try {
113              MyRunnable runnable = new MyRunnable();
114 <            ScheduledExecutor one = new ScheduledExecutor(1);
115 <            one.schedule(runnable, 500, TimeUnit.MILLISECONDS);
116 <            //      Thread.sleep(505);
117 <            assertTrue(runnable.waiting);
124 <            Thread.sleep(2000);
114 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
115 >            p1.schedule(runnable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
116 >            assertFalse(runnable.done);
117 >            Thread.sleep(MEDIUM_DELAY_MS);
118              assertTrue(runnable.done);
119 <            one.shutdown();
119 >            p1.shutdown();
120 >            joinPool(p1);
121          } catch(Exception e){
122 <            fail("unexpected exception");
122 >            unexpectedException();
123          }
124      }
125      
# Line 133 | Line 127 | public class ScheduledExecutorTest exten
127      // exception tests
128  
129      /**
130 <     *  Test to verify schedule(Runnable, long) throws RejectedExecutionException
130 >     *   schedule(Runnable, long) throws RejectedExecutionException
131       *  This occurs on an attempt to schedule a task on a shutdown executor
132       */
133 <    public void testSchedule1_RejectedExecutionException(){
134 <        try{
135 <            ScheduledExecutor se = new ScheduledExecutor(1);
133 >    public void testSchedule1_RejectedExecutionException() {
134 >        ScheduledExecutor se = new ScheduledExecutor(1);
135 >        try {
136              se.shutdown();
137 <            se.schedule(new Runnable(){
138 <                    public void run(){}
139 <                }, 10000, TimeUnit.MILLISECONDS);
140 <            fail("shoud throw");
141 <        }catch(RejectedExecutionException e){}    
137 >            se.schedule(new NoOpRunnable(),
138 >                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
139 >            shouldThrow();
140 >        } catch(RejectedExecutionException success){
141 >        }
142 >        joinPool(se);
143 >
144      }
145  
146      /**
147 <     *  Test to verify schedule(Callable, long, TimeUnit) throws RejectedExecutionException
147 >     *   schedule(Callable, long, TimeUnit) throws RejectedExecutionException
148       *  This occurs on an attempt to schedule a task on a shutdown executor
149       */
150 <    public void testSchedule2_RejectedExecutionException(){
151 <        try{
152 <            ScheduledExecutor se = new ScheduledExecutor(1);
150 >    public void testSchedule2_RejectedExecutionException() {
151 >        ScheduledExecutor se = new ScheduledExecutor(1);
152 >        try {
153              se.shutdown();
154 <            se.schedule(new Callable(){
155 <                    public Object call(){
156 <                        return Boolean.TRUE;
157 <                    }
158 <                }, (long)100, TimeUnit.SECONDS);
159 <            fail("should throw");
164 <        }catch(RejectedExecutionException e){}    
154 >            se.schedule(new NoOpCallable(),
155 >                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
156 >            shouldThrow();
157 >        } catch(RejectedExecutionException success){
158 >        }
159 >        joinPool(se);
160      }
161  
162      /**
163 <     *  Test to verify schedule(Callable, long) throws RejectedExecutionException
163 >     *   schedule(Callable, long) throws RejectedExecutionException
164       *  This occurs on an attempt to schedule a task on a shutdown executor
165       */
166 <     public void testSchedule3_RejectedExecutionException(){
167 <        try{
168 <            ScheduledExecutor se = new ScheduledExecutor(1);
166 >     public void testSchedule3_RejectedExecutionException() {
167 >         ScheduledExecutor se = new ScheduledExecutor(1);
168 >         try {
169              se.shutdown();
170 <            se.schedule(new Callable(){
171 <                    public Object call(){
172 <                        return Boolean.TRUE;
173 <                    }
174 <                },  10000, TimeUnit.MILLISECONDS);
175 <            fail("should throw");
181 <        }catch(RejectedExecutionException e){}    
170 >            se.schedule(new NoOpCallable(),
171 >                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
172 >            shouldThrow();
173 >        } catch(RejectedExecutionException success){
174 >        }
175 >         joinPool(se);
176      }
177  
178      /**
179 <     *  Test to verify scheduleAtFixedRate(Runnable, long, long, TimeUnit) throws
179 >     *   scheduleAtFixedRate(Runnable, long, long, TimeUnit) throws
180       *  RejectedExecutionException.
181       *  This occurs on an attempt to schedule a task on a shutdown executor
182       */
183 <    public void testScheduleAtFixedRate1_RejectedExecutionException(){
184 <        try{
185 <            ScheduledExecutor se = new ScheduledExecutor(1);
183 >    public void testScheduleAtFixedRate1_RejectedExecutionException() {
184 >        ScheduledExecutor se = new ScheduledExecutor(1);
185 >        try {
186              se.shutdown();
187 <            se.scheduleAtFixedRate(new Runnable(){
188 <                    public void run(){}
189 <                }, 100, 100, TimeUnit.SECONDS);
190 <            fail("should throw");
191 <        }catch(RejectedExecutionException e){}    
187 >            se.scheduleAtFixedRate(new NoOpRunnable(),
188 >                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
189 >            shouldThrow();
190 >        } catch(RejectedExecutionException success){
191 >        }
192 >        joinPool(se);
193      }
194      
195      /**
196 <     *  Test to verify scheduleAtFixedRate(Runnable, long, long, TimeUnit) throws
196 >     *   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 <        try{
202 <            ScheduledExecutor se = new ScheduledExecutor(1);
200 >    public void testScheduleAtFixedRate2_RejectedExecutionException() {
201 >        ScheduledExecutor se = new ScheduledExecutor(1);
202 >        try {
203              se.shutdown();
204 <            se.scheduleAtFixedRate(new Runnable(){
205 <                    public void run(){}
206 <                },  1, 100, TimeUnit.SECONDS);
207 <            fail("should throw");
208 <        }catch(RejectedExecutionException e){}    
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 <     *  Test to verify scheduleWithFixedDelay(Runnable, long, long, TimeUnit) throws
213 >     *   scheduleWithFixedDelay(Runnable, long, long, TimeUnit) throws
214       *  RejectedExecutionException.
215       *  This occurs on an attempt to schedule a task on a shutdown executor
216       */
217 <    public void testScheduleWithFixedDelay1_RejectedExecutionException(){
218 <        try{
219 <            ScheduledExecutor se = new ScheduledExecutor(1);
217 >    public void testScheduleWithFixedDelay1_RejectedExecutionException() {
218 >        ScheduledExecutor se = new ScheduledExecutor(1);
219 >        try {
220              se.shutdown();
221 <            se.scheduleWithFixedDelay(new Runnable(){
222 <                    public void run(){}
223 <                }, 100, 100, TimeUnit.SECONDS);
224 <            fail("should throw");
225 <        }catch(RejectedExecutionException e){}    
221 >            se.scheduleWithFixedDelay(new NoOpRunnable(),
222 >                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
223 >            shouldThrow();
224 >        } catch(RejectedExecutionException success){
225 >        }
226 >        joinPool(se);
227      }
228  
229      /**
230 <     *  Test to verify scheduleWithFixedDelay(Runnable, long, long, TimeUnit) throws
230 >     *   scheduleWithFixedDelay(Runnable, long, long, TimeUnit) throws
231       *  RejectedExecutionException.
232       *  This occurs on an attempt to schedule a task on a shutdown executor
233       */
234 <     public void testScheduleWithFixedDelay2_RejectedExecutionException(){
235 <        try{
236 <            ScheduledExecutor se = new ScheduledExecutor(1);
234 >     public void testScheduleWithFixedDelay2_RejectedExecutionException() {
235 >         ScheduledExecutor se = new ScheduledExecutor(1);
236 >        try {
237              se.shutdown();
238 <            se.scheduleWithFixedDelay(new Runnable(){
239 <                    public void run(){}
240 <                },  1, 100, TimeUnit.SECONDS);
241 <            fail("should throw");
242 <        }catch(RejectedExecutionException e){}    
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 <     *  Test to verify execute throws RejectedExecutionException
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 <        try{
252 <            ScheduledExecutor se = new ScheduledExecutor(1);
250 >    public void testExecute_RejectedExecutionException() {
251 >        ScheduledExecutor se = new ScheduledExecutor(1);
252 >        try {
253              se.shutdown();
254 <            se.execute(new Runnable(){
255 <                    public void run(){}
256 <                });
257 <            fail("should throw");
258 <        }catch(RejectedExecutionException e){}    
254 >            se.execute(new NoOpRunnable());
255 >            shouldThrow();
256 >        } catch(RejectedExecutionException success){
257 >        }
258 >        joinPool(se);
259 >    }
260 >
261 >    /**
262 >     *   getActiveCount gives correct values
263 >     */
264 >    public void testGetActiveCount() {
265 >        ScheduledExecutor p2 = new ScheduledExecutor(2);
266 >        assertEquals(0, p2.getActiveCount());
267 >        p2.execute(new SmallRunnable());
268 >        try {
269 >            Thread.sleep(SHORT_DELAY_MS);
270 >        } catch(Exception e){
271 >            unexpectedException();
272 >        }
273 >        assertEquals(1, p2.getActiveCount());
274 >        joinPool(p2);
275 >    }
276 >    
277 >    /**
278 >     *   getCompleteTaskCount gives correct values
279 >     */
280 >    public void testGetCompletedTaskCount() {
281 >        ScheduledExecutor p2 = new ScheduledExecutor(2);
282 >        assertEquals(0, p2.getCompletedTaskCount());
283 >        p2.execute(new SmallRunnable());
284 >        try {
285 >            Thread.sleep(MEDIUM_DELAY_MS);
286 >        } catch(Exception e){
287 >            unexpectedException();
288 >        }
289 >        assertEquals(1, p2.getCompletedTaskCount());
290 >        joinPool(p2);
291 >    }
292 >    
293 >    /**
294 >     *   getCorePoolSize gives correct values
295 >     */
296 >    public void testGetCorePoolSize() {
297 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
298 >        assertEquals(1, p1.getCorePoolSize());
299 >        joinPool(p1);
300 >    }
301 >    
302 >    /**
303 >     *   getLargestPoolSize gives correct values
304 >     */
305 >    public void testGetLargestPoolSize() {
306 >        ScheduledExecutor p2 = new ScheduledExecutor(2);
307 >        assertEquals(0, p2.getLargestPoolSize());
308 >        p2.execute(new SmallRunnable());
309 >        p2.execute(new SmallRunnable());
310 >        try {
311 >            Thread.sleep(SHORT_DELAY_MS);
312 >        } catch(Exception e){
313 >            unexpectedException();
314 >        }
315 >        assertEquals(2, p2.getLargestPoolSize());
316 >        joinPool(p2);
317 >    }
318 >    
319 >    /**
320 >     *   getPoolSize gives correct values
321 >     */
322 >    public void testGetPoolSize() {
323 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
324 >        assertEquals(0, p1.getPoolSize());
325 >        p1.execute(new SmallRunnable());
326 >        assertEquals(1, p1.getPoolSize());
327 >        joinPool(p1);
328 >    }
329 >    
330 >    /**
331 >     *   getTaskCount gives correct values
332 >     */
333 >    public void testGetTaskCount() {
334 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
335 >        assertEquals(0, p1.getTaskCount());
336 >        for(int i = 0; i < 5; i++)
337 >            p1.execute(new SmallRunnable());
338 >        try {
339 >            Thread.sleep(SHORT_DELAY_MS);
340 >        } catch(Exception e){
341 >            unexpectedException();
342 >        }
343 >        assertEquals(5, p1.getTaskCount());
344 >        joinPool(p1);
345 >    }
346 >    
347 >    /**
348 >     *   isShutDown gives correct values
349 >     */
350 >    public void testIsShutdown() {
351 >        
352 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
353 >        try {
354 >            assertFalse(p1.isShutdown());
355 >        }
356 >        finally {
357 >            p1.shutdown();
358 >        }
359 >        assertTrue(p1.isShutdown());
360 >    }
361 >
362 >        
363 >    /**
364 >     *  isTerminated gives correct values
365 >     */
366 >    public void testIsTerminated() {
367 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
368 >        try {
369 >            p1.execute(new SmallRunnable());
370 >        } finally {
371 >            p1.shutdown();
372 >        }
373 >        try {
374 >            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
375 >            assertTrue(p1.isTerminated());
376 >        } catch(Exception e){
377 >            unexpectedException();
378 >        }      
379 >    }
380 >
381 >    /**
382 >     *  isTerminating gives correct values
383 >     */
384 >    public void testIsTerminating() {
385 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
386 >        assertFalse(p1.isTerminating());
387 >        try {
388 >            p1.execute(new SmallRunnable());
389 >            assertFalse(p1.isTerminating());
390 >        } finally {
391 >            p1.shutdown();
392 >        }
393 >        try {
394 >            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
395 >            assertTrue(p1.isTerminated());
396 >            assertFalse(p1.isTerminating());
397 >        } catch(Exception e){
398 >            unexpectedException();
399 >        }      
400 >    }
401 >
402 >    /**
403 >     *   that purge correctly removes cancelled tasks
404 >     *  from the queue
405 >     */
406 >    public void testPurge() {
407 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
408 >        ScheduledCancellable[] tasks = new ScheduledCancellable[5];
409 >        for(int i = 0; i < 5; i++){
410 >            tasks[i] = p1.schedule(new SmallRunnable(), 1, TimeUnit.MILLISECONDS);
411 >        }
412 >        int max = 5;
413 >        if (tasks[4].cancel(true)) --max;
414 >        if (tasks[3].cancel(true)) --max;
415 >        p1.purge();
416 >        long count = p1.getTaskCount();
417 >        assertTrue(count > 0 && count <= max);
418 >        joinPool(p1);
419 >    }
420 >
421 >    /**
422 >     *   shutDownNow returns a list
423 >     *  containing the correct number of elements
424 >     */
425 >    public void testShutDownNow() {
426 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
427 >        for(int i = 0; i < 5; i++)
428 >            p1.schedule(new SmallRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
429 >        List l = p1.shutdownNow();
430 >        assertTrue(p1.isShutdown());
431 >        assertTrue(l.size() > 0 && l.size() <= 5);
432 >        joinPool(p1);
433 >    }
434 >
435 >    /**
436 >     *
437 >     */
438 >    public void testShutDown1() {
439 >        try {
440 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
441 >            assertTrue(p1.getExecuteExistingDelayedTasksAfterShutdownPolicy());
442 >            assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy());
443 >
444 >            ScheduledCancellable[] tasks = new ScheduledCancellable[5];
445 >            for(int i = 0; i < 5; i++)
446 >                tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
447 >            p1.shutdown();
448 >            BlockingQueue q = p1.getQueue();
449 >            for (Iterator it = q.iterator(); it.hasNext();) {
450 >                ScheduledCancellable t = (ScheduledCancellable)it.next();
451 >                assertFalse(t.isCancelled());
452 >            }
453 >            assertTrue(p1.isShutdown());
454 >            Thread.sleep(SMALL_DELAY_MS);
455 >            for (int i = 0; i < 5; ++i) {
456 >                assertTrue(tasks[i].isDone());
457 >                assertFalse(tasks[i].isCancelled());
458 >            }
459 >            
460 >        }
461 >        catch(Exception ex) {
462 >            unexpectedException();
463 >        }
464 >    }
465 >
466 >
467 >    /**
468 >     *
469 >     */
470 >    public void testShutDown2() {
471 >        try {
472 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
473 >            p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
474 >            ScheduledCancellable[] tasks = new ScheduledCancellable[5];
475 >            for(int i = 0; i < 5; i++)
476 >                tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
477 >            p1.shutdown();
478 >            assertTrue(p1.isShutdown());
479 >            BlockingQueue q = p1.getQueue();
480 >            assertTrue(q.isEmpty());
481 >            Thread.sleep(SMALL_DELAY_MS);
482 >            assertTrue(p1.isTerminated());
483 >        }
484 >        catch(Exception ex) {
485 >            unexpectedException();
486 >        }
487 >    }
488 >
489 >
490 >    /**
491 >     *
492 >     */
493 >    public void testShutDown3() {
494 >        try {
495 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
496 >            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
497 >            ScheduledCancellable task =
498 >                p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
499 >            p1.shutdown();
500 >            assertTrue(p1.isShutdown());
501 >            BlockingQueue q = p1.getQueue();
502 >            assertTrue(q.isEmpty());
503 >            Thread.sleep(SHORT_DELAY_MS);
504 >            assertTrue(p1.isTerminated());
505 >        }
506 >        catch(Exception ex) {
507 >            unexpectedException();
508 >        }
509 >    }
510 >
511 >    /**
512 >     *
513 >     */
514 >    public void testShutDown4() {
515 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
516 >        try {
517 >            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
518 >            ScheduledCancellable task =
519 >                p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
520 >            assertFalse(task.isCancelled());
521 >            p1.shutdown();
522 >            assertFalse(task.isCancelled());
523 >            assertFalse(p1.isTerminated());
524 >            assertTrue(p1.isShutdown());
525 >            Thread.sleep(SHORT_DELAY_MS);
526 >            assertFalse(task.isCancelled());
527 >            task.cancel(true);
528 >            assertTrue(task.isCancelled());
529 >            Thread.sleep(SHORT_DELAY_MS);
530 >            assertTrue(p1.isTerminated());
531 >        }
532 >        catch(Exception ex) {
533 >            unexpectedException();
534 >        }
535 >        finally {
536 >            p1.shutdownNow();
537 >        }
538      }
539  
540   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines