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.184 by jsr166, Sat Mar 18 20:42:20 2017 UTC vs.
Revision 1.191 by jsr166, Sun Jan 7 22:59:17 2018 UTC

# Line 59 | Line 59 | public class CompletableFutureTest exten
59      void checkIncomplete(CompletableFuture<?> f) {
60          assertFalse(f.isDone());
61          assertFalse(f.isCancelled());
62 <        assertTrue(f.toString().contains("Not completed"));
62 >        assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
63          try {
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());
83          assertFalse(f.isCancelled());
84          assertFalse(f.isCompletedExceptionally());
85 <        assertTrue(f.toString().contains("[Completed normally]"));
85 >        assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
86      }
87  
88      /**
# Line 142 | Line 138 | public class CompletableFutureTest exten
138          assertFalse(f.isCancelled());
139          assertTrue(f.isDone());
140          assertTrue(f.isCompletedExceptionally());
141 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
141 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
142      }
143  
144      void checkCompletedWithWrappedCFException(CompletableFuture<?> f) {
# Line 197 | Line 193 | public class CompletableFutureTest exten
193          assertTrue(f.isDone());
194          assertTrue(f.isCompletedExceptionally());
195          assertTrue(f.isCancelled());
196 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
196 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
197      }
198  
199      /**
# Line 333 | Line 329 | public class CompletableFutureTest exten
329      /**
330       * toString indicates current completion state
331       */
332 <    public void testToString() {
333 <        CompletableFuture<String> f;
334 <
335 <        f = new CompletableFuture<String>();
336 <        assertTrue(f.toString().contains("[Not completed]"));
332 >    public void testToString_incomplete() {
333 >        CompletableFuture<String> f = new CompletableFuture<>();
334 >        assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]"));
335 >        if (testImplementationDetails)
336 >            assertEquals(identityString(f) + "[Not completed]",
337 >                         f.toString());
338 >    }
339  
340 +    public void testToString_normal() {
341 +        CompletableFuture<String> f = new CompletableFuture<>();
342          assertTrue(f.complete("foo"));
343 <        assertTrue(f.toString().contains("[Completed normally]"));
343 >        assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]"));
344 >        if (testImplementationDetails)
345 >            assertEquals(identityString(f) + "[Completed normally]",
346 >                         f.toString());
347 >    }
348  
349 <        f = new CompletableFuture<String>();
349 >    public void testToString_exception() {
350 >        CompletableFuture<String> f = new CompletableFuture<>();
351          assertTrue(f.completeExceptionally(new IndexOutOfBoundsException()));
352 <        assertTrue(f.toString().contains("[Completed exceptionally]"));
352 >        assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
353 >        if (testImplementationDetails)
354 >            assertTrue(f.toString().startsWith(
355 >                               identityString(f) + "[Completed exceptionally: "));
356 >    }
357  
358 +    public void testToString_cancelled() {
359          for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
360 <            f = new CompletableFuture<String>();
360 >            CompletableFuture<String> f = new CompletableFuture<>();
361              assertTrue(f.cancel(mayInterruptIfRunning));
362 <            assertTrue(f.toString().contains("[Completed exceptionally]"));
362 >            assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]"));
363 >            if (testImplementationDetails)
364 >                assertTrue(f.toString().startsWith(
365 >                                   identityString(f) + "[Completed exceptionally: "));
366          }
367      }
368  
# Line 1242 | Line 1255 | public class CompletableFutureTest exten
1255          r.assertInvoked();
1256      }}
1257  
1258 +    @SuppressWarnings("FutureReturnValueIgnored")
1259      public void testRunAsync_rejectingExecutor() {
1260          CountingRejectingExecutor e = new CountingRejectingExecutor();
1261          try {
# Line 1288 | Line 1302 | public class CompletableFutureTest exten
1302          r.assertInvoked();
1303      }}
1304  
1305 +    @SuppressWarnings("FutureReturnValueIgnored")
1306      public void testSupplyAsync_rejectingExecutor() {
1307          CountingRejectingExecutor e = new CountingRejectingExecutor();
1308          try {
# Line 3238 | Line 3253 | public class CompletableFutureTest exten
3253      /**
3254       * Completion methods throw NullPointerException with null arguments
3255       */
3256 +    @SuppressWarnings("FutureReturnValueIgnored")
3257      public void testNPE() {
3258          CompletableFuture<Integer> f = new CompletableFuture<>();
3259          CompletableFuture<Integer> g = new CompletableFuture<>();
# Line 4299 | Line 4315 | public class CompletableFutureTest exten
4315      }
4316  
4317      /** Test long recursive chains of CompletableFutures with cascading completions */
4318 +    @SuppressWarnings("FutureReturnValueIgnored")
4319      public void testRecursiveChains() throws Throwable {
4320          for (ExecutionMode m : ExecutionMode.values())
4321          for (boolean addDeadEnds : new boolean[] { true, false })
# Line 4323 | Line 4340 | public class CompletableFutureTest exten
4340       * A single CompletableFuture with many dependents.
4341       * A demo of scalability - runtime is O(n).
4342       */
4343 +    @SuppressWarnings("FutureReturnValueIgnored")
4344      public void testManyDependents() throws Throwable {
4345          final int n = expensiveTests ? 1_000_000 : 10;
4346          final CompletableFuture<Void> head = new CompletableFuture<>();
# Line 4352 | Line 4370 | public class CompletableFutureTest exten
4370      }
4371  
4372      /** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */
4373 +    @SuppressWarnings("FutureReturnValueIgnored")
4374      public void testCoCompletionGarbageRetention() throws Throwable {
4375          final int n = expensiveTests ? 1_000_000 : 10;
4376          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines