Copilot commented on code in PR #4050:
URL: https://github.com/apache/solr/pull/4050#discussion_r2692307506


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateJdkSolrClient.java:
##########
@@ -0,0 +1,102 @@
+/*

Review Comment:
   Missing Apache License header. All Java source files in the Apache Solr 
project should include the standard Apache License 2.0 header at the top of the 
file.



##########
solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTestBase.java:
##########
@@ -0,0 +1,414 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.impl;
+
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.invoke.MethodHandles;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.SocketTimeoutException;
+import java.net.http.HttpConnectTimeoutException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec;
+import org.apache.solr.client.solrj.request.SolrQuery;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.util.ExecutorUtil;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
+import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.util.SolrJettyTestRule;
+import org.eclipse.jetty.ee10.servlet.ServletHolder;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class ConcurrentUpdateSolrClientTestBase extends 
SolrTestCaseJ4 {
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  public abstract HttpSolrClientBase solrClient(Integer overrideIdleTimeoutMs);
+
+  public abstract ConcurrentUpdateBaseSolrClient concurrentClient(
+      HttpSolrClientBase solrClient,
+      String baseUrl,
+      String defaultCollection,
+      int queueSize,
+      int threadCount,
+      boolean disablePollQueue);
+
+  public abstract ConcurrentUpdateBaseSolrClient 
outcomeCountingConcurrentClient(
+      String serverUrl,
+      int queueSize,
+      int threadCount,
+      HttpSolrClientBase solrClient,
+      AtomicInteger successCoounter,
+      AtomicInteger failureCoounter,

Review Comment:
   Corrected spelling of 'Coounter' to 'Counter'.
   ```suggestion
         AtomicInteger successCounter,
         AtomicInteger failureCounter,
   ```



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java:
##########
@@ -143,29 +143,36 @@ protected HttpJdkSolrClient(String serverBaseUrl, 
HttpJdkSolrClient.Builder buil
     assert ObjectReleaseTracker.track(this);
   }
 
-  @Override
-  public CompletableFuture<NamedList<Object>> requestAsync(
-      final SolrRequest<?> solrRequest, String collection) {
+  protected CompletableFuture<HttpResponse<InputStream>> 
requestInputStreamAsync(
+      String overrideBaseUrl, final SolrRequest<?> solrRequest, String 
collection) {
     try {
-      PreparedRequest pReq = prepareRequest(solrRequest, collection, null);
-      return httpClient
-          .sendAsync(pReq.reqb.build(), 
HttpResponse.BodyHandlers.ofInputStream())
-          .thenApply(
-              httpResponse -> {
-                try {
-                  return processErrorsAndResponse(
-                      solrRequest, pReq.parserToUse, httpResponse, pReq.url);
-                } catch (SolrServerException e) {
-                  throw new RuntimeException(e);
-                }
-              });
+      PreparedRequest pReq = prepareRequest(solrRequest, collection, 
overrideBaseUrl);
+      return httpClient.sendAsync(pReq.reqb.build(), 
HttpResponse.BodyHandlers.ofInputStream());
     } catch (Exception e) {
-      CompletableFuture<NamedList<Object>> cf = new CompletableFuture<>();
+      CompletableFuture<HttpResponse<InputStream>> cf = new 
CompletableFuture<>();
       cf.completeExceptionally(e);
       return cf;
     }
   }
 
+  @Override
+  public CompletableFuture<NamedList<Object>> requestAsync(
+      final SolrRequest<?> solrRequest, String collection) {
+    return requestInputStreamAsync(null, solrRequest, collection)
+        .thenApply(
+            httpResponse -> {
+              try {
+                PreparedRequest pReq = prepareRequest(solrRequest, collection, 
null);

Review Comment:
   The prepareRequest method is called twice for the same request - once in 
requestInputStreamAsync (line 149) and again here in the thenApply callback. 
This duplicate work should be avoided by storing and reusing the 
PreparedRequest from the first call.
   ```suggestion
       final PreparedRequest pReq;
       try {
         pReq = prepareRequest(solrRequest, collection, null);
       } catch (Exception e) {
         CompletableFuture<NamedList<Object>> cf = new CompletableFuture<>();
         cf.completeExceptionally(e);
         return cf;
       }
   
       return httpClient
           .sendAsync(pReq.reqb.build(), 
HttpResponse.BodyHandlers.ofInputStream())
           .thenApply(
               httpResponse -> {
                 try {
   ```



##########
solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateJdkSolrClientTest.java:
##########
@@ -0,0 +1,122 @@
+/*

Review Comment:
   Missing Apache License header. All Java source files in the Apache Solr 
project should include the standard Apache License 2.0 header at the top of the 
file.



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateJdkSolrClient.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.http.HttpResponse;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+
+/** A ConcurrentUpdate SolrClient using {@link HttpJdkSolrClient}. */
+public class ConcurrentUpdateJdkSolrClient extends 
ConcurrentUpdateBaseSolrClient {
+
+  private final HttpJdkSolrClient client;
+
+  protected 
ConcurrentUpdateJdkSolrClient(ConcurrentUpdateJdkSolrClient.Builder builder) {
+    super(builder);
+    this.client = (HttpJdkSolrClient) builder.getClient();
+  }
+
+  @Override
+  protected StreamingResponse doSendUpdateStream(Update update) {
+    UpdateRequest req = update.request();
+    String collection = update.collection();
+    CompletableFuture<HttpResponse<InputStream>> resp =
+        client.requestInputStreamAsync(basePath, req, collection);
+
+    return new StreamingResponse() {
+
+      @Override
+      public int awaitResponse(long timeoutMillis) throws Exception {
+        return resp.get(timeoutMillis, TimeUnit.MILLISECONDS).statusCode();
+      }
+
+      @Override
+      public InputStream getInputStream() {
+        try {
+          return resp.get().body();
+        } catch (InterruptedException e) {
+          Thread.currentThread().interrupt();
+          return InputStream.nullInputStream();
+        } catch (ExecutionException e) {
+          throw new RuntimeException(e);
+        }
+      }
+
+      @Override
+      public Object getUnderlyingResponse() {
+        return resp;
+      }
+
+      @Override

Review Comment:
   The hardcoded idle timeout value of 1000ms should be documented, explaining 
why this specific value was chosen. Additionally, consider adding a comment 
explaining that the JDK HTTP client doesn't use idle timeout in the same way as 
the Jetty client (as noted in HttpJdkSolrClient line 99), but this value is 
still required for the base class's StreamingResponse.awaitResponse method.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to