aboutsummaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-12-08 15:00:07 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-12-08 15:00:07 +0100
commit4f11c490da2bee48a40e80cfbbfda9914457043c (patch)
treef2f784afe2c80bc04b2b32b5b588ac65f5643226 /container-search
parent92fb7c5a6b124a9f384ed54cb5be166c14a5e910 (diff)
Deprecate methods using Guava ListenableFuture
- com.yahoo.processing.Response.recursiveComplete() - com.yahoo.processing.response.DataList.complete() - com.yahoo.processing.response.IncomingData.completed() Also fixes bug in FutureResponse where `get()` does not return value produced by async task.
Diffstat (limited to 'container-search')
-rw-r--r--container-search/abi-spec.json1
-rw-r--r--container-search/src/main/java/com/yahoo/search/result/HitGroup.java12
-rw-r--r--container-search/src/test/java/com/yahoo/search/rendering/AsyncGroupPopulationTestCase.java30
-rw-r--r--container-search/src/test/java/com/yahoo/search/searchchain/test/FutureDataTestCase.java11
4 files changed, 33 insertions, 21 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index d88701dab03..28d1d2c217b 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -7705,6 +7705,7 @@
"public java.util.Set getFilled()",
"public com.yahoo.processing.response.IncomingData incoming()",
"public com.google.common.util.concurrent.ListenableFuture complete()",
+ "public java.util.concurrent.CompletableFuture future()",
"public void addDataListener(java.lang.Runnable)",
"public void close()",
"public bridge synthetic com.yahoo.search.result.Hit clone()",
diff --git a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java
index 1ae3f4e60cc..b3704c379fe 100644
--- a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java
+++ b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java
@@ -5,6 +5,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture;
import com.yahoo.collections.ListenableArrayList;
+import com.yahoo.concurrent.CompletableFutures;
import com.yahoo.net.URI;
import com.yahoo.prelude.fastsearch.SortDataHitSorter;
import com.yahoo.processing.response.ArrayDataList;
@@ -19,6 +20,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
@@ -84,7 +86,7 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable<
*/
private DefaultErrorHit errorHit = null;
- private final ListenableFuture<DataList<Hit>> completedFuture;
+ private final CompletableFuture<DataList<Hit>> completedFuture;
private final IncomingData<Hit> incomingHits;
@@ -965,7 +967,13 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable<
public IncomingData<Hit> incoming() { return incomingHits; }
@Override
- public ListenableFuture<DataList<Hit>> complete() { return completedFuture; }
+ @SuppressWarnings("removal")
+ @Deprecated(forRemoval = true, since = "7")
+ public ListenableFuture<DataList<Hit>> complete() {
+ return CompletableFutures.toGuavaListenableFuture(completedFuture);
+ }
+
+ @Override public CompletableFuture<DataList<Hit>> future() { return completedFuture; }
@Override
public void addDataListener(Runnable runnable) {
diff --git a/container-search/src/test/java/com/yahoo/search/rendering/AsyncGroupPopulationTestCase.java b/container-search/src/test/java/com/yahoo/search/rendering/AsyncGroupPopulationTestCase.java
index 59aaf60d981..b5e6e243a9f 100644
--- a/container-search/src/test/java/com/yahoo/search/rendering/AsyncGroupPopulationTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/rendering/AsyncGroupPopulationTestCase.java
@@ -1,10 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.rendering;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.util.concurrent.ListenableFuture;
import com.yahoo.concurrent.Receiver;
import com.yahoo.processing.response.Data;
import com.yahoo.processing.response.DataList;
@@ -21,10 +18,12 @@ import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Map;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.function.BiConsumer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -35,18 +34,20 @@ import static org.junit.Assert.assertTrue;
* @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
*/
public class AsyncGroupPopulationTestCase {
- private static class WrappedFuture<F> implements ListenableFuture<F> {
+ private static class WrappedFuture<F> extends CompletableFuture<F> {
Receiver<Boolean> isListening = new Receiver<>();
- private ListenableFuture<F> wrapped;
+ private final CompletableFuture<F> wrapped;
- WrappedFuture(ListenableFuture<F> wrapped) {
+ WrappedFuture(CompletableFuture<F> wrapped) {
this.wrapped = wrapped;
}
- public void addListener(Runnable listener, Executor executor) {
- wrapped.addListener(listener, executor);
+ @Override
+ public CompletableFuture<F> whenCompleteAsync(BiConsumer<? super F, ? super Throwable> action, Executor executor) {
+ wrapped.whenCompleteAsync(action);
isListening.put(Boolean.TRUE);
+ return this;
}
public boolean cancel(boolean mayInterruptIfRunning) {
@@ -72,14 +73,14 @@ public class AsyncGroupPopulationTestCase {
}
private static class ObservableIncoming<DATATYPE extends Data> extends DefaultIncomingData<DATATYPE> {
- WrappedFuture<DataList<DATATYPE>> waitForIt = null;
+ volatile WrappedFuture<DataList<DATATYPE>> waitForIt = null;
private final Object lock = new Object();
@Override
- public ListenableFuture<DataList<DATATYPE>> completed() {
+ public CompletableFuture<DataList<DATATYPE>> future() {
synchronized (lock) {
if (waitForIt == null) {
- waitForIt = new WrappedFuture<>(super.completed());
+ waitForIt = new WrappedFuture<>(super.future());
}
}
return waitForIt;
@@ -97,9 +98,8 @@ public class AsyncGroupPopulationTestCase {
}
@Test
- @SuppressWarnings("removal")
public final void test() throws InterruptedException, ExecutionException,
- JsonParseException, JsonMappingException, IOException {
+ IOException {
String rawExpected = "{"
+ " \"root\": {"
+ " \"children\": ["
@@ -125,10 +125,10 @@ public class AsyncGroupPopulationTestCase {
JsonRenderer renderer = new JsonRenderer();
Result result = new Result(new Query(), h);
renderer.init();
- ListenableFuture<Boolean> f = renderer.render(out, result,
+ CompletableFuture<Boolean> f = renderer.renderResponse(out, result,
new Execution(Execution.Context.createContextStub()),
result.getQuery());
- WrappedFuture<DataList<Hit>> x = (WrappedFuture<DataList<Hit>>) h.incoming().completed();
+ WrappedFuture<DataList<Hit>> x = (WrappedFuture<DataList<Hit>>) h.incoming().future();
x.isListening.get(86_400_000);
h.incoming().add(new Hit("yahoo2"));
h.incoming().markComplete();
diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/FutureDataTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/FutureDataTestCase.java
index 9c36971f688..2426b18f018 100644
--- a/container-search/src/test/java/com/yahoo/search/searchchain/test/FutureDataTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/FutureDataTestCase.java
@@ -2,7 +2,8 @@
package com.yahoo.search.searchchain.test;
import com.yahoo.component.ComponentId;
-import com.yahoo.processing.response.*;
+import com.yahoo.component.chain.Chain;
+import com.yahoo.processing.response.IncomingData;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
@@ -11,18 +12,18 @@ import com.yahoo.search.federation.sourceref.SearchChainResolver;
import com.yahoo.search.result.Hit;
import com.yahoo.search.result.HitGroup;
import com.yahoo.search.searchchain.Execution;
-
import com.yahoo.search.searchchain.SearchChainRegistry;
import com.yahoo.search.searchchain.model.federation.FederationOptions;
import org.junit.Test;
-import static org.junit.Assert.*;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import com.yahoo.component.chain.Chain;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
/**
* Tests using the async capabilities of the Processing parent framework of searchers.
@@ -31,6 +32,7 @@ import com.yahoo.component.chain.Chain;
*/
public class FutureDataTestCase {
+ @SuppressWarnings("removal")
@Test
public void testAsyncFederation() throws InterruptedException, ExecutionException {
// Setup environment
@@ -77,6 +79,7 @@ public class FutureDataTestCase {
assertEquals("async:1", asyncGroup.get(1).getId().toString());
}
+ @SuppressWarnings("removal")
@Test
public void testFutureData() throws InterruptedException, ExecutionException, TimeoutException {
// Set up