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.27 by jsr166, Sat Oct 9 19:30:34 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 53 | Line 52 | public class AbstractExecutorServiceTest
52          assertTrue(task.done);
53      }
54  
56
55      /**
56       * Completed submit(callable) returns result
57       */
# Line 84 | Line 82 | public class AbstractExecutorServiceTest
82          assertSame(TEST_STRING, result);
83      }
84  
87
85      /**
86       * A submitted privileged action runs to completion
87       */
# Line 157 | Line 154 | public class AbstractExecutorServiceTest
154          } catch (NullPointerException success) {}
155      }
156  
160
157      /**
158       * submit(null callable) throws NPE
159       */
# Line 170 | Line 166 | public class AbstractExecutorServiceTest
166      }
167  
168      /**
173     * submit(runnable) throws RejectedExecutionException if
174     * executor is saturated.
175     */
176    public void testExecute1() {
177        ThreadPoolExecutor p =
178            new ThreadPoolExecutor(1, 1,
179                                   60, TimeUnit.SECONDS,
180                                   new ArrayBlockingQueue<Runnable>(1));
181        try {
182            for (int i = 0; i < 2; ++i)
183                p.submit(new MediumRunnable());
184            for (int i = 0; i < 2; ++i) {
185                try {
186                    p.submit(new MediumRunnable());
187                    shouldThrow();
188                } catch (RejectedExecutionException success) {}
189            }
190        } finally {
191            joinPool(p);
192        }
193    }
194
195    /**
196     * submit(callable) throws RejectedExecutionException
197     * if executor is saturated.
198     */
199    public void testExecute2() {
200        ThreadPoolExecutor p =
201            new ThreadPoolExecutor(1, 1,
202                                   60, TimeUnit.SECONDS,
203                                   new ArrayBlockingQueue<Runnable>(1));
204        try {
205            for (int i = 0; i < 2; ++i)
206                p.submit(new MediumRunnable());
207            for (int i = 0; i < 2; ++i) {
208                try {
209                    p.submit(new SmallCallable());
210                    shouldThrow();
211                } catch (RejectedExecutionException success) {}
212            }
213        } finally {
214            joinPool(p);
215        }
216    }
217
218
219    /**
169       * submit(callable).get() throws InterruptedException if interrupted
170       */
171      public void testInterruptedSubmit() throws InterruptedException {
# Line 248 | Line 197 | public class AbstractExecutorServiceTest
197      }
198  
199      /**
251     * get of submitted callable throws InterruptedException if callable
252     * interrupted
253     */
254    public void testSubmitIE() throws InterruptedException {
255        final ThreadPoolExecutor p =
256            new ThreadPoolExecutor(1, 1,
257                                   60, TimeUnit.SECONDS,
258                                   new ArrayBlockingQueue<Runnable>(10));
259
260        Thread t = new Thread(new CheckedInterruptedRunnable() {
261            public void realRun() throws Exception {
262                p.submit(new SmallCallable()).get();
263            }});
264
265        t.start();
266        Thread.sleep(SHORT_DELAY_MS);
267        t.interrupt();
268        t.join();
269        joinPool(p);
270    }
271
272    /**
200       * get of submit(callable) throws ExecutionException if callable
201       * throws exception
202       */
# Line 294 | Line 221 | public class AbstractExecutorServiceTest
221      /**
222       * invokeAny(null) throws NPE
223       */
224 <    public void testInvokeAny1()
298 <        throws InterruptedException, ExecutionException {
224 >    public void testInvokeAny1() throws Exception {
225          ExecutorService e = new DirectExecutorService();
226          try {
227              e.invokeAny(null);
# Line 309 | Line 235 | public class AbstractExecutorServiceTest
235      /**
236       * invokeAny(empty collection) throws IAE
237       */
238 <    public void testInvokeAny2()
313 <        throws InterruptedException, ExecutionException {
238 >    public void testInvokeAny2() throws Exception {
239          ExecutorService e = new DirectExecutorService();
240          try {
241              e.invokeAny(new ArrayList<Callable<String>>());
# Line 455 | Line 380 | public class AbstractExecutorServiceTest
380          }
381      }
382  
458
383      /**
384       * timed invokeAny(null) throws NPE
385       */
# Line 660 | 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 672 | 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