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

Comparing jsr166/src/test/tck/ScheduledExecutorSubclassTest.java (file contents):
Revision 1.1 by dl, Fri May 20 16:30:17 2005 UTC vs.
Revision 1.2 by jsr166, Mon Nov 2 20:28:31 2009 UTC

# Line 11 | Line 11 | import java.util.concurrent.atomic.*;
11  
12   public class ScheduledExecutorSubclassTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());  
14 >        junit.textui.TestRunner.run (suite());
15      }
16      public static Test suite() {
17          return new TestSuite(ScheduledExecutorTest.class);
18      }
19  
20 <    static class CustomTask<V> implements RunnableScheduledFuture<V> {
20 >    static class CustomTask<V> implements RunnableScheduledFuture<V> {
21          RunnableScheduledFuture<V> task;
22          volatile boolean ran;
23          CustomTask(RunnableScheduledFuture<V> t) { task = t; }
24          public boolean isPeriodic() { return task.isPeriodic(); }
25 <        public void run() {
25 >        public void run() {
26              ran = true;
27 <            task.run();
27 >            task.run();
28          }
29          public long getDelay(TimeUnit unit) { return task.getDelay(unit); }
30          public int compareTo(Delayed t) {
31 <            return task.compareTo(((CustomTask)t).task);
31 >            return task.compareTo(((CustomTask)t).task);
32          }
33          public boolean cancel(boolean mayInterruptIfRunning) {
34              return task.cancel(mayInterruptIfRunning);
# Line 46 | Line 46 | public class ScheduledExecutorSubclassTe
46              return v;
47          }
48      }
49 <    
49 >
50  
51      public class CustomExecutor extends ScheduledThreadPoolExecutor {
52  
# Line 65 | Line 65 | public class ScheduledExecutorSubclassTe
65          CustomExecutor(int corePoolSize, ThreadFactory threadFactory) {
66              super(corePoolSize, threadFactory);
67          }
68 <        CustomExecutor(int corePoolSize, ThreadFactory threadFactory,
68 >        CustomExecutor(int corePoolSize, ThreadFactory threadFactory,
69                         RejectedExecutionHandler handler) {
70              super(corePoolSize, threadFactory, handler);
71          }
72 <        
72 >
73      }
74 <
74 >
75  
76  
77      /**
# Line 97 | Line 97 | public class ScheduledExecutorSubclassTe
97          catch(Exception e){
98              unexpectedException();
99          }
100 <        
100 >
101      }
102  
103  
# Line 140 | Line 140 | public class ScheduledExecutorSubclassTe
140              unexpectedException();
141          }
142      }
143 <    
143 >
144      /**
145       * scheduleAtFixedRate executes runnable after given initial delay
146       */
# Line 181 | Line 181 | public class ScheduledExecutorSubclassTe
181              unexpectedException();
182          }
183      }
184 <    
184 >
185      /**
186       * scheduleAtFixedRate executes series of tasks at given rate
187       */
# Line 189 | Line 189 | public class ScheduledExecutorSubclassTe
189          try {
190              CustomExecutor p1 = new CustomExecutor(1);
191              RunnableCounter counter = new RunnableCounter();
192 <            ScheduledFuture h =
192 >            ScheduledFuture h =
193                  p1.scheduleAtFixedRate(counter, 0, 1, TimeUnit.MILLISECONDS);
194              Thread.sleep(SMALL_DELAY_MS);
195              h.cancel(true);
# Line 211 | Line 211 | public class ScheduledExecutorSubclassTe
211          try {
212              CustomExecutor p1 = new CustomExecutor(1);
213              RunnableCounter counter = new RunnableCounter();
214 <            ScheduledFuture h =
214 >            ScheduledFuture h =
215                  p1.scheduleWithFixedDelay(counter, 0, 1, TimeUnit.MILLISECONDS);
216              Thread.sleep(SMALL_DELAY_MS);
217              h.cancel(true);
# Line 238 | Line 238 | public class ScheduledExecutorSubclassTe
238          catch(Exception e){
239              unexpectedException();
240          }
241 <        
241 >
242          joinPool(se);
243      }
244  
# Line 257 | Line 257 | public class ScheduledExecutorSubclassTe
257          }
258          joinPool(se);
259      }
260 <  
260 >
261      /**
262       * execute throws RejectedExecutionException if shutdown
263       */
# Line 271 | Line 271 | public class ScheduledExecutorSubclassTe
271          } catch(RejectedExecutionException success){
272          } catch (SecurityException ok) {
273          }
274 <        
274 >
275          joinPool(se);
276  
277      }
# Line 320 | Line 320 | public class ScheduledExecutorSubclassTe
320              shouldThrow();
321          } catch(RejectedExecutionException success){
322          } catch (SecurityException ok) {
323 <        }
323 >        }
324          joinPool(se);
325      }
326 <    
326 >
327      /**
328       * scheduleWithFixedDelay throws RejectedExecutionException if shutdown
329       */
# Line 336 | Line 336 | public class ScheduledExecutorSubclassTe
336              shouldThrow();
337          } catch(RejectedExecutionException success){
338          } catch (SecurityException ok) {
339 <        }
339 >        }
340          joinPool(se);
341      }
342  
# Line 356 | Line 356 | public class ScheduledExecutorSubclassTe
356          assertEquals(1, p2.getActiveCount());
357          joinPool(p2);
358      }
359 <    
359 >
360      /**
361       *    getCompletedTaskCount increases, but doesn't overestimate,
362       *   when tasks complete
# Line 373 | Line 373 | public class ScheduledExecutorSubclassTe
373          assertEquals(1, p2.getCompletedTaskCount());
374          joinPool(p2);
375      }
376 <    
376 >
377      /**
378 <     *  getCorePoolSize returns size given in constructor if not otherwise set
378 >     *  getCorePoolSize returns size given in constructor if not otherwise set
379       */
380      public void testGetCorePoolSize() {
381          CustomExecutor p1 = new CustomExecutor(1);
382          assertEquals(1, p1.getCorePoolSize());
383          joinPool(p1);
384      }
385 <    
385 >
386      /**
387       *    getLargestPoolSize increases, but doesn't overestimate, when
388       *   multiple threads active
# Line 400 | Line 400 | public class ScheduledExecutorSubclassTe
400          assertEquals(2, p2.getLargestPoolSize());
401          joinPool(p2);
402      }
403 <    
403 >
404      /**
405       *   getPoolSize increases, but doesn't overestimate, when threads
406       *   become active
# Line 412 | Line 412 | public class ScheduledExecutorSubclassTe
412          assertEquals(1, p1.getPoolSize());
413          joinPool(p1);
414      }
415 <    
415 >
416      /**
417       *    getTaskCount increases, but doesn't overestimate, when tasks
418       *    submitted
# Line 431 | Line 431 | public class ScheduledExecutorSubclassTe
431          joinPool(p1);
432      }
433  
434 <    /**
434 >    /**
435       * getThreadFactory returns factory in constructor if not set
436       */
437      public void testGetThreadFactory() {
# Line 441 | Line 441 | public class ScheduledExecutorSubclassTe
441          joinPool(p);
442      }
443  
444 <    /**
444 >    /**
445       * setThreadFactory sets the thread factory returned by getThreadFactory
446       */
447      public void testSetThreadFactory() {
# Line 452 | Line 452 | public class ScheduledExecutorSubclassTe
452          joinPool(p);
453      }
454  
455 <    /**
455 >    /**
456       * setThreadFactory(null) throws NPE
457       */
458      public void testSetThreadFactoryNull() {
# Line 465 | Line 465 | public class ScheduledExecutorSubclassTe
465              joinPool(p);
466          }
467      }
468 <    
468 >
469      /**
470       *   is isShutDown is false before shutdown, true after
471       */
472      public void testIsShutdown() {
473 <        
473 >
474          CustomExecutor p1 = new CustomExecutor(1);
475          try {
476              assertFalse(p1.isShutdown());
# Line 481 | Line 481 | public class ScheduledExecutorSubclassTe
481          assertTrue(p1.isShutdown());
482      }
483  
484 <        
484 >
485      /**
486       *   isTerminated is false before termination, true after
487       */
# Line 497 | Line 497 | public class ScheduledExecutorSubclassTe
497              assertTrue(p1.isTerminated());
498          } catch(Exception e){
499              unexpectedException();
500 <        }      
500 >        }
501      }
502  
503      /**
# Line 518 | Line 518 | public class ScheduledExecutorSubclassTe
518              assertFalse(p1.isTerminating());
519          } catch(Exception e){
520              unexpectedException();
521 <        }      
521 >        }
522      }
523  
524      /**
# Line 611 | Line 611 | public class ScheduledExecutorSubclassTe
611          List l;
612          try {
613              l = p1.shutdownNow();
614 <        } catch (SecurityException ok) {
614 >        } catch (SecurityException ok) {
615              return;
616          }
617          assertTrue(p1.isShutdown());
# Line 644 | Line 644 | public class ScheduledExecutorSubclassTe
644                  assertTrue(tasks[i].isDone());
645                  assertFalse(tasks[i].isCancelled());
646              }
647 <            
647 >
648          }
649          catch(Exception ex) {
650              unexpectedException();
# Line 723 | Line 723 | public class ScheduledExecutorSubclassTe
723          catch(Exception ex) {
724              unexpectedException();
725          }
726 <        finally {
726 >        finally {
727              joinPool(p1);
728          }
729      }
# Line 930 | Line 930 | public class ScheduledExecutorSubclassTe
930              l.add(new NPETask());
931              List<Future<String>> result = e.invokeAll(l);
932              assertEquals(1, result.size());
933 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
933 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
934                  it.next().get();
935          } catch(ExecutionException success) {
936          } catch(Exception ex) {
# Line 951 | Line 951 | public class ScheduledExecutorSubclassTe
951              l.add(new StringTask());
952              List<Future<String>> result = e.invokeAll(l);
953              assertEquals(2, result.size());
954 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
954 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
955                  assertSame(TEST_STRING, it.next().get());
956          } catch (ExecutionException success) {
957          } catch(Exception ex) {
# Line 1138 | Line 1138 | public class ScheduledExecutorSubclassTe
1138              l.add(new NPETask());
1139              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1140              assertEquals(1, result.size());
1141 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1141 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1142                  it.next().get();
1143          } catch(ExecutionException success) {
1144          } catch(Exception ex) {
# Line 1159 | Line 1159 | public class ScheduledExecutorSubclassTe
1159              l.add(new StringTask());
1160              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1161              assertEquals(2, result.size());
1162 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1162 >            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1163                  assertSame(TEST_STRING, it.next().get());
1164          } catch (ExecutionException success) {
1165          } catch(Exception ex) {
# Line 1181 | Line 1181 | public class ScheduledExecutorSubclassTe
1181              l.add(new StringTask());
1182              List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1183              assertEquals(3, result.size());
1184 <            Iterator<Future<String>> it = result.iterator();
1184 >            Iterator<Future<String>> it = result.iterator();
1185              Future<String> f1 = it.next();
1186              Future<String> f2 = it.next();
1187              Future<String> f3 = it.next();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines