Apache Solr open-source search software
SOLR-16426: LBHttp2SolrClient now passes info to child client. (#1036)
Houston Putmanf97264ada434
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex a7e0e08a88c..f76e667420d 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -164,6 +164,8 @@ Bug Fixes* SOLR-16219: ICUCollationField protected field IllegalAccessException from different classloader (Michael Gibney)+* SOLR-16426: LBHttp2SolrClient (and therefore CloudHttp2SolrClient) now respect requestWriter, responseParser and queryParam changes (Houston Putman)+Other Changes---------------------* SOLR-16351: Upgrade Carrot2 to 4.4.3, upgrade randomizedtesting to 2.8.0. (Dawid Weiss)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 22ed9433698..8f8230ae511 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@@ -854,6 +854,10 @@ public class Http2SolrClient extends SolrClient {this.requestWriter = requestWriter;}+ protected RequestWriter getRequestWriter() {+ return requestWriter;+ }+public void setFollowRedirects(boolean follow) {httpClient.setFollowRedirects(follow);}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 5abf0c3abc3..4d82a4a6d86 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@@ -23,11 +23,14 @@ import java.net.ConnectException;import java.net.SocketException;import java.net.SocketTimeoutException;import java.util.Arrays;+import java.util.Set;import java.util.concurrent.atomic.AtomicBoolean;import java.util.concurrent.atomic.AtomicReference;+import org.apache.solr.client.solrj.ResponseParser;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;@@ -78,7 +81,7 @@ import org.slf4j.MDC;* @since solr 8.0*/public class LBHttp2SolrClient extends LBSolrClient {- private Http2SolrClient httpClient;+ private final Http2SolrClient httpClient;public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {super(Arrays.asList(baseSolrUrls));@@ -90,6 +93,30 @@ public class LBHttp2SolrClient extends LBSolrClient {return httpClient;}+ @Override+ public void setParser(ResponseParser parser) {+ super.setParser(parser);+ this.httpClient.setParser(parser);+ }++ @Override+ public void setRequestWriter(RequestWriter writer) {+ super.setRequestWriter(writer);+ this.httpClient.setRequestWriter(writer);+ }++ @Override+ public void setQueryParams(Set<String> queryParams) {+ super.setQueryParams(queryParams);+ this.httpClient.setQueryParams(queryParams);+ }++ @Override+ public void addQueryParams(String queryOnlyParam) {+ super.addQueryParams(queryOnlyParam);+ this.httpClient.setQueryParams(getQueryParams());+ }+public Cancellable asyncReq(Req req, AsyncListener<Rsp> asyncListener) {Rsp rsp = new Rsp();boolean isNonRetryable =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.javanew file mode 100644index 00000000000..fde2bfea382--- /dev/null+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientTest.java@@ -0,0 +1,113 @@+/*+ * 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 static org.junit.Assert.assertArrayEquals;+import static org.junit.Assert.assertEquals;+import static org.junit.Assert.assertNull;++import java.io.IOException;+import java.util.HashSet;+import java.util.Set;+import org.apache.solr.client.solrj.ResponseParser;+import org.apache.solr.client.solrj.request.RequestWriter;+import org.junit.Test;++/** Test the LBHttp2SolrClient. */+public class LBHttp2SolrClientTest {++ /**+ * Test method for {@link LBHttp2SolrClient#setParser(ResponseParser)}.+ *+ * <p>Validate that the parser passed in is used in the base <code>Http2SolrClient</code>+ * instance.+ */+ @Test+ public void testLBHttp2SolrClientSetRequestParser() throws IOException {+ String url = "http://127.0.0.1:8080";+ try (Http2SolrClient http2Client = new Http2SolrClient.Builder(url).build();+ LBHttp2SolrClient testClient = new LBHttp2SolrClient(http2Client, url)) {+ testClient.setParser(null);+ assertNull("Generated lb client should have null parser.", testClient.getParser());+ assertNull("Generated base client should have null parser.", http2Client.getParser());++ ResponseParser parser = new NoOpResponseParser("json");+ testClient.setParser(parser);+ assertEquals("Wrong parser found in lb client.", parser, testClient.getParser());+ assertEquals("Wrong parser found in base client.", parser, http2Client.getParser());+ }+ }++ /**+ * Test method for {@link LBHttp2SolrClient#setRequestWriter(RequestWriter)}.+ *+ * <p>Validate that the requestWriter passed in is used in the base <code>Http2SolrClient</code>+ * instance.+ */+ @Test+ public void testLBHttp2SolrClientSetRequestWriter() throws IOException {+ String url = "http://127.0.0.1:8080";+ try (Http2SolrClient http2Client = new Http2SolrClient.Builder(url).build();+ LBHttp2SolrClient testClient = new LBHttp2SolrClient(http2Client, url)) {+ testClient.setRequestWriter(null);+ assertNull("Generated lb client should have null writer.", testClient.getRequestWriter());+ assertNull("Generated base client should have null writer.", http2Client.getRequestWriter());++ RequestWriter writer = new BinaryRequestWriter();+ testClient.setRequestWriter(writer);+ assertEquals("Wrong writer found in lb client.", writer, testClient.getRequestWriter());+ assertEquals("Wrong writer found in base client.", writer, http2Client.getRequestWriter());+ }+ }++ /**+ * Test method for {@link LBHttp2SolrClient#setQueryParams(Set)} and {@link+ * LBHttp2SolrClient#addQueryParams(String)}.+ *+ * <p>Validate that the query params passed in are used in the base <code>Http2SolrClient</code>+ * instance.+ */+ @Test+ public void testLBHttp2SolrClientSetQueryParams() throws IOException {+ String url = "http://127.0.0.1:8080";+ try (Http2SolrClient http2Client = new Http2SolrClient.Builder(url).build();+ LBHttp2SolrClient testClient = new LBHttp2SolrClient(http2Client, url)) {+ Set<String> queryParams = new HashSet<>(2);+ queryParams.add("param1=this");+ testClient.setQueryParams(new HashSet<>(queryParams));+ assertArrayEquals(+ "Wrong queryParams found in lb client.",+ queryParams.toArray(),+ testClient.getQueryParams().toArray());+ assertArrayEquals(+ "Wrong queryParams found in base client.",+ queryParams.toArray(),+ http2Client.getQueryParams().toArray());++ testClient.addQueryParams("param2=that");+ queryParams.add("param2=that");+ assertArrayEquals(+ "Wrong queryParams found in lb client.",+ queryParams.toArray(),+ testClient.getQueryParams().toArray());+ assertArrayEquals(+ "Wrong queryParams found in base client.",+ queryParams.toArray(),+ http2Client.getQueryParams().toArray());+ }+ }+}