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.181 by jsr166, Sat Nov 26 20:32:24 2016 UTC vs.
Revision 1.187 by jsr166, Mon Jul 3 21:18:37 2017 UTC

# Line 64 | Line 64 | public class CompletableFutureTest exten
64              assertNull(f.getNow(null));
65          } catch (Throwable fail) { threadUnexpectedException(fail); }
66          try {
67 <            f.get(0L, SECONDS);
67 >            f.get(randomExpiredTimeout(), randomTimeUnit());
68              shouldThrow();
69          }
70          catch (TimeoutException success) {}
# Line 76 | Line 76 | public class CompletableFutureTest exten
76  
77          try {
78              assertEquals(value, f.join());
79        } catch (Throwable fail) { threadUnexpectedException(fail); }
80        try {
79              assertEquals(value, f.getNow(null));
82        } catch (Throwable fail) { threadUnexpectedException(fail); }
83        try {
80              assertEquals(value, f.get());
81          } catch (Throwable fail) { threadUnexpectedException(fail); }
82          assertTrue(f.isDone());
# Line 93 | Line 89 | public class CompletableFutureTest exten
89       * Returns the "raw" internal exceptional completion of f,
90       * without any additional wrapping with CompletionException.
91       */
92 <    <U> Throwable exceptionalCompletion(CompletableFuture<U> f) {
93 <        // handle (and whenComplete) can distinguish between "direct"
94 <        // and "wrapped" exceptional completion
95 <        return f.handle((U u, Throwable t) -> t).join();
92 >    Throwable exceptionalCompletion(CompletableFuture<?> f) {
93 >        // handle (and whenComplete and exceptionally) can distinguish
94 >        // between "direct" and "wrapped" exceptional completion
95 >        return f.handle((u, t) -> t).join();
96      }
97  
98      void checkCompletedExceptionally(CompletableFuture<?> f,
# Line 1242 | Line 1238 | public class CompletableFutureTest exten
1238          r.assertInvoked();
1239      }}
1240  
1241 +    @SuppressWarnings("FutureReturnValueIgnored")
1242      public void testRunAsync_rejectingExecutor() {
1243          CountingRejectingExecutor e = new CountingRejectingExecutor();
1244          try {
# Line 1288 | Line 1285 | public class CompletableFutureTest exten
1285          r.assertInvoked();
1286      }}
1287  
1288 +    @SuppressWarnings("FutureReturnValueIgnored")
1289      public void testSupplyAsync_rejectingExecutor() {
1290          CountingRejectingExecutor e = new CountingRejectingExecutor();
1291          try {
# Line 2562 | Line 2560 | public class CompletableFutureTest exten
2560  
2561          // unspecified behavior - both source completions available
2562          try {
2563 <            assertEquals(null, h0.join());
2563 >            assertNull(h0.join());
2564              rs[0].assertValue(v1);
2565          } catch (CompletionException ok) {
2566              checkCompletedWithWrappedException(h0, ex);
2567              rs[0].assertNotInvoked();
2568          }
2569          try {
2570 <            assertEquals(null, h1.join());
2570 >            assertNull(h1.join());
2571              rs[1].assertValue(v1);
2572          } catch (CompletionException ok) {
2573              checkCompletedWithWrappedException(h1, ex);
2574              rs[1].assertNotInvoked();
2575          }
2576          try {
2577 <            assertEquals(null, h2.join());
2577 >            assertNull(h2.join());
2578              rs[2].assertValue(v1);
2579          } catch (CompletionException ok) {
2580              checkCompletedWithWrappedException(h2, ex);
2581              rs[2].assertNotInvoked();
2582          }
2583          try {
2584 <            assertEquals(null, h3.join());
2584 >            assertNull(h3.join());
2585              rs[3].assertValue(v1);
2586          } catch (CompletionException ok) {
2587              checkCompletedWithWrappedException(h3, ex);
# Line 2822 | Line 2820 | public class CompletableFutureTest exten
2820  
2821          // unspecified behavior - both source completions available
2822          try {
2823 <            assertEquals(null, h0.join());
2823 >            assertNull(h0.join());
2824              rs[0].assertInvoked();
2825          } catch (CompletionException ok) {
2826              checkCompletedWithWrappedException(h0, ex);
2827              rs[0].assertNotInvoked();
2828          }
2829          try {
2830 <            assertEquals(null, h1.join());
2830 >            assertNull(h1.join());
2831              rs[1].assertInvoked();
2832          } catch (CompletionException ok) {
2833              checkCompletedWithWrappedException(h1, ex);
2834              rs[1].assertNotInvoked();
2835          }
2836          try {
2837 <            assertEquals(null, h2.join());
2837 >            assertNull(h2.join());
2838              rs[2].assertInvoked();
2839          } catch (CompletionException ok) {
2840              checkCompletedWithWrappedException(h2, ex);
2841              rs[2].assertNotInvoked();
2842          }
2843          try {
2844 <            assertEquals(null, h3.join());
2844 >            assertNull(h3.join());
2845              rs[3].assertInvoked();
2846          } catch (CompletionException ok) {
2847              checkCompletedWithWrappedException(h3, ex);
# Line 3238 | Line 3236 | public class CompletableFutureTest exten
3236      /**
3237       * Completion methods throw NullPointerException with null arguments
3238       */
3239 +    @SuppressWarnings("FutureReturnValueIgnored")
3240      public void testNPE() {
3241          CompletableFuture<Integer> f = new CompletableFuture<>();
3242          CompletableFuture<Integer> g = new CompletableFuture<>();
# Line 3532 | Line 3531 | public class CompletableFutureTest exten
3531       */
3532      public void testCompletedStage() {
3533          AtomicInteger x = new AtomicInteger(0);
3534 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3534 >        AtomicReference<Throwable> r = new AtomicReference<>();
3535          CompletionStage<Integer> f = CompletableFuture.completedStage(1);
3536          f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3537          assertEquals(x.get(), 1);
# Line 3634 | Line 3633 | public class CompletableFutureTest exten
3633          CompletableFuture<Integer> f = new CompletableFuture<>();
3634          CompletionStage<Integer> g = f.minimalCompletionStage();
3635          AtomicInteger x = new AtomicInteger(0);
3636 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3636 >        AtomicReference<Throwable> r = new AtomicReference<>();
3637          checkIncomplete(f);
3638          g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3639          f.complete(1);
# Line 3651 | Line 3650 | public class CompletableFutureTest exten
3650          CompletableFuture<Integer> f = new CompletableFuture<>();
3651          CompletionStage<Integer> g = f.minimalCompletionStage();
3652          AtomicInteger x = new AtomicInteger(0);
3653 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3653 >        AtomicReference<Throwable> r = new AtomicReference<>();
3654          g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3655          checkIncomplete(f);
3656          CFException ex = new CFException();
# Line 3669 | Line 3668 | public class CompletableFutureTest exten
3668          CFException ex = new CFException();
3669          CompletionStage<Integer> f = CompletableFuture.failedStage(ex);
3670          AtomicInteger x = new AtomicInteger(0);
3671 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3671 >        AtomicReference<Throwable> r = new AtomicReference<>();
3672          f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3673          assertEquals(x.get(), 0);
3674          assertEquals(r.get(), ex);
# Line 4299 | Line 4298 | public class CompletableFutureTest exten
4298      }
4299  
4300      /** Test long recursive chains of CompletableFutures with cascading completions */
4301 +    @SuppressWarnings("FutureReturnValueIgnored")
4302      public void testRecursiveChains() throws Throwable {
4303          for (ExecutionMode m : ExecutionMode.values())
4304          for (boolean addDeadEnds : new boolean[] { true, false })
# Line 4323 | Line 4323 | public class CompletableFutureTest exten
4323       * A single CompletableFuture with many dependents.
4324       * A demo of scalability - runtime is O(n).
4325       */
4326 +    @SuppressWarnings("FutureReturnValueIgnored")
4327      public void testManyDependents() throws Throwable {
4328          final int n = expensiveTests ? 1_000_000 : 10;
4329          final CompletableFuture<Void> head = new CompletableFuture<>();
# Line 4352 | Line 4353 | public class CompletableFutureTest exten
4353      }
4354  
4355      /** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */
4356 +    @SuppressWarnings("FutureReturnValueIgnored")
4357      public void testCoCompletionGarbageRetention() throws Throwable {
4358          final int n = expensiveTests ? 1_000_000 : 10;
4359          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines