Apache Solr open-source search software
SOLR-14763 SolrJ Async - remove deprecated apis from Solr10/main (#2407)
James Dyerdc4ab76420cf
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 067eef0617b..66385572605 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -59,6 +59,10 @@ Deprecation Removals* SOLR-12089: Remove deprecated `breakSugestionTieBreaker` parameter in favor of `breakSuggestionTieBreaker`in WordBreakSolrSpellChecker (Andrey Bozhko via Eric Pugh)+* SOLR-14763: Remove deprecated asynchronous request methods from `Http2SolrClient`, `HttpJdkSolrClient` and `LBHttp2SolrClient`+ in favor of the new CompletableFuture based methods. Remove the related deprecated interfaces `AsyncListener` and ``Cancellable`+ (James Dyer)+Dependency Upgrades---------------------(No changes)diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.javaindex 549bb45320f..40fd27b7c8e 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java@@ -47,8 +47,6 @@ import org.apache.solr.client.solrj.impl.BaseHttpSolrClient.RemoteSolrException;import org.apache.solr.client.solrj.impl.HttpListenerFactory.RequestResponseListener;import org.apache.solr.client.solrj.request.RequestWriter;import org.apache.solr.client.solrj.request.UpdateRequest;-import org.apache.solr.client.solrj.util.AsyncListener;-import org.apache.solr.client.solrj.util.Cancellable;import org.apache.solr.client.solrj.util.ClientUtils;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;@@ -417,26 +415,6 @@ public class Http2SolrClient extends HttpSolrClientBase {outStream.flush();}- @Override- public Cancellable asyncRequest(- SolrRequest<?> solrRequest,- String collection,- AsyncListener<NamedList<Object>> asyncListener) {-- asyncListener.onStart();- CompletableFuture<NamedList<Object>> cf =- requestAsync(solrRequest, collection)- .whenComplete(- (nl, t) -> {- if (t != null) {- asyncListener.onFailure(t);- } else {- asyncListener.onSuccess(nl);- }- });- return () -> cf.cancel(true);- }-@Overridepublic CompletableFuture<NamedList<Object>> requestAsync(final SolrRequest<?> solrRequest, String collection) {diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.javaindex 96366d08c0f..034e16ac679 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java@@ -52,8 +52,6 @@ import org.apache.solr.client.solrj.SolrRequest;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.request.QueryRequest;import org.apache.solr.client.solrj.request.RequestWriter;-import org.apache.solr.client.solrj.util.AsyncListener;-import org.apache.solr.client.solrj.util.Cancellable;import org.apache.solr.client.solrj.util.ClientUtils;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.ModifiableSolrParams;@@ -136,26 +134,6 @@ public class HttpJdkSolrClient extends HttpSolrClientBase {assert ObjectReleaseTracker.track(this);}- @Override- public Cancellable asyncRequest(- SolrRequest<?> solrRequest,- String collection,- AsyncListener<NamedList<Object>> asyncListener) {- asyncListener.onStart();- CompletableFuture<NamedList<Object>> cf =- requestAsync(solrRequest, collection)- .whenComplete(- (nl, t) -> {- if (t != null) {- asyncListener.onFailure(t);- } else {- asyncListener.onSuccess(nl);- }- });-- return new HttpSolrClientCancellable(cf);- }-@Overridepublic CompletableFuture<NamedList<Object>> requestAsync(final SolrRequest<?> solrRequest, String collection) {@@ -539,23 +517,6 @@ public class HttpJdkSolrClient extends HttpSolrClientBase {.collect(Collectors.joining(", "));}- protected static class HttpSolrClientCancellable implements Cancellable {- private final CompletableFuture<NamedList<Object>> response;-- protected HttpSolrClientCancellable(CompletableFuture<NamedList<Object>> response) {- this.response = response;- }-- @Override- public void cancel() {- response.cancel(true);- }-- protected CompletableFuture<NamedList<Object>> getResponse() {- return response;- }- }-public static class Builderextends HttpSolrClientBuilderBase<HttpJdkSolrClient.Builder, HttpJdkSolrClient> {diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBase.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBase.javaindex 95e448df762..56df7cafe61 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBase.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBase.java@@ -42,8 +42,6 @@ import org.apache.solr.client.solrj.SolrRequest;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.request.RequestWriter;import org.apache.solr.client.solrj.request.V2Request;-import org.apache.solr.client.solrj.util.AsyncListener;-import org.apache.solr.client.solrj.util.Cancellable;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ModifiableSolrParams;@@ -377,20 +375,6 @@ public abstract class HttpSolrClientBase extends SolrClient {protected abstract void updateDefaultMimeTypeForParser();- /**- * @deprecated use {@link #requestAsync(SolrRequest, String)}.- * @param solrRequest the request to perform- * @param collection if null the default collection is used- * @param asyncListener callers should provide an implementation to handle events: start, success,- * exception- * @return Cancellable allowing the caller to attempt cancellation- */- @Deprecated- public abstract Cancellable asyncRequest(- SolrRequest<?> solrRequest,- String collection,- AsyncListener<NamedList<Object>> asyncListener);-/*** Execute an asynchronous request against a Solr server for a given collection.*diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.javaindex ec44802f17b..e6633aff4d5 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java@@ -32,8 +32,6 @@ import org.apache.solr.client.solrj.SolrClient;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.request.IsUpdateRequest;import org.apache.solr.client.solrj.request.RequestWriter;-import org.apache.solr.client.solrj.util.AsyncListener;-import org.apache.solr.client.solrj.util.Cancellable;import org.apache.solr.common.SolrException;import org.apache.solr.common.util.NamedList;import org.slf4j.MDC;@@ -126,31 +124,6 @@ public class LBHttp2SolrClient extends LBSolrClient {return solrClient.getUrlParamNames();}- /**- * Execute an asynchronous request against a one or more hosts for a given collection.- *- * @param req the wrapped request to perform- * @param asyncListener callers should provide an implementation to handle events: start, success,- * exception- * @return Cancellable allowing the caller to attempt cancellation- * @deprecated Use {@link #requestAsync(Req)}.- */- @Deprecated- public Cancellable asyncReq(Req req, AsyncListener<Rsp> asyncListener) {- asyncListener.onStart();- CompletableFuture<Rsp> cf =- requestAsync(req)- .whenComplete(- (rsp, t) -> {- if (t != null) {- asyncListener.onFailure(t);- } else {- asyncListener.onSuccess(rsp);- }- });- return () -> cf.cancel(true);- }-/*** Execute an asynchronous request against one or more hosts for a given collection. The passed-in* Req object includes a List of Endpoints. This method always begins with the first Endpoint indiff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/util/AsyncListener.java b/solr/solrj/src/java/org/apache/solr/client/solrj/util/AsyncListener.javadeleted file mode 100644index 690c558e51b..00000000000--- a/solr/solrj/src/java/org/apache/solr/client/solrj/util/AsyncListener.java+++ /dev/null@@ -1,36 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.solr.client.solrj.util;--/**- * Listener for async requests- *- * @param <T> The result type returned by the {@code onSuccess} method- * @deprecated Use the async variants that return CompletableFuture.- */-@Deprecated-public interface AsyncListener<T> {- /** Callback method invoked before processing the request */- default void onStart() {}-- /** Callback method invoked when the request completes successfully */- void onSuccess(T t);-- /** Callback method invoked when the request completes in failure */- void onFailure(Throwable throwable);-}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/util/Cancellable.java b/solr/solrj/src/java/org/apache/solr/client/solrj/util/Cancellable.javadeleted file mode 100644index 2dff867d546..00000000000--- a/solr/solrj/src/java/org/apache/solr/client/solrj/util/Cancellable.java+++ /dev/null@@ -1,34 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.solr.client.solrj.util;--/**- * The return type for solrJ asynchronous requests, providing a mechanism whereby callers may- * request cancellation.- *- * @deprecated Use the async variants that return CompletableFuture.- */-@Deprecated-public interface Cancellable {-- /**- * Request to cancel the asynchronous request. This may be a no-op in some situations, for- * instance, if the request failed or otherwise is complete.- */- void cancel();-}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/DebugAsyncListener.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/DebugAsyncListener.javadeleted file mode 100644index f6db888421c..00000000000--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/DebugAsyncListener.java+++ /dev/null@@ -1,79 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--package org.apache.solr.client.solrj.impl;--import java.util.concurrent.CompletableFuture;-import java.util.concurrent.CountDownLatch;-import org.apache.solr.client.solrj.SolrRequest;-import org.apache.solr.client.solrj.util.AsyncListener;-import org.apache.solr.common.util.NamedList;-import org.junit.Assert;--@Deprecated-public class DebugAsyncListener- implements AsyncListener<NamedList<Object>>, PauseableHttpSolrClient {-- private final CountDownLatch latch;-- public volatile boolean onStartCalled;-- public volatile boolean latchCounted;-- public volatile NamedList<Object> onSuccessResult = null;-- public volatile Throwable onFailureResult = null;-- public DebugAsyncListener(CountDownLatch latch) {- this.latch = latch;- }-- @Override- public void onStart() {- onStartCalled = true;- }-- @Override- public void onSuccess(NamedList<Object> entries) {- pause();- onSuccessResult = entries;- if (latchCounted) {- Assert.fail("either 'onSuccess' or 'onFailure' should be called exactly once.");- }- latch.countDown();- latchCounted = true;- unPause();- }-- @Override- public void onFailure(Throwable throwable) {- pause();- onFailureResult = throwable;- if (latchCounted) {- Assert.fail("either 'onSuccess' or 'onFailure' should be called exactly once.");- }- latch.countDown();- latchCounted = true;- unPause();- }-- @Override- public CompletableFuture<NamedList<Object>> requestAsync(- SolrRequest<?> solrRequest, String collection) {- throw new UnsupportedOperationException();- }-}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.javaindex 620c24020ef..c1c2580e7a5 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java@@ -265,34 +265,19 @@ public class Http2SolrClientTest extends HttpSolrClientTestBase {}}- @Test- public void testDeprecatedAsyncGet() throws Exception {- super.testQueryAsync(true);- }-@Testpublic void testAsyncGet() throws Exception {- super.testQueryAsync(false);- }-- @Test- public void testDeprecatedAsyncPost() throws Exception {- super.testUpdateAsync(true);+ super.testQueryAsync();}@Testpublic void testAsyncPost() throws Exception {- super.testUpdateAsync(false);- }-- @Test- public void testDeprecatedAsyncException() throws Exception {- super.testAsyncExceptionBase(true);+ super.testUpdateAsync();}@Testpublic void testAsyncException() throws Exception {- super.testAsyncExceptionBase(false);+ super.testAsyncExceptionBase();}@Testdiff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.javaindex 5cbfaa3dcd5..e5af5bd5f52 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java@@ -29,9 +29,6 @@ import java.util.Arrays;import java.util.Collections;import java.util.Objects;import java.util.Set;-import java.util.concurrent.CompletableFuture;-import java.util.concurrent.CompletionException;-import java.util.concurrent.CountDownLatch;import java.util.concurrent.ExecutorService;import java.util.concurrent.TimeUnit;import java.util.stream.Collectors;@@ -46,10 +43,8 @@ import org.apache.solr.client.solrj.ResponseParser;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrRequest;import org.apache.solr.client.solrj.SolrServerException;-import org.apache.solr.client.solrj.request.QueryRequest;import org.apache.solr.client.solrj.request.RequestWriter;import org.apache.solr.client.solrj.response.SolrPingResponse;-import org.apache.solr.client.solrj.util.Cancellable;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.MapSolrParams;import org.apache.solr.common.util.ExecutorUtil;@@ -199,38 +194,19 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {}}- @Test- public void testDeprecatedAsyncGet() throws Exception {- super.testQueryAsync(true);- }-@Testpublic void testAsyncGet() throws Exception {- super.testQueryAsync(false);- }-- @Test- public void testDeprecatedAsyncPost() throws Exception {- super.testUpdateAsync(true);+ super.testQueryAsync();}@Testpublic void testAsyncPost() throws Exception {- super.testUpdateAsync(false);- }-- @Test- public void testDeprecatedAsyncException() throws Exception {- DebugAsyncListener listener = super.testAsyncExceptionBase(true);- assertTrue(listener.onFailureResult instanceof CompletionException);- CompletionException ce = (CompletionException) listener.onFailureResult;- assertTrue(ce.getCause() instanceof BaseHttpSolrClient.RemoteSolrException);- assertTrue(ce.getMessage(), ce.getMessage().contains("mime type"));+ super.testUpdateAsync();}@Testpublic void testAsyncException() throws Exception {- super.testAsyncExceptionBase(false);+ super.testAsyncExceptionBase();}@Test@@ -279,50 +255,6 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {}}- @Test- public void testDeprecatedAsyncAndCancel() throws Exception {- ResponseParser rp = new XMLResponseParser();- DebugServlet.clear();- DebugServlet.addResponseHeader("Content-Type", "application/xml; charset=UTF-8");- DebugServlet.responseBodyByQueryFragment.put(- "", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response />");- String url = getBaseUrl() + DEBUG_SERVLET_PATH;- HttpJdkSolrClient.Builder b = builder(url).withResponseParser(rp);- CountDownLatch latch = new CountDownLatch(0);- DebugAsyncListener listener = new DebugAsyncListener(latch);- Cancellable cancelMe = null;- try (HttpJdkSolrClient client = b.build()) {- QueryRequest query = new QueryRequest(new MapSolrParams(Collections.singletonMap("id", "1")));-- // We are pausing in the "whenComplete" stage, in the unlikely event the http request- // finishes before the test calls "cancel".- listener.pause();-- // Make the request then immediately cancel it!- cancelMe = client.asyncRequest(query, "collection1", listener);- cancelMe.cancel();-- // We are safe to unpause our client, having guaranteed that our cancel was before everything- // completed.- listener.unPause();- }-- // "onStart" fires before the async call. This part of the request cannot be cancelled.- assertTrue(listener.onStartCalled);-- // The client exposes the CompletableFuture to us via this inner class- assertTrue(cancelMe instanceof HttpJdkSolrClient.HttpSolrClientCancellable);- CompletableFuture<NamedList<Object>> response =- ((HttpJdkSolrClient.HttpSolrClientCancellable) cancelMe).getResponse();-- // Even if our cancel didn't happen until we were at "whenComplete", the CompletableFuture will- // have set "isCancelled".- assertTrue(response.isCancelled());-- // But we cannot guarantee the response will have been returned, or that "onFailure" was fired- // with a "CompletionException". This depends on where we were when the cancellation hit.- }-@Testpublic void testTimeout() throws Exception {SolrQuery q = new SolrQuery("*:*");diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientTestBase.javaindex 76b5f07841c..977275f5ea8 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientTestBase.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientTestBase.java@@ -43,7 +43,6 @@ import org.apache.solr.client.solrj.request.QueryRequest;import org.apache.solr.client.solrj.request.SolrPing;import org.apache.solr.client.solrj.request.UpdateRequest;import org.apache.solr.client.solrj.response.QueryResponse;-import org.apache.solr.client.solrj.util.Cancellable;import org.apache.solr.common.SolrDocumentList;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrInputDocument;@@ -544,16 +543,12 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {"No authorization headers expected. Headers: " + DebugServlet.headers, authorizationHeader);}- protected void testUpdateAsync(boolean useDeprecatedApi) throws Exception {+ protected void testUpdateAsync() throws Exception {ResponseParser rp = new XMLResponseParser();String url = getBaseUrl();HttpSolrClientBuilderBase<?, ?> b =builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);int limit = 10;-- DebugAsyncListener[] listeners = new DebugAsyncListener[limit]; // Deprecated API use- Cancellable[] cancellables = new Cancellable[limit]; // Deprecated API use-CountDownLatch latch = new CountDownLatch(limit);try (HttpSolrClientBase client = b.build()) {@@ -573,12 +568,7 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {ur.add("id", "KEY-" + i);ur.setMethod(SolrRequest.METHOD.POST);- if (useDeprecatedApi) {- listeners[i] = new DebugAsyncListener(latch);- client.asyncRequest(ur, COLLECTION_1, listeners[i]);- } else {- client.requestAsync(ur, COLLECTION_1).whenComplete((nl, e) -> latch.countDown());- }+ client.requestAsync(ur, COLLECTION_1).whenComplete((nl, e) -> latch.countDown());}latch.await(1, TimeUnit.MINUTES);client.commit(COLLECTION_1);@@ -597,7 +587,7 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {}}- protected void testQueryAsync(boolean useDeprecatedApi) throws Exception {+ protected void testQueryAsync() throws Exception {ResponseParser rp = new XMLResponseParser();DebugServlet.clear();DebugServlet.addResponseHeader("Content-Type", "application/xml; charset=UTF-8");@@ -606,10 +596,6 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);int limit = 10;- CountDownLatch latch = new CountDownLatch(limit); // Deprecated API use- DebugAsyncListener[] listeners = new DebugAsyncListener[limit]; // Deprecated API use- Cancellable[] cancellables = new Cancellable[limit]; // Deprecated API use-List<CompletableFuture<NamedList<Object>>> futures = new ArrayList<>();try (HttpSolrClientBase client = b.build()) {@@ -622,24 +608,11 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {QueryRequest query =new QueryRequest(new MapSolrParams(Collections.singletonMap("id", "KEY-" + i)));query.setMethod(SolrRequest.METHOD.GET);- if (useDeprecatedApi) {- listeners[i] = new DebugAsyncListener(latch);- client.asyncRequest(query, null, listeners[i]);- } else {- futures.add(client.requestAsync(query));- }- }- if (useDeprecatedApi) {- latch.await(1, TimeUnit.MINUTES);+ futures.add(client.requestAsync(query));}for (int i = 0; i < limit; i++) {- NamedList<Object> result;- if (useDeprecatedApi) {- result = listeners[i].onSuccessResult;- } else {- result = futures.get(i).get(1, TimeUnit.MINUTES);- }+ NamedList<Object> result = futures.get(i).get(1, TimeUnit.MINUTES);SolrDocumentList sdl = (SolrDocumentList) result.get("response");assertEquals(2, sdl.getNumFound());assertEquals(1, sdl.getStart());@@ -647,18 +620,12 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {assertEquals(1, sdl.size());assertEquals(1, sdl.iterator().next().size());assertEquals("KEY-" + i, sdl.iterator().next().get("id"));-- if (useDeprecatedApi) {- assertNull(listeners[i].onFailureResult);- assertTrue(listeners[i].onStartCalled);- } else {- assertFalse(futures.get(i).isCompletedExceptionally());- }+ assertFalse(futures.get(i).isCompletedExceptionally());}}}- protected DebugAsyncListener testAsyncExceptionBase(boolean useDeprecatedApi) throws Exception {+ protected void testAsyncExceptionBase() throws Exception {ResponseParser rp = new XMLResponseParser();DebugServlet.clear();DebugServlet.addResponseHeader("Content-Type", "Wrong Content Type!");@@ -666,40 +633,20 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {HttpSolrClientBuilderBase<?, ?> b =builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);- CompletableFuture<NamedList<Object>> future = null;- ExecutionException ee = null;-- CountDownLatch latch = new CountDownLatch(1); // Deprecated API use- DebugAsyncListener listener = new DebugAsyncListener(latch); // Deprecated API use-try (HttpSolrClientBase client = b.build()) {QueryRequest query = new QueryRequest(new MapSolrParams(Collections.singletonMap("id", "1")));- if (useDeprecatedApi) {- client.asyncRequest(query, COLLECTION_1, listener);- } else {- future = client.requestAsync(query, COLLECTION_1);- }- if (useDeprecatedApi) {- latch.await(1, TimeUnit.MINUTES);- } else {- try {- future.get(1, TimeUnit.MINUTES);- fail("Should have thrown ExecutionException");- } catch (ExecutionException ee1) {- ee = ee1;- }+ CompletableFuture<NamedList<Object>> future = client.requestAsync(query, COLLECTION_1);+ ExecutionException ee = null;+ try {+ future.get(1, TimeUnit.MINUTES);+ fail("Should have thrown ExecutionException");+ } catch (ExecutionException ee1) {+ ee = ee1;}- }- if (useDeprecatedApi) {- assertNotNull(listener.onFailureResult);- assertTrue(listener.onStartCalled);- assertNull(listener.onSuccessResult);- } else {assertTrue(future.isCompletedExceptionally());assertTrue(ee.getCause() instanceof BaseHttpSolrClient.RemoteSolrException);assertTrue(ee.getMessage(), ee.getMessage().contains("mime type"));}- return listener;}protected void testAsyncAndCancel(PauseableHttpSolrClient client) throws Exception {diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientTest.javaindex 8e29050cb81..203f050efc5 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientTest.java@@ -23,15 +23,12 @@ import java.util.List;import java.util.Map;import java.util.Set;import java.util.concurrent.CompletableFuture;-import java.util.concurrent.CountDownLatch;import java.util.concurrent.ExecutionException;import java.util.concurrent.TimeUnit;import java.util.concurrent.TimeoutException;import org.apache.solr.SolrTestCase;import org.apache.solr.client.solrj.SolrRequest;import org.apache.solr.client.solrj.request.QueryRequest;-import org.apache.solr.client.solrj.util.AsyncListener;-import org.apache.solr.client.solrj.util.Cancellable;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.MapSolrParams;import org.apache.solr.common.util.NamedList;@@ -68,16 +65,6 @@ public class LBHttp2SolrClientTest extends SolrTestCase {}}- @Test- public void testAsyncDeprecated() {- testAsync(true);- }-- @Test- public void testAsync() {- testAsync(false);- }-@Testpublic void testAsyncWithFailures() {@@ -138,7 +125,8 @@ public class LBHttp2SolrClientTest extends SolrTestCase {}}- private void testAsync(boolean useDeprecatedApi) {+ @Test+ public void testAsync() {LBSolrClient.Endpoint ep1 = new LBSolrClient.Endpoint("http://endpoint.one");LBSolrClient.Endpoint ep2 = new LBSolrClient.Endpoint("http://endpoint.two");List<LBSolrClient.Endpoint> endpointList = List.of(ep1, ep2);@@ -149,31 +137,12 @@ public class LBHttp2SolrClientTest extends SolrTestCase {LBHttp2SolrClient testClient = new LBHttp2SolrClient.Builder(client, ep1, ep2).build()) {int limit = 10; // For simplicity use an even limit-- CountDownLatch latch = new CountDownLatch(limit); // deprecated API use- List<LBTestAsyncListener> listeners = new ArrayList<>(); // deprecated API useList<CompletableFuture<LBSolrClient.Rsp>> responses = new ArrayList<>();for (int i = 0; i < limit; i++) {QueryRequest queryRequest = new QueryRequest(new MapSolrParams(Map.of("q", "" + i)));LBSolrClient.Req req = new LBSolrClient.Req(queryRequest, endpointList);- if (useDeprecatedApi) {- LBTestAsyncListener listener = new LBTestAsyncListener(latch);- listeners.add(listener);- testClient.asyncReq(req, listener);- } else {- responses.add(testClient.requestAsync(req));- }- }-- if (useDeprecatedApi) {- try {- // This is just a formality. This is a single-threaded test.- latch.await(1, TimeUnit.MINUTES);- } catch (InterruptedException ie) {- Thread.currentThread().interrupt();- fail("interrupted");- }+ responses.add(testClient.requestAsync(req));}QueryRequest[] queryRequests = new QueryRequest[limit];@@ -191,25 +160,17 @@ public class LBHttp2SolrClientTest extends SolrTestCase {} else if (lastQueryReq.getBasePath().equals(ep2.toString())) {numEndpointTwo++;}- NamedList<Object> lastResponse;- if (useDeprecatedApi) {- LBTestAsyncListener lastAsyncListener = listeners.get(index);- assertTrue(lastAsyncListener.onStartCalled);- assertNull(lastAsyncListener.failure);- assertNotNull(lastAsyncListener.success);- lastResponse = lastAsyncListener.success.getResponse();- } else {- LBSolrClient.Rsp lastRsp = null;- try {- lastRsp = responses.get(index).get();- } catch (InterruptedException ie) {- Thread.currentThread().interrupt();- fail("interrupted");- } catch (ExecutionException ee) {- fail("Response " + index + " ended in failure: " + ee);- }- lastResponse = lastRsp.getResponse();++ LBSolrClient.Rsp lastRsp = null;+ try {+ lastRsp = responses.get(index).get();+ } catch (InterruptedException ie) {+ Thread.currentThread().interrupt();+ fail("interrupted");+ } catch (ExecutionException ee) {+ fail("Response " + index + " ended in failure: " + ee);}+ NamedList<Object> lastResponse = lastRsp.getResponse();// The Mock will return {"response": index}.assertEquals("" + index, lastResponse.get("response"));@@ -226,44 +187,6 @@ public class LBHttp2SolrClientTest extends SolrTestCase {}}- @Deprecated(forRemoval = true)- public static class LBTestAsyncListener implements AsyncListener<LBSolrClient.Rsp> {- private final CountDownLatch latch;- private volatile boolean countDownCalled = false;- public boolean onStartCalled = false;- public LBSolrClient.Rsp success = null;- public Throwable failure = null;-- public LBTestAsyncListener(CountDownLatch latch) {- this.latch = latch;- }-- @Override- public void onStart() {- onStartCalled = true;- }-- @Override- public void onSuccess(LBSolrClient.Rsp entries) {- success = entries;- countdown();- }-- @Override- public void onFailure(Throwable throwable) {- failure = throwable;- countdown();- }-- private void countdown() {- if (countDownCalled) {- throw new IllegalStateException("Already counted down.");- }- latch.countDown();- countDownCalled = true;- }- }-public static class MockHttp2SolrClient extends Http2SolrClient {public List<SolrRequest<?>> lastSolrRequests = new ArrayList<>();@@ -281,14 +204,6 @@ public class LBHttp2SolrClientTest extends SolrTestCase {super(serverBaseUrl, builder);}- @Override- public Cancellable asyncRequest(- SolrRequest<?> solrRequest,- String collection,- AsyncListener<NamedList<Object>> asyncListener) {- throw new UnsupportedOperationException("do not use deprecated method.");- }-@Overridepublic CompletableFuture<NamedList<Object>> requestAsync(final SolrRequest<?> solrRequest, String collection) {