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

Comparing jsr166/src/test/tck/ForkJoinTaskTest.java (file contents):
Revision 1.24 by jsr166, Sun Nov 21 19:06:53 2010 UTC vs.
Revision 1.32 by jsr166, Fri May 27 17:15:48 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   */
6   import java.util.concurrent.ExecutionException;
7   import java.util.concurrent.CancellationException;
# Line 93 | Line 93 | public class ForkJoinTaskTest extends JS
93          assertFalse(a.isCompletedAbnormally());
94          assertNull(a.getException());
95          assertSame(expected, a.getRawResult());
96 <        assertSame(expected, a.join());
96 >
97 >        {
98 >            Thread.currentThread().interrupt();
99 >            long t0 = System.nanoTime();
100 >            assertSame(expected, a.join());
101 >            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
102 >            Thread.interrupted();
103 >        }
104 >
105 >        {
106 >            Thread.currentThread().interrupt();
107 >            long t0 = System.nanoTime();
108 >            a.quietlyJoin();        // should be no-op
109 >            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
110 >            Thread.interrupted();
111 >        }
112 >
113 >        assertFalse(a.cancel(false));
114 >        assertFalse(a.cancel(true));
115          try {
116              assertSame(expected, a.get());
117          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 109 | Line 127 | public class ForkJoinTaskTest extends JS
127          assertTrue(a.isCompletedAbnormally());
128          assertTrue(a.getException() instanceof CancellationException);
129          assertNull(a.getRawResult());
130 +        assertTrue(a.cancel(false));
131 +        assertTrue(a.cancel(true));
132  
133          try {
134 +            Thread.currentThread().interrupt();
135              a.join();
136              shouldThrow();
137          } catch (CancellationException success) {
138          } catch (Throwable fail) { threadUnexpectedException(fail); }
139 +        Thread.interrupted();
140 +
141 +        {
142 +            long t0 = System.nanoTime();
143 +            a.quietlyJoin();        // should be no-op
144 +            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
145 +        }
146  
147          try {
148              a.get();
# Line 134 | Line 162 | public class ForkJoinTaskTest extends JS
162          assertFalse(a.isCancelled());
163          assertFalse(a.isCompletedNormally());
164          assertTrue(a.isCompletedAbnormally());
165 <        assertSame(t, a.getException());
165 >        assertSame(t.getClass(), a.getException().getClass());
166          assertNull(a.getRawResult());
167 +        assertFalse(a.cancel(false));
168 +        assertFalse(a.cancel(true));
169  
170          try {
171 +            Thread.currentThread().interrupt();
172              a.join();
173              shouldThrow();
174          } catch (Throwable expected) {
175 <            assertSame(t, expected);
175 >            assertSame(t.getClass(), expected.getClass());
176 >        }
177 >        Thread.interrupted();
178 >
179 >        {
180 >            long t0 = System.nanoTime();
181 >            a.quietlyJoin();        // should be no-op
182 >            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
183          }
184  
185          try {
186              a.get();
187              shouldThrow();
188          } catch (ExecutionException success) {
189 <            assertSame(t, success.getCause());
189 >            assertSame(t.getClass(), success.getCause().getClass());
190          } catch (Throwable fail) { threadUnexpectedException(fail); }
191  
192          try {
193              a.get(5L, SECONDS);
194              shouldThrow();
195          } catch (ExecutionException success) {
196 <            assertSame(t, success.getCause());
196 >            assertSame(t.getClass(), success.getCause().getClass());
197          } catch (Throwable fail) { threadUnexpectedException(fail); }
198      }
199  
# Line 167 | Line 205 | public class ForkJoinTaskTest extends JS
205       * differently than supplied Recursive forms.
206       */
207  
208 <    static final class FJException extends RuntimeException {
208 >    public static final class FJException extends RuntimeException {
209          FJException() { super(); }
210      }
211  
# Line 343 | Line 381 | public class ForkJoinTaskTest extends JS
381      /**
382       * invoke returns when task completes normally.
383       * isCompletedAbnormally and isCancelled return false for normally
384 <     * completed tasks. getRawResult of a RecursiveAction returns null;
384 >     * completed tasks; getRawResult returns null.
385       */
386      public void testInvoke() {
387          RecursiveAction a = new CheckedRecursiveAction() {
# Line 458 | Line 496 | public class ForkJoinTaskTest extends JS
496              public void realCompute() {
497                  AsyncFib f = new AsyncFib(8);
498                  assertSame(f, f.fork());
499 <                f.helpQuiesce();
499 >                helpQuiesce();
500                  assertEquals(21, f.number);
501                  assertEquals(0, getQueuedTaskCount());
502                  checkCompletedNormally(f);
# Line 713 | Line 751 | public class ForkJoinTaskTest extends JS
751          RecursiveAction a = new CheckedRecursiveAction() {
752              public void realCompute() {
753                  setRawResult(null);
754 +                assertNull(getRawResult());
755              }};
756          assertNull(a.invoke());
757      }
# Line 1069 | Line 1108 | public class ForkJoinTaskTest extends JS
1108      /**
1109       * invoke returns when task completes normally.
1110       * isCompletedAbnormally and isCancelled return false for normally
1111 <     * completed tasks. getRawResult of a RecursiveAction returns null;
1111 >     * completed tasks; getRawResult returns null.
1112       */
1113      public void testInvokeSingleton() {
1114          RecursiveAction a = new CheckedRecursiveAction() {
# Line 1184 | Line 1223 | public class ForkJoinTaskTest extends JS
1223              public void realCompute() {
1224                  AsyncFib f = new AsyncFib(8);
1225                  assertSame(f, f.fork());
1226 <                f.helpQuiesce();
1226 >                helpQuiesce();
1227                  assertEquals(0, getQueuedTaskCount());
1228                  assertEquals(21, f.number);
1229                  checkCompletedNormally(f);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines