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.157 by jsr166, Mon Jun 27 02:47:42 2016 UTC vs.
Revision 1.161 by jsr166, Tue Jun 28 14:49:48 2016 UTC

# Line 3354 | Line 3354 | public class CompletableFutureTest exten
3354       * Test submissions to an executor that rejects all tasks.
3355       */
3356      public void testRejectingExecutor() {
3357 <        for (Integer v : new Integer[] { 1, null }) {
3358 <
3357 >        for (Integer v : new Integer[] { 1, null })
3358 >    {
3359          final CountingRejectingExecutor e = new CountingRejectingExecutor();
3360  
3361          final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v);
# Line 3434 | Line 3434 | public class CompletableFutureTest exten
3434              checkCompletedWithWrappedException(future, e.ex);
3435  
3436          assertEquals(futures.size(), e.count.get());
3437 <
3438 <        }
3439 <    }
3437 >    }}
3438  
3439      /**
3440       * Test submissions to an executor that rejects all tasks, but
# Line 3444 | Line 3442 | public class CompletableFutureTest exten
3442       * explicitly completed.
3443       */
3444      public void testRejectingExecutorNeverInvoked() {
3445 +        for (Integer v : new Integer[] { 1, null })
3446 +    {
3447          final CountingRejectingExecutor e = new CountingRejectingExecutor();
3448  
3449        for (Integer v : new Integer[] { 1, null }) {
3450
3449          final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v);
3450          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3451  
# Line 3495 | Line 3493 | public class CompletableFutureTest exten
3493              checkCompletedNormally(future, null);
3494  
3495          assertEquals(0, e.count.get());
3496 <
3499 <        }
3500 <    }
3496 >    }}
3497  
3498      /**
3499       * toCompletableFuture returns this CompletableFuture.
# Line 4143 | Line 4139 | public class CompletableFutureTest exten
4139       * A demo of scalability - runtime is O(n).
4140       */
4141      public void testManyDependents() throws Throwable {
4142 <        final int n = 1_000;
4142 >        final int n = expensiveTests ? 1_000_000 : 10;
4143          final CompletableFuture<Void> head = new CompletableFuture<>();
4144          final CompletableFuture<Void> complete = CompletableFuture.completedFuture((Void)null);
4145          final AtomicInteger count = new AtomicInteger(0);
# Line 4170 | Line 4166 | public class CompletableFutureTest exten
4166          assertEquals(5 * 3 * n, count.get());
4167      }
4168  
4169 <    /** ant -Dvmoptions=-Xmx8m -Djsr166.tckTestClass=CompletableFutureTest tck */
4170 <    public void testCoCompletionGarbage() throws Throwable {
4171 <        // final int n = 3_000_000;
4176 <        final int n = 100;
4169 >    /** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */
4170 >    public void testCoCompletionGarbageRetention() throws Throwable {
4171 >        final int n = expensiveTests ? 1_000_000 : 10;
4172          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
4173          CompletableFuture<Integer> f;
4174          for (int i = 0; i < n; i++) {
# Line 4213 | Line 4208 | public class CompletableFutureTest exten
4208          }
4209      }
4210  
4211 +    /*
4212 +     * Tests below currently fail in stress mode due to memory retention.
4213 +     * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck
4214 +     */
4215 +
4216 +    /** Checks for garbage retention with anyOf. */
4217 +    public void testAnyOfGarbageRetention() throws Throwable {
4218 +        for (Integer v : new Integer[] { 1, null })
4219 +    {
4220 +        final int n = expensiveTests ? 100_000 : 10;
4221 +        CompletableFuture<Integer>[] fs
4222 +            = (CompletableFuture<Integer>[]) new CompletableFuture<?>[100];
4223 +        for (int i = 0; i < fs.length; i++)
4224 +            fs[i] = new CompletableFuture<>();
4225 +        fs[fs.length - 1].complete(v);
4226 +        for (int i = 0; i < n; i++)
4227 +            checkCompletedNormally(CompletableFuture.anyOf(fs), v);
4228 +    }}
4229 +
4230 +    /** Checks for garbage retention with allOf. */
4231 +    public void testCancelledAllOfGarbageRetention() throws Throwable {
4232 +        final int n = expensiveTests ? 100_000 : 10;
4233 +        CompletableFuture<Integer>[] fs
4234 +            = (CompletableFuture<Integer>[]) new CompletableFuture<?>[100];
4235 +        for (int i = 0; i < fs.length; i++)
4236 +            fs[i] = new CompletableFuture<>();
4237 +        for (int i = 0; i < n; i++)
4238 +            assertTrue(CompletableFuture.allOf(fs).cancel(false));
4239 +    }
4240 +
4241   //     static <U> U join(CompletionStage<U> stage) {
4242   //         CompletableFuture<U> f = new CompletableFuture<>();
4243   //         stage.whenComplete((v, ex) -> {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines