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

Comparing jsr166/src/test/tck/RecursiveActionTest.java (file contents):
Revision 1.20 by jsr166, Sun Nov 21 08:35:40 2010 UTC vs.
Revision 1.25 by jsr166, Tue Nov 23 06:33:26 2010 UTC

# Line 90 | Line 90 | public class RecursiveActionTest extends
90          assertNull(a.getException());
91          assertNull(a.getRawResult());
92          assertNull(a.join());
93 +        assertFalse(a.cancel(false));
94 +        assertFalse(a.cancel(true));
95          try {
96              assertNull(a.get());
97          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 125 | Line 127 | public class RecursiveActionTest extends
127          } catch (Throwable fail) { threadUnexpectedException(fail); }
128      }
129  
130 <    void checkTaskThrew(RecursiveAction a, Throwable t) {
130 >    void checkCompletedAbnormally(RecursiveAction a, Throwable t) {
131          assertTrue(a.isDone());
132          assertFalse(a.isCancelled());
133          assertFalse(a.isCompletedNormally());
134          assertTrue(a.isCompletedAbnormally());
135          assertSame(t, a.getException());
136          assertNull(a.getRawResult());
137 +        assertFalse(a.cancel(false));
138 +        assertFalse(a.cancel(true));
139  
140          try {
141              a.join();
# Line 243 | Line 247 | public class RecursiveActionTest extends
247      }
248  
249      /**
250 +     * join/quietlyJoin of a forked task succeeds in the presence of interrupts
251 +     */
252 +    public void testJoinIgnoresInterrupts() {
253 +        RecursiveAction a = new CheckedRecursiveAction() {
254 +            public void realCompute() {
255 +                FibAction f = new FibAction(8);
256 +
257 +                // test join()
258 +                assertSame(f, f.fork());
259 +                Thread.currentThread().interrupt();
260 +                assertNull(f.join());
261 +                Thread.interrupted();
262 +                assertEquals(21, f.result);
263 +                checkCompletedNormally(f);
264 +
265 +                f.reinitialize();
266 +                f.cancel(true);
267 +                assertSame(f, f.fork());
268 +                Thread.currentThread().interrupt();
269 +                try {
270 +                    f.join();
271 +                    shouldThrow();
272 +                } catch (CancellationException success) {
273 +                    Thread.interrupted();
274 +                    checkCancelled(f);
275 +                }
276 +
277 +                f.reinitialize();
278 +                f.completeExceptionally(new FJException());
279 +                assertSame(f, f.fork());
280 +                Thread.currentThread().interrupt();
281 +                try {
282 +                    f.join();
283 +                    shouldThrow();
284 +                } catch (FJException success) {
285 +                    Thread.interrupted();
286 +                    checkCompletedAbnormally(f, success);
287 +                }
288 +
289 +                // test quietlyJoin()
290 +                f.reinitialize();
291 +                assertSame(f, f.fork());
292 +                Thread.currentThread().interrupt();
293 +                f.quietlyJoin();
294 +                Thread.interrupted();
295 +                assertEquals(21, f.result);
296 +                checkCompletedNormally(f);
297 +
298 +                f.reinitialize();
299 +                f.cancel(true);
300 +                assertSame(f, f.fork());
301 +                Thread.currentThread().interrupt();
302 +                f.quietlyJoin();
303 +                Thread.interrupted();
304 +                checkCancelled(f);
305 +
306 +                f.reinitialize();
307 +                f.completeExceptionally(new FJException());
308 +                assertSame(f, f.fork());
309 +                Thread.currentThread().interrupt();
310 +                f.quietlyJoin();
311 +                Thread.interrupted();
312 +                checkCompletedAbnormally(f, f.getException());
313 +            }};
314 +        testInvokeOnPool(mainPool(), a);
315 +        a.reinitialize();
316 +        testInvokeOnPool(singletonPool(), a);
317 +    }
318 +
319 +    /**
320       * get of a forked task returns when task completes
321       */
322      public void testForkGet() {
# Line 333 | Line 407 | public class RecursiveActionTest extends
407                      f.invoke();
408                      shouldThrow();
409                  } catch (FJException success) {
410 <                    checkTaskThrew(f, success);
410 >                    checkCompletedAbnormally(f, success);
411                  }
412              }};
413          testInvokeOnPool(mainPool(), a);
# Line 348 | Line 422 | public class RecursiveActionTest extends
422                  FailingFibAction f = new FailingFibAction(8);
423                  f.quietlyInvoke();
424                  assertTrue(f.getException() instanceof FJException);
425 <                checkTaskThrew(f, f.getException());
425 >                checkCompletedAbnormally(f, f.getException());
426              }};
427          testInvokeOnPool(mainPool(), a);
428      }
# Line 365 | Line 439 | public class RecursiveActionTest extends
439                      f.join();
440                      shouldThrow();
441                  } catch (FJException success) {
442 <                    checkTaskThrew(f, success);
442 >                    checkCompletedAbnormally(f, success);
443                  }
444              }};
445          testInvokeOnPool(mainPool(), a);
# Line 383 | Line 457 | public class RecursiveActionTest extends
457                      f.get();
458                      shouldThrow();
459                  } catch (ExecutionException success) {
460 <                    checkTaskThrew(f, success.getCause());
460 >                    Throwable cause = success.getCause();
461 >                    assertTrue(cause instanceof FJException);
462 >                    checkCompletedAbnormally(f, cause);
463                  }
464              }};
465          testInvokeOnPool(mainPool(), a);
# Line 401 | Line 477 | public class RecursiveActionTest extends
477                      f.get(5L, TimeUnit.SECONDS);
478                      shouldThrow();
479                  } catch (ExecutionException success) {
480 <                    checkTaskThrew(f, success.getCause());
480 >                    Throwable cause = success.getCause();
481 >                    assertTrue(cause instanceof FJException);
482 >                    checkCompletedAbnormally(f, cause);
483                  }
484              }};
485          testInvokeOnPool(mainPool(), a);
# Line 417 | Line 495 | public class RecursiveActionTest extends
495                  assertSame(f, f.fork());
496                  f.quietlyJoin();
497                  assertTrue(f.getException() instanceof FJException);
498 <                checkTaskThrew(f, f.getException());
498 >                checkCompletedAbnormally(f, f.getException());
499              }};
500          testInvokeOnPool(mainPool(), a);
501      }
# Line 594 | Line 672 | public class RecursiveActionTest extends
672          RecursiveAction a = new CheckedRecursiveAction() {
673              public void realCompute() {
674                  setRawResult(null);
675 +                assertNull(getRawResult());
676              }};
677          assertNull(a.invoke());
678      }
# Line 630 | Line 709 | public class RecursiveActionTest extends
709                      f.invoke();
710                      shouldThrow();
711                  } catch (FJException success) {
712 <                    checkTaskThrew(f, success);
712 >                    checkCompletedAbnormally(f, success);
713                  }
714              }};
715          testInvokeOnPool(mainPool(), a);
# Line 762 | Line 841 | public class RecursiveActionTest extends
841                      invokeAll(f, g);
842                      shouldThrow();
843                  } catch (FJException success) {
844 <                    checkTaskThrew(g, success);
844 >                    checkCompletedAbnormally(g, success);
845                  }
846              }};
847          testInvokeOnPool(mainPool(), a);
# Line 779 | Line 858 | public class RecursiveActionTest extends
858                      invokeAll(g);
859                      shouldThrow();
860                  } catch (FJException success) {
861 <                    checkTaskThrew(g, success);
861 >                    checkCompletedAbnormally(g, success);
862                  }
863              }};
864          testInvokeOnPool(mainPool(), a);
# Line 798 | Line 877 | public class RecursiveActionTest extends
877                      invokeAll(f, g, h);
878                      shouldThrow();
879                  } catch (FJException success) {
880 <                    checkTaskThrew(g, success);
880 >                    checkCompletedAbnormally(g, success);
881                  }
882              }};
883          testInvokeOnPool(mainPool(), a);
# Line 821 | Line 900 | public class RecursiveActionTest extends
900                      invokeAll(set);
901                      shouldThrow();
902                  } catch (FJException success) {
903 <                    checkTaskThrew(f, success);
903 >                    checkCompletedAbnormally(f, success);
904                  }
905              }};
906          testInvokeOnPool(mainPool(), a);
# Line 861 | Line 940 | public class RecursiveActionTest extends
940                  assertSame(f, f.fork());
941                  assertTrue(getSurplusQueuedTaskCount() > 0);
942                  helpQuiesce();
943 +                assertEquals(0, getSurplusQueuedTaskCount());
944                  checkCompletedNormally(f);
945                  checkCompletedNormally(g);
946                  checkCompletedNormally(h);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines