@Test public void failFast() throws Exception { future1.completeExceptionally(new Exception()); future2.completeExceptionally(new Exception()); try { underTest.run().join(); fail(); } catch (Exception ignore) {} assertThat(future1.isCancelled(), is(false)); assertThat(future2.isCancelled(), is(false)); assertThat(future3.isCancelled(), is(true)); }
@Override public CompletableFuture<LanderConfiguration> run() { CompletableFuture<?> anyException = new CompletableFuture<>(); List<CompletableFuture<LanderConfiguration>> landerFutures = landers.stream().map(Lander::run).collect(toList()); landerFutures.forEach(f -> f.exceptionally(t -> { landerFutures.forEach(lander -> lander.cancel(true)); anyException.completeExceptionally(t); return null; })); CompletableFuture<Void> allSucceed = runAsync(() -> landerFutures.forEach(CompletableFuture::join)); return anyOf(anyException, allSucceed).thenApply(x -> landerConfig); }
ParallelKubernetesLander implements Lander { @Override public CompletableFuture<LanderConfiguration> run() { CompletableFuture<?> anyException = new CompletableFuture<>(); List<CompletableFuture<LanderConfiguration>> landerFutures = landers.stream().map(Lander::run).collect(toList()); landerFutures.forEach(f -> f.exceptionally(t -> { landerFutures.forEach(lander -> lander.cancel(true)); anyException.completeExceptionally(t); return null; })); CompletableFuture<Void> allSucceed = runAsync(() -> landerFutures.forEach(CompletableFuture::join)); return anyOf(anyException, allSucceed).thenApply(x -> landerConfig); } }
ParallelKubernetesLander implements Lander { @Override public CompletableFuture<LanderConfiguration> run() { CompletableFuture<?> anyException = new CompletableFuture<>(); List<CompletableFuture<LanderConfiguration>> landerFutures = landers.stream().map(Lander::run).collect(toList()); landerFutures.forEach(f -> f.exceptionally(t -> { landerFutures.forEach(lander -> lander.cancel(true)); anyException.completeExceptionally(t); return null; })); CompletableFuture<Void> allSucceed = runAsync(() -> landerFutures.forEach(CompletableFuture::join)); return anyOf(anyException, allSucceed).thenApply(x -> landerConfig); }  }
ParallelKubernetesLander implements Lander { @Override public CompletableFuture<LanderConfiguration> run() { CompletableFuture<?> anyException = new CompletableFuture<>(); List<CompletableFuture<LanderConfiguration>> landerFutures = landers.stream().map(Lander::run).collect(toList()); landerFutures.forEach(f -> f.exceptionally(t -> { landerFutures.forEach(lander -> lander.cancel(true)); anyException.completeExceptionally(t); return null; })); CompletableFuture<Void> allSucceed = runAsync(() -> landerFutures.forEach(CompletableFuture::join)); return anyOf(anyException, allSucceed).thenApply(x -> landerConfig); }  @Override CompletableFuture<LanderConfiguration> run(); }
ParallelKubernetesLander implements Lander { @Override public CompletableFuture<LanderConfiguration> run() { CompletableFuture<?> anyException = new CompletableFuture<>(); List<CompletableFuture<LanderConfiguration>> landerFutures = landers.stream().map(Lander::run).collect(toList()); landerFutures.forEach(f -> f.exceptionally(t -> { landerFutures.forEach(lander -> lander.cancel(true)); anyException.completeExceptionally(t); return null; })); CompletableFuture<Void> allSucceed = runAsync(() -> landerFutures.forEach(CompletableFuture::join)); return anyOf(anyException, allSucceed).thenApply(x -> landerConfig); }  @Override CompletableFuture<LanderConfiguration> run();  }