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

Comparing jsr166/src/test/tck/AbstractExecutorServiceTest.java (file contents):
Revision 1.1 by tim, Wed Dec 10 01:51:12 2003 UTC vs.
Revision 1.5 by dl, Fri Dec 19 20:42:44 2003 UTC

# Line 27 | Line 27 | public class AbstractExecutorServiceTest
27      static class DirectExecutorService extends AbstractExecutorService {
28          public void execute(Runnable r) { r.run(); }
29          public void shutdown() { shutdown = true; }
30 <        public List shutdownNow() { shutdown = true; return Collections.EMPTY_LIST; }
30 >        public List<Runnable> shutdownNow() { shutdown = true; return Collections.EMPTY_LIST; }
31          public boolean isShutdown() { return shutdown; }
32          public boolean isTerminated() { return isShutdown(); }
33          public boolean awaitTermination(long timeout, TimeUnit unit) { return isShutdown(); }
# Line 60 | Line 60 | public class AbstractExecutorServiceTest
60          }
61      }
62  
63    /**
64     * invoke of a runnable runs it to completion
65     */
66    public void testInvokeRunnable() {
67        try {
68            ExecutorService e = new DirectExecutorService();
69            TrackedShortRunnable task = new TrackedShortRunnable();
70            assertFalse(task.done);
71            e.invoke(task);
72            assertTrue(task.done);
73        }
74        catch (ExecutionException ex) {
75            unexpectedException();
76        }
77        catch (InterruptedException ex) {
78            unexpectedException();
79        }
80    }
63  
64      /**
65       * execute of a callable runs it to completion
# Line 109 | Line 91 | public class AbstractExecutorServiceTest
91          Policy.setPolicy(policy);
92          try {
93              ExecutorService e = new DirectExecutorService();
94 <            Future future = e.submit(new PrivilegedAction() {
94 >            Future future = e.submit(Executors.callable(new PrivilegedAction() {
95                      public Object run() {
96                          return TEST_STRING;
97 <                    }});
97 >                    }}));
98  
99              Object result = future.get();
100              assertSame(TEST_STRING, result);
# Line 139 | Line 121 | public class AbstractExecutorServiceTest
121          Policy.setPolicy(policy);
122          try {
123              ExecutorService e = new DirectExecutorService();
124 <            Future future = e.submit(new PrivilegedExceptionAction() {
124 >            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
125                      public Object run() {
126                          return TEST_STRING;
127 <                    }});
127 >                    }}));
128  
129              Object result = future.get();
130              assertSame(TEST_STRING, result);
# Line 169 | Line 151 | public class AbstractExecutorServiceTest
151          Policy.setPolicy(policy);
152          try {
153              ExecutorService e = new DirectExecutorService();
154 <            Future future = e.submit(new PrivilegedExceptionAction() {
154 >            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
155                      public Object run() throws Exception {
156                          throw new IndexOutOfBoundsException();
157 <                    }});
157 >                    }}));
158  
159              Object result = future.get();
160              shouldThrow();
# Line 188 | Line 170 | public class AbstractExecutorServiceTest
170      }
171  
172      /**
173 <     * invoke of a collable runs it to completion
173 >     * invoke of a callable runs it to completion
174       */
175      public void testInvokeCallable() {
176          try {
# Line 222 | Line 204 | public class AbstractExecutorServiceTest
204          }
205      }
206  
225    /**
226     * invoke of a null runnable throws NPE
227     */
228    public void testInvokeNullRunnable() {
229        try {
230            ExecutorService e = new DirectExecutorService();
231            TrackedShortRunnable task = null;
232            e.invoke(task);
233            shouldThrow();
234        }
235        catch (NullPointerException success) {
236        }
237        catch (Exception ex) {
238            unexpectedException();
239        }
240    }
207  
208      /**
209       * execute of a null callable throws NPE
# Line 306 | Line 272 | public class AbstractExecutorServiceTest
272  
273  
274      /**
275 <     *  invoke(Executor, Runnable) throws InterruptedException if
275 >     *  invoke(Executor, Callable) throws InterruptedException if
276       *  caller interrupted.
277       */
278      public void testInterruptedInvoke() {
# Line 314 | Line 280 | public class AbstractExecutorServiceTest
280          Thread t = new Thread(new Runnable() {
281                  public void run() {
282                      try {
283 <                        p.invoke(new Runnable() {
284 <                                public void run() {
283 >                        p.invoke(new Callable<Object>() {
284 >                                public Object call() {
285                                      try {
286                                          Thread.sleep(MEDIUM_DELAY_MS);
287                                          shouldThrow();
288                                      } catch(InterruptedException e){
289                                      }
290 +                                    return null;
291                                  }
292                              });
293                      } catch(InterruptedException success){
# Line 341 | Line 308 | public class AbstractExecutorServiceTest
308      }
309  
310      /**
344     *  invoke(Executor, Runnable) throws ExecutionException if
345     *  runnable throws exception.
346     */
347    public void testInvoke3() {
348        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
349        try {
350            Runnable r = new Runnable() {
351                    public void run() {
352                        int i = 5/0;
353                    }
354                };
355
356            for(int i =0; i < 5; i++){
357                p.invoke(r);
358            }
359
360            shouldThrow();
361        } catch(ExecutionException success){
362        } catch(Exception e){
363            unexpectedException();
364        }
365        joinPool(p);
366    }
367
368
369
370    /**
311       *  invoke(Executor, Callable) throws InterruptedException if
312       *  callable throws exception
313       */
# Line 435 | Line 375 | public class AbstractExecutorServiceTest
375          joinPool(p);
376      }
377  
378 < }
378 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines