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.186 by jsr166, Mon Jul 3 20:55:45 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 2562 | Line 2558 | public class CompletableFutureTest exten
2558  
2559          // unspecified behavior - both source completions available
2560          try {
2561 <            assertEquals(null, h0.join());
2561 >            assertNull(h0.join());
2562              rs[0].assertValue(v1);
2563          } catch (CompletionException ok) {
2564              checkCompletedWithWrappedException(h0, ex);
2565              rs[0].assertNotInvoked();
2566          }
2567          try {
2568 <            assertEquals(null, h1.join());
2568 >            assertNull(h1.join());
2569              rs[1].assertValue(v1);
2570          } catch (CompletionException ok) {
2571              checkCompletedWithWrappedException(h1, ex);
2572              rs[1].assertNotInvoked();
2573          }
2574          try {
2575 <            assertEquals(null, h2.join());
2575 >            assertNull(h2.join());
2576              rs[2].assertValue(v1);
2577          } catch (CompletionException ok) {
2578              checkCompletedWithWrappedException(h2, ex);
2579              rs[2].assertNotInvoked();
2580          }
2581          try {
2582 <            assertEquals(null, h3.join());
2582 >            assertNull(h3.join());
2583              rs[3].assertValue(v1);
2584          } catch (CompletionException ok) {
2585              checkCompletedWithWrappedException(h3, ex);
# Line 2822 | Line 2818 | public class CompletableFutureTest exten
2818  
2819          // unspecified behavior - both source completions available
2820          try {
2821 <            assertEquals(null, h0.join());
2821 >            assertNull(h0.join());
2822              rs[0].assertInvoked();
2823          } catch (CompletionException ok) {
2824              checkCompletedWithWrappedException(h0, ex);
2825              rs[0].assertNotInvoked();
2826          }
2827          try {
2828 <            assertEquals(null, h1.join());
2828 >            assertNull(h1.join());
2829              rs[1].assertInvoked();
2830          } catch (CompletionException ok) {
2831              checkCompletedWithWrappedException(h1, ex);
2832              rs[1].assertNotInvoked();
2833          }
2834          try {
2835 <            assertEquals(null, h2.join());
2835 >            assertNull(h2.join());
2836              rs[2].assertInvoked();
2837          } catch (CompletionException ok) {
2838              checkCompletedWithWrappedException(h2, ex);
2839              rs[2].assertNotInvoked();
2840          }
2841          try {
2842 <            assertEquals(null, h3.join());
2842 >            assertNull(h3.join());
2843              rs[3].assertInvoked();
2844          } catch (CompletionException ok) {
2845              checkCompletedWithWrappedException(h3, ex);
# Line 3238 | Line 3234 | public class CompletableFutureTest exten
3234      /**
3235       * Completion methods throw NullPointerException with null arguments
3236       */
3237 +    @SuppressWarnings("FutureReturnValueIgnored")
3238      public void testNPE() {
3239          CompletableFuture<Integer> f = new CompletableFuture<>();
3240          CompletableFuture<Integer> g = new CompletableFuture<>();
# Line 3532 | Line 3529 | public class CompletableFutureTest exten
3529       */
3530      public void testCompletedStage() {
3531          AtomicInteger x = new AtomicInteger(0);
3532 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3532 >        AtomicReference<Throwable> r = new AtomicReference<>();
3533          CompletionStage<Integer> f = CompletableFuture.completedStage(1);
3534          f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3535          assertEquals(x.get(), 1);
# Line 3634 | Line 3631 | public class CompletableFutureTest exten
3631          CompletableFuture<Integer> f = new CompletableFuture<>();
3632          CompletionStage<Integer> g = f.minimalCompletionStage();
3633          AtomicInteger x = new AtomicInteger(0);
3634 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3634 >        AtomicReference<Throwable> r = new AtomicReference<>();
3635          checkIncomplete(f);
3636          g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3637          f.complete(1);
# Line 3651 | Line 3648 | public class CompletableFutureTest exten
3648          CompletableFuture<Integer> f = new CompletableFuture<>();
3649          CompletionStage<Integer> g = f.minimalCompletionStage();
3650          AtomicInteger x = new AtomicInteger(0);
3651 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3651 >        AtomicReference<Throwable> r = new AtomicReference<>();
3652          g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3653          checkIncomplete(f);
3654          CFException ex = new CFException();
# Line 3669 | Line 3666 | public class CompletableFutureTest exten
3666          CFException ex = new CFException();
3667          CompletionStage<Integer> f = CompletableFuture.failedStage(ex);
3668          AtomicInteger x = new AtomicInteger(0);
3669 <        AtomicReference<Throwable> r = new AtomicReference<Throwable>();
3669 >        AtomicReference<Throwable> r = new AtomicReference<>();
3670          f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
3671          assertEquals(x.get(), 0);
3672          assertEquals(r.get(), ex);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines