Apache Solr open-source search software
SOLR-17464 (#2733)
James Dyere5d266195096
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 8d5134a6920..b092cc13791 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -167,6 +167,8 @@ Bug Fixes* SOLR-6962: bin/solr stop/start/restart should complain about missing value for options that expect a value. (Eric Pugh, Rahul Goswami)+* SOLR-17464: Fixed Http2SolrClient bug in that 'requestAsync' triggered NPE when using a shared Jetty client (Jason Gerlowski, 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 9795cf4ebdc..8188b292ab1 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@@ -128,6 +128,9 @@ public class Http2SolrClient extends HttpSolrClientBase {if (builder.httpClient != null) {this.httpClient = builder.httpClient;+ if (this.executor == null) {+ this.executor = builder.executor;+ }this.closeClient = false;} else {this.httpClient = createHttpClient(builder);@@ -1044,6 +1047,9 @@ public class Http2SolrClient extends HttpSolrClientBase {this.listenerFactory = new ArrayList<HttpListenerFactory>();http2SolrClient.listenerFactory.forEach(this.listenerFactory::add);}+ if (this.executor == null) {+ this.executor = http2SolrClient.executor;+ }return this;}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 64de4199f01..e61ced5f2bc 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@@ -20,6 +20,7 @@ package org.apache.solr.client.solrj.impl;import java.io.IOException;import java.nio.charset.StandardCharsets;import java.util.Base64;+import java.util.Collections;import java.util.HashMap;import java.util.concurrent.TimeUnit;import org.apache.solr.client.solrj.ResponseParser;@@ -265,7 +266,11 @@ public class Http2SolrClientTest extends HttpSolrClientTestBase {@Testpublic void testAsyncGet() throws Exception {- super.testQueryAsync();+ String url = getBaseUrl() + DEBUG_SERVLET_PATH;+ ResponseParser rp = new XMLResponseParser();+ HttpSolrClientBuilderBase<?, ?> b =+ builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);+ super.testQueryAsync(b);}@Test@@ -278,6 +283,20 @@ public class Http2SolrClientTest extends HttpSolrClientTestBase {super.testAsyncExceptionBase();}+ @Test+ public void testAsyncQueryWithSharedClient() throws Exception {+ DebugServlet.clear();+ final var url = getBaseUrl() + DEBUG_SERVLET_PATH;+ ResponseParser rp = new XMLResponseParser();+ final var queryParams = new MapSolrParams(Collections.singletonMap("q", "*:*"));+ final var builder =+ new Http2SolrClient.Builder(url).withDefaultCollection(DEFAULT_CORE).withResponseParser(rp);+ try (Http2SolrClient originalClient = builder.build()) {+ final var derivedBuilder = builder.withHttpClient(originalClient);+ super.testQueryAsync(derivedBuilder);+ }+ }+@Testpublic void testFollowRedirect() throws Exception {final String clientUrl = getBaseUrl() + REDIRECT_SERVLET_PATH;diff --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 bd5c411fdbf..698658a8528 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@@ -195,7 +195,11 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {@Testpublic void testAsyncGet() throws Exception {- super.testQueryAsync();+ String url = getBaseUrl() + DEBUG_SERVLET_PATH;+ ResponseParser rp = new XMLResponseParser();+ HttpSolrClientBuilderBase<?, ?> b =+ builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);+ super.testQueryAsync(b);}@Testdiff --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 9f5c915f5bf..b2e51cbc63f 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@@ -599,18 +599,14 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {}}- protected void testQueryAsync() throws Exception {- ResponseParser rp = new XMLResponseParser();+ protected void testQueryAsync(HttpSolrClientBuilderBase<?, ?> builder) throws Exception {DebugServlet.clear();DebugServlet.addResponseHeader("Content-Type", "application/xml; charset=UTF-8");- String url = getBaseUrl() + DEBUG_SERVLET_PATH;- HttpSolrClientBuilderBase<?, ?> b =- builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);int limit = 10;List<CompletableFuture<NamedList<Object>>> futures = new ArrayList<>();- try (HttpSolrClientBase client = b.build()) {+ try (HttpSolrClientBase client = builder.build()) {for (int i = 0; i < limit; i++) {DebugServlet.responseBodyByQueryFragment.put(("id=KEY-" + i),