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

Comparing jsr166/src/test/tck/FutureTaskTest.java (file contents):
Revision 1.8 by dl, Mon Dec 22 00:48:55 2003 UTC vs.
Revision 1.12 by jsr166, Mon Nov 2 20:28:31 2009 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 12 | Line 13 | import java.util.*;
13   public class FutureTaskTest extends JSR166TestCase {
14  
15      public static void main(String[] args) {
16 <        junit.textui.TestRunner.run (suite());  
16 >        junit.textui.TestRunner.run (suite());
17      }
18      public static Test suite() {
19          return new TestSuite(FutureTaskTest.class);
# Line 23 | Line 24 | public class FutureTaskTest extends JSR1
24       */
25      static class PublicFutureTask extends FutureTask {
26          public PublicFutureTask(Callable r) { super(r); }
27 <        public boolean reset() { return super.reset(); }
27 <        public void setCancelled() { super.setCancelled(); }
27 >        public boolean runAndReset() { return super.runAndReset(); }
28          public void set(Object x) { super.set(x); }
29          public void setException(Throwable t) { super.setException(t); }
30      }
# Line 64 | Line 64 | public class FutureTaskTest extends JSR1
64      }
65  
66      /**
67 <     * reset of a done task succeeds and changes status to not done
67 >     * runAndReset of a non-cancelled task succeeds
68       */
69 <    public void testReset() {
69 >    public void testRunAndReset() {
70          PublicFutureTask task = new PublicFutureTask(new NoOpCallable());
71 <        task.run();
72 <        assertTrue(task.isDone());
73 <        assertTrue(task.reset());      
71 >        assertTrue(task.runAndReset());
72          assertFalse(task.isDone());
73      }
74  
75      /**
76 <     * Resetting after cancellation fails
76 >     * runAndReset after cancellation fails
77       */
78      public void testResetAfterCancel() {
79          PublicFutureTask task = new PublicFutureTask(new NoOpCallable());
80          assertTrue(task.cancel(false));
81 <        task.run();
81 >        assertFalse(task.runAndReset());
82          assertTrue(task.isDone());
83          assertTrue(task.isCancelled());
86        assertFalse(task.reset());
84      }
85  
86  
90    /**
91     * setCancelled of a new task causes isCancelled to be true
92     */
93    public void testSetCancelled() {
94        PublicFutureTask task = new PublicFutureTask(new NoOpCallable());
95        assertTrue(task.cancel(false));
96        task.setCancelled();
97        assertTrue(task.isDone());
98        assertTrue(task.isCancelled());
99    }
87  
88      /**
89 <     * setting value gauses get to return it
89 >     * setting value causes get to return it
90       */
91      public void testSet() {
92          PublicFutureTask task = new PublicFutureTask(new NoOpCallable());
# Line 180 | Line 167 | public class FutureTaskTest extends JSR1
167                  } });
168          Thread t = new  Thread(task);
169          t.start();
170 <        
170 >
171          try {
172              Thread.sleep(SHORT_DELAY_MS);
173              assertTrue(task.cancel(true));
# Line 209 | Line 196 | public class FutureTaskTest extends JSR1
196                  } });
197          Thread t = new  Thread(task);
198          t.start();
199 <        
199 >
200          try {
201              Thread.sleep(SHORT_DELAY_MS);
202              assertTrue(task.cancel(false));
# Line 256 | Line 243 | public class FutureTaskTest extends JSR1
243          } catch(InterruptedException e){
244              unexpectedException();
245  
246 <        }      
246 >        }
247      }
248  
249      /**
# Line 293 | Line 280 | public class FutureTaskTest extends JSR1
280              assertFalse(ft.isCancelled());
281          } catch(InterruptedException e){
282              unexpectedException();
283 <            
284 <        }      
283 >
284 >        }
285      }
286  
287      /**
# Line 324 | Line 311 | public class FutureTaskTest extends JSR1
311                      }
312                  });
313              Thread t2 = new Thread(ft);
314 <            t1.start();
314 >            t1.start();
315              t2.start();
316              Thread.sleep(SHORT_DELAY_MS);
317              ft.cancel(true);
# Line 363 | Line 350 | public class FutureTaskTest extends JSR1
350                      }
351                  });
352              Thread t2 = new Thread(ft);
353 <            t1.start();
353 >            t1.start();
354              t2.start();
355              Thread.sleep(SHORT_DELAY_MS);
356              ft.cancel(true);
# Line 373 | Line 360 | public class FutureTaskTest extends JSR1
360              unexpectedException();
361          }
362      }
363 <    
363 >
364  
365      /**
366       * A runtime exception in task causes get to throw ExecutionException
# Line 395 | Line 382 | public class FutureTaskTest extends JSR1
382              unexpectedException();
383          }
384      }
385 <  
385 >
386      /**
387       *  A runtime exception in task causes timed get to throw ExecutionException
388       */
# Line 410 | Line 397 | public class FutureTaskTest extends JSR1
397              ft.run();
398              ft.get(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
399              shouldThrow();
400 <        } catch(ExecutionException success) {
400 >        } catch(ExecutionException success) {
401          } catch(TimeoutException success) { } // unlikely but OK
402          catch(Exception e){
403              unexpectedException();
404          }
405      }
406 <      
406 >
407  
408      /**
409       * Interrupting a waiting get causes it to throw InterruptedException
# Line 424 | Line 411 | public class FutureTaskTest extends JSR1
411      public void testGet_InterruptedException() {
412          final FutureTask ft = new FutureTask(new NoOpCallable());
413          Thread t = new Thread(new Runnable() {
414 <                public void run() {                
414 >                public void run() {
415                      try {
416                          ft.get();
417                          threadShouldThrow();
# Line 450 | Line 437 | public class FutureTaskTest extends JSR1
437      public void testTimedGet_InterruptedException2() {
438          final FutureTask ft = new FutureTask(new NoOpCallable());
439          Thread t = new Thread(new Runnable() {
440 <                public void run() {                
440 >                public void run() {
441                      try {
442                          ft.get(LONG_DELAY_MS,TimeUnit.MILLISECONDS);
443                          threadShouldThrow();
# Line 469 | Line 456 | public class FutureTaskTest extends JSR1
456              unexpectedException();
457          }
458      }
459 <    
459 >
460      /**
461       * A timed out timed get throws TimeoutException
462       */
# Line 483 | Line 470 | public class FutureTaskTest extends JSR1
470              unexpectedException();
471          }
472      }
473 <    
473 >
474   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines