You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2022/09/22 18:34:35 UTC

[solr] branch branch_9x updated: SOLR-16426: LBHttp2SolrClient now passes info to child client. (#1036)

This is an automated email from the ASF dual-hosted git repository.

houston pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 46c2eeaf2b7 SOLR-16426: LBHttp2SolrClient now passes info to child client. (#1036)
46c2eeaf2b7 is described below

commit 46c2eeaf2b7b0ec4bc8ea82e21f19ca0cf5c2097
Author: Houston Putman <ho...@apache.org>
AuthorDate: Thu Sep 22 14:29:58 2022 -0400

    SOLR-16426: LBHttp2SolrClient now passes info to child client. (#1036)
    
    (cherry picked from commit f97264ada4349dfe5c95733e7193cbcedad6914f)
---
 solr/CHANGES.txt                                   |   2 +
 .../solr/client/solrj/impl/Http2SolrClient.java    |   4 +
 .../solr/client/solrj/impl/LBHttp2SolrClient.java  |  29 +++++-
 .../client/solrj/impl/LBHttp2SolrClientTest.java   | 113 +++++++++++++++++++++
 4 files changed, 147 insertions(+), 1 deletion(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 558f813e7f1..e5c293b6ed7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -137,6 +137,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.java
index 8db33b4125e..d2cef8b7667 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
@@ -848,6 +848,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.java
index 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.java
new file mode 100644
index 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());
+    }
+  }
+}