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); } |
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 |
|
/** |
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) { |
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 |
|
/** |
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 |
|
|
1255 |
|
r.assertInvoked(); |
1256 |
|
}} |
1257 |
|
|
1258 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
1259 |
|
public void testRunAsync_rejectingExecutor() { |
1260 |
|
CountingRejectingExecutor e = new CountingRejectingExecutor(); |
1261 |
|
try { |
1302 |
|
r.assertInvoked(); |
1303 |
|
}} |
1304 |
|
|
1305 |
+ |
@SuppressWarnings("FutureReturnValueIgnored") |
1306 |
|
public void testSupplyAsync_rejectingExecutor() { |
1307 |
|
CountingRejectingExecutor e = new CountingRejectingExecutor(); |
1308 |
|
try { |
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<>(); |
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 }) |
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<>(); |
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<>(); |