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

Comparing jsr166/src/test/tck/ExecutorCompletionServiceTest.java (file contents):
Revision 1.28 by jsr166, Sat Mar 25 21:41:10 2017 UTC vs.
Revision 1.29 by jsr166, Sun Dec 3 17:15:21 2017 UTC

# Line 78 | Line 78 | public class ExecutorCompletionServiceTe
78      /**
79       * A taken submitted task is completed
80       */
81 <    public void testTake()
82 <        throws InterruptedException, ExecutionException {
81 >    public void testTake() throws Exception {
82          CompletionService cs = new ExecutorCompletionService(cachedThreadPool);
83          cs.submit(new StringTask());
84          Future f = cs.take();
# Line 100 | Line 99 | public class ExecutorCompletionServiceTe
99      /**
100       * poll returns non-null when the returned task is completed
101       */
102 <    public void testPoll1()
104 <        throws InterruptedException, ExecutionException {
102 >    public void testPoll1() throws Exception {
103          CompletionService cs = new ExecutorCompletionService(cachedThreadPool);
104          assertNull(cs.poll());
105          cs.submit(new StringTask());
# Line 120 | Line 118 | public class ExecutorCompletionServiceTe
118      /**
119       * timed poll returns non-null when the returned task is completed
120       */
121 <    public void testPoll2()
124 <        throws InterruptedException, ExecutionException {
121 >    public void testPoll2() throws Exception {
122          CompletionService cs = new ExecutorCompletionService(cachedThreadPool);
123          assertNull(cs.poll());
124          cs.submit(new StringTask());
125  
126          long startTime = System.nanoTime();
127          Future f;
128 <        while ((f = cs.poll(SHORT_DELAY_MS, MILLISECONDS)) == null) {
128 >        while ((f = cs.poll(timeoutMillis(), MILLISECONDS)) == null) {
129 >            assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
130              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
131                  fail("timed out");
132              Thread.yield();
# Line 140 | Line 138 | public class ExecutorCompletionServiceTe
138      /**
139       * poll returns null before the returned task is completed
140       */
141 <    public void testPollReturnsNull()
144 <        throws InterruptedException, ExecutionException {
141 >    public void testPollReturnsNullBeforeCompletion() throws Exception {
142          CompletionService cs = new ExecutorCompletionService(cachedThreadPool);
143          final CountDownLatch proceed = new CountDownLatch(1);
144          cs.submit(new Callable() { public String call() throws Exception {
# Line 161 | Line 158 | public class ExecutorCompletionServiceTe
158      /**
159       * successful and failed tasks are both returned
160       */
161 <    public void testTaskAssortment()
165 <        throws InterruptedException, ExecutionException {
161 >    public void testTaskAssortment() throws Exception {
162          CompletionService cs = new ExecutorCompletionService(cachedThreadPool);
163          ArithmeticException ex = new ArithmeticException();
164 <        for (int i = 0; i < 2; i++) {
164 >        final int rounds = 2;
165 >        for (int i = rounds; i--> 0; ) {
166              cs.submit(new StringTask());
167              cs.submit(callableThrowing(ex));
168              cs.submit(runnableThrowing(ex), null);
169          }
170          int normalCompletions = 0;
171          int exceptionalCompletions = 0;
172 <        for (int i = 0; i < 3 * 2; i++) {
172 >        for (int i = 3 * rounds; i--> 0; ) {
173              try {
174 <                if (cs.take().get() == TEST_STRING)
175 <                    normalCompletions++;
176 <            }
177 <            catch (ExecutionException expected) {
181 <                assertTrue(expected.getCause() instanceof ArithmeticException);
174 >                assertSame(TEST_STRING, cs.take().get());
175 >                normalCompletions++;
176 >            } catch (ExecutionException expected) {
177 >                assertSame(ex, expected.getCause());
178                  exceptionalCompletions++;
179              }
180          }
181 <        assertEquals(2 * 1, normalCompletions);
182 <        assertEquals(2 * 2, exceptionalCompletions);
181 >        assertEquals(1 * rounds, normalCompletions);
182 >        assertEquals(2 * rounds, exceptionalCompletions);
183          assertNull(cs.poll());
184      }
185  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines