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.25 by jsr166, Thu Sep 16 02:54:10 2010 UTC vs.
Revision 1.31 by jsr166, Sat May 28 22:33:35 2011 UTC

# Line 1 | Line 1
1   /*
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
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
8  
9
9   import junit.framework.*;
10   import java.util.*;
11   import java.util.concurrent.*;
# Line 29 | Line 28 | public class AbstractExecutorServiceTest
28      static class DirectExecutorService extends AbstractExecutorService {
29          public void execute(Runnable r) { r.run(); }
30          public void shutdown() { shutdown = true; }
31 <        public List<Runnable> shutdownNow() { shutdown = true; return Collections.EMPTY_LIST; }
31 >        public List<Runnable> shutdownNow() {
32 >            shutdown = true;
33 >            return Collections.EMPTY_LIST;
34 >        }
35          public boolean isShutdown() { return shutdown; }
36          public boolean isTerminated() { return isShutdown(); }
37 <        public boolean awaitTermination(long timeout, TimeUnit unit) { return isShutdown(); }
37 >        public boolean awaitTermination(long timeout, TimeUnit unit) {
38 >            return isShutdown();
39 >        }
40          private volatile boolean shutdown = false;
41      }
42  
# Line 48 | Line 52 | public class AbstractExecutorServiceTest
52          assertTrue(task.done);
53      }
54  
51
55      /**
56       * Completed submit(callable) returns result
57       */
# Line 79 | Line 82 | public class AbstractExecutorServiceTest
82          assertSame(TEST_STRING, result);
83      }
84  
82
85      /**
86       * A submitted privileged action runs to completion
87       */
# Line 152 | Line 154 | public class AbstractExecutorServiceTest
154          } catch (NullPointerException success) {}
155      }
156  
155
157      /**
158       * submit(null callable) throws NPE
159       */
# Line 165 | Line 166 | public class AbstractExecutorServiceTest
166      }
167  
168      /**
168     * submit(runnable) throws RejectedExecutionException if
169     * executor is saturated.
170     */
171    public void testExecute1() {
172        ThreadPoolExecutor p =
173            new ThreadPoolExecutor(1, 1,
174                                   60, TimeUnit.SECONDS,
175                                   new ArrayBlockingQueue<Runnable>(1));
176        try {
177            for (int i = 0; i < 2; ++i)
178                p.submit(new MediumRunnable());
179            for (int i = 0; i < 2; ++i) {
180                try {
181                    p.submit(new MediumRunnable());
182                    shouldThrow();
183                } catch (RejectedExecutionException success) {}
184            }
185        } finally {
186            joinPool(p);
187        }
188    }
189
190    /**
191     * submit(callable) throws RejectedExecutionException
192     * if executor is saturated.
193     */
194    public void testExecute2() {
195        ThreadPoolExecutor p =
196            new ThreadPoolExecutor(1, 1,
197                                   60, TimeUnit.SECONDS,
198                                   new ArrayBlockingQueue<Runnable>(1));
199        try {
200            for (int i = 0; i < 2; ++i)
201                p.submit(new MediumRunnable());
202            for (int i = 0; i < 2; ++i) {
203                try {
204                    p.submit(new SmallCallable());
205                    shouldThrow();
206                } catch (RejectedExecutionException success) {}
207            }
208        } finally {
209            joinPool(p);
210        }
211    }
212
213
214    /**
169       * submit(callable).get() throws InterruptedException if interrupted
170       */
171      public void testInterruptedSubmit() throws InterruptedException {
# Line 243 | Line 197 | public class AbstractExecutorServiceTest
197      }
198  
199      /**
200 <     *  get of submitted callable throws InterruptedException if callable
201 <     *  interrupted
248 <     */
249 <    public void testSubmitIE() throws InterruptedException {
250 <        final ThreadPoolExecutor p =
251 <            new ThreadPoolExecutor(1, 1,
252 <                                   60, TimeUnit.SECONDS,
253 <                                   new ArrayBlockingQueue<Runnable>(10));
254 <
255 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
256 <            public void realRun() throws Exception {
257 <                p.submit(new SmallCallable()).get();
258 <            }});
259 <
260 <        t.start();
261 <        Thread.sleep(SHORT_DELAY_MS);
262 <        t.interrupt();
263 <        t.join();
264 <        joinPool(p);
265 <    }
266 <
267 <    /**
268 <     *  get of submit(callable) throws ExecutionException if callable
269 <     *  throws exception
200 >     * get of submit(callable) throws ExecutionException if callable
201 >     * throws exception
202       */
203      public void testSubmitEE() throws InterruptedException {
204          ThreadPoolExecutor p =
# Line 289 | Line 221 | public class AbstractExecutorServiceTest
221      /**
222       * invokeAny(null) throws NPE
223       */
224 <    public void testInvokeAny1()
293 <        throws InterruptedException, ExecutionException {
224 >    public void testInvokeAny1() throws Exception {
225          ExecutorService e = new DirectExecutorService();
226          try {
227              e.invokeAny(null);
# Line 304 | Line 235 | public class AbstractExecutorServiceTest
235      /**
236       * invokeAny(empty collection) throws IAE
237       */
238 <    public void testInvokeAny2()
308 <        throws InterruptedException, ExecutionException {
238 >    public void testInvokeAny2() throws Exception {
239          ExecutorService e = new DirectExecutorService();
240          try {
241              e.invokeAny(new ArrayList<Callable<String>>());
# Line 450 | Line 380 | public class AbstractExecutorServiceTest
380          }
381      }
382  
453
383      /**
384       * timed invokeAny(null) throws NPE
385       */
# Line 655 | Line 584 | public class AbstractExecutorServiceTest
584          try {
585              List<Callable<String>> l = new ArrayList<Callable<String>>();
586              l.add(new StringTask());
587 <            l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
587 >            l.add(Executors.callable(possiblyInterruptedRunnable(2 * SHORT_DELAY_MS), TEST_STRING));
588              l.add(new StringTask());
589              List<Future<String>> futures =
590 <                e.invokeAll(l, SMALL_DELAY_MS, MILLISECONDS);
590 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
591              assertEquals(3, futures.size());
592              Iterator<Future<String>> it = futures.iterator();
593              Future<String> f1 = it.next();
# Line 667 | Line 596 | public class AbstractExecutorServiceTest
596              assertTrue(f1.isDone());
597              assertFalse(f1.isCancelled());
598              assertTrue(f2.isDone());
599 +            assertFalse(f2.isCancelled());
600              assertTrue(f3.isDone());
601              assertTrue(f3.isCancelled());
602          } finally {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines