Skip to content

Commit

Permalink
SOLR-17464 (apache#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdyer1 authored Oct 3, 2024
1 parent bd4d55c commit e5d2661
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ protected Http2SolrClient(String serverBaseUrl, Builder builder) {

if (builder.httpClient != null) {
this.httpClient = builder.httpClient;
if (this.executor == null) {
this.executor = builder.executor;
}
this.closeClient = false;
} else {
this.httpClient = createHttpClient(builder);
Expand Down Expand Up @@ -1044,6 +1047,9 @@ public Builder withHttpClient(Http2SolrClient http2SolrClient) {
this.listenerFactory = new ArrayList<HttpListenerFactory>();
http2SolrClient.listenerFactory.forEach(this.listenerFactory::add);
}
if (this.executor == null) {
this.executor = http2SolrClient.executor;
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -265,7 +266,11 @@ public void testUpdateJavabin() throws Exception {

@Test
public 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
Expand All @@ -278,6 +283,20 @@ public void testAsyncException() throws Exception {
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);
}
}

@Test
public void testFollowRedirect() throws Exception {
final String clientUrl = getBaseUrl() + REDIRECT_SERVLET_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ public void testGetById() throws Exception {

@Test
public 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,18 +599,14 @@ protected void testUpdateAsync() throws Exception {
}
}

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),
Expand Down

0 comments on commit e5d2661

Please sign in to comment.