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.29 by jsr166, Mon Oct 11 08:30:50 2010 UTC vs.
Revision 1.34 by jsr166, Wed Sep 25 07:39:17 2013 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.*;
12 + import java.util.concurrent.atomic.AtomicBoolean;
13   import static java.util.concurrent.TimeUnit.MILLISECONDS;
14 import java.math.BigInteger;
14   import java.security.*;
15  
16   public class AbstractExecutorServiceTest extends JSR166TestCase {
# Line 46 | Line 45 | public class AbstractExecutorServiceTest
45       */
46      public void testExecuteRunnable() throws Exception {
47          ExecutorService e = new DirectExecutorService();
48 <        TrackedShortRunnable task = new TrackedShortRunnable();
49 <        assertFalse(task.done);
50 <        Future<?> future = e.submit(task);
51 <        future.get();
52 <        assertTrue(task.done);
48 >        final AtomicBoolean done = new AtomicBoolean(false);
49 >        Future<?> future = e.submit(new CheckedRunnable() {
50 >            public void realRun() {
51 >                done.set(true);
52 >            }});
53 >        assertNull(future.get());
54 >        assertNull(future.get(0, MILLISECONDS));
55 >        assertTrue(done.get());
56 >        assertTrue(future.isDone());
57 >        assertFalse(future.isCancelled());
58      }
59  
56
60      /**
61       * Completed submit(callable) returns result
62       */
# Line 84 | Line 87 | public class AbstractExecutorServiceTest
87          assertSame(TEST_STRING, result);
88      }
89  
87
90      /**
91       * A submitted privileged action runs to completion
92       */
# Line 157 | Line 159 | public class AbstractExecutorServiceTest
159          } catch (NullPointerException success) {}
160      }
161  
160
162      /**
163       * submit(null callable) throws NPE
164       */
# Line 211 | Line 212 | public class AbstractExecutorServiceTest
212                                     new ArrayBlockingQueue<Runnable>(10));
213  
214          Callable c = new Callable() {
215 <            public Object call() { return 5/0; }};
215 >            public Object call() { throw new ArithmeticException(); }};
216  
217          try {
218              p.submit(c).get();
# Line 255 | Line 256 | public class AbstractExecutorServiceTest
256       */
257      public void testInvokeAny3() throws Exception {
258          ExecutorService e = new DirectExecutorService();
259 <        List<Callable<Integer>> l = new ArrayList<Callable<Integer>>();
260 <        l.add(new Callable<Integer>() {
261 <                  public Integer call() { return 5/0; }});
259 >        List<Callable<Long>> l = new ArrayList<Callable<Long>>();
260 >        l.add(new Callable<Long>() {
261 >            public Long call() { throw new ArithmeticException(); }});
262          l.add(null);
263          try {
264              e.invokeAny(l);
# Line 384 | Line 385 | public class AbstractExecutorServiceTest
385          }
386      }
387  
387
388      /**
389       * timed invokeAny(null) throws NPE
390       */
# Line 434 | Line 434 | public class AbstractExecutorServiceTest
434       */
435      public void testTimedInvokeAny3() throws Exception {
436          ExecutorService e = new DirectExecutorService();
437 <        List<Callable<Integer>> l = new ArrayList<Callable<Integer>>();
438 <        l.add(new Callable<Integer>() {
439 <                  public Integer call() { return 5/0; }});
437 >        List<Callable<Long>> l = new ArrayList<Callable<Long>>();
438 >        l.add(new Callable<Long>() {
439 >            public Long call() { throw new ArithmeticException(); }});
440          l.add(null);
441          try {
442              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 593 | Line 593 | public class AbstractExecutorServiceTest
593              l.add(new StringTask());
594              List<Future<String>> futures =
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();
599 <            Future<String> f2 = it.next();
600 <            Future<String> f3 = it.next();
601 <            assertTrue(f1.isDone());
602 <            assertFalse(f1.isCancelled());
603 <            assertTrue(f2.isDone());
604 <            assertFalse(f2.isCancelled());
605 <            assertTrue(f3.isDone());
606 <            assertTrue(f3.isCancelled());
596 >            assertEquals(l.size(), futures.size());
597 >            for (Future future : futures)
598 >                assertTrue(future.isDone());
599 >            assertFalse(futures.get(0).isCancelled());
600 >            assertFalse(futures.get(1).isCancelled());
601 >            assertTrue(futures.get(2).isCancelled());
602          } finally {
603              joinPool(e);
604          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines