391 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
392 public Integer realCompute() {
393 FailingFibTask f = new FailingFibTask(8);
394 f.quietlyInvoke();
395 assertTrue(f.getException() instanceof FJException);
396 checkCompletedAbnormally(f, f.getException());
397 return NoResult;
398 }};
399 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
400 }
401
402 /**
403 * join of a forked task throws exception when task completes abnormally
404 */
405 public void testAbnormalForkJoin() {
406 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
407 public Integer realCompute() {
408 FailingFibTask f = new FailingFibTask(8);
409 assertSame(f, f.fork());
410 try {
411 Integer r = f.join();
412 shouldThrow();
413 } catch (FJException success) {
414 checkCompletedAbnormally(f, success);
415 }
416 return NoResult;
417 }};
418 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
419 }
420
421 /**
422 * get of a forked task throws exception when task completes abnormally
423 */
424 public void testAbnormalForkGet() {
425 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
426 public Integer realCompute() throws Exception {
427 FailingFibTask f = new FailingFibTask(8);
428 assertSame(f, f.fork());
429 try {
430 Integer r = f.get();
431 shouldThrow();
432 } catch (ExecutionException success) {
433 Throwable cause = success.getCause();
434 assertTrue(cause instanceof FJException);
435 checkCompletedAbnormally(f, cause);
436 }
437 return NoResult;
438 }};
439 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
440 }
441
442 /**
443 * timed get of a forked task throws exception when task completes abnormally
444 */
445 public void testAbnormalForkTimedGet() {
446 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
447 public Integer realCompute() throws Exception {
448 FailingFibTask f = new FailingFibTask(8);
449 assertSame(f, f.fork());
450 try {
451 Integer r = f.get(LONG_DELAY_MS, MILLISECONDS);
452 shouldThrow();
453 } catch (ExecutionException success) {
454 Throwable cause = success.getCause();
455 assertTrue(cause instanceof FJException);
456 checkCompletedAbnormally(f, cause);
457 }
458 return NoResult;
459 }};
460 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
461 }
462
463 /**
464 * quietlyJoin of a forked task returns when task completes abnormally
465 */
466 public void testAbnormalForkQuietlyJoin() {
467 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
468 public Integer realCompute() {
469 FailingFibTask f = new FailingFibTask(8);
470 assertSame(f, f.fork());
471 f.quietlyJoin();
472 assertTrue(f.getException() instanceof FJException);
473 checkCompletedAbnormally(f, f.getException());
474 return NoResult;
475 }};
476 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
477 }
478
479 /**
480 * invoke task throws exception when task cancelled
481 */
482 public void testCancelledInvoke() {
483 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
484 public Integer realCompute() {
485 FibTask f = new FibTask(8);
486 assertTrue(f.cancel(true));
487 try {
488 Integer r = f.invoke();
489 shouldThrow();
490 } catch (CancellationException success) {
491 checkCancelled(f);
492 }
493 return NoResult;
494 }};
495 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
496 }
497
498 /**
499 * join of a forked task throws exception when task cancelled
500 */
501 public void testCancelledForkJoin() {
502 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
503 public Integer realCompute() {
504 FibTask f = new FibTask(8);
505 assertTrue(f.cancel(true));
506 assertSame(f, f.fork());
507 try {
508 Integer r = f.join();
509 shouldThrow();
510 } catch (CancellationException success) {
511 checkCancelled(f);
512 }
513 return NoResult;
514 }};
515 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
516 }
517
518 /**
519 * get of a forked task throws exception when task cancelled
520 */
521 public void testCancelledForkGet() {
522 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
523 public Integer realCompute() throws Exception {
524 FibTask f = new FibTask(8);
525 assertTrue(f.cancel(true));
526 assertSame(f, f.fork());
527 try {
528 Integer r = f.get();
529 shouldThrow();
530 } catch (CancellationException success) {
531 checkCancelled(f);
532 }
533 return NoResult;
534 }};
535 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
536 }
537
538 /**
539 * timed get of a forked task throws exception when task cancelled
540 */
541 public void testCancelledForkTimedGet() {
542 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
543 public Integer realCompute() throws Exception {
544 FibTask f = new FibTask(8);
545 assertTrue(f.cancel(true));
546 assertSame(f, f.fork());
547 try {
548 Integer r = f.get(LONG_DELAY_MS, MILLISECONDS);
549 shouldThrow();
550 } catch (CancellationException success) {
551 checkCancelled(f);
552 }
553 return NoResult;
554 }};
555 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
556 }
557
558 /**
559 * quietlyJoin of a forked task returns when task cancelled
560 */
561 public void testCancelledForkQuietlyJoin() {
562 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
563 public Integer realCompute() {
564 FibTask f = new FibTask(8);
565 assertTrue(f.cancel(true));
566 assertSame(f, f.fork());
567 f.quietlyJoin();
568 checkCancelled(f);
672 } catch (FJException success) {
673 checkCompletedAbnormally(f, success);
674 }
675 f.reinitialize();
676 checkNotDone(f);
677 }
678 return NoResult;
679 }};
680 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
681 }
682
683 /**
684 * invoke task throws exception after invoking completeExceptionally
685 */
686 public void testCompleteExceptionally() {
687 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
688 public Integer realCompute() {
689 FibTask f = new FibTask(8);
690 f.completeExceptionally(new FJException());
691 try {
692 Integer r = f.invoke();
693 shouldThrow();
694 } catch (FJException success) {
695 checkCompletedAbnormally(f, success);
696 }
697 return NoResult;
698 }};
699 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
700 }
701
702 /**
703 * invoke task suppresses execution invoking complete
704 */
705 public void testComplete() {
706 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
707 public Integer realCompute() {
708 FibTask f = new FibTask(8);
709 f.complete(NoResult);
710 Integer r = f.invoke();
711 assertSame(NoResult, r);
712 checkCompletedNormally(f, NoResult);
|
391 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
392 public Integer realCompute() {
393 FailingFibTask f = new FailingFibTask(8);
394 f.quietlyInvoke();
395 assertTrue(f.getException() instanceof FJException);
396 checkCompletedAbnormally(f, f.getException());
397 return NoResult;
398 }};
399 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
400 }
401
402 /**
403 * join of a forked task throws exception when task completes abnormally
404 */
405 public void testAbnormalForkJoin() {
406 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
407 public Integer realCompute() {
408 FailingFibTask f = new FailingFibTask(8);
409 assertSame(f, f.fork());
410 try {
411 f.join();
412 shouldThrow();
413 } catch (FJException success) {
414 checkCompletedAbnormally(f, success);
415 }
416 return NoResult;
417 }};
418 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
419 }
420
421 /**
422 * get of a forked task throws exception when task completes abnormally
423 */
424 public void testAbnormalForkGet() {
425 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
426 public Integer realCompute() throws Exception {
427 FailingFibTask f = new FailingFibTask(8);
428 assertSame(f, f.fork());
429 try {
430 f.get();
431 shouldThrow();
432 } catch (ExecutionException success) {
433 Throwable cause = success.getCause();
434 assertTrue(cause instanceof FJException);
435 checkCompletedAbnormally(f, cause);
436 }
437 return NoResult;
438 }};
439 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
440 }
441
442 /**
443 * timed get of a forked task throws exception when task completes abnormally
444 */
445 public void testAbnormalForkTimedGet() {
446 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
447 public Integer realCompute() throws Exception {
448 FailingFibTask f = new FailingFibTask(8);
449 assertSame(f, f.fork());
450 try {
451 f.get(LONG_DELAY_MS, MILLISECONDS);
452 shouldThrow();
453 } catch (ExecutionException success) {
454 Throwable cause = success.getCause();
455 assertTrue(cause instanceof FJException);
456 checkCompletedAbnormally(f, cause);
457 }
458 return NoResult;
459 }};
460 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
461 }
462
463 /**
464 * quietlyJoin of a forked task returns when task completes abnormally
465 */
466 public void testAbnormalForkQuietlyJoin() {
467 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
468 public Integer realCompute() {
469 FailingFibTask f = new FailingFibTask(8);
470 assertSame(f, f.fork());
471 f.quietlyJoin();
472 assertTrue(f.getException() instanceof FJException);
473 checkCompletedAbnormally(f, f.getException());
474 return NoResult;
475 }};
476 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
477 }
478
479 /**
480 * invoke task throws exception when task cancelled
481 */
482 public void testCancelledInvoke() {
483 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
484 public Integer realCompute() {
485 FibTask f = new FibTask(8);
486 assertTrue(f.cancel(true));
487 try {
488 f.invoke();
489 shouldThrow();
490 } catch (CancellationException success) {
491 checkCancelled(f);
492 }
493 return NoResult;
494 }};
495 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
496 }
497
498 /**
499 * join of a forked task throws exception when task cancelled
500 */
501 public void testCancelledForkJoin() {
502 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
503 public Integer realCompute() {
504 FibTask f = new FibTask(8);
505 assertTrue(f.cancel(true));
506 assertSame(f, f.fork());
507 try {
508 f.join();
509 shouldThrow();
510 } catch (CancellationException success) {
511 checkCancelled(f);
512 }
513 return NoResult;
514 }};
515 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
516 }
517
518 /**
519 * get of a forked task throws exception when task cancelled
520 */
521 public void testCancelledForkGet() {
522 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
523 public Integer realCompute() throws Exception {
524 FibTask f = new FibTask(8);
525 assertTrue(f.cancel(true));
526 assertSame(f, f.fork());
527 try {
528 f.get();
529 shouldThrow();
530 } catch (CancellationException success) {
531 checkCancelled(f);
532 }
533 return NoResult;
534 }};
535 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
536 }
537
538 /**
539 * timed get of a forked task throws exception when task cancelled
540 */
541 public void testCancelledForkTimedGet() {
542 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
543 public Integer realCompute() throws Exception {
544 FibTask f = new FibTask(8);
545 assertTrue(f.cancel(true));
546 assertSame(f, f.fork());
547 try {
548 f.get(LONG_DELAY_MS, MILLISECONDS);
549 shouldThrow();
550 } catch (CancellationException success) {
551 checkCancelled(f);
552 }
553 return NoResult;
554 }};
555 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
556 }
557
558 /**
559 * quietlyJoin of a forked task returns when task cancelled
560 */
561 public void testCancelledForkQuietlyJoin() {
562 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
563 public Integer realCompute() {
564 FibTask f = new FibTask(8);
565 assertTrue(f.cancel(true));
566 assertSame(f, f.fork());
567 f.quietlyJoin();
568 checkCancelled(f);
672 } catch (FJException success) {
673 checkCompletedAbnormally(f, success);
674 }
675 f.reinitialize();
676 checkNotDone(f);
677 }
678 return NoResult;
679 }};
680 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
681 }
682
683 /**
684 * invoke task throws exception after invoking completeExceptionally
685 */
686 public void testCompleteExceptionally() {
687 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
688 public Integer realCompute() {
689 FibTask f = new FibTask(8);
690 f.completeExceptionally(new FJException());
691 try {
692 f.invoke();
693 shouldThrow();
694 } catch (FJException success) {
695 checkCompletedAbnormally(f, success);
696 }
697 return NoResult;
698 }};
699 assertSame(NoResult, testInvokeOnPool(mainPool(), a));
700 }
701
702 /**
703 * invoke task suppresses execution invoking complete
704 */
705 public void testComplete() {
706 RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
707 public Integer realCompute() {
708 FibTask f = new FibTask(8);
709 f.complete(NoResult);
710 Integer r = f.invoke();
711 assertSame(NoResult, r);
712 checkCompletedNormally(f, NoResult);
|