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.11 by dl, Mon Dec 29 19:05:40 2003 UTC vs.
Revision 1.14 by jsr166, Mon Nov 16 05:30:07 2009 UTC

# Line 2 | Line 2
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.
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 13 | 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 37 | Line 37 | public class FutureTaskTest extends JSR1
37              FutureTask task = new FutureTask(null);
38              shouldThrow();
39          }
40 <        catch(NullPointerException success) {
40 >        catch (NullPointerException success) {
41          }
42      }
43  
# Line 49 | Line 49 | public class FutureTaskTest extends JSR1
49              FutureTask task = new FutureTask(null, Boolean.TRUE);
50              shouldThrow();
51          }
52 <        catch(NullPointerException success) {
52 >        catch (NullPointerException success) {
53          }
54      }
55  
# Line 94 | Line 94 | public class FutureTaskTest extends JSR1
94          try {
95              assertEquals(task.get(), one);
96          }
97 <        catch(Exception e) {
97 >        catch (Exception e) {
98              unexpectedException();
99          }
100      }
# Line 110 | Line 110 | public class FutureTaskTest extends JSR1
110              Object x = task.get();
111              shouldThrow();
112          }
113 <        catch(ExecutionException ee) {
113 >        catch (ExecutionException ee) {
114              Throwable cause = ee.getCause();
115              assertEquals(cause, nse);
116          }
117 <        catch(Exception e) {
117 >        catch (Exception e) {
118              unexpectedException();
119          }
120      }
# Line 167 | 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));
174              t.join();
175              assertTrue(task.isDone());
176              assertTrue(task.isCancelled());
177 <        } catch(InterruptedException e){
177 >        } catch (InterruptedException e) {
178              unexpectedException();
179          }
180      }
# Line 196 | 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));
203              t.join();
204              assertTrue(task.isDone());
205              assertTrue(task.isCancelled());
206 <        } catch(InterruptedException e){
206 >        } catch (InterruptedException e) {
207              unexpectedException();
208          }
209      }
# Line 216 | Line 216 | public class FutureTaskTest extends JSR1
216                  public Object call() {
217                      try {
218                          Thread.sleep(MEDIUM_DELAY_MS);
219 <                    } catch(InterruptedException e){
219 >                    } catch (InterruptedException e) {
220                          threadUnexpectedException();
221                      }
222                      return Boolean.TRUE;
# Line 226 | Line 226 | public class FutureTaskTest extends JSR1
226                  public void run() {
227                      try {
228                          ft.get();
229 <                    } catch(Exception e){
229 >                    } catch (Exception e) {
230                          threadUnexpectedException();
231                      }
232                  }
# Line 240 | Line 240 | public class FutureTaskTest extends JSR1
240              t.join();
241              assertTrue(ft.isDone());
242              assertFalse(ft.isCancelled());
243 <        } catch(InterruptedException e){
243 >        } catch (InterruptedException e) {
244              unexpectedException();
245  
246 <        }      
246 >        }
247      }
248  
249      /**
# Line 254 | Line 254 | public class FutureTaskTest extends JSR1
254                  public Object call() {
255                      try {
256                          Thread.sleep(MEDIUM_DELAY_MS);
257 <                    } catch(InterruptedException e){
257 >                    } catch (InterruptedException e) {
258                          threadUnexpectedException();
259                      }
260                      return Boolean.TRUE;
# Line 264 | Line 264 | public class FutureTaskTest extends JSR1
264                  public void run() {
265                      try {
266                          ft.get(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
267 <                    } catch(TimeoutException success) {
268 <                    } catch(Exception e){
267 >                    } catch (TimeoutException success) {
268 >                    } catch (Exception e) {
269                          threadUnexpectedException();
270                      }
271                  }
# Line 278 | Line 278 | public class FutureTaskTest extends JSR1
278              t.join();
279              assertTrue(ft.isDone());
280              assertFalse(ft.isCancelled());
281 <        } catch(InterruptedException e){
281 >        } catch (InterruptedException e) {
282              unexpectedException();
283 <            
284 <        }      
283 >
284 >        }
285      }
286  
287      /**
# Line 293 | Line 293 | public class FutureTaskTest extends JSR1
293                      try {
294                          Thread.sleep(SMALL_DELAY_MS);
295                          threadShouldThrow();
296 <                    } catch(InterruptedException e) {
296 >                    } catch (InterruptedException e) {
297                      }
298                      return Boolean.TRUE;
299                  }
# Line 304 | Line 304 | public class FutureTaskTest extends JSR1
304                          try {
305                              ft.get(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
306                              threadShouldThrow();
307 <                        } catch(CancellationException success) {}
308 <                        catch(Exception e){
307 >                        } catch (CancellationException success) {}
308 >                        catch (Exception e) {
309                              threadUnexpectedException();
310                          }
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);
318              t1.join();
319              t2.join();
320 <        } catch(InterruptedException ie){
320 >        } catch (InterruptedException ie) {
321              unexpectedException();
322          }
323      }
# Line 331 | Line 331 | public class FutureTaskTest extends JSR1
331                      try {
332                          Thread.sleep(MEDIUM_DELAY_MS);
333                          threadShouldThrow();
334 <                    } catch(InterruptedException e){
334 >                    } catch (InterruptedException e) {
335                      }
336                      return Boolean.TRUE;
337                  }
# Line 342 | Line 342 | public class FutureTaskTest extends JSR1
342                          try {
343                              ft.get();
344                              threadShouldThrow();
345 <                        } catch(CancellationException success){
345 >                        } catch (CancellationException success) {
346                          }
347 <                        catch(Exception e){
347 >                        catch (Exception e) {
348                              threadUnexpectedException();
349                          }
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);
357              t1.join();
358              t2.join();
359 <        } catch(InterruptedException success){
359 >        } catch (InterruptedException success) {
360              unexpectedException();
361          }
362      }
363 <    
363 >
364  
365      /**
366       * A runtime exception in task causes get to throw ExecutionException
# Line 376 | Line 376 | public class FutureTaskTest extends JSR1
376              ft.run();
377              ft.get();
378              shouldThrow();
379 <        } catch(ExecutionException success){
379 >        } catch (ExecutionException success) {
380          }
381 <        catch(Exception e){
381 >        catch (Exception e) {
382              unexpectedException();
383          }
384      }
385 <  
385 >
386      /**
387       *  A runtime exception in task causes timed get to throw ExecutionException
388       */
# Line 397 | Line 397 | public class FutureTaskTest extends JSR1
397              ft.run();
398              ft.get(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
399              shouldThrow();
400 <        } catch(ExecutionException success) {
401 <        } catch(TimeoutException success) { } // unlikely but OK
402 <        catch(Exception e){
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 411 | 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();
418 <                    } catch(InterruptedException success){
419 <                    } catch(Exception e){
418 >                    } catch (InterruptedException success) {
419 >                    } catch (Exception e) {
420                          threadUnexpectedException();
421                      }
422                  }
# Line 426 | Line 426 | public class FutureTaskTest extends JSR1
426              Thread.sleep(SHORT_DELAY_MS);
427              t.interrupt();
428              t.join();
429 <        } catch(Exception e){
429 >        } catch (Exception e) {
430              unexpectedException();
431          }
432      }
# Line 437 | 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();
444 <                    } catch(InterruptedException success){}
445 <                    catch(Exception e){
444 >                    } catch (InterruptedException success) {}
445 >                    catch (Exception e) {
446                          threadUnexpectedException();
447                      }
448                  }
# Line 452 | Line 452 | public class FutureTaskTest extends JSR1
452              Thread.sleep(SHORT_DELAY_MS);
453              t.interrupt();
454              t.join();
455 <        } catch(Exception e){
455 >        } catch (Exception e) {
456              unexpectedException();
457          }
458      }
459 <    
459 >
460      /**
461       * A timed out timed get throws TimeoutException
462       */
# Line 465 | Line 465 | public class FutureTaskTest extends JSR1
465              FutureTask ft = new FutureTask(new NoOpCallable());
466              ft.get(1,TimeUnit.MILLISECONDS);
467              shouldThrow();
468 <        } catch(TimeoutException success){}
469 <        catch(Exception success){
468 >        } catch (TimeoutException success) {}
469 >        catch (Exception success) {
470              unexpectedException();
471          }
472      }
473 <    
473 >
474   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines