summaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/test/java/com/yahoo
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-12-09 16:25:27 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-12-10 10:28:28 +0100
commit134af4f00cb0302f1ba465e51973fe44e1646e19 (patch)
tree5724df56111808aca6c33161e6f2d6740be0f8dd /jdisc_core/src/test/java/com/yahoo
parent4bc0e6916d4532f00b735a79905e40f3b8eb51ea (diff)
Remove use of Guava ListenableFuture from com.yahoo.jdisc.handler
This change is not 100% API compatible. Many classes from this package inherited types from Guava. The classes will have the same methods as before, but their type has obviously changed. Two options; merge now with the small risk of breakage or wait for Vespa 8 branch.
Diffstat (limited to 'jdisc_core/src/test/java/com/yahoo')
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/handler/FastContentWriterTestCase.java3
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureCompletionTestCase.java5
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureConjunctionTestCase.java48
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureResponseTestCase.java3
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDispatchTestCase.java9
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/handler/ResponseDispatchTestCase.java11
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/handler/ThreadedRequestHandlerTestCase.java12
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/test/ServerProviderConformanceTestTest.java14
8 files changed, 48 insertions, 57 deletions
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FastContentWriterTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FastContentWriterTestCase.java
index aa6c4ce3b1b..45bc230896f 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FastContentWriterTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FastContentWriterTestCase.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
-import com.google.common.util.concurrent.MoreExecutors;
import org.junit.Test;
import org.mockito.Mockito;
@@ -188,7 +187,7 @@ public class FastContentWriterTestCase {
ReadableContentChannel buf = new ReadableContentChannel();
FastContentWriter out = new FastContentWriter(buf);
RunnableLatch listener = new RunnableLatch();
- out.addListener(listener, MoreExecutors.directExecutor());
+ out.addListener(listener, Runnable::run);
out.write(new byte[] { 6, 9 });
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureCompletionTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureCompletionTestCase.java
index 6c3803f4f56..ef63b200b5f 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureCompletionTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureCompletionTestCase.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
-import com.google.common.util.concurrent.MoreExecutors;
import org.junit.Test;
import java.util.concurrent.ExecutionException;
@@ -91,14 +90,14 @@ public class FutureCompletionTestCase {
public void requireThatCompletionCanBeListenedTo() throws InterruptedException {
FutureCompletion completion = new FutureCompletion();
RunnableLatch listener = new RunnableLatch();
- completion.addListener(listener, MoreExecutors.directExecutor());
+ completion.addListener(listener, Runnable::run);
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
completion.completed();
assertTrue(listener.await(600, TimeUnit.SECONDS));
completion = new FutureCompletion();
listener = new RunnableLatch();
- completion.addListener(listener, MoreExecutors.directExecutor());
+ completion.addListener(listener, Runnable::run);
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
completion.failed(new Throwable());
assertTrue(listener.await(600, TimeUnit.SECONDS));
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureConjunctionTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureConjunctionTestCase.java
index 346b06e0f23..1aa78a16dfc 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureConjunctionTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureConjunctionTestCase.java
@@ -1,41 +1,37 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
-import com.google.common.util.concurrent.AbstractFuture;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.MoreExecutors;
import org.junit.Test;
-import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* @author Simon Thoresen Hult
*/
public class FutureConjunctionTestCase {
- private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
+ private final ExecutorService executor = Executors.newCachedThreadPool();
@Test
public void requireThatAllFuturesAreWaitedFor() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
FutureConjunction future = new FutureConjunction();
- future.addOperand(executor.submit(new Callable<Boolean>() {
-
- @Override
- public Boolean call() throws Exception {
- return latch.await(600, TimeUnit.SECONDS);
- }
- }));
+ CompletableFuture<Boolean> cf = new CompletableFuture<>();
+ cf.completeAsync(() -> {
+ try { return latch.await(600, TimeUnit.SECONDS); }
+ catch (InterruptedException e) { return false; }
+ }, executor);
+ future.addOperand(cf);
try {
future.get(100, TimeUnit.MILLISECONDS);
fail();
@@ -118,7 +114,7 @@ public class FutureConjunctionTestCase {
public void requireThatConjunctionCanBeListenedTo() throws InterruptedException {
FutureConjunction conjunction = new FutureConjunction();
RunnableLatch listener = new RunnableLatch();
- conjunction.addListener(listener, MoreExecutors.directExecutor());
+ conjunction.addListener(listener, Runnable::run);
assertTrue(listener.await(600, TimeUnit.SECONDS));
conjunction = new FutureConjunction();
@@ -127,7 +123,7 @@ public class FutureConjunctionTestCase {
FutureBoolean bar = new FutureBoolean();
conjunction.addOperand(bar);
listener = new RunnableLatch();
- conjunction.addListener(listener, MoreExecutors.directExecutor());
+ conjunction.addListener(listener, Runnable::run);
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
foo.set(true);
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
@@ -140,7 +136,7 @@ public class FutureConjunctionTestCase {
bar = new FutureBoolean();
conjunction.addOperand(bar);
listener = new RunnableLatch();
- conjunction.addListener(listener, MoreExecutors.directExecutor());
+ conjunction.addListener(listener, Runnable::run);
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
bar.set(true);
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
@@ -190,14 +186,14 @@ public class FutureConjunctionTestCase {
return foo.isCancelled();
}
- private static class FutureBoolean extends AbstractFuture<Boolean> {
+ private static class FutureBoolean extends CompletableFuture<Boolean> {
public boolean set(Boolean val) {
- return super.set(val);
+ return super.complete(val);
}
}
- private static class MyFuture extends AbstractFuture<Boolean> {
+ private static class MyFuture extends CompletableFuture<Boolean> {
final boolean value;
final boolean isDone;
@@ -236,19 +232,19 @@ public class FutureConjunctionTestCase {
return value;
}
- static ListenableFuture<Boolean> newInstance(boolean value) {
+ static CompletableFuture<Boolean> newInstance(boolean value) {
return new MyFuture(value, false, false, false);
}
- static ListenableFuture<Boolean> newIsDone(boolean isDone) {
+ static CompletableFuture<Boolean> newIsDone(boolean isDone) {
return new MyFuture(false, isDone, false, false);
}
- static ListenableFuture<Boolean> newCanCancel(boolean canCancel) {
+ static CompletableFuture<Boolean> newCanCancel(boolean canCancel) {
return new MyFuture(false, false, canCancel, false);
}
- static ListenableFuture<Boolean> newIsCancelled(boolean isCancelled) {
+ static CompletableFuture<Boolean> newIsCancelled(boolean isCancelled) {
return new MyFuture(false, false, false, isCancelled);
}
}
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureResponseTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureResponseTestCase.java
index 440698257a4..398f288e307 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureResponseTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/FutureResponseTestCase.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
-import com.google.common.util.concurrent.MoreExecutors;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.test.NonWorkingContentChannel;
import org.junit.Test;
@@ -73,7 +72,7 @@ public class FutureResponseTestCase {
public void requireThatResponseCanBeListenedTo() throws InterruptedException {
FutureResponse response = new FutureResponse();
RunnableLatch listener = new RunnableLatch();
- response.addListener(listener, MoreExecutors.directExecutor());
+ response.addListener(listener, Runnable::run);
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
response.handleResponse(new Response(Response.Status.OK));
assertTrue(listener.await(600, TimeUnit.SECONDS));
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDispatchTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDispatchTestCase.java
index 3b49d1f349e..6ec78f01733 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDispatchTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDispatchTestCase.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
-import com.google.common.util.concurrent.MoreExecutors;
import com.yahoo.jdisc.Request;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.application.ContainerBuilder;
@@ -17,12 +16,12 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* @author Simon Thoresen Hult
@@ -218,7 +217,7 @@ public class RequestDispatchTestCase {
protected Request newRequest() {
return new Request(driver, URI.create("http://localhost/"));
}
- }.dispatch().addListener(listener, MoreExecutors.directExecutor());
+ }.dispatch().whenComplete((__, ___) -> listener.run());
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
ContentChannel responseContent = ResponseDispatch.newInstance(Response.Status.OK)
.connect(requestHandler.responseHandler);
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/ResponseDispatchTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/ResponseDispatchTestCase.java
index f9a5c22837f..4006ab072cb 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/ResponseDispatchTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/ResponseDispatchTestCase.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
-import com.google.common.util.concurrent.MoreExecutors;
import com.yahoo.jdisc.Response;
import org.junit.Test;
@@ -14,13 +13,13 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* @author Simon Thoresen Hult
@@ -179,7 +178,7 @@ public class ResponseDispatchTestCase {
ReadableContentChannel responseContent = new ReadableContentChannel();
ResponseDispatch.newInstance(6, ByteBuffer.allocate(9))
.dispatch(new MyResponseHandler(responseContent))
- .addListener(listener, MoreExecutors.directExecutor());
+ .whenComplete((__, ___) -> listener.run());
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
assertNotNull(responseContent.read());
assertFalse(listener.await(100, TimeUnit.MILLISECONDS));
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/ThreadedRequestHandlerTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/ThreadedRequestHandlerTestCase.java
index 71f207bbbff..f639877b87b 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/ThreadedRequestHandlerTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/ThreadedRequestHandlerTestCase.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
-import com.google.common.util.concurrent.ListenableFuture;
import com.yahoo.jdisc.Request;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.application.ContainerBuilder;
@@ -12,18 +11,19 @@ import org.junit.Test;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Arrays;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* @author Simon Thoresen Hult
@@ -159,8 +159,8 @@ public class ThreadedRequestHandlerTestCase {
return driver;
}
- private static ListenableFuture<Response> dispatchRequest(final CurrentContainer container, final String uri,
- final ByteBuffer... content) {
+ private static CompletableFuture<Response> dispatchRequest(final CurrentContainer container, final String uri,
+ final ByteBuffer... content) {
return new RequestDispatch() {
@Override
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/test/ServerProviderConformanceTestTest.java b/jdisc_core/src/test/java/com/yahoo/jdisc/test/ServerProviderConformanceTestTest.java
index 01b1e72d0b6..c9c7ec1db48 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/test/ServerProviderConformanceTestTest.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/test/ServerProviderConformanceTestTest.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.test;
-import com.google.common.util.concurrent.SettableFuture;
import com.google.inject.Inject;
import com.google.inject.Module;
import com.google.inject.util.Modules;
@@ -20,6 +19,7 @@ import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -571,7 +571,7 @@ public class ServerProviderConformanceTestTest extends ServerProviderConformance
try {
request = new Request(server.container, URI.create("http://localhost/"));
} catch (Throwable t) {
- responseHandler.response.set(new Response(Response.Status.INTERNAL_SERVER_ERROR, t));
+ responseHandler.response.complete(new Response(Response.Status.INTERNAL_SERVER_ERROR, t));
return responseHandler;
}
try {
@@ -581,7 +581,7 @@ public class ServerProviderConformanceTestTest extends ServerProviderConformance
}
tryClose(out);
} catch (Throwable t) {
- responseHandler.response.set(new Response(Response.Status.INTERNAL_SERVER_ERROR, t));
+ responseHandler.response.complete(new Response(Response.Status.INTERNAL_SERVER_ERROR, t));
// Simulate handling the failure.
t.getMessage();
return responseHandler;
@@ -594,13 +594,13 @@ public class ServerProviderConformanceTestTest extends ServerProviderConformance
private static class MyResponseHandler implements ResponseHandler {
- final SettableFuture<Response> response = SettableFuture.create();
- final SettableFuture<String> content = SettableFuture.create();
+ final CompletableFuture<Response> response = new CompletableFuture<>();
+ final CompletableFuture<String> content = new CompletableFuture<>();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
@Override
public ContentChannel handleResponse(final Response response) {
- this.response.set(response);
+ this.response.complete(response);
return new ContentChannel() {
@Override
@@ -613,7 +613,7 @@ public class ServerProviderConformanceTestTest extends ServerProviderConformance
@Override
public void close(final CompletionHandler handler) {
- content.set(new String(out.toByteArray(), StandardCharsets.UTF_8));
+ content.complete(new String(out.toByteArray(), StandardCharsets.UTF_8));
tryComplete(handler);
}
};