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.16 by jsr166, Mon Sep 13 23:23:44 2010 UTC vs.
Revision 1.17 by jsr166, Thu Sep 16 00:52:49 2010 UTC

# Line 40 | Line 40 | public class ForkJoinTaskTest extends JS
40  
41      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
42          try {
43 <            assertTrue(pool.invoke(a) == null);
43 >            assertFalse(a.isDone());
44 >            assertFalse(a.isCompletedNormally());
45 >            assertFalse(a.isCompletedAbnormally());
46 >            assertFalse(a.isCancelled());
47 >            assertNull(a.getException());
48 >
49 >            assertNull(pool.invoke(a));
50 >
51 >            assertTrue(a.isDone());
52 >            assertTrue(a.isCompletedNormally());
53 >            assertFalse(a.isCompletedAbnormally());
54 >            assertFalse(a.isCancelled());
55 >            assertNull(a.getException());
56          } finally {
57              joinPool(pool);
58          }
# Line 233 | Line 245 | public class ForkJoinTaskTest extends JS
245       * completed tasks. getRawResult of a RecursiveAction returns null;
246       */
247      public void testInvoke() {
248 <        RecursiveAction a = new RecursiveAction() {
249 <            public void compute() {
248 >        RecursiveAction a = new CheckedRecursiveAction() {
249 >            public void realCompute() {
250                  AsyncFib f = new AsyncFib(8);
251 <                threadAssertNull(f.invoke());
252 <                threadAssertTrue(f.number == 21);
253 <                threadAssertTrue(f.isDone());
254 <                threadAssertFalse(f.isCancelled());
255 <                threadAssertFalse(f.isCompletedAbnormally());
256 <                threadAssertTrue(f.getRawResult() == null);
251 >                assertNull(f.invoke());
252 >                assertEquals(21, f.number);
253 >                assertTrue(f.isDone());
254 >                assertFalse(f.isCancelled());
255 >                assertFalse(f.isCompletedAbnormally());
256 >                assertNull(f.getRawResult());
257              }};
258          testInvokeOnPool(mainPool(), a);
259      }
# Line 252 | Line 264 | public class ForkJoinTaskTest extends JS
264       * completed tasks
265       */
266      public void testQuietlyInvoke() {
267 <        RecursiveAction a = new RecursiveAction() {
268 <            public void compute() {
267 >        RecursiveAction a = new CheckedRecursiveAction() {
268 >            public void realCompute() {
269                  AsyncFib f = new AsyncFib(8);
270                  f.quietlyInvoke();
271 <                threadAssertTrue(f.number == 21);
272 <                threadAssertTrue(f.isDone());
273 <                threadAssertFalse(f.isCancelled());
274 <                threadAssertFalse(f.isCompletedAbnormally());
275 <                threadAssertTrue(f.getRawResult() == null);
271 >                assertEquals(21, f.number);
272 >                assertTrue(f.isDone());
273 >                assertFalse(f.isCancelled());
274 >                assertFalse(f.isCompletedAbnormally());
275 >                assertNull(f.getRawResult());
276              }};
277          testInvokeOnPool(mainPool(), a);
278      }
# Line 269 | Line 281 | public class ForkJoinTaskTest extends JS
281       * join of a forked task returns when task completes
282       */
283      public void testForkJoin() {
284 <        RecursiveAction a = new RecursiveAction() {
285 <            public void compute() {
284 >        RecursiveAction a = new CheckedRecursiveAction() {
285 >            public void realCompute() {
286                  AsyncFib f = new AsyncFib(8);
287 <                threadAssertSame(f, f.fork());
288 <                threadAssertNull(f.join());
289 <                threadAssertTrue(f.number == 21);
290 <                threadAssertTrue(f.isDone());
291 <                threadAssertTrue(f.getRawResult() == null);
287 >                assertSame(f, f.fork());
288 >                assertNull(f.join());
289 >                assertEquals(21, f.number);
290 >                assertTrue(f.isDone());
291 >                assertNull(f.getRawResult());
292              }};
293          testInvokeOnPool(mainPool(), a);
294      }
# Line 285 | Line 297 | public class ForkJoinTaskTest extends JS
297       * get of a forked task returns when task completes
298       */
299      public void testForkGet() {
300 <        RecursiveAction a = new RecursiveAction() {
301 <            public void compute() {
302 <                try {
303 <                    AsyncFib f = new AsyncFib(8);
304 <                    threadAssertSame(f, f.fork());
305 <                    threadAssertNull(f.get());
306 <                    threadAssertTrue(f.number == 21);
295 <                    threadAssertTrue(f.isDone());
296 <                } catch (Exception ex) {
297 <                    unexpectedException(ex);
298 <                }
300 >        RecursiveAction a = new CheckedRecursiveAction() {
301 >            public void realCompute() throws Exception {
302 >                AsyncFib f = new AsyncFib(8);
303 >                assertSame(f, f.fork());
304 >                assertNull(f.get());
305 >                assertEquals(21, f.number);
306 >                assertTrue(f.isDone());
307              }};
308          testInvokeOnPool(mainPool(), a);
309      }
# Line 304 | Line 312 | public class ForkJoinTaskTest extends JS
312       * timed get of a forked task returns when task completes
313       */
314      public void testForkTimedGet() {
315 <        RecursiveAction a = new RecursiveAction() {
316 <            public void compute() {
317 <                try {
318 <                    AsyncFib f = new AsyncFib(8);
319 <                    threadAssertSame(f, f.fork());
320 <                    threadAssertNull(f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
321 <                    threadAssertTrue(f.number == 21);
314 <                    threadAssertTrue(f.isDone());
315 <                } catch (Exception ex) {
316 <                    unexpectedException(ex);
317 <                }
315 >        RecursiveAction a = new CheckedRecursiveAction() {
316 >            public void realCompute() throws Exception {
317 >                AsyncFib f = new AsyncFib(8);
318 >                assertSame(f, f.fork());
319 >                assertNull(f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
320 >                assertEquals(21, f.number);
321 >                assertTrue(f.isDone());
322              }};
323          testInvokeOnPool(mainPool(), a);
324      }
# Line 323 | Line 327 | public class ForkJoinTaskTest extends JS
327       * timed get with null time unit throws NPE
328       */
329      public void testForkTimedGetNPE() {
330 <        RecursiveAction a = new RecursiveAction() {
331 <            public void compute() {
330 >        RecursiveAction a = new CheckedRecursiveAction() {
331 >            public void realCompute() throws Exception {
332 >                AsyncFib f = new AsyncFib(8);
333 >                assertSame(f, f.fork());
334                  try {
329                    AsyncFib f = new AsyncFib(8);
330                    threadAssertSame(f, f.fork());
335                      f.get(5L, null);
336                      shouldThrow();
337 <                } catch (NullPointerException success) {
334 <                } catch (Exception ex) {
335 <                    unexpectedException(ex);
336 <                }
337 >                } catch (NullPointerException success) {}
338              }};
339          testInvokeOnPool(mainPool(), a);
340      }
# Line 342 | Line 343 | public class ForkJoinTaskTest extends JS
343       * quietlyJoin of a forked task returns when task completes
344       */
345      public void testForkQuietlyJoin() {
346 <        RecursiveAction a = new RecursiveAction() {
347 <            public void compute() {
346 >        RecursiveAction a = new CheckedRecursiveAction() {
347 >            public void realCompute() {
348                  AsyncFib f = new AsyncFib(8);
349 <                threadAssertSame(f, f.fork());
349 >                assertSame(f, f.fork());
350                  f.quietlyJoin();
351 <                threadAssertTrue(f.number == 21);
352 <                threadAssertTrue(f.isDone());
351 >                assertEquals(21, f.number);
352 >                assertTrue(f.isDone());
353              }};
354          testInvokeOnPool(mainPool(), a);
355      }
# Line 359 | Line 360 | public class ForkJoinTaskTest extends JS
360       * getQueuedTaskCount returns 0 when quiescent
361       */
362      public void testForkHelpQuiesce() {
363 <        RecursiveAction a = new RecursiveAction() {
364 <            public void compute() {
363 >        RecursiveAction a = new CheckedRecursiveAction() {
364 >            public void realCompute() {
365                  AsyncFib f = new AsyncFib(8);
366 <                threadAssertSame(f, f.fork());
366 >                assertSame(f, f.fork());
367                  f.helpQuiesce();
368 <                threadAssertTrue(f.number == 21);
369 <                threadAssertTrue(f.isDone());
370 <                threadAssertTrue(getQueuedTaskCount() == 0);
368 >                assertEquals(21, f.number);
369 >                assertTrue(f.isDone());
370 >                assertEquals(0, getQueuedTaskCount());
371              }};
372          testInvokeOnPool(mainPool(), a);
373      }
# Line 376 | Line 377 | public class ForkJoinTaskTest extends JS
377       * invoke task throws exception when task completes abnormally
378       */
379      public void testAbnormalInvoke() {
380 <        RecursiveAction a = new RecursiveAction() {
381 <            public void compute() {
380 >        RecursiveAction a = new CheckedRecursiveAction() {
381 >            public void realCompute() {
382 >                FailingAsyncFib f = new FailingAsyncFib(8);
383                  try {
382                    FailingAsyncFib f = new FailingAsyncFib(8);
384                      f.invoke();
385                      shouldThrow();
386 <                } catch (FJException success) {
386 <                }
386 >                } catch (FJException success) {}
387              }};
388          testInvokeOnPool(mainPool(), a);
389      }
# Line 392 | Line 392 | public class ForkJoinTaskTest extends JS
392       * quietlyInvoke task returns when task completes abnormally
393       */
394      public void testAbnormalQuietlyInvoke() {
395 <        RecursiveAction a = new RecursiveAction() {
396 <            public void compute() {
395 >        RecursiveAction a = new CheckedRecursiveAction() {
396 >            public void realCompute() {
397                  FailingAsyncFib f = new FailingAsyncFib(8);
398                  f.quietlyInvoke();
399 <                threadAssertTrue(f.isDone());
399 >                assertTrue(f.isDone());
400              }};
401          testInvokeOnPool(mainPool(), a);
402      }
# Line 405 | Line 405 | public class ForkJoinTaskTest extends JS
405       * join of a forked task throws exception when task completes abnormally
406       */
407      public void testAbnormalForkJoin() {
408 <        RecursiveAction a = new RecursiveAction() {
409 <            public void compute() {
408 >        RecursiveAction a = new CheckedRecursiveAction() {
409 >            public void realCompute() {
410 >                FailingAsyncFib f = new FailingAsyncFib(8);
411 >                assertSame(f, f.fork());
412                  try {
411                    FailingAsyncFib f = new FailingAsyncFib(8);
412                    threadAssertSame(f, f.fork());
413                      f.join();
414                      shouldThrow();
415 <                } catch (FJException success) {
416 <                }
415 >                } catch (FJException success) {}
416              }};
417          testInvokeOnPool(mainPool(), a);
418      }
# Line 422 | Line 421 | public class ForkJoinTaskTest extends JS
421       * get of a forked task throws exception when task completes abnormally
422       */
423      public void testAbnormalForkGet() {
424 <        RecursiveAction a = new RecursiveAction() {
425 <            public void compute() {
424 >        RecursiveAction a = new CheckedRecursiveAction() {
425 >            public void realCompute() throws Exception {
426 >                FailingAsyncFib f = new FailingAsyncFib(8);
427 >                assertSame(f, f.fork());
428                  try {
428                    FailingAsyncFib f = new FailingAsyncFib(8);
429                    threadAssertSame(f, f.fork());
429                      f.get();
430                      shouldThrow();
431 <                } catch (ExecutionException success) {
433 <                } catch (Exception ex) {
434 <                    unexpectedException(ex);
435 <                }
431 >                } catch (ExecutionException success) {}
432              }};
433          testInvokeOnPool(mainPool(), a);
434      }
# Line 441 | Line 437 | public class ForkJoinTaskTest extends JS
437       * timed get of a forked task throws exception when task completes abnormally
438       */
439      public void testAbnormalForkTimedGet() {
440 <        RecursiveAction a = new RecursiveAction() {
441 <            public void compute() {
440 >        RecursiveAction a = new CheckedRecursiveAction() {
441 >            public void realCompute() throws Exception {
442 >                FailingAsyncFib f = new FailingAsyncFib(8);
443 >                assertSame(f, f.fork());
444                  try {
447                    FailingAsyncFib f = new FailingAsyncFib(8);
448                    threadAssertSame(f, f.fork());
445                      f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
446                      shouldThrow();
447 <                } catch (ExecutionException success) {
452 <                } catch (Exception ex) {
453 <                    unexpectedException(ex);
454 <                }
447 >                } catch (ExecutionException success) {}
448              }};
449          testInvokeOnPool(mainPool(), a);
450      }
# Line 460 | Line 453 | public class ForkJoinTaskTest extends JS
453       * quietlyJoin of a forked task returns when task completes abnormally
454       */
455      public void testAbnormalForkQuietlyJoin() {
456 <        RecursiveAction a = new RecursiveAction() {
457 <            public void compute() {
456 >        RecursiveAction a = new CheckedRecursiveAction() {
457 >            public void realCompute() {
458                  FailingAsyncFib f = new FailingAsyncFib(8);
459 <                threadAssertSame(f, f.fork());
459 >                assertSame(f, f.fork());
460                  f.quietlyJoin();
461 <                threadAssertTrue(f.isDone());
462 <                threadAssertTrue(f.isCompletedAbnormally());
463 <                threadAssertTrue(f.getException() instanceof FJException);
461 >                assertTrue(f.isDone());
462 >                assertTrue(f.isCompletedAbnormally());
463 >                assertTrue(f.getException() instanceof FJException);
464              }};
465          testInvokeOnPool(mainPool(), a);
466      }
# Line 476 | Line 469 | public class ForkJoinTaskTest extends JS
469       * invoke task throws exception when task cancelled
470       */
471      public void testCancelledInvoke() {
472 <        RecursiveAction a = new RecursiveAction() {
473 <            public void compute() {
472 >        RecursiveAction a = new CheckedRecursiveAction() {
473 >            public void realCompute() {
474 >                AsyncFib f = new AsyncFib(8);
475 >                assertTrue(f.cancel(true));
476                  try {
482                    AsyncFib f = new AsyncFib(8);
483                    threadAssertTrue(f.cancel(true));
477                      f.invoke();
478                      shouldThrow();
479 <                } catch (CancellationException success) {
487 <                }
479 >                } catch (CancellationException success) {}
480              }};
481          testInvokeOnPool(mainPool(), a);
482      }
# Line 493 | Line 485 | public class ForkJoinTaskTest extends JS
485       * join of a forked task throws exception when task cancelled
486       */
487      public void testCancelledForkJoin() {
488 <        RecursiveAction a = new RecursiveAction() {
489 <            public void compute() {
488 >        RecursiveAction a = new CheckedRecursiveAction() {
489 >            public void realCompute() {
490 >                AsyncFib f = new AsyncFib(8);
491 >                assertTrue(f.cancel(true));
492 >                assertSame(f, f.fork());
493                  try {
499                    AsyncFib f = new AsyncFib(8);
500                    threadAssertTrue(f.cancel(true));
501                    threadAssertSame(f, f.fork());
494                      f.join();
495                      shouldThrow();
496 <                } catch (CancellationException success) {
505 <                }
496 >                } catch (CancellationException success) {}
497              }};
498          testInvokeOnPool(mainPool(), a);
499      }
# Line 511 | Line 502 | public class ForkJoinTaskTest extends JS
502       * get of a forked task throws exception when task cancelled
503       */
504      public void testCancelledForkGet() {
505 <        RecursiveAction a = new RecursiveAction() {
506 <            public void compute() {
505 >        RecursiveAction a = new CheckedRecursiveAction() {
506 >            public void realCompute() throws Exception {
507 >                AsyncFib f = new AsyncFib(8);
508 >                assertTrue(f.cancel(true));
509 >                assertSame(f, f.fork());
510                  try {
517                    AsyncFib f = new AsyncFib(8);
518                    threadAssertTrue(f.cancel(true));
519                    threadAssertSame(f, f.fork());
511                      f.get();
512                      shouldThrow();
513 <                } catch (CancellationException success) {
523 <                } catch (Exception ex) {
524 <                    unexpectedException(ex);
525 <                }
513 >                } catch (CancellationException success) {}
514              }};
515          testInvokeOnPool(mainPool(), a);
516      }
# Line 530 | Line 518 | public class ForkJoinTaskTest extends JS
518      /**
519       * timed get of a forked task throws exception when task cancelled
520       */
521 <    public void testCancelledForkTimedGet() {
522 <        RecursiveAction a = new RecursiveAction() {
523 <            public void compute() {
524 <                try {
525 <                    AsyncFib f = new AsyncFib(8);
526 <                    threadAssertTrue(f.cancel(true));
527 <                    threadAssertSame(f, f.fork());
521 >    public void testCancelledForkTimedGet() throws Exception {
522 >        RecursiveAction a = new CheckedRecursiveAction() {
523 >            public void realCompute() throws Exception {
524 >                AsyncFib f = new AsyncFib(8);
525 >                assertTrue(f.cancel(true));
526 >                assertSame(f, f.fork());
527 >                try {
528                      f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
529                      shouldThrow();
530 <                } catch (CancellationException success) {
543 <                } catch (Exception ex) {
544 <                    unexpectedException(ex);
545 <                }
530 >                } catch (CancellationException success) {}
531              }};
532          testInvokeOnPool(mainPool(), a);
533      }
# Line 551 | Line 536 | public class ForkJoinTaskTest extends JS
536       * quietlyJoin of a forked task returns when task cancelled
537       */
538      public void testCancelledForkQuietlyJoin() {
539 <        RecursiveAction a = new RecursiveAction() {
540 <            public void compute() {
539 >        RecursiveAction a = new CheckedRecursiveAction() {
540 >            public void realCompute() {
541                  AsyncFib f = new AsyncFib(8);
542 <                threadAssertTrue(f.cancel(true));
543 <                threadAssertSame(f, f.fork());
542 >                assertTrue(f.cancel(true));
543 >                assertSame(f, f.fork());
544                  f.quietlyJoin();
545 <                threadAssertTrue(f.isDone());
546 <                threadAssertTrue(f.isCompletedAbnormally());
547 <                threadAssertTrue(f.getException() instanceof CancellationException);
545 >                assertTrue(f.isDone());
546 >                assertTrue(f.isCompletedAbnormally());
547 >                assertTrue(f.isCancelled());
548 >                assertTrue(f.getException() instanceof CancellationException);
549              }};
550          testInvokeOnPool(mainPool(), a);
551      }
# Line 569 | Line 555 | public class ForkJoinTaskTest extends JS
555       */
556      public void testGetPool() {
557          final ForkJoinPool mainPool = mainPool();
558 <        RecursiveAction a = new RecursiveAction() {
559 <            public void compute() {
560 <                threadAssertTrue(getPool() == mainPool);
558 >        RecursiveAction a = new CheckedRecursiveAction() {
559 >            public void realCompute() {
560 >                assertSame(mainPool, getPool());
561              }};
562          testInvokeOnPool(mainPool, a);
563      }
# Line 580 | Line 566 | public class ForkJoinTaskTest extends JS
566       * getPool of non-FJ task returns null
567       */
568      public void testGetPool2() {
569 <        RecursiveAction a = new RecursiveAction() {
570 <            public void compute() {
571 <                threadAssertTrue(getPool() == null);
569 >        RecursiveAction a = new CheckedRecursiveAction() {
570 >            public void realCompute() {
571 >                assertNull(getPool());
572              }};
573          assertNull(a.invoke());
574      }
# Line 591 | Line 577 | public class ForkJoinTaskTest extends JS
577       * inForkJoinPool of executing task returns true
578       */
579      public void testInForkJoinPool() {
580 <        RecursiveAction a = new RecursiveAction() {
581 <            public void compute() {
582 <                threadAssertTrue(inForkJoinPool());
580 >        RecursiveAction a = new CheckedRecursiveAction() {
581 >            public void realCompute() {
582 >                assertTrue(inForkJoinPool());
583              }};
584          testInvokeOnPool(mainPool(), a);
585      }
# Line 602 | Line 588 | public class ForkJoinTaskTest extends JS
588       * inForkJoinPool of non-FJ task returns false
589       */
590      public void testInForkJoinPool2() {
591 <        RecursiveAction a = new RecursiveAction() {
592 <            public void compute() {
593 <                threadAssertTrue(!inForkJoinPool());
591 >        RecursiveAction a = new CheckedRecursiveAction() {
592 >            public void realCompute() {
593 >                assertTrue(!inForkJoinPool());
594              }};
595          assertNull(a.invoke());
596      }
# Line 613 | Line 599 | public class ForkJoinTaskTest extends JS
599       * setRawResult(null) succeeds
600       */
601      public void testSetRawResult() {
602 <        RecursiveAction a = new RecursiveAction() {
603 <            public void compute() {
602 >        RecursiveAction a = new CheckedRecursiveAction() {
603 >            public void realCompute() {
604                  setRawResult(null);
605              }};
606          assertNull(a.invoke());
# Line 624 | Line 610 | public class ForkJoinTaskTest extends JS
610       * invoke task throws exception after invoking completeExceptionally
611       */
612      public void testCompleteExceptionally() {
613 <        RecursiveAction a = new RecursiveAction() {
614 <            public void compute() {
613 >        RecursiveAction a = new CheckedRecursiveAction() {
614 >            public void realCompute() {
615 >                AsyncFib f = new AsyncFib(8);
616 >                f.completeExceptionally(new FJException());
617                  try {
630                    AsyncFib f = new AsyncFib(8);
631                    f.completeExceptionally(new FJException());
618                      f.invoke();
619                      shouldThrow();
620 <                } catch (FJException success) {
635 <                }
620 >                } catch (FJException success) {}
621              }};
622          testInvokeOnPool(mainPool(), a);
623      }
# Line 641 | Line 626 | public class ForkJoinTaskTest extends JS
626       * invokeAll(t1, t2) invokes all task arguments
627       */
628      public void testInvokeAll2() {
629 <        RecursiveAction a = new RecursiveAction() {
630 <            public void compute() {
629 >        RecursiveAction a = new CheckedRecursiveAction() {
630 >            public void realCompute() {
631                  AsyncFib f = new AsyncFib(8);
632                  AsyncFib g = new AsyncFib(9);
633                  invokeAll(f, g);
634 <                threadAssertTrue(f.isDone());
635 <                threadAssertTrue(f.number == 21);
636 <                threadAssertTrue(g.isDone());
637 <                threadAssertTrue(g.number == 34);
634 >                assertTrue(f.isDone());
635 >                assertEquals(21, f.number);
636 >                assertTrue(g.isDone());
637 >                assertEquals(34, g.number);
638              }};
639          testInvokeOnPool(mainPool(), a);
640      }
# Line 658 | Line 643 | public class ForkJoinTaskTest extends JS
643       * invokeAll(tasks) with 1 argument invokes task
644       */
645      public void testInvokeAll1() {
646 <        RecursiveAction a = new RecursiveAction() {
647 <            public void compute() {
646 >        RecursiveAction a = new CheckedRecursiveAction() {
647 >            public void realCompute() {
648                  AsyncFib f = new AsyncFib(8);
649                  invokeAll(f);
650 <                threadAssertTrue(f.isDone());
651 <                threadAssertTrue(f.number == 21);
650 >                assertTrue(f.isDone());
651 >                assertEquals(21, f.number);
652              }};
653          testInvokeOnPool(mainPool(), a);
654      }
# Line 672 | Line 657 | public class ForkJoinTaskTest extends JS
657       * invokeAll(tasks) with > 2 argument invokes tasks
658       */
659      public void testInvokeAll3() {
660 <        RecursiveAction a = new RecursiveAction() {
661 <            public void compute() {
660 >        RecursiveAction a = new CheckedRecursiveAction() {
661 >            public void realCompute() {
662                  AsyncFib f = new AsyncFib(8);
663                  AsyncFib g = new AsyncFib(9);
664                  AsyncFib h = new AsyncFib(7);
665                  invokeAll(f, g, h);
666 <                threadAssertTrue(f.isDone());
667 <                threadAssertTrue(f.number == 21);
668 <                threadAssertTrue(g.isDone());
669 <                threadAssertTrue(g.number == 34);
670 <                threadAssertTrue(h.isDone());
671 <                threadAssertTrue(h.number == 13);
666 >                assertTrue(f.isDone());
667 >                assertEquals(21, f.number);
668 >                assertTrue(g.isDone());
669 >                assertEquals(34, g.number);
670 >                assertTrue(h.isDone());
671 >                assertEquals(13, h.number);
672              }};
673          testInvokeOnPool(mainPool(), a);
674      }
# Line 692 | Line 677 | public class ForkJoinTaskTest extends JS
677       * invokeAll(collection) invokes all tasks in the collection
678       */
679      public void testInvokeAllCollection() {
680 <        RecursiveAction a = new RecursiveAction() {
681 <            public void compute() {
680 >        RecursiveAction a = new CheckedRecursiveAction() {
681 >            public void realCompute() {
682                  AsyncFib f = new AsyncFib(8);
683                  AsyncFib g = new AsyncFib(9);
684                  AsyncFib h = new AsyncFib(7);
# Line 702 | Line 687 | public class ForkJoinTaskTest extends JS
687                  set.add(g);
688                  set.add(h);
689                  invokeAll(set);
690 <                threadAssertTrue(f.isDone());
691 <                threadAssertTrue(f.number == 21);
692 <                threadAssertTrue(g.isDone());
693 <                threadAssertTrue(g.number == 34);
694 <                threadAssertTrue(h.isDone());
695 <                threadAssertTrue(h.number == 13);
690 >                assertTrue(f.isDone());
691 >                assertEquals(21, f.number);
692 >                assertTrue(g.isDone());
693 >                assertEquals(34, g.number);
694 >                assertTrue(h.isDone());
695 >                assertEquals(13, h.number);
696              }};
697          testInvokeOnPool(mainPool(), a);
698      }
# Line 717 | Line 702 | public class ForkJoinTaskTest extends JS
702       * invokeAll(tasks) with any null task throws NPE
703       */
704      public void testInvokeAllNPE() {
705 <        RecursiveAction a = new RecursiveAction() {
706 <            public void compute() {
705 >        RecursiveAction a = new CheckedRecursiveAction() {
706 >            public void realCompute() {
707 >                AsyncFib f = new AsyncFib(8);
708 >                AsyncFib g = new AsyncFib(9);
709 >                AsyncFib h = null;
710                  try {
723                    AsyncFib f = new AsyncFib(8);
724                    AsyncFib g = new AsyncFib(9);
725                    AsyncFib h = null;
711                      invokeAll(f, g, h);
712                      shouldThrow();
713 <                } catch (NullPointerException success) {
729 <                }
713 >                } catch (NullPointerException success) {}
714              }};
715          testInvokeOnPool(mainPool(), a);
716      }
# Line 735 | Line 719 | public class ForkJoinTaskTest extends JS
719       * invokeAll(t1, t2) throw exception if any task does
720       */
721      public void testAbnormalInvokeAll2() {
722 <        RecursiveAction a = new RecursiveAction() {
723 <            public void compute() {
722 >        RecursiveAction a = new CheckedRecursiveAction() {
723 >            public void realCompute() {
724 >                AsyncFib f = new AsyncFib(8);
725 >                FailingAsyncFib g = new FailingAsyncFib(9);
726                  try {
741                    AsyncFib f = new AsyncFib(8);
742                    FailingAsyncFib g = new FailingAsyncFib(9);
727                      invokeAll(f, g);
728                      shouldThrow();
729 <                } catch (FJException success) {
746 <                }
729 >                } catch (FJException success) {}
730              }};
731          testInvokeOnPool(mainPool(), a);
732      }
# Line 752 | Line 735 | public class ForkJoinTaskTest extends JS
735       * invokeAll(tasks) with 1 argument throws exception if task does
736       */
737      public void testAbnormalInvokeAll1() {
738 <        RecursiveAction a = new RecursiveAction() {
739 <            public void compute() {
738 >        RecursiveAction a = new CheckedRecursiveAction() {
739 >            public void realCompute() {
740 >                FailingAsyncFib g = new FailingAsyncFib(9);
741                  try {
758                    FailingAsyncFib g = new FailingAsyncFib(9);
742                      invokeAll(g);
743                      shouldThrow();
744 <                } catch (FJException success) {
762 <                }
744 >                } catch (FJException success) {}
745              }};
746          testInvokeOnPool(mainPool(), a);
747      }
# Line 768 | Line 750 | public class ForkJoinTaskTest extends JS
750       * invokeAll(tasks) with > 2 argument throws exception if any task does
751       */
752      public void testAbnormalInvokeAll3() {
753 <        RecursiveAction a = new RecursiveAction() {
754 <            public void compute() {
753 >        RecursiveAction a = new CheckedRecursiveAction() {
754 >            public void realCompute() {
755 >                AsyncFib f = new AsyncFib(8);
756 >                FailingAsyncFib g = new FailingAsyncFib(9);
757 >                AsyncFib h = new AsyncFib(7);
758                  try {
774                    AsyncFib f = new AsyncFib(8);
775                    FailingAsyncFib g = new FailingAsyncFib(9);
776                    AsyncFib h = new AsyncFib(7);
759                      invokeAll(f, g, h);
760                      shouldThrow();
761 <                } catch (FJException success) {
780 <                }
761 >                } catch (FJException success) {}
762              }};
763          testInvokeOnPool(mainPool(), a);
764      }
# Line 786 | Line 767 | public class ForkJoinTaskTest extends JS
767       * invokeAll(collection)  throws exception if any task does
768       */
769      public void testAbnormalInvokeAllCollection() {
770 <        RecursiveAction a = new RecursiveAction() {
771 <            public void compute() {
770 >        RecursiveAction a = new CheckedRecursiveAction() {
771 >            public void realCompute() {
772 >                FailingAsyncFib f = new FailingAsyncFib(8);
773 >                AsyncFib g = new AsyncFib(9);
774 >                AsyncFib h = new AsyncFib(7);
775 >                HashSet set = new HashSet();
776 >                set.add(f);
777 >                set.add(g);
778 >                set.add(h);
779                  try {
792                    FailingAsyncFib f = new FailingAsyncFib(8);
793                    AsyncFib g = new AsyncFib(9);
794                    AsyncFib h = new AsyncFib(7);
795                    HashSet set = new HashSet();
796                    set.add(f);
797                    set.add(g);
798                    set.add(h);
780                      invokeAll(set);
781                      shouldThrow();
782 <                } catch (FJException success) {
802 <                }
782 >                } catch (FJException success) {}
783              }};
784          testInvokeOnPool(mainPool(), a);
785      }
# Line 809 | Line 789 | public class ForkJoinTaskTest extends JS
789       * and suppresses execution
790       */
791      public void testTryUnfork() {
792 <        RecursiveAction a = new RecursiveAction() {
793 <            public void compute() {
792 >        RecursiveAction a = new CheckedRecursiveAction() {
793 >            public void realCompute() {
794                  AsyncFib g = new AsyncFib(9);
795 <                threadAssertSame(g, g.fork());
795 >                assertSame(g, g.fork());
796                  AsyncFib f = new AsyncFib(8);
797 <                threadAssertSame(f, f.fork());
798 <                threadAssertTrue(f.tryUnfork());
797 >                assertSame(f, f.fork());
798 >                assertTrue(f.tryUnfork());
799                  helpQuiesce();
800 <                threadAssertFalse(f.isDone());
801 <                threadAssertTrue(g.isDone());
800 >                assertFalse(f.isDone());
801 >                assertTrue(g.isDone());
802              }};
803          testInvokeOnPool(singletonPool(), a);
804      }
# Line 828 | Line 808 | public class ForkJoinTaskTest extends JS
808       * there are more tasks than threads
809       */
810      public void testGetSurplusQueuedTaskCount() {
811 <        RecursiveAction a = new RecursiveAction() {
812 <            public void compute() {
811 >        RecursiveAction a = new CheckedRecursiveAction() {
812 >            public void realCompute() {
813                  AsyncFib h = new AsyncFib(7);
814 <                threadAssertSame(h, h.fork());
814 >                assertSame(h, h.fork());
815                  AsyncFib g = new AsyncFib(9);
816 <                threadAssertSame(g, g.fork());
816 >                assertSame(g, g.fork());
817                  AsyncFib f = new AsyncFib(8);
818 <                threadAssertSame(f, f.fork());
819 <                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
818 >                assertSame(f, f.fork());
819 >                assertTrue(getSurplusQueuedTaskCount() > 0);
820                  helpQuiesce();
821              }};
822          testInvokeOnPool(singletonPool(), a);
# Line 846 | Line 826 | public class ForkJoinTaskTest extends JS
826       * peekNextLocalTask returns most recent unexecuted task.
827       */
828      public void testPeekNextLocalTask() {
829 <        RecursiveAction a = new RecursiveAction() {
830 <            public void compute() {
829 >        RecursiveAction a = new CheckedRecursiveAction() {
830 >            public void realCompute() {
831                  AsyncFib g = new AsyncFib(9);
832 <                threadAssertSame(g, g.fork());
832 >                assertSame(g, g.fork());
833                  AsyncFib f = new AsyncFib(8);
834 <                threadAssertSame(f, f.fork());
835 <                threadAssertTrue(peekNextLocalTask() == f);
836 <                threadAssertNull(f.join());
837 <                threadAssertTrue(f.isDone());
834 >                assertSame(f, f.fork());
835 >                assertSame(f, peekNextLocalTask());
836 >                assertNull(f.join());
837 >                assertTrue(f.isDone());
838                  helpQuiesce();
839              }};
840          testInvokeOnPool(singletonPool(), a);
# Line 865 | Line 845 | public class ForkJoinTaskTest extends JS
845       * without executing it
846       */
847      public void testPollNextLocalTask() {
848 <        RecursiveAction a = new RecursiveAction() {
849 <            public void compute() {
848 >        RecursiveAction a = new CheckedRecursiveAction() {
849 >            public void realCompute() {
850                  AsyncFib g = new AsyncFib(9);
851 <                threadAssertSame(g, g.fork());
851 >                assertSame(g, g.fork());
852                  AsyncFib f = new AsyncFib(8);
853 <                threadAssertSame(f, f.fork());
854 <                threadAssertTrue(pollNextLocalTask() == f);
853 >                assertSame(f, f.fork());
854 >                assertSame(f, pollNextLocalTask());
855                  helpQuiesce();
856 <                threadAssertFalse(f.isDone());
856 >                assertFalse(f.isDone());
857              }};
858          testInvokeOnPool(singletonPool(), a);
859      }
# Line 883 | Line 863 | public class ForkJoinTaskTest extends JS
863       * without executing it
864       */
865      public void testPollTask() {
866 <        RecursiveAction a = new RecursiveAction() {
867 <            public void compute() {
866 >        RecursiveAction a = new CheckedRecursiveAction() {
867 >            public void realCompute() {
868                  AsyncFib g = new AsyncFib(9);
869 <                threadAssertSame(g, g.fork());
869 >                assertSame(g, g.fork());
870                  AsyncFib f = new AsyncFib(8);
871 <                threadAssertSame(f, f.fork());
872 <                threadAssertTrue(pollTask() == f);
871 >                assertSame(f, f.fork());
872 >                assertSame(f, pollTask());
873                  helpQuiesce();
874 <                threadAssertFalse(f.isDone());
875 <                threadAssertTrue(g.isDone());
874 >                assertFalse(f.isDone());
875 >                assertTrue(g.isDone());
876              }};
877          testInvokeOnPool(singletonPool(), a);
878      }
# Line 901 | Line 881 | public class ForkJoinTaskTest extends JS
881       * peekNextLocalTask returns least recent unexecuted task in async mode
882       */
883      public void testPeekNextLocalTaskAsync() {
884 <        RecursiveAction a = new RecursiveAction() {
885 <            public void compute() {
884 >        RecursiveAction a = new CheckedRecursiveAction() {
885 >            public void realCompute() {
886                  AsyncFib g = new AsyncFib(9);
887 <                threadAssertSame(g, g.fork());
887 >                assertSame(g, g.fork());
888                  AsyncFib f = new AsyncFib(8);
889 <                threadAssertSame(f, f.fork());
890 <                threadAssertTrue(peekNextLocalTask() == g);
891 <                threadAssertNull(f.join());
889 >                assertSame(f, f.fork());
890 >                assertSame(g, peekNextLocalTask());
891 >                assertNull(f.join());
892                  helpQuiesce();
893 <                threadAssertTrue(f.isDone());
893 >                assertTrue(f.isDone());
894              }};
895          testInvokeOnPool(asyncSingletonPool(), a);
896      }
# Line 920 | Line 900 | public class ForkJoinTaskTest extends JS
900       * without executing it, in async mode
901       */
902      public void testPollNextLocalTaskAsync() {
903 <        RecursiveAction a = new RecursiveAction() {
904 <            public void compute() {
903 >        RecursiveAction a = new CheckedRecursiveAction() {
904 >            public void realCompute() {
905                  AsyncFib g = new AsyncFib(9);
906 <                threadAssertSame(g, g.fork());
906 >                assertSame(g, g.fork());
907                  AsyncFib f = new AsyncFib(8);
908 <                threadAssertSame(f, f.fork());
909 <                threadAssertTrue(pollNextLocalTask() == g);
908 >                assertSame(f, f.fork());
909 >                assertSame(g, pollNextLocalTask());
910                  helpQuiesce();
911 <                threadAssertTrue(f.isDone());
912 <                threadAssertFalse(g.isDone());
911 >                assertTrue(f.isDone());
912 >                assertFalse(g.isDone());
913              }};
914          testInvokeOnPool(asyncSingletonPool(), a);
915      }
# Line 939 | Line 919 | public class ForkJoinTaskTest extends JS
919       * without executing it, in async mode
920       */
921      public void testPollTaskAsync() {
922 <        RecursiveAction a = new RecursiveAction() {
923 <            public void compute() {
922 >        RecursiveAction a = new CheckedRecursiveAction() {
923 >            public void realCompute() {
924                  AsyncFib g = new AsyncFib(9);
925 <                threadAssertSame(g, g.fork());
925 >                assertSame(g, g.fork());
926                  AsyncFib f = new AsyncFib(8);
927 <                threadAssertSame(f, f.fork());
928 <                threadAssertTrue(pollTask() == g);
927 >                assertSame(f, f.fork());
928 >                assertSame(g, pollTask());
929                  helpQuiesce();
930 <                threadAssertTrue(f.isDone());
931 <                threadAssertFalse(g.isDone());
930 >                assertTrue(f.isDone());
931 >                assertFalse(g.isDone());
932              }};
933          testInvokeOnPool(asyncSingletonPool(), a);
934      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines