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.58 by jsr166, Mon Jun 2 23:10:08 2014 UTC vs.
Revision 1.60 by jsr166, Tue Jun 3 06:16:41 2014 UTC

# Line 320 | Line 320 | public class CompletableFutureTest exten
320          checkCompletedNormally(f, "test");
321      }
322  
323    // Choose non-commutative actions for better coverage
324
325    // A non-commutative function that handles and produces null values as well.
326    static Integer subtract(Integer x, Integer y) {
327        return (x == null && y == null) ? null :
328            ((x == null) ? 42 : x.intValue())
329            - ((y == null) ? 99 : y.intValue());
330    }
331
332    // A function that handles and produces null values as well.
333    static Integer inc(Integer x) {
334        return (x == null) ? null : x + 1;
335    }
336
323      static final class IntegerSupplier implements Supplier<Integer> {
324          final ExecutionMode m;
325          int invocationCount = 0;
# Line 348 | Line 334 | public class CompletableFutureTest exten
334              return value;
335          }
336      }
337 <        
337 >
338 >    // A function that handles and produces null values as well.
339 >    static Integer inc(Integer x) {
340 >        return (x == null) ? null : x + 1;
341 >    }
342 >
343      static final class IncAction implements Consumer<Integer> {
344          int invocationCount = 0;
345          Integer value;
# Line 368 | Line 359 | public class CompletableFutureTest exten
359              return value = inc(x);
360          }
361      }
362 +
363 +    // Choose non-commutative actions for better coverage
364 +    // A non-commutative function that handles and produces null values as well.
365 +    static Integer subtract(Integer x, Integer y) {
366 +        return (x == null && y == null) ? null :
367 +            ((x == null) ? 42 : x.intValue())
368 +            - ((y == null) ? 99 : y.intValue());
369 +    }
370 +
371      static final class SubtractAction implements BiConsumer<Integer, Integer> {
372          final ExecutionMode m;
373          int invocationCount = 0;
# Line 392 | Line 392 | public class CompletableFutureTest exten
392              return value = subtract(x, y);
393          }
394      }
395 +
396      static final class Noop implements Runnable {
397          final ExecutionMode m;
398          int invocationCount = 0;
# Line 505 | Line 506 | public class CompletableFutureTest exten
506  
507      /**
508       * Permits the testing of parallel code for the 3 different
509 <     * execution modes without repeating all the testing code.
509 >     * execution modes without copy/pasting all the test methods.
510       */
511      enum ExecutionMode {
512          DEFAULT {
513              public void checkExecutionMode() {
514 +                assertFalse(ThreadExecutor.startedCurrentThread());
515                  assertNull(ForkJoinTask.getPool());
516              }
517              public CompletableFuture<Void> runAsync(Runnable a) {
# Line 2614 | Line 2616 | public class CompletableFutureTest exten
2616       */
2617      public void testAllOf_normal() throws Exception {
2618          for (int k = 1; k < 20; ++k) {
2619 <            CompletableFuture<Integer>[] fs = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2619 >            CompletableFuture<Integer>[] fs
2620 >                = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2621              for (int i = 0; i < k; ++i)
2622                  fs[i] = new CompletableFuture<>();
2623              CompletableFuture<Void> f = CompletableFuture.allOf(fs);
# Line 2622 | Line 2625 | public class CompletableFutureTest exten
2625                  checkIncomplete(f);
2626                  checkIncomplete(CompletableFuture.allOf(fs));
2627                  fs[i].complete(one);
2628 +            }
2629 +            checkCompletedNormally(f, null);
2630 +            checkCompletedNormally(CompletableFuture.allOf(fs), null);
2631 +        }
2632 +    }
2633 +
2634 +    public void testAllOf_backwards() throws Exception {
2635 +        for (int k = 1; k < 20; ++k) {
2636 +            CompletableFuture<Integer>[] fs
2637 +                = (CompletableFuture<Integer>[]) new CompletableFuture[k];
2638 +            for (int i = 0; i < k; ++i)
2639 +                fs[i] = new CompletableFuture<>();
2640 +            CompletableFuture<Void> f = CompletableFuture.allOf(fs);
2641 +            for (int i = k - 1; i >= 0; i--) {
2642 +                checkIncomplete(f);
2643 +                checkIncomplete(CompletableFuture.allOf(fs));
2644 +                fs[i].complete(one);
2645              }
2646              checkCompletedNormally(f, null);
2647              checkCompletedNormally(CompletableFuture.allOf(fs), null);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines