317 |
|
* getNumberOfDependents returns number of dependent tasks |
318 |
|
*/ |
319 |
|
public void testGetNumberOfDependents() { |
320 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
321 |
+ |
{ |
322 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
323 |
|
assertEquals(0, f.getNumberOfDependents()); |
324 |
< |
CompletableFuture g = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
324 |
> |
final CompletableFuture<Void> g = m.thenRun(f, new Noop(m)); |
325 |
|
assertEquals(1, f.getNumberOfDependents()); |
326 |
|
assertEquals(0, g.getNumberOfDependents()); |
327 |
< |
CompletableFuture h = f.thenRun(new Noop(ExecutionMode.DEFAULT)); |
327 |
> |
final CompletableFuture<Void> h = m.thenRun(f, new Noop(m)); |
328 |
|
assertEquals(2, f.getNumberOfDependents()); |
329 |
+ |
assertEquals(0, h.getNumberOfDependents()); |
330 |
|
f.complete(1); |
331 |
|
checkCompletedNormally(g, null); |
332 |
+ |
checkCompletedNormally(h, null); |
333 |
|
assertEquals(0, f.getNumberOfDependents()); |
334 |
|
assertEquals(0, g.getNumberOfDependents()); |
335 |
< |
} |
335 |
> |
assertEquals(0, h.getNumberOfDependents()); |
336 |
> |
}} |
337 |
|
|
338 |
|
/** |
339 |
|
* toString indicates current completion state |
351 |
|
f.completeExceptionally(new IndexOutOfBoundsException()); |
352 |
|
assertTrue(f.toString().contains("[Completed exceptionally]")); |
353 |
|
|
354 |
< |
f = new CompletableFuture<String>(); |
355 |
< |
f.cancel(true); |
356 |
< |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
357 |
< |
|
358 |
< |
f = new CompletableFuture<String>(); |
354 |
< |
f.cancel(false); |
355 |
< |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
354 |
> |
for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { |
355 |
> |
f = new CompletableFuture<String>(); |
356 |
> |
f.cancel(mayInterruptIfRunning); |
357 |
> |
assertTrue(f.toString().contains("[Completed exceptionally]")); |
358 |
> |
} |
359 |
|
} |
360 |
|
|
361 |
|
/** |