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.4 by dl, Sun Sep 14 20:42:40 2003 UTC vs.
Revision 1.5 by dl, Sat Sep 20 18:20:08 2003 UTC

# Line 19 | Line 19 | public class ScheduledExecutorTest exten
19  
20      static class MyRunnable implements Runnable {
21          volatile boolean done = false;
22 <        public void run(){
23 <            try{
22 >        public void run() {
23 >            try {
24                  Thread.sleep(SMALL_DELAY_MS);
25                  done = true;
26              } catch(Exception e){
# Line 30 | Line 30 | public class ScheduledExecutorTest exten
30  
31      static class MyCallable implements Callable {
32          volatile boolean done = false;
33 <        public Object call(){
34 <            try{
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 <    public void testExecute(){
44 <        try{
43 >    /**
44 >     *
45 >     */
46 >    public void testExecute() {
47 >        try {
48              MyRunnable runnable =new MyRunnable();
49 <            ScheduledExecutor one = new ScheduledExecutor(1);
50 <            one.execute(runnable);
49 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
50 >            p1.execute(runnable);
51              assertFalse(runnable.done);
52              Thread.sleep(SHORT_DELAY_MS);
53 <            one.shutdown();
54 <            try{
53 >            p1.shutdown();
54 >            try {
55                  Thread.sleep(MEDIUM_DELAY_MS);
56              } catch(InterruptedException e){
57 <                fail("unexpected exception");
57 >                unexpectedException();
58              }
59              assertTrue(runnable.done);
60 <            one.shutdown();
61 <            joinPool(one);
60 >            p1.shutdown();
61 >            joinPool(p1);
62          }
63          catch(Exception e){
64 <            fail("unexpected exception");
64 >            unexpectedException();
65          }
66          
67      }
68  
69 <    public void testSchedule1(){
70 <        try{
69 >    /**
70 >     *
71 >     */
72 >    public void testSchedule1() {
73 >        try {
74              MyCallable callable = new MyCallable();
75 <            ScheduledExecutor one = new ScheduledExecutor(1);
76 <            Future f = one.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
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 <            joinPool(one);
83 <        }catch(RejectedExecutionException e){}
81 >            p1.shutdown();
82 >            joinPool(p1);
83 >        } catch(RejectedExecutionException e){}
84          catch(Exception e){
85 <            fail("unexpected exception");
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, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
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();
102 <            joinPool(one);
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, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
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();
120 <            joinPool(one);
119 >            p1.shutdown();
120 >            joinPool(p1);
121          } catch(Exception e){
122 <            fail("unexpected exception");
122 >            unexpectedException();
123          }
124      }
125      
# Line 123 | Line 130 | public class ScheduledExecutorTest exten
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(){
133 >    public void testSchedule1_RejectedExecutionException() {
134          ScheduledExecutor se = new ScheduledExecutor(1);
135 <        try{
135 >        try {
136              se.shutdown();
137              se.schedule(new NoOpRunnable(),
138                          MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
139 <            fail("shoud throw");
139 >            shouldThrow();
140          } catch(RejectedExecutionException success){
141          }
142          joinPool(se);
# Line 140 | Line 147 | public class ScheduledExecutorTest exten
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(){
150 >    public void testSchedule2_RejectedExecutionException() {
151          ScheduledExecutor se = new ScheduledExecutor(1);
152 <        try{
152 >        try {
153              se.shutdown();
154              se.schedule(new NoOpCallable(),
155                          MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
156 <            fail("should throw");
156 >            shouldThrow();
157          } catch(RejectedExecutionException success){
158          }
159          joinPool(se);
# Line 156 | Line 163 | public class ScheduledExecutorTest exten
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(){
166 >     public void testSchedule3_RejectedExecutionException() {
167           ScheduledExecutor se = new ScheduledExecutor(1);
168 <         try{
168 >         try {
169              se.shutdown();
170              se.schedule(new NoOpCallable(),
171                          MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
172 <            fail("should throw");
172 >            shouldThrow();
173          } catch(RejectedExecutionException success){
174          }
175           joinPool(se);
# Line 173 | Line 180 | public class ScheduledExecutorTest exten
180       *  RejectedExecutionException.
181       *  This occurs on an attempt to schedule a task on a shutdown executor
182       */
183 <    public void testScheduleAtFixedRate1_RejectedExecutionException(){
183 >    public void testScheduleAtFixedRate1_RejectedExecutionException() {
184          ScheduledExecutor se = new ScheduledExecutor(1);
185 <        try{
185 >        try {
186              se.shutdown();
187              se.scheduleAtFixedRate(new NoOpRunnable(),
188                                     MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
189 <            fail("should throw");
189 >            shouldThrow();
190          } catch(RejectedExecutionException success){
191          }
192          joinPool(se);
# Line 190 | Line 197 | public class ScheduledExecutorTest exten
197       *  RejectedExecutionException.
198       *  This occurs on an attempt to schedule a task on a shutdown executor
199       */
200 <    public void testScheduleAtFixedRate2_RejectedExecutionException(){
200 >    public void testScheduleAtFixedRate2_RejectedExecutionException() {
201          ScheduledExecutor se = new ScheduledExecutor(1);
202 <        try{
202 >        try {
203              se.shutdown();
204              se.scheduleAtFixedRate(new NoOpRunnable(),
205                                     1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
206 <            fail("should throw");
206 >            shouldThrow();
207          } catch(RejectedExecutionException success){
208          }
209          joinPool(se);
# Line 207 | Line 214 | public class ScheduledExecutorTest exten
214       *  RejectedExecutionException.
215       *  This occurs on an attempt to schedule a task on a shutdown executor
216       */
217 <    public void testScheduleWithFixedDelay1_RejectedExecutionException(){
217 >    public void testScheduleWithFixedDelay1_RejectedExecutionException() {
218          ScheduledExecutor se = new ScheduledExecutor(1);
219 <        try{
219 >        try {
220              se.shutdown();
221              se.scheduleWithFixedDelay(new NoOpRunnable(),
222                                        MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
223 <            fail("should throw");
223 >            shouldThrow();
224          } catch(RejectedExecutionException success){
225          }
226          joinPool(se);
# Line 224 | Line 231 | public class ScheduledExecutorTest exten
231       *  RejectedExecutionException.
232       *  This occurs on an attempt to schedule a task on a shutdown executor
233       */
234 <     public void testScheduleWithFixedDelay2_RejectedExecutionException(){
234 >     public void testScheduleWithFixedDelay2_RejectedExecutionException() {
235           ScheduledExecutor se = new ScheduledExecutor(1);
236 <        try{
236 >        try {
237              se.shutdown();
238              se.scheduleWithFixedDelay(new NoOpRunnable(),
239                                        1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
240 <            fail("should throw");
240 >            shouldThrow();
241          } catch(RejectedExecutionException success){
242          }
243          joinPool(se);
# Line 240 | Line 247 | public class ScheduledExecutorTest exten
247       *   execute throws RejectedExecutionException
248       *  This occurs on an attempt to schedule a task on a shutdown executor
249       */
250 <    public void testExecute_RejectedExecutionException(){
250 >    public void testExecute_RejectedExecutionException() {
251          ScheduledExecutor se = new ScheduledExecutor(1);
252 <        try{
252 >        try {
253              se.shutdown();
254              se.execute(new NoOpRunnable());
255 <            fail("should throw");
255 >            shouldThrow();
256          } catch(RejectedExecutionException success){
257          }
258          joinPool(se);
# Line 254 | Line 261 | public class ScheduledExecutorTest exten
261      /**
262       *   getActiveCount gives correct values
263       */
264 <    public void testGetActiveCount(){
265 <        ScheduledExecutor two = new ScheduledExecutor(2);
266 <        assertEquals(0, two.getActiveCount());
267 <        two.execute(new SmallRunnable());
268 <        try{
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 <            fail("unexpected exception");
271 >            unexpectedException();
272          }
273 <        assertEquals(1, two.getActiveCount());
274 <        joinPool(two);
273 >        assertEquals(1, p2.getActiveCount());
274 >        joinPool(p2);
275      }
276      
277      /**
278       *   getCompleteTaskCount gives correct values
279       */
280 <    public void testGetCompletedTaskCount(){
281 <        ScheduledExecutor two = new ScheduledExecutor(2);
282 <        assertEquals(0, two.getCompletedTaskCount());
283 <        two.execute(new SmallRunnable());
284 <        try{
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 <            fail("unexpected exception");
287 >            unexpectedException();
288          }
289 <        assertEquals(1, two.getCompletedTaskCount());
290 <        joinPool(two);
289 >        assertEquals(1, p2.getCompletedTaskCount());
290 >        joinPool(p2);
291      }
292      
293      /**
294       *   getCorePoolSize gives correct values
295       */
296 <    public void testGetCorePoolSize(){
297 <        ScheduledExecutor one = new ScheduledExecutor(1);
298 <        assertEquals(1, one.getCorePoolSize());
299 <        joinPool(one);
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 two = new ScheduledExecutor(2);
307 <        assertEquals(0, two.getLargestPoolSize());
308 <        two.execute(new SmallRunnable());
309 <        two.execute(new SmallRunnable());
310 <        try{
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 <            fail("unexpected exception");
313 >            unexpectedException();
314          }
315 <        assertEquals(2, two.getLargestPoolSize());
316 <        joinPool(two);
315 >        assertEquals(2, p2.getLargestPoolSize());
316 >        joinPool(p2);
317      }
318      
319      /**
320       *   getPoolSize gives correct values
321       */
322 <    public void testGetPoolSize(){
323 <        ScheduledExecutor one = new ScheduledExecutor(1);
324 <        assertEquals(0, one.getPoolSize());
325 <        one.execute(new SmallRunnable());
326 <        assertEquals(1, one.getPoolSize());
327 <        joinPool(one);
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 one = new ScheduledExecutor(1);
335 <        assertEquals(0, one.getTaskCount());
333 >    public void testGetTaskCount() {
334 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
335 >        assertEquals(0, p1.getTaskCount());
336          for(int i = 0; i < 5; i++)
337 <            one.execute(new SmallRunnable());
338 <        try{
337 >            p1.execute(new SmallRunnable());
338 >        try {
339              Thread.sleep(SHORT_DELAY_MS);
340          } catch(Exception e){
341 <            fail("unexpected exception");
341 >            unexpectedException();
342          }
343 <        assertEquals(5, one.getTaskCount());
344 <        joinPool(one);
343 >        assertEquals(5, p1.getTaskCount());
344 >        joinPool(p1);
345      }
346      
347      /**
348       *   isShutDown gives correct values
349       */
350 <    public void testIsShutdown(){
350 >    public void testIsShutdown() {
351          
352 <        ScheduledExecutor one = new ScheduledExecutor(1);
352 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
353          try {
354 <            assertFalse(one.isShutdown());
354 >            assertFalse(p1.isShutdown());
355          }
356          finally {
357 <            one.shutdown();
357 >            p1.shutdown();
358          }
359 <        assertTrue(one.isShutdown());
359 >        assertTrue(p1.isShutdown());
360      }
361  
362          
363      /**
364 <     *   isTerminated gives correct values
358 <     *  Makes sure termination does not take an innapropriate
359 <     *  amount of time
364 >     *  isTerminated gives correct values
365       */
366 <    public void testIsTerminated(){
367 <        ScheduledExecutor one = new ScheduledExecutor(1);
366 >    public void testIsTerminated() {
367 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
368          try {
369 <            one.execute(new SmallRunnable());
369 >            p1.execute(new SmallRunnable());
370          } finally {
371 <            one.shutdown();
371 >            p1.shutdown();
372          }
373          try {
374 <            assertTrue(one.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
375 <            assertTrue(one.isTerminated());
374 >            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
375 >            assertTrue(p1.isTerminated());
376          } catch(Exception e){
377 <            fail("unexpected exception");
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  
# Line 377 | Line 403 | public class ScheduledExecutorTest exten
403       *   that purge correctly removes cancelled tasks
404       *  from the queue
405       */
406 <    public void testPurge(){
407 <        ScheduledExecutor one = new ScheduledExecutor(1);
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] = one.schedule(new SmallRunnable(), 1, TimeUnit.MILLISECONDS);
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 <        one.purge();
416 <        long count = one.getTaskCount();
415 >        p1.purge();
416 >        long count = p1.getTaskCount();
417          assertTrue(count > 0 && count <= max);
418 <        joinPool(one);
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 one = new ScheduledExecutor(1);
425 >    public void testShutDownNow() {
426 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
427          for(int i = 0; i < 5; i++)
428 <            one.schedule(new SmallRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
429 <        List l = one.shutdownNow();
430 <        assertTrue(one.isShutdown());
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(one);
432 >        joinPool(p1);
433      }
434  
435 <    public void testShutDown1(){
435 >    /**
436 >     *
437 >     */
438 >    public void testShutDown1() {
439          try {
440 <            ScheduledExecutor one = new ScheduledExecutor(1);
441 <            assertTrue(one.getExecuteExistingDelayedTasksAfterShutdownPolicy());
442 <            assertFalse(one.getContinueExistingPeriodicTasksAfterShutdownPolicy());
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] = one.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
447 <            one.shutdown();
448 <            BlockingQueue q = one.getQueue();
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(one.isShutdown());
453 >            assertTrue(p1.isShutdown());
454              Thread.sleep(SMALL_DELAY_MS);
455              for (int i = 0; i < 5; ++i) {
456                  assertTrue(tasks[i].isDone());
# Line 430 | Line 459 | public class ScheduledExecutorTest exten
459              
460          }
461          catch(Exception ex) {
462 <            fail("unexpected exception");
462 >            unexpectedException();
463          }
464      }
465  
466  
467 <    public void testShutDown2(){
467 >    /**
468 >     *
469 >     */
470 >    public void testShutDown2() {
471          try {
472 <            ScheduledExecutor one = new ScheduledExecutor(1);
473 <            one.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
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] = one.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
477 <            one.shutdown();
478 <            assertTrue(one.isShutdown());
479 <            BlockingQueue q = one.getQueue();
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(one.isTerminated());
482 >            assertTrue(p1.isTerminated());
483          }
484          catch(Exception ex) {
485 <            fail("unexpected exception");
485 >            unexpectedException();
486          }
487      }
488  
489  
490 <    public void testShutDown3(){
490 >    /**
491 >     *
492 >     */
493 >    public void testShutDown3() {
494          try {
495 <            ScheduledExecutor one = new ScheduledExecutor(1);
496 <            one.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
495 >            ScheduledExecutor p1 = new ScheduledExecutor(1);
496 >            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
497              ScheduledCancellable task =
498 <                one.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
499 <            one.shutdown();
500 <            assertTrue(one.isShutdown());
501 <            BlockingQueue q = one.getQueue();
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(one.isTerminated());
504 >            assertTrue(p1.isTerminated());
505          }
506          catch(Exception ex) {
507 <            fail("unexpected exception");
507 >            unexpectedException();
508          }
509      }
510  
511 <    public void testShutDown4(){
512 <        ScheduledExecutor one = new ScheduledExecutor(1);
511 >    /**
512 >     *
513 >     */
514 >    public void testShutDown4() {
515 >        ScheduledExecutor p1 = new ScheduledExecutor(1);
516          try {
517 <            one.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
517 >            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
518              ScheduledCancellable task =
519 <                one.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
519 >                p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
520              assertFalse(task.isCancelled());
521 <            one.shutdown();
521 >            p1.shutdown();
522              assertFalse(task.isCancelled());
523 <            assertFalse(one.isTerminated());
524 <            assertTrue(one.isShutdown());
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(one.isTerminated());
530 >            assertTrue(p1.isTerminated());
531          }
532          catch(Exception ex) {
533 <            fail("unexpected exception");
533 >            unexpectedException();
534          }
535          finally {
536 <            one.shutdownNow();
536 >            p1.shutdownNow();
537          }
538      }
539  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines