summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2020-12-02 08:04:14 +0100
committerGitHub <noreply@github.com>2020-12-02 08:04:14 +0100
commit8ec5101abf70f9f723383b874fd55ecc27581783 (patch)
tree02ac1373f672b4bebd78351b03bdfeaac47d7ba8 /vespajlib
parent4cf13bc7db215e77f7688e429f700880c115fe76 (diff)
Revert "Bjorncs/cluster controller reindexing status"
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/pom.xml5
-rw-r--r--vespajlib/src/main/java/com/yahoo/concurrent/CompletableFutures.java67
-rw-r--r--vespajlib/src/test/java/com/yahoo/concurrent/CompletableFuturesTest.java66
3 files changed, 0 insertions, 138 deletions
diff --git a/vespajlib/pom.xml b/vespajlib/pom.xml
index 68639d30ab2..302a3c6f5bf 100644
--- a/vespajlib/pom.xml
+++ b/vespajlib/pom.xml
@@ -78,11 +78,6 @@
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/CompletableFutures.java b/vespajlib/src/main/java/com/yahoo/concurrent/CompletableFutures.java
deleted file mode 100644
index b1fa6a9438d..00000000000
--- a/vespajlib/src/main/java/com/yahoo/concurrent/CompletableFutures.java
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.concurrent;
-
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-
-/**
- * Helper for {@link java.util.concurrent.CompletableFuture} / {@link java.util.concurrent.CompletionStage}.
- *
- * @author bjorncs
- */
-public class CompletableFutures {
-
- private CompletableFutures() {}
-
- /**
- * Returns a new completable future that is either
- * - completed when any of the provided futures complete without exception
- * - completed exceptionally once all provided futures complete exceptionally
- */
- public static <T> CompletableFuture<T> firstOf(List<CompletableFuture<T>> futures) {
- class Combiner {
- final Object monitor = new Object();
- final CompletableFuture<T> combined = new CompletableFuture<>();
- final int futuresCount;
-
- Throwable error = null;
- int exceptionCount = 0;
-
- Combiner(int futuresCount) { this.futuresCount = futuresCount; }
-
- void onCompletion(T value, Throwable error) {
- if (combined.isDone()) return;
- T valueToComplete = null;
- Throwable exceptionToComplete = null;
-
- synchronized (monitor) {
- if (value != null) {
- valueToComplete = value;
- } else {
- if (this.error == null) {
- this.error = error;
- } else {
- this.error.addSuppressed(error);
- }
- if (++exceptionCount == futuresCount) {
- exceptionToComplete = this.error;
- }
- }
- }
- if (valueToComplete != null) {
- combined.complete(value);
- } else if (exceptionToComplete != null) {
- combined.completeExceptionally(exceptionToComplete);
- }
- }
- }
-
- int size = futures.size();
- if (size == 0) throw new IllegalArgumentException();
- if (size == 1) return futures.get(0);
- Combiner combiner = new Combiner(size);
- futures.forEach(future -> future.whenComplete(combiner::onCompletion));
- return combiner.combined;
- }
-
-}
diff --git a/vespajlib/src/test/java/com/yahoo/concurrent/CompletableFuturesTest.java b/vespajlib/src/test/java/com/yahoo/concurrent/CompletableFuturesTest.java
deleted file mode 100644
index cf9c36537d9..00000000000
--- a/vespajlib/src/test/java/com/yahoo/concurrent/CompletableFuturesTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.yahoo.concurrent;// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-import org.junit.jupiter.api.Test;
-
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionException;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-/**
- * @author bjorncs
- */
-class CompletableFuturesTest {
-
- @Test
- public void firstof_completes_when_first_futures_has_completed() {
- CompletableFuture<String> f1 = new CompletableFuture<>();
- CompletableFuture<String> f2 = new CompletableFuture<>();
- CompletableFuture<String> f3 = new CompletableFuture<>();
- CompletableFuture<String> result = CompletableFutures.firstOf(List.of(f1, f2, f3));
- f1.complete("success");
- assertTrue(result.isDone());
- assertFalse(result.isCompletedExceptionally());
- assertEquals("success", result.join());
- }
-
- @Test
- public void firstof_completes_if_any_futures_completes() {
- CompletableFuture<String> f1 = new CompletableFuture<>();
- CompletableFuture<String> f2 = new CompletableFuture<>();
- CompletableFuture<String> f3 = new CompletableFuture<>();
- CompletableFuture<String> result = CompletableFutures.firstOf(List.of(f1, f2, f3));
- f1.completeExceptionally(new Throwable("t1"));
- f2.completeExceptionally(new Throwable("t2"));
- f3.complete("success");
- assertTrue(result.isDone());
- assertFalse(result.isCompletedExceptionally());
- assertEquals("success", result.join());
- }
-
- @Test
- public void firstof_completes_exceptionally_when_all_futures_have_complete_exceptionally() {
- CompletableFuture<String> f1 = new CompletableFuture<>();
- CompletableFuture<String> f2 = new CompletableFuture<>();
- CompletableFuture<String> f3 = new CompletableFuture<>();
- CompletableFuture<String> result = CompletableFutures.firstOf(List.of(f1, f2, f3));
- f1.completeExceptionally(new Throwable("t1"));
- f2.completeExceptionally(new Throwable("t2"));
- f3.completeExceptionally(new Throwable("t3"));
- assertTrue(result.isDone());
- assertTrue(result.isCompletedExceptionally());
- try {
- result.join();
- fail("Exception expected");
- } catch (CompletionException e) {
- Throwable cause = e.getCause();
- assertEquals("t1", cause.getMessage());
- assertEquals(2, cause.getSuppressed().length);
- }
- }
-
-} \ No newline at end of file