You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/12/03 00:48:02 UTC

[GitHub] [solr] epugh opened a new pull request, #1211: SOLR-8975: Use Builder Pattern with Solr Clients

epugh opened a new pull request, #1211:
URL: https://github.com/apache/solr/pull/1211

   https://issues.apache.org/jira/browse/SOLR-8975
   
   Please note, this was originally https://github.com/apache/solr/pull/1158, however we had a different JIRA open that more accurately reflected this work.  So I closed and reopened a new branch.
   
   # Description
   
   
   Now that builders are in place for SolrClients, the setters used in each SolrClient can be deprecated, and their functionality moved over to the Builders. This change brings a few benefits:
   
       * unifies SolrClient configuration under the new Builders. It'll be nice to have all the knobs, and levers used to tweak SolrClients available in a single place (the Builders).
       * reduces SolrClient thread-safety concerns. Currently, clients are mutable. Using some SolrClient setters can result in erratic and "trappy" behavior when the clients are used across multiple threads.
   
   Proposed Commit message is:
   
   ```
   Introduce Builder Pattern with all Solr Clients
   ```
   
   and
   ```
   Deprecate all setters on Solr Clients, and introduce equivalents on the Builders.  Migrate tests to using Builders.  Use the try/with resources pattern when creating SolrClients in the tests.
   ``
   
   # Solution
   
   Added Builders where approapriate, and moved over tests to using the builders.   Did not remove any of the deprecated code.   And there are definitly some place still in the tests that need more work when we remove deprecated methods.
   
   # Tests
   ran the tests.
   
   # Checklist
   
   Please review the following and check all that apply:
   
   - [ x] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms to the standards described there to the best of my ability.
   - [x ] I have created a Jira issue and added the issue ID to my pull request title.
   - [ x] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
   - [x ] I have developed this patch against the `main` branch.
   - [ x] I have run `./gradlew check`.
   - [ x] I have added tests for my changes.
   - [ ] I have added documentation for the [Reference Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039703254


##########
solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java:
##########
@@ -102,18 +102,23 @@ public void showExceptions() throws Exception {
 
   @Test
   public void testWithXml() throws Exception {
-    HttpSolrClient client = (HttpSolrClient) getSolrClient();
-    client.setRequestWriter(new RequestWriter());
-    client.deleteByQuery("*:*"); // delete everything!
-    doIt(client);
+    try (SolrClient client =

Review Comment:
   Same point as previous ;-).    I could imagine the getSolrClient() method being removed if we go with try/with resources everywhere.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039704639


##########
solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java:
##########
@@ -534,16 +534,15 @@ public SortedMap<Class<? extends Filter>, String> getExtraRequestFilters() {
   }
 
   protected SolrClient createNewSolrClient(int port) {
-    try {
-      // setup the client...
-      String baseUrl = buildUrl(port);
-      if (baseUrl.endsWith("/")) {
-        return getHttpSolrClient(baseUrl + DEFAULT_TEST_CORENAME);
-      } else {
-        return getHttpSolrClient(baseUrl + "/" + DEFAULT_TEST_CORENAME);
-      }
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
+    return getHttpSolrClient(getServerUrl(port));
+  }
+
+  protected String getServerUrl(int port) {

Review Comment:
   Do you want this change in this PR?   I was thinking this might be nice clean up in the next one.....  Oh, and I like the name...   getSolrRootUrl and getSolrWithCollectionUrl???



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039797943


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {

Review Comment:
   should this be 'protected' instead of 'public'?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1339216936

   I'd love a candidate change log....    The one I proposed was based on the review input...   I could also instead use the text from the proposed commit message.....


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039879271


##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2871,10 +2871,30 @@ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
     return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
   }
 
+  /** This method creates a HttpClient from a URL. */
+  public static HttpClient getHttpClient(String url) {
+    return new HttpSolrClient.Builder(url).build().getHttpClient();
+  }
+
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   */

Review Comment:
   i actually did just that, and then took all of those changes out based on review feedback.    Part of why I want to get this merged is cause I can't remember all the twists and turns we've made, and so I'ld love to get this in, and then in the next one revisit moving to Http2SolrClient etc...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039812882


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {
+    super(baseSolrUrls);
+    this.httpClient = httpClient;
+    if (builder.responseParser != null) {
+      this.parser = builder.responseParser;
+    }
+    if (builder.requestWriter != null) {
+      this.httpClient.setRequestWriter(builder.requestWriter);
+    }
+  }
+
   @Override
   protected SolrClient getClient(String baseUrl) {
     return httpClient;
   }
 
+  /**
+   * Note: This setter method is <b>not thread-safe</b>.
+   *
+   * @param parser Default Response Parser chosen to parse the response if the parser were not
+   *     specified as part of the request.
+   * @see org.apache.solr.client.solrj.SolrRequest#getResponseParser()
+   * @deprecated use {@link LBHttp2SolrClient.Builder#withResponseParser(ResponseParser)} instead
+   */
+  @Deprecated
   @Override
   public void setParser(ResponseParser parser) {
     super.setParser(parser);
     this.httpClient.setParser(parser);
   }
 
+  @Override
+  public ResponseParser getParser() {
+    return httpClient.getParser();

Review Comment:
   this `getParser()` method overrides the one in the super class, then there is no need for the `super.setParser(parser);` on line 119 above. I would actually mark the LBSolrClient#setParser() method as deprecated too, to convey a clearer message. (and actually same for requestWriter)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1040002378


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {

Review Comment:
   could you explain a bit? I am not seeing the visibility change on the constructor (I am seeing the builder removal)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1038808801


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java:
##########
@@ -132,6 +141,8 @@ public static class Builder {
     protected boolean parallelUpdates = true;
     protected ClusterStateProvider stateProvider;
     protected Http2SolrClient.Builder internalClientBuilder;
+    private RequestWriter requestWriter;
+    private ResponseParser responseParser;

Review Comment:
   In your commit message & CHANGES.txt, call this out explicitly.  e.g.: CloudHttp2SolrClient.Builder now has setters for the request writer & responseParser.



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java:
##########
@@ -28,8 +30,12 @@
 
   protected HttpClient httpClient;
   protected ResponseParser responseParser;
+  protected RequestWriter requestWriter;
+  protected boolean useMultiPartPost;
   protected Integer connectionTimeoutMillis = 15000;
   protected Integer socketTimeoutMillis = 120000;
+  protected boolean followRedirects = false;
+  protected Set<String> queryParams;

Review Comment:
   more stuff to explicitly call out in CHANGES.txt



##########
solr/solrj/src/test/org/apache/solr/client/solrj/TestBatchUpdate.java:
##########
@@ -46,61 +46,68 @@ public static void beforeTest() throws Exception {
 
   @Test
   public void testWithXml() throws Exception {
-    HttpSolrClient client = (HttpSolrClient) getSolrClient();
-    client.setRequestWriter(new RequestWriter());
-    client.deleteByQuery("*:*"); // delete everything!
-    doIt(client);
+    try (SolrClient client =
+        new HttpSolrClient.Builder(getServerUrl()).withRequestWriter(new RequestWriter()).build()) {
+      client.deleteByQuery("*:*"); // delete everything!
+      doIt(client);
+    }

Review Comment:
   Hmm; I'm wondering why this code was specifying HttpSolrClient and why was it specifying a new RequestWriter.  Do you know?  Preferably it would do neither and continue to call getSolrClient vs your change to create a new one.



##########
solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java:
##########
@@ -116,8 +116,10 @@ public void testNoUrlAccess() throws Exception {
     SolrQuery query = new SolrQuery();
     query.setQuery("*:*"); // for anything
     query.add("stream.url", makeDeleteAllUrl());
-    SolrException se = expectThrows(SolrException.class, () -> getSolrClient().query(query));
-    assertSame(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode(se.code()));
+    try (SolrClient solrClient = getHttpSolrClient(getServerUrl())) {

Review Comment:
   What was wrong with it before?  Now it depends on Http.



##########
solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java:
##########
@@ -32,19 +35,13 @@ public static void beforeTest() throws Exception {
 
   @Override
   public SolrClient createNewSolrClient() {
-    try {
-      // setup the server...
-      String url = jetty.getBaseUrl().toString() + "/collection1";
-      HttpSolrClient client = getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT);
-      client.setUseMultiPartPost(random().nextBoolean());
+    HttpSolrClient.Builder httpSolrClientBuilder = new HttpSolrClient.Builder(getServerUrl());

Review Comment:
   minor: I don't think you need to declare any variables in this method; just a one-liner to return.  Variables need names, add verbosity, lines of code etc.



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -258,4 +299,32 @@ public void onFailure(Throwable oe) {
               }
             });
   }
+
+  public static class Builder {
+    private final Http2SolrClient http2Client;
+    private final String[] baseSolrUrls;
+    private ResponseParser responseParser;
+    private RequestWriter requestWriter;
+
+    public Builder(Http2SolrClient http2Client, String... baseSolrUrls) {
+      this.http2Client = http2Client;
+      this.baseSolrUrls = baseSolrUrls;
+    }
+
+    /** Provides a {@link ResponseParser} for created clients to use when handling requests. */
+    public LBHttp2SolrClient.Builder withResponseParser(ResponseParser responseParser) {
+      this.responseParser = responseParser;
+      return this;
+    }
+
+    /** Provides a {@link RequestWriter} for created clients to use when handing requests. */
+    public LBHttp2SolrClient.Builder withRequestWriter(RequestWriter requestWriter) {
+      this.requestWriter = requestWriter;
+      return this;
+    }

Review Comment:
   Question: do we actually use response parsers/writers that are *different* on this LB instance than that of the Http2SolrClient it delegates to?



##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java:
##########
@@ -120,72 +112,22 @@ public void testUtf8PerfDegradation() throws Exception {
     doc.addField("id", "1");
     doc.addField("b_is", IntStream.range(0, 30000).boxed().collect(Collectors.toList()));
 
-    HttpSolrClient client = (HttpSolrClient) getSolrClient();
-    client.add(doc);
-    client.commit();
-    long start = System.nanoTime();
-    QueryResponse rsp = client.query(new SolrQuery("*:*"));
-    System.out.println("time taken : " + ((System.nanoTime() - start)) / (1000 * 1000));
-    assertEquals(1, rsp.getResults().getNumFound());
-  }
-
-  @Ignore
-  public void testUtf8QueryPerf() throws Exception {

Review Comment:
   deleted because?



##########
solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java:
##########
@@ -34,19 +37,15 @@ public static void beforeTest() throws Exception {
 
   @Override
   public SolrClient createNewSolrClient() {
-    try {
-      // setup the server...
-      String url = jetty.getBaseUrl().toString() + "/collection1";
-      Http2SolrClient client =
-          new Http2SolrClient.Builder(url).connectionTimeout(DEFAULT_CONNECTION_TIMEOUT).build();
-
-      // where the magic happens
-      client.setParser(new BinaryResponseParser());
-      client.setRequestWriter(new BinaryRequestWriter());
+    String url = jetty.getBaseUrl().toString() + "/collection1";
+    Http2SolrClient client =
+        new Http2SolrClient.Builder(url)
+            .connectionTimeout(DEFAULT_CONNECTION_TIMEOUT)
+            .withRequestWriter(new BinaryRequestWriter())
+            // where the magic happens
+            .withResponseParser(new BinaryResponseParser())
+            .build();
 
-      return client;
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
-    }
+    return client;

Review Comment:
   super minor but it's no longer necessary to declare a field and separately return it. Return directly -- less typing, one less variable to name :-)



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java:
##########
@@ -62,6 +64,12 @@ protected CloudHttp2SolrClient(Builder builder) {
       this.clientIsInternal = false;
       this.myClient = builder.httpClient;
     }
+    if (builder.requestWriter != null) {
+      this.myClient.setRequestWriter(builder.requestWriter); // should be part of builder

Review Comment:
   What do you mean by "should be part of builder" -- it *is* (thanks to you); no?



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java:
##########
@@ -854,6 +858,7 @@ public static class Builder extends SolrClientBuilder<Builder> {
     protected String baseSolrUrl;
     protected int queueSize = 10;
     protected int threadCount;
+    protected int pollQueueTime;

Review Comment:
   again, lets call this out in CHANGES.txt



##########
solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java:
##########
@@ -476,9 +484,20 @@ public void testUpdate() throws Exception {
       // parameter encoding
       assertEquals(1, DebugServlet.parameters.get("a").length);
       assertEquals("\u1234", DebugServlet.parameters.get("a")[0]);
+    }
+    DebugServlet.clear();
+    // XML response and writer
+    try (HttpSolrClient client =
+        new HttpSolrClient.Builder(url)
+            .withRequestWriter(new RequestWriter())
+            .withResponseParser(new XMLResponseParser())
+            .build()) {
+      UpdateRequest req = new UpdateRequest();
+      req.add(new SolrInputDocument());
+      req.setParam("a", "\u1234");
 
-      // XML response and writer
-      client.setParser(new XMLResponseParser());
+      // Have not been able to move this to the Builder pattern, the below check for application/xml
+      // always returns as application/javabin when .setRequestWriter() is commented out.

Review Comment:
   BTW needs to be called out as a "nocommit" (for discussion; not necessarily stays this way) so we draw attention to this in a big PR



##########
solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java:
##########
@@ -102,18 +102,23 @@ public void showExceptions() throws Exception {
 
   @Test
   public void testWithXml() throws Exception {
-    HttpSolrClient client = (HttpSolrClient) getSolrClient();
-    client.setRequestWriter(new RequestWriter());
-    client.deleteByQuery("*:*"); // delete everything!
-    doIt(client);
+    try (SolrClient client =

Review Comment:
   same as my last comment



##########
solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java:
##########
@@ -132,20 +132,14 @@ public void testFieldMutating() throws Exception {
 
   @Override
   public SolrClient createNewSolrClient() {
-    try {
-      // setup the server...
-      String url = jetty.getBaseUrl().toString() + "/collection1";
-      HttpSolrClient client = getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT);
-      client.setUseMultiPartPost(random().nextBoolean());
-
-      if (random().nextBoolean()) {
-        client.setParser(new BinaryResponseParser());
-        client.setRequestWriter(new BinaryRequestWriter());
-      }
-
-      return client;
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
+    HttpSolrClient.Builder httpSolrClientBuilder = new HttpSolrClient.Builder(getServerUrl());

Review Comment:
   getServerUrl I assume doesn't have "/collection1" in it, or at least shouldn't?



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java:
##########
@@ -174,11 +174,18 @@ protected Http2SolrClient(String serverBaseUrl, Builder builder) {
     } else {
       basicAuthAuthorizationStr = null;
     }
+    if (builder.requestWriter != null) {

Review Comment:
   again, lets call this out in CHANGES.txt



##########
solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java:
##########
@@ -599,25 +599,9 @@ public void testUnicode() throws Exception {
     Random random = random();
     int numIterations = atLeast(3);
 
-    SolrClient client = getSolrClient();
-
-    // save the old parser, so we can set it back.
-    ResponseParser oldParser = null;
-    if (client instanceof HttpSolrClient) {
-      HttpSolrClient httpSolrClient = (HttpSolrClient) client;
-      oldParser = httpSolrClient.getParser();
-    }
+    try (SolrClient client = getSolrClient()) {
 
-    try {
       for (int iteration = 0; iteration < numIterations; iteration++) {
-        // choose format
-        if (client instanceof HttpSolrClient) {
-          if (random.nextBoolean()) {
-            ((HttpSolrClient) client).setParser(new BinaryResponseParser());
-          } else {
-            ((HttpSolrClient) client).setParser(new XMLResponseParser());
-          }

Review Comment:
   So we're losing randomized testing of some things?  Okay but just confirming this loss was deliberate because...?



##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2871,10 +2871,30 @@ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
     return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
   }
 
+  /** This method creates a HttpClient from a URL. */
+  public static HttpClient getHttpClient(String url) {
+    return new HttpSolrClient.Builder(url).build().getHttpClient();
+  }
+
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   */

Review Comment:
   again; deprecated and suggest clients simply *don't* use Apache HttpClient?



##########
solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java:
##########
@@ -534,16 +534,15 @@ public SortedMap<Class<? extends Filter>, String> getExtraRequestFilters() {
   }
 
   protected SolrClient createNewSolrClient(int port) {
-    try {
-      // setup the client...
-      String baseUrl = buildUrl(port);
-      if (baseUrl.endsWith("/")) {
-        return getHttpSolrClient(baseUrl + DEFAULT_TEST_CORENAME);
-      } else {
-        return getHttpSolrClient(baseUrl + "/" + DEFAULT_TEST_CORENAME);
-      }
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
+    return getHttpSolrClient(getServerUrl(port));
+  }
+
+  protected String getServerUrl(int port) {

Review Comment:
   Can we please call this getSolrWithCollectionUrl or something like that to indicate it contains a collection in there?  The word "serverUrl" by itself suggests it points to the root of a Solr node, not to a particular collection there.



##########
solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java:
##########
@@ -129,6 +129,10 @@ public static JettySolrRunner createAndStartJetty(
     return jetty;
   }
 
+  protected String getServerUrl() {

Review Comment:
   Same as last comment



##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2886,28 +2906,25 @@ public static HttpSolrClient getHttpSolrClient(
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
    */
   public static HttpSolrClient getHttpSolrClient(
       String url, HttpClient httpClient, ResponseParser responseParser) {
     return new Builder(url).withHttpClient(httpClient).withResponseParser(responseParser).build();
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
    */
   public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient) {
     return new Builder(url).withHttpClient(httpClient).build();
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly

Review Comment:
   Did we discuss this overall change of direction away from randomization?  I brought this in once so I'm biased :-)



##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2871,10 +2871,30 @@ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
     return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
   }
 
+  /** This method creates a HttpClient from a URL. */
+  public static HttpClient getHttpClient(String url) {
+    return new HttpSolrClient.Builder(url).build().getHttpClient();
+  }

Review Comment:
   The direction our project is going in is to move away from Apache HttpClient.  Here you add a new utility method on SolrTestCaseJ4.  Maybe mark this deprecated?



##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2871,10 +2871,30 @@ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
     return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
   }
 
+  /** This method creates a HttpClient from a URL. */
+  public static HttpClient getHttpClient(String url) {
+    return new HttpSolrClient.Builder(url).build().getHttpClient();
+  }
+
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   */
+  public static HttpSolrClient getHttp1SolrClient(String url) {
+    return new HttpSolrClient.Builder(url).build();
+  }
+
+  /**
+   * This method creates a basic Http2SolrClient. Tests that want to control the creation process

Review Comment:
   There's a Javadoc style guide I once saw where, in this first sentence, avoid saying "this method" or "this class".  get immediately to the point, probably with a verb "Creates ...".  And avoid being obvious, as this is.  this creates a clients based on Jetty HttpClient which supports not only HTTP 2 but HTTP 1.1 as well



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039703992


##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java:
##########
@@ -120,72 +112,22 @@ public void testUtf8PerfDegradation() throws Exception {
     doc.addField("id", "1");
     doc.addField("b_is", IntStream.range(0, 30000).boxed().collect(Collectors.toList()));
 
-    HttpSolrClient client = (HttpSolrClient) getSolrClient();
-    client.add(doc);
-    client.commit();
-    long start = System.nanoTime();
-    QueryResponse rsp = client.query(new SolrQuery("*:*"));
-    System.out.println("time taken : " + ((System.nanoTime() - start)) / (1000 * 1000));
-    assertEquals(1, rsp.getResults().getNumFound());
-  }
-
-  @Ignore
-  public void testUtf8QueryPerf() throws Exception {

Review Comment:
   cause it was marked @Ignore......   I could put it back in...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039717680


##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2886,28 +2906,25 @@ public static HttpSolrClient getHttpSolrClient(
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
    */
   public static HttpSolrClient getHttpSolrClient(
       String url, HttpClient httpClient, ResponseParser responseParser) {
     return new Builder(url).withHttpClient(httpClient).withResponseParser(responseParser).build();
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
    */
   public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient) {
     return new Builder(url).withHttpClient(httpClient).build();
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly

Review Comment:
   I don't think we did....  This change was to make sure the docs reflect the actual code..   Unless I misread the code, it actually doesn't do any randomization!   
   
   I do think that there is room to rethink adding randomization into tests, right now it's a werid mix of some un random and some random...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039646202


##########
solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java:
##########
@@ -116,8 +116,10 @@ public void testNoUrlAccess() throws Exception {
     SolrQuery query = new SolrQuery();
     query.setQuery("*:*"); // for anything
     query.add("stream.url", makeDeleteAllUrl());
-    SolrException se = expectThrows(SolrException.class, () -> getSolrClient().query(query));
-    assertSame(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode(se.code()));
+    try (SolrClient solrClient = getHttpSolrClient(getServerUrl())) {

Review Comment:
   so, there was a discussion that we should always use the try/with resources pattern with SolrClient...   So I moved in the direction, with maybe the idea that the SolrJettyTestBase.getSolrClient() might go away, because we would always create our own and then close it, instead of having the base test class provide one and be responsible for it...   
   
   There is the createNewSolrClient method, so I am swapping to that.    
   
   We do need a better policy, ideally written down and/or code checked on if we use base classes to manage lifecycle of SolrClient in tests or do the try/with resources...
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039858105


##########
solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java:
##########
@@ -534,16 +534,15 @@ public SortedMap<Class<? extends Filter>, String> getExtraRequestFilters() {
   }
 
   protected SolrClient createNewSolrClient(int port) {
-    try {
-      // setup the client...
-      String baseUrl = buildUrl(port);
-      if (baseUrl.endsWith("/")) {
-        return getHttpSolrClient(baseUrl + DEFAULT_TEST_CORENAME);
-      } else {
-        return getHttpSolrClient(baseUrl + "/" + DEFAULT_TEST_CORENAME);
-      }
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
+    return getHttpSolrClient(getServerUrl(port));
+  }
+
+  protected String getServerUrl(int port) {

Review Comment:
   For a new PR is fine; thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039938801


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {

Review Comment:
   @epugh raising this comment for your review, in case it got lost



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039812882


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {
+    super(baseSolrUrls);
+    this.httpClient = httpClient;
+    if (builder.responseParser != null) {
+      this.parser = builder.responseParser;
+    }
+    if (builder.requestWriter != null) {
+      this.httpClient.setRequestWriter(builder.requestWriter);
+    }
+  }
+
   @Override
   protected SolrClient getClient(String baseUrl) {
     return httpClient;
   }
 
+  /**
+   * Note: This setter method is <b>not thread-safe</b>.
+   *
+   * @param parser Default Response Parser chosen to parse the response if the parser were not
+   *     specified as part of the request.
+   * @see org.apache.solr.client.solrj.SolrRequest#getResponseParser()
+   * @deprecated use {@link LBHttp2SolrClient.Builder#withResponseParser(ResponseParser)} instead
+   */
+  @Deprecated
   @Override
   public void setParser(ResponseParser parser) {
     super.setParser(parser);
     this.httpClient.setParser(parser);
   }
 
+  @Override
+  public ResponseParser getParser() {
+    return httpClient.getParser();

Review Comment:
   this `getParser()` method overrides the one in the super class, then there is no need for the `super.setParser(parser);` on line 119 above. I would actually mark the LBSolrClient#setParser() method as deprecated too, to convey a clearer message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039871082


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {
+    super(baseSolrUrls);
+    this.httpClient = httpClient;
+    if (builder.responseParser != null) {
+      this.parser = builder.responseParser;
+    }
+    if (builder.requestWriter != null) {
+      this.httpClient.setRequestWriter(builder.requestWriter);
+    }
+  }
+
   @Override
   protected SolrClient getClient(String baseUrl) {
     return httpClient;
   }
 
+  /**
+   * Note: This setter method is <b>not thread-safe</b>.
+   *
+   * @param parser Default Response Parser chosen to parse the response if the parser were not
+   *     specified as part of the request.
+   * @see org.apache.solr.client.solrj.SolrRequest#getResponseParser()
+   * @deprecated use {@link LBHttp2SolrClient.Builder#withResponseParser(ResponseParser)} instead
+   */
+  @Deprecated
   @Override
   public void setParser(ResponseParser parser) {
     super.setParser(parser);
     this.httpClient.setParser(parser);
   }
 
+  @Override
+  public ResponseParser getParser() {
+    return httpClient.getParser();

Review Comment:
   Okay, so, just to be clear, I'm going to remove those two methods on the LBSolrClient...    In this PR ;-).     I like removing code!!!!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039715151


##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2871,10 +2871,30 @@ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
     return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
   }
 
+  /** This method creates a HttpClient from a URL. */
+  public static HttpClient getHttpClient(String url) {
+    return new HttpSolrClient.Builder(url).build().getHttpClient();
+  }
+
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   */
+  public static HttpSolrClient getHttp1SolrClient(String url) {
+    return new HttpSolrClient.Builder(url).build();
+  }
+
+  /**
+   * This method creates a basic Http2SolrClient. Tests that want to control the creation process

Review Comment:
   I checked, and a LOT of these methods are used by 1 test class...   In the next PR, I'd like to just remove these not very much used at all helper methods.  I think they are more confusing to the the test author then helpful....



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039832255


##########
solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java:
##########
@@ -116,8 +116,10 @@ public void testNoUrlAccess() throws Exception {
     SolrQuery query = new SolrQuery();
     query.setQuery("*:*"); // for anything
     query.add("stream.url", makeDeleteAllUrl());
-    SolrException se = expectThrows(SolrException.class, () -> getSolrClient().query(query));
-    assertSame(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode(se.code()));
+    try (SolrClient solrClient = getHttpSolrClient(getServerUrl())) {

Review Comment:
   If you have a *new* SolrClient, then yes -- we should use try-with-resources.  Ideally any utility methods that create a new one would have "create" or "new" in their name; alas this isn't true.  If you have some SolrClient managed by test infrastructure somehow, then there we shouldn't close it.  I don't think we should mandate either path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039855030


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -258,4 +299,32 @@ public void onFailure(Throwable oe) {
               }
             });
   }
+
+  public static class Builder {
+    private final Http2SolrClient http2Client;
+    private final String[] baseSolrUrls;
+    private ResponseParser responseParser;
+    private RequestWriter requestWriter;
+
+    public Builder(Http2SolrClient http2Client, String... baseSolrUrls) {
+      this.http2Client = http2Client;
+      this.baseSolrUrls = baseSolrUrls;
+    }
+
+    /** Provides a {@link ResponseParser} for created clients to use when handling requests. */
+    public LBHttp2SolrClient.Builder withResponseParser(ResponseParser responseParser) {
+      this.responseParser = responseParser;
+      return this;
+    }
+
+    /** Provides a {@link RequestWriter} for created clients to use when handing requests. */
+    public LBHttp2SolrClient.Builder withRequestWriter(RequestWriter requestWriter) {
+      this.requestWriter = requestWriter;
+      return this;
+    }

Review Comment:
   Yes; I think @stillalex identified this as well just now.  I left a comment a minute ago that I hope succinctly makes the point:
   > In general, we don't want fields on LBSolrClient and its subclasses (there are two) that are redundant with that of the client/builder it delegates to. It'll add confusion as to which one is real/used vs shadowed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1338126326

   > > > I'm going to remove those two methods on the LBSolrClient
   > > 
   > > 
   > > sorry, I am not seeing any changes in LBSolrClient, if not removing maybe marking as deprecated for future removal.
   > 
   > are you saying we would expect the method `public void setParser(ResponseParser parser)` to be marked deprecated?
   
   Just pushed up a commit for this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039660985


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java:
##########
@@ -62,6 +64,12 @@ protected CloudHttp2SolrClient(Builder builder) {
       this.clientIsInternal = false;
       this.myClient = builder.httpClient;
     }
+    if (builder.requestWriter != null) {
+      this.myClient.setRequestWriter(builder.requestWriter); // should be part of builder

Review Comment:
   duh!   I remember thinking "gosh darn it, something is off", and yes, you are totally correct...!    Doh!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039635774


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java:
##########
@@ -132,6 +141,8 @@ public static class Builder {
     protected boolean parallelUpdates = true;
     protected ClusterStateProvider stateProvider;
     protected Http2SolrClient.Builder internalClientBuilder;
+    private RequestWriter requestWriter;
+    private ResponseParser responseParser;

Review Comment:
   Adding proposed commit message, thanks for this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039667900


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -258,4 +299,32 @@ public void onFailure(Throwable oe) {
               }
             });
   }
+
+  public static class Builder {
+    private final Http2SolrClient http2Client;
+    private final String[] baseSolrUrls;
+    private ResponseParser responseParser;
+    private RequestWriter requestWriter;
+
+    public Builder(Http2SolrClient http2Client, String... baseSolrUrls) {
+      this.http2Client = http2Client;
+      this.baseSolrUrls = baseSolrUrls;
+    }
+
+    /** Provides a {@link ResponseParser} for created clients to use when handling requests. */
+    public LBHttp2SolrClient.Builder withResponseParser(ResponseParser responseParser) {
+      this.responseParser = responseParser;
+      return this;
+    }
+
+    /** Provides a {@link RequestWriter} for created clients to use when handing requests. */
+    public LBHttp2SolrClient.Builder withRequestWriter(RequestWriter requestWriter) {
+      this.requestWriter = requestWriter;
+      return this;
+    }

Review Comment:
   are you suggesting that maybe these methods aren't actually needed?  because you would never set them in the LBHttp2SolrClient, you would do this in the Http2SolrClient that underlies it?   That does intuitively make sense...   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039698417


##########
solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java:
##########
@@ -132,20 +132,14 @@ public void testFieldMutating() throws Exception {
 
   @Override
   public SolrClient createNewSolrClient() {
-    try {
-      // setup the server...
-      String url = jetty.getBaseUrl().toString() + "/collection1";
-      HttpSolrClient client = getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT);
-      client.setUseMultiPartPost(random().nextBoolean());
-
-      if (random().nextBoolean()) {
-        client.setParser(new BinaryResponseParser());
-        client.setRequestWriter(new BinaryRequestWriter());
-      }
-
-      return client;
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
+    HttpSolrClient.Builder httpSolrClientBuilder = new HttpSolrClient.Builder(getServerUrl());

Review Comment:
   getServerUrl definitly does assume collection1...   I'd like, in the next PR, to tackle the whole naming thing...   When to use DEFAULT_TEST_CORENAME, DEFAULT_TEST_COLLECTION_NAME...   make both DEFAULTS_* have the same pattern...  CORENAME versus COLLECTION_NAME...   and maybe rename getServerUrl to soemthing else...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1337579391

   @dsmiley I think I've responded to all your comments, thanks for doing that.   The only i think big outstanding issue is the question about the two LB clients...   Does it ever make sense to configure the requestwriter and responseparser on the LB?  when you literally pass in a HttpSolrClient or Http2SolrClient?
   
   The only place we use withRequestWriter or withResponseParser is in the unit tests.   Do you think I should rip that stuff out?
   
   
   In future PR's I'd like to tackle:
   
   * Fix the getServerUrl stuff, and the confusion over a root url and a /collection1 url.
   * Change getHttpClient to be the Jetty HttpClient
   * Go through the various createHttpClient helpers and see if we need all of them, or if only used by one class, move it there.  Or even remove them in favour of the try/with resources and builders in our methods...
   * Get rid of the deprecated methods on the various Clients.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1338033643

   > I'm going to remove those two methods on the LBSolrClient
   
   sorry, I am not seeing any changes in LBSolrClient, if not removing maybe marking as deprecated for future removal.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1040052738


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {

Review Comment:
   Humm...  I may be getting confused...    (honestly, if you want to push up a commit, I'd love to see it!).   Right now on `LBHttpSolrClient` we have `protected LBHttpSolrClient(Builder builder)` and that's it...      On `LBHttp2SolrClient` we have the deprecated `public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) ` and `private LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls)` methods...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039860132


##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2871,10 +2871,30 @@ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
     return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
   }
 
+  /** This method creates a HttpClient from a URL. */
+  public static HttpClient getHttpClient(String url) {
+    return new HttpSolrClient.Builder(url).build().getHttpClient();
+  }
+
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   */

Review Comment:
   HttpSolrClient and CloudLegacySolrClient are already deprecated and many methods that return them are likewise.  It's not clear to me why tests can't use the Http2 (Jetty) one; can you tell me?



##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2871,10 +2871,30 @@ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
     return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
   }
 
+  /** This method creates a HttpClient from a URL. */
+  public static HttpClient getHttpClient(String url) {
+    return new HttpSolrClient.Builder(url).build().getHttpClient();
+  }
+
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   */
+  public static HttpSolrClient getHttp1SolrClient(String url) {
+    return new HttpSolrClient.Builder(url).build();
+  }
+
+  /**
+   * This method creates a basic Http2SolrClient. Tests that want to control the creation process

Review Comment:
   Fantastic; thanks.  Reduction of stuff from STCJ4 is helpful to a direction I'm doing with @joshgog in [SOLR-11872](https://issues.apache.org/jira/browse/SOLR-11872)



##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2886,28 +2906,25 @@ public static HttpSolrClient getHttpSolrClient(
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
    */
   public static HttpSolrClient getHttpSolrClient(
       String url, HttpClient httpClient, ResponseParser responseParser) {
     return new Builder(url).withHttpClient(httpClient).withResponseParser(responseParser).build();
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
    */
   public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient) {
     return new Builder(url).withHttpClient(httpClient).build();
   }
 
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly

Review Comment:
   Huh; I see you are correct.  But we do want randomization; adding it here would be out of scope really.  I suppose the javadoc changes are okay although I'd prefer to leave the javadoc be.  It uses the word *may* randomize.  A core idea of the randomized testing philosophy is that tests use random-ishly configured implementations/settings that a test shouldn't care about.  Very few tests should fundamentally care about Apache vs Jetty clients, HTTP2 vs HTTP1.1, etc..  Our tests already do similar randomization for other things, like the underlying Lucene Directory implementation.  Ideally these utility methods would simply return SolrClient but I understand there may be too many tests that can accept that today, and would be out of scope here any way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039797943


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {

Review Comment:
   should this be 'protected' instead of 'public'?
   also you could consider marking the existing constructor as Deprecated, if you want to move to Builder only patterns, no one should call it directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1338116411

   > > I'm going to remove those two methods on the LBSolrClient
   > 
   > sorry, I am not seeing any changes in LBSolrClient, if not removing maybe marking as deprecated for future removal.
   
   are you saying we would expect the method `public void setParser(ResponseParser parser)` to be marked deprecated?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
dsmiley commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1338673045

   It would be nice if the scope of this PR could be clearer -- like the setters (... specify here ...) on all SolrClients are now supported on the Builder of these SolrClients, and their setters are deprecated.  Then stick to this scope and do other things in other PRs.  Then you needn't list how some specific clients changed; it's kind of a needless detail I suppose.  This might not lead to an actual change on this PR; the test changes are fine?  My goal is communicating clearly to users (and us) what happened here).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh merged pull request #1211: SOLR-8975: Use Builder Setters with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh merged PR #1211:
URL: https://github.com/apache/solr/pull/1211


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1337884722

   Okay @stillalex and @dsmiley ...  Thoughts now?  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1339215598

   `./gradlew test` completed successfully.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039711167


##########
solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java:
##########
@@ -2871,10 +2871,30 @@ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
     return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
   }
 
+  /** This method creates a HttpClient from a URL. */
+  public static HttpClient getHttpClient(String url) {
+    return new HttpSolrClient.Builder(url).build().getHttpClient();
+  }
+
   /**
-   * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
-   * not wish to have any randomized behavior should use the {@link
-   * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   * This method creates a basic HttpSolrClient. Tests that want to control the creation process
+   * should use the {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+   */

Review Comment:
   makes sense.   adding language..  I don't have a recommendation of what to move too since we aren't I think quite there yet...  future PR move everyone to the jetty httpclient?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039737488


##########
solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java:
##########
@@ -476,9 +484,20 @@ public void testUpdate() throws Exception {
       // parameter encoding
       assertEquals(1, DebugServlet.parameters.get("a").length);
       assertEquals("\u1234", DebugServlet.parameters.get("a")[0]);
+    }
+    DebugServlet.clear();
+    // XML response and writer
+    try (HttpSolrClient client =
+        new HttpSolrClient.Builder(url)
+            .withRequestWriter(new RequestWriter())
+            .withResponseParser(new XMLResponseParser())
+            .build()) {
+      UpdateRequest req = new UpdateRequest();
+      req.add(new SolrInputDocument());
+      req.setParam("a", "\u1234");
 
-      // XML response and writer
-      client.setParser(new XMLResponseParser());
+      // Have not been able to move this to the Builder pattern, the below check for application/xml
+      // always returns as application/javabin when .setRequestWriter() is commented out.

Review Comment:
   thanks for calling this out.   With fresh eyes, I realized, the test was failing PROPERLY, as the code wasn't right...   So I fixed it finally.  Phew, it would have been an annoying bug.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039994242


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {

Review Comment:
   Okay, check out the latest ocmmit @stillalex  ;-)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1338148884

   looks good to me!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] sonatype-lift[bot] commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
sonatype-lift[bot] commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1038659135


##########
solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java:
##########
@@ -2165,46 +2165,14 @@ protected SolrClient createNewSolrClient(int port) {
     return createNewSolrClient(DEFAULT_COLLECTION, port);
   }
 
-  protected SolrClient createNewSolrClient(
-      int port, int connectionTimeoutMillis, int socketTimeoutMillis) {
-    return createNewSolrClient(
-        DEFAULT_COLLECTION, port, connectionTimeoutMillis, socketTimeoutMillis);
-  }
-
   protected SolrClient createNewSolrClient(String coreName, int port) {
-    try {
-      // setup the server...
-      String baseUrl = buildUrl(port);
-      String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + coreName;
-      SolrClient client = getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT, 60000);
-      return client;
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
-    }
-  }
-
-  protected SolrClient createNewSolrClient(
-      String coreName, int port, int connectionTimeoutMillis, int socketTimeoutMillis) {
-    try {
-      // setup the server...
-      String baseUrl = buildUrl(port);
-      String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + coreName;
-      SolrClient client = getHttpSolrClient(url, connectionTimeoutMillis, socketTimeoutMillis);
-      return client;
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
-    }
+    String baseUrl = buildUrl(port);
+    String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + coreName;
+    return getHttpSolrClient(url, DEFAULT_CONNECTION_TIMEOUT, 60000);

Review Comment:
   ![25% of developers fix this issue](https://lift.sonatype.com/api/commentimage/fixrate/25/display.svg)
   
   đŸ’Ŧ 2 similar findings have been found in this PR
   
   ---
   
   *THREAD_SAFETY_VIOLATION:*  Unprotected write. Non-private method `AbstractFullDistribZkTestBase.createNewSolrClient(...)` indirectly mutates container `util.ObjectReleaseTracker.OBJECTS` via call to `Map.put(...)` outside of synchronization.
    Reporting because another access to the same memory occurs on a background thread, although this access may not.
   
   ---
   
   <details><summary><b>🔎 Expand here to view all instances of this finding</b></summary><br/>
   
   <div align="center">
   
   | **File Path** | **Line Number** |
   | ------------- | ------------- |
   | solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java | [2175](https://github.com/epugh/solr/blob/739ae262bf91c1bdd3af58be28fde7e2be7af7c4/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java#L2175)|
   | solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java | [163](https://github.com/epugh/solr/blob/739ae262bf91c1bdd3af58be28fde7e2be7af7c4/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java#L163)|
   <p><a href="https://lift.sonatype.com/results/github.com/apache/solr/01GKAQ8NBQRSMFA45DRC24MRGT?t=Infer|THREAD_SAFETY_VIOLATION" target="_blank">Visit the Lift Web Console</a> to find more details in your report.</p></div></details>
   
   
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=357596458&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=357596458&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=357596458&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=357596458&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=357596458&lift_comment_rating=5) ]



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on PR #1211:
URL: https://github.com/apache/solr/pull/1211#issuecomment-1336167107

   Ran all the tests and they passed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039669909


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java:
##########
@@ -28,8 +30,12 @@
 
   protected HttpClient httpClient;
   protected ResponseParser responseParser;
+  protected RequestWriter requestWriter;
+  protected boolean useMultiPartPost;
   protected Integer connectionTimeoutMillis = 15000;
   protected Integer socketTimeoutMillis = 120000;
+  protected boolean followRedirects = false;
+  protected Set<String> queryParams;

Review Comment:
   added to the proposed changes entry in the github PR description.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039704639


##########
solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java:
##########
@@ -534,16 +534,15 @@ public SortedMap<Class<? extends Filter>, String> getExtraRequestFilters() {
   }
 
   protected SolrClient createNewSolrClient(int port) {
-    try {
-      // setup the client...
-      String baseUrl = buildUrl(port);
-      if (baseUrl.endsWith("/")) {
-        return getHttpSolrClient(baseUrl + DEFAULT_TEST_CORENAME);
-      } else {
-        return getHttpSolrClient(baseUrl + "/" + DEFAULT_TEST_CORENAME);
-      }
-    } catch (Exception ex) {
-      throw new RuntimeException(ex);
+    return getHttpSolrClient(getServerUrl(port));
+  }
+
+  protected String getServerUrl(int port) {

Review Comment:
   Do you want this change in this PR?   I was thinking this might be nice clean up in the next one.....



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039853213


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {
+    super(baseSolrUrls);
+    this.httpClient = httpClient;
+    if (builder.responseParser != null) {
+      this.parser = builder.responseParser;
+    }
+    if (builder.requestWriter != null) {
+      this.httpClient.setRequestWriter(builder.requestWriter);
+    }
+  }
+
   @Override
   protected SolrClient getClient(String baseUrl) {
     return httpClient;
   }
 
+  /**
+   * Note: This setter method is <b>not thread-safe</b>.
+   *
+   * @param parser Default Response Parser chosen to parse the response if the parser were not
+   *     specified as part of the request.
+   * @see org.apache.solr.client.solrj.SolrRequest#getResponseParser()
+   * @deprecated use {@link LBHttp2SolrClient.Builder#withResponseParser(ResponseParser)} instead
+   */
+  @Deprecated
   @Override
   public void setParser(ResponseParser parser) {
     super.setParser(parser);
     this.httpClient.setParser(parser);
   }
 
+  @Override
+  public ResponseParser getParser() {
+    return httpClient.getParser();

Review Comment:
   Yes, you make a great point!  In general, we don't want fields on LBSolrClient and its subclasses (there are two) that are redundant with that of the client/builder it delegates to.  It'll add confusion as to which one is real/used vs shadowed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] epugh commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039702040


##########
solr/solrj/src/test/org/apache/solr/client/solrj/TestBatchUpdate.java:
##########
@@ -46,61 +46,68 @@ public static void beforeTest() throws Exception {
 
   @Test
   public void testWithXml() throws Exception {
-    HttpSolrClient client = (HttpSolrClient) getSolrClient();
-    client.setRequestWriter(new RequestWriter());
-    client.deleteByQuery("*:*"); // delete everything!
-    doIt(client);
+    try (SolrClient client =
+        new HttpSolrClient.Builder(getServerUrl()).withRequestWriter(new RequestWriter()).build()) {
+      client.deleteByQuery("*:*"); // delete everything!
+      doIt(client);
+    }

Review Comment:
   i think this method, if you look at the others, is being explicit...  testWithXML is the method name, and so it's demosntrating that REquestWriter is the XML requestwriter...   We moved all of these to using try/with pattern as well..
   
   DOes that make sense?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1039884568


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -258,4 +299,32 @@ public void onFailure(Throwable oe) {
               }
             });
   }
+
+  public static class Builder {
+    private final Http2SolrClient http2Client;
+    private final String[] baseSolrUrls;
+    private ResponseParser responseParser;
+    private RequestWriter requestWriter;
+
+    public Builder(Http2SolrClient http2Client, String... baseSolrUrls) {
+      this.http2Client = http2Client;
+      this.baseSolrUrls = baseSolrUrls;
+    }
+
+    /** Provides a {@link ResponseParser} for created clients to use when handling requests. */
+    public LBHttp2SolrClient.Builder withResponseParser(ResponseParser responseParser) {
+      this.responseParser = responseParser;
+      return this;
+    }
+
+    /** Provides a {@link RequestWriter} for created clients to use when handing requests. */
+    public LBHttp2SolrClient.Builder withRequestWriter(RequestWriter requestWriter) {
+      this.requestWriter = requestWriter;
+      return this;
+    }

Review Comment:
   there is a lot of overlap with the other discussion thread (I created some of that confusion, sorry). I agree with @dsmiley here. if we don't expect the response parser to be different (which it doesn't look like we do), we can assume the client is already 'well configured' via its own builder and do not expose these extra methods on this builder.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] stillalex commented on a diff in pull request #1211: SOLR-8975: Use Builder Pattern with Solr Clients

Posted by GitBox <gi...@apache.org>.
stillalex commented on code in PR #1211:
URL: https://github.com/apache/solr/pull/1211#discussion_r1040083573


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java:
##########
@@ -88,23 +89,63 @@ public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls) {
     this.httpClient = httpClient;
   }
 
+  public LBHttp2SolrClient(Http2SolrClient httpClient, List<String> baseSolrUrls, Builder builder) {

Review Comment:
   this looks perfect! thank you. I think part of the confusion is me seeing intermediary versions of this file across commits :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org