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.140 by jsr166, Mon Mar 28 19:18:16 2016 UTC vs.
Revision 1.143 by jsr166, Sun Apr 3 17:09:46 2016 UTC

# Line 640 | Line 640 | public class CompletableFutureTest exten
640  
641          ASYNC {
642              public void checkExecutionMode() {
643 <                assertEquals(defaultExecutorIsCommonPool,
644 <                             (ForkJoinPool.commonPool() == ForkJoinTask.getPool()));
643 >                // If tests are added that may run across different
644 >                // pools, this needs to be weakened to no-op.
645 >                ForkJoinPool p = ForkJoinTask.getPool();
646 >                assertTrue(p == null ||
647 >                           (defaultExecutorIsCommonPool &&
648 >                            p == ForkJoinPool.commonPool()));
649              }
650              public CompletableFuture<Void> runAsync(Runnable a) {
651                  return CompletableFuture.runAsync(a);
# Line 3295 | Line 3299 | public class CompletableFutureTest exten
3299              () -> f.obtrudeException(null),
3300  
3301              () -> CompletableFuture.delayedExecutor(1L, SECONDS, null),
3302 <            () -> CompletableFuture.delayedExecutor(1L, null, new ThreadExecutor()),
3302 >            () -> CompletableFuture.delayedExecutor(1L, null, exec),
3303              () -> CompletableFuture.delayedExecutor(1L, null),
3304  
3305              () -> f.orTimeout(1L, null),
# Line 3927 | Line 3931 | public class CompletableFutureTest exten
3931  
3932      /**
3933       * A single CompletableFuture with many dependents.
3934 +     * A demo of scalability - runtime is O(n).
3935       */
3936      public void testManyDependents() throws Throwable {
3937 <        final int n = 10_000;
3937 >        final int n = 1_000;
3938          final CompletableFuture<Void> head = new CompletableFuture<>();
3934        final CompletableFuture<Void> incomplete = new CompletableFuture<>();
3939          final CompletableFuture<Void> complete = CompletableFuture.completedFuture((Void)null);
3940          final AtomicInteger count = new AtomicInteger(0);
3941          for (int i = 0; i < n; i++) {
3942              head.thenRun(() -> count.getAndIncrement());
3943              head.thenAccept((x) -> count.getAndIncrement());
3944              head.thenApply((x) -> count.getAndIncrement());
3945 +
3946              head.runAfterBoth(complete, () -> count.getAndIncrement());
3947              head.thenAcceptBoth(complete, (x, y) -> count.getAndIncrement());
3948              head.thenCombine(complete, (x, y) -> count.getAndIncrement());
3949 <            head.runAfterEither(incomplete, () -> count.getAndIncrement());
3950 <            head.acceptEither(incomplete, (x) -> count.getAndIncrement());
3951 <            head.applyToEither(incomplete, (x) -> count.getAndIncrement());
3949 >            complete.runAfterBoth(head, () -> count.getAndIncrement());
3950 >            complete.thenAcceptBoth(head, (x, y) -> count.getAndIncrement());
3951 >            complete.thenCombine(head, (x, y) -> count.getAndIncrement());
3952 >
3953 >            head.runAfterEither(new CompletableFuture<Void>(), () -> count.getAndIncrement());
3954 >            head.acceptEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement());
3955 >            head.applyToEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement());
3956 >            new CompletableFuture<Void>().runAfterEither(head, () -> count.getAndIncrement());
3957 >            new CompletableFuture<Void>().acceptEither(head, (x) -> count.getAndIncrement());
3958 >            new CompletableFuture<Void>().applyToEither(head, (x) -> count.getAndIncrement());
3959          }
3960          head.complete(null);
3961 <        assertEquals(9 * n, count.get());
3961 >        assertEquals(5 * 3 * n, count.get());
3962      }
3963  
3964   //     static <U> U join(CompletionStage<U> stage) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines