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

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.22 by jsr166, Mon Apr 8 20:46:59 2013 UTC vs.
Revision 1.24 by jsr166, Sun Apr 14 05:45:38 2013 UTC

# Line 495 | Line 495 | public class CompletableFutureTest exten
495       * thenRun result completes normally after normal completion of source
496       */
497      public void testThenRun() {
498 <        CompletableFuture<Integer> f = new CompletableFuture<>();
499 <        Noop r = new Noop();
500 <        CompletableFuture<Void> g = f.thenRun(r);
498 >        CompletableFuture<Integer> f;
499 >        CompletableFuture<Void> g;
500 >        Noop r;
501 >
502 >        f = new CompletableFuture<>();
503 >        g = f.thenRun(r = new Noop());
504          f.complete(null);
505          checkCompletedNormally(g, null);
506 <        // reordered version
506 >        assertTrue(r.ran);
507 >
508          f = new CompletableFuture<>();
509          f.complete(null);
510 <        r = new Noop();
507 <        g = f.thenRun(r);
510 >        g = f.thenRun(r = new Noop());
511          checkCompletedNormally(g, null);
512 +        assertTrue(r.ran);
513      }
514  
515      /**
# Line 513 | Line 517 | public class CompletableFutureTest exten
517       * completion of source
518       */
519      public void testThenRun2() {
520 <        CompletableFuture<Integer> f = new CompletableFuture<>();
521 <        Noop r = new Noop();
522 <        CompletableFuture<Void> g = f.thenRun(r);
520 >        CompletableFuture<Integer> f;
521 >        CompletableFuture<Void> g;
522 >        Noop r;
523 >
524 >        f = new CompletableFuture<>();
525 >        g = f.thenRun(r = new Noop());
526 >        f.completeExceptionally(new CFException());
527 >        checkCompletedWithWrappedCFException(g);
528 >        assertFalse(r.ran);
529 >
530 >        f = new CompletableFuture<>();
531          f.completeExceptionally(new CFException());
532 +        g = f.thenRun(r = new Noop());
533          checkCompletedWithWrappedCFException(g);
534 +        assertFalse(r.ran);
535      }
536  
537      /**
538       * thenRun result completes exceptionally if action does
539       */
540      public void testThenRun3() {
541 <        CompletableFuture<Integer> f = new CompletableFuture<>();
542 <        FailingNoop r = new FailingNoop();
543 <        CompletableFuture<Void> g = f.thenRun(r);
541 >        CompletableFuture<Integer> f;
542 >        CompletableFuture<Void> g;
543 >        FailingNoop r;
544 >
545 >        f = new CompletableFuture<>();
546 >        g = f.thenRun(r = new FailingNoop());
547          f.complete(null);
548          checkCompletedWithWrappedCFException(g);
549 +
550 +        f = new CompletableFuture<>();
551 +        f.complete(null);
552 +        g = f.thenRun(r = new FailingNoop());
553 +        checkCompletedWithWrappedCFException(g);
554      }
555  
556      /**
557       * thenRun result completes exceptionally if source cancelled
558       */
559      public void testThenRun4() {
560 <        CompletableFuture<Integer> f = new CompletableFuture<>();
561 <        Noop r = new Noop();
562 <        CompletableFuture<Void> g = f.thenRun(r);
560 >        CompletableFuture<Integer> f;
561 >        CompletableFuture<Void> g;
562 >        Noop r;
563 >
564 >        f = new CompletableFuture<>();
565 >        g = f.thenRun(r = new Noop());
566 >        assertTrue(f.cancel(true));
567 >        checkCompletedWithWrappedCancellationException(g);
568 >
569 >        f = new CompletableFuture<>();
570          assertTrue(f.cancel(true));
571 +        g = f.thenRun(r = new Noop());
572          checkCompletedWithWrappedCancellationException(g);
573      }
574  
# Line 2826 | Line 2856 | public class CompletableFutureTest exten
2856       * with the value null
2857       */
2858      public void testAllOf_empty() throws Exception {
2859 <        CompletableFuture<?> f = CompletableFuture.allOf();
2859 >        CompletableFuture<Void> f = CompletableFuture.allOf();
2860          checkCompletedNormally(f, null);
2861      }
2862  
# Line 2841 | Line 2871 | public class CompletableFutureTest exten
2871              CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2872              for (int i = 0; i < k; ++i) {
2873                  checkIncomplete(f);
2874 +                checkIncomplete(CompletableFuture.allOf(fs));
2875                  fs[i].complete(one);
2876              }
2877              checkCompletedNormally(f, null);
2878 +            checkCompletedNormally(CompletableFuture.allOf(fs), null);
2879          }
2880      }
2881  
# Line 2851 | Line 2883 | public class CompletableFutureTest exten
2883       * anyOf(no component futures) returns an incomplete future
2884       */
2885      public void testAnyOf_empty() throws Exception {
2886 <        CompletableFuture<?> f = CompletableFuture.anyOf();
2886 >        CompletableFuture<Object> f = CompletableFuture.anyOf();
2887          checkIncomplete(f);
2888      }
2889  
2890      /**
2891       * anyOf returns a future completed when any components complete
2892       */
2893 <    public void testAnyOf() throws Exception {
2894 <        for (int k = 1; k < 20; ++k) {
2893 >    public void testAnyOf_normal() throws Exception {
2894 >        for (int k = 0; k < 10; ++k) {
2895              CompletableFuture[] fs = new CompletableFuture[k];
2896              for (int i = 0; i < k; ++i)
2897                  fs[i] = new CompletableFuture<>();
# Line 2868 | Line 2900 | public class CompletableFutureTest exten
2900              for (int i = 0; i < k; ++i) {
2901                  fs[i].complete(one);
2902                  checkCompletedNormally(f, one);
2903 +                checkCompletedNormally(CompletableFuture.anyOf(fs), one);
2904 +            }
2905 +        }
2906 +    }
2907 +
2908 +    /**
2909 +     * anyOf result completes exceptionally when any component does.
2910 +     */
2911 +    public void testAnyOf_exceptional() throws Exception {
2912 +        for (int k = 0; k < 10; ++k) {
2913 +            CompletableFuture[] fs = new CompletableFuture[k];
2914 +            for (int i = 0; i < k; ++i)
2915 +                fs[i] = new CompletableFuture<>();
2916 +            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2917 +            checkIncomplete(f);
2918 +            for (int i = 0; i < k; ++i) {
2919 +                fs[i].completeExceptionally(new CFException());
2920 +                checkCompletedWithWrappedCFException(f);
2921 +                checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
2922              }
2923          }
2924      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines