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.153 by jsr166, Sun Jun 26 19:17:08 2016 UTC vs.
Revision 1.155 by jsr166, Sun Jun 26 20:03:10 2016 UTC

# Line 550 | Line 550 | public class CompletableFutureTest exten
550          }
551      }
552  
553 +    static class CountingRejectingExecutor implements Executor {
554 +        final RejectedExecutionException ex = new RejectedExecutionException();
555 +        final AtomicInteger count = new AtomicInteger(0);
556 +        public void execute(Runnable r) {
557 +            count.getAndIncrement();
558 +            throw ex;
559 +        }
560 +    }
561 +
562      // Used for explicit executor tests
563      static final class ThreadExecutor implements Executor {
564          final AtomicInteger count = new AtomicInteger(0);
# Line 1234 | Line 1243 | public class CompletableFutureTest exten
1243          r.assertInvoked();
1244      }}
1245  
1246 +    public void testRunAsync_rejectingExecutor() {
1247 +        CountingRejectingExecutor e = new CountingRejectingExecutor();
1248 +        try {
1249 +            CompletableFuture.runAsync(() -> {}, e);
1250 +            shouldThrow();
1251 +        } catch (Throwable t) {
1252 +            assertSame(e.ex, t);
1253 +        }
1254 +
1255 +        assertEquals(1, e.count.get());
1256 +    }
1257 +
1258      /**
1259       * supplyAsync completes with result of supplier
1260       */
# Line 1268 | Line 1289 | public class CompletableFutureTest exten
1289          r.assertInvoked();
1290      }}
1291  
1292 +    public void testSupplyAsync_rejectingExecutor() {
1293 +        CountingRejectingExecutor e = new CountingRejectingExecutor();
1294 +        try {
1295 +            CompletableFuture.supplyAsync(() -> null, e);
1296 +            shouldThrow();
1297 +        } catch (Throwable t) {
1298 +            assertSame(e.ex, t);
1299 +        }
1300 +
1301 +        assertEquals(1, e.count.get());
1302 +    }
1303 +
1304      // seq completion methods
1305  
1306      /**
# Line 3321 | Line 3354 | public class CompletableFutureTest exten
3354       * Test submissions to an executor that rejects all tasks.
3355       */
3356      public void testRejectingExecutor() {
3324        final RejectedExecutionException ex = new RejectedExecutionException();
3325        final Executor e = (Runnable r) -> { throw ex; };
3326
3357          for (Integer v : new Integer[] { 1, null }) {
3358  
3359 +        final CountingRejectingExecutor e = new CountingRejectingExecutor();
3360 +
3361          final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v);
3362          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3363  
# Line 3355 | Line 3387 | public class CompletableFutureTest exten
3387  
3388              for (CompletableFuture<?> future : fs) {
3389                  if (src.isDone())
3390 <                    checkCompletedWithWrappedException(future, ex);
3390 >                    checkCompletedWithWrappedException(future, e.ex);
3391                  else
3392                      checkIncomplete(future);
3393              }
# Line 3392 | Line 3424 | public class CompletableFutureTest exten
3424              fs.add(incomplete.runAfterEitherAsync(complete, () -> {}, e));
3425  
3426              for (CompletableFuture<?> future : fs)
3427 <                checkCompletedWithWrappedException(future, ex);
3427 >                checkCompletedWithWrappedException(future, e.ex);
3428              futures.addAll(fs);
3429          }
3430  
3431          incomplete.complete(v);
3432  
3433          for (CompletableFuture<?> future : futures)
3434 <            checkCompletedWithWrappedException(future, ex);
3434 >            checkCompletedWithWrappedException(future, e.ex);
3435 >
3436 >        assertEquals(futures.size(), e.count.get());
3437 >
3438          }
3439      }
3440  
# Line 3409 | Line 3444 | public class CompletableFutureTest exten
3444       * explicitly completed.
3445       */
3446      public void testRejectingExecutorNeverInvoked() {
3412        final RejectedExecutionException ex = new RejectedExecutionException();
3413        class CountingRejectingExecutor implements Executor {
3414            final AtomicInteger count = new AtomicInteger(0);
3415            public void execute(Runnable r) {
3416                count.getAndIncrement();
3417                throw ex;
3418            }
3419        }
3447          final CountingRejectingExecutor e = new CountingRejectingExecutor();
3448  
3449          for (Integer v : new Integer[] { 1, null }) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines