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.26 by jsr166, Fri Sep 17 00:53:15 2010 UTC vs.
Revision 1.30 by jsr166, Tue Mar 15 19:47:06 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   */
# Line 170 | Line 170 | public class AbstractExecutorServiceTest
170      }
171  
172      /**
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    /**
173       * submit(callable).get() throws InterruptedException if interrupted
174       */
175      public void testInterruptedSubmit() throws InterruptedException {
# Line 248 | Line 201 | public class AbstractExecutorServiceTest
201      }
202  
203      /**
204 <     *  get of submitted callable throws InterruptedException if callable
205 <     *  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 <    /**
273 <     *  get of submit(callable) throws ExecutionException if callable
274 <     *  throws exception
204 >     * get of submit(callable) throws ExecutionException if callable
205 >     * throws exception
206       */
207      public void testSubmitEE() throws InterruptedException {
208          ThreadPoolExecutor p =
# Line 294 | Line 225 | public class AbstractExecutorServiceTest
225      /**
226       * invokeAny(null) throws NPE
227       */
228 <    public void testInvokeAny1()
298 <        throws InterruptedException, ExecutionException {
228 >    public void testInvokeAny1() throws Exception {
229          ExecutorService e = new DirectExecutorService();
230          try {
231              e.invokeAny(null);
# Line 309 | Line 239 | public class AbstractExecutorServiceTest
239      /**
240       * invokeAny(empty collection) throws IAE
241       */
242 <    public void testInvokeAny2()
313 <        throws InterruptedException, ExecutionException {
242 >    public void testInvokeAny2() throws Exception {
243          ExecutorService e = new DirectExecutorService();
244          try {
245              e.invokeAny(new ArrayList<Callable<String>>());
# Line 660 | Line 589 | public class AbstractExecutorServiceTest
589          try {
590              List<Callable<String>> l = new ArrayList<Callable<String>>();
591              l.add(new StringTask());
592 <            l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
592 >            l.add(Executors.callable(possiblyInterruptedRunnable(2 * SHORT_DELAY_MS), TEST_STRING));
593              l.add(new StringTask());
594              List<Future<String>> futures =
595 <                e.invokeAll(l, SMALL_DELAY_MS, MILLISECONDS);
595 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
596              assertEquals(3, futures.size());
597              Iterator<Future<String>> it = futures.iterator();
598              Future<String> f1 = it.next();
# Line 672 | Line 601 | public class AbstractExecutorServiceTest
601              assertTrue(f1.isDone());
602              assertFalse(f1.isCancelled());
603              assertTrue(f2.isDone());
604 +            assertFalse(f2.isCancelled());
605              assertTrue(f3.isDone());
606              assertTrue(f3.isCancelled());
607          } finally {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines