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.25 by jsr166, Sat Apr 20 23:28:35 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  
2863      /**
2864 <     * allOf returns a future completed when all components complete
2864 >     * allOf returns a future completed normally with the value null
2865 >     * when all components complete normally
2866       */
2867 <    public void testAllOf() throws Exception {
2867 >    public void testAllOf_normal() throws Exception {
2868          for (int k = 1; k < 20; ++k) {
2869              CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2870              for (int i = 0; i < k; ++i)
# Line 2841 | Line 2872 | public class CompletableFutureTest exten
2872              CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2873              for (int i = 0; i < k; ++i) {
2874                  checkIncomplete(f);
2875 +                checkIncomplete(CompletableFuture.allOf(fs));
2876                  fs[i].complete(one);
2877              }
2878              checkCompletedNormally(f, null);
2879 +            checkCompletedNormally(CompletableFuture.allOf(fs), null);
2880          }
2881      }
2882  
# Line 2851 | Line 2884 | public class CompletableFutureTest exten
2884       * anyOf(no component futures) returns an incomplete future
2885       */
2886      public void testAnyOf_empty() throws Exception {
2887 <        CompletableFuture<?> f = CompletableFuture.anyOf();
2887 >        CompletableFuture<Object> f = CompletableFuture.anyOf();
2888          checkIncomplete(f);
2889      }
2890  
2891      /**
2892 <     * anyOf returns a future completed when any components complete
2892 >     * anyOf returns a future completed normally with a value when
2893 >     * a component future does
2894       */
2895 <    public void testAnyOf() throws Exception {
2896 <        for (int k = 1; k < 20; ++k) {
2895 >    public void testAnyOf_normal() throws Exception {
2896 >        for (int k = 0; k < 10; ++k) {
2897              CompletableFuture[] fs = new CompletableFuture[k];
2898              for (int i = 0; i < k; ++i)
2899                  fs[i] = new CompletableFuture<>();
# Line 2868 | Line 2902 | public class CompletableFutureTest exten
2902              for (int i = 0; i < k; ++i) {
2903                  fs[i].complete(one);
2904                  checkCompletedNormally(f, one);
2905 +                checkCompletedNormally(CompletableFuture.anyOf(fs), one);
2906 +            }
2907 +        }
2908 +    }
2909 +
2910 +    /**
2911 +     * anyOf result completes exceptionally when any component does.
2912 +     */
2913 +    public void testAnyOf_exceptional() throws Exception {
2914 +        for (int k = 0; k < 10; ++k) {
2915 +            CompletableFuture[] fs = new CompletableFuture[k];
2916 +            for (int i = 0; i < k; ++i)
2917 +                fs[i] = new CompletableFuture<>();
2918 +            CompletableFuture<Object> f = CompletableFuture.anyOf(fs);
2919 +            checkIncomplete(f);
2920 +            for (int i = 0; i < k; ++i) {
2921 +                fs[i].completeExceptionally(new CFException());
2922 +                checkCompletedWithWrappedCFException(f);
2923 +                checkCompletedWithWrappedCFException(CompletableFuture.anyOf(fs));
2924              }
2925          }
2926      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines