Apache Lucene open-source search software
SOLR-12550: ConcurrentUpdateSolrClient doesn't respect timeouts for commits and optimize (#417)
Marc A. Morissette051133c13f98
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.javaindex edc8270cfc3..c774e033671 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java@@ -125,6 +125,8 @@ public class ConcurrentUpdateSolrClient extends SolrClient {this.internalHttpClient = (builder.httpClient == null);this.client = new HttpSolrClient.Builder(builder.baseSolrUrl).withHttpClient(builder.httpClient)+ .withConnectionTimeout(builder.connectionTimeoutMillis)+ .withSocketTimeout(builder.socketTimeoutMillis).build();this.client.setFollowRedirects(false);this.queue = new LinkedBlockingQueue<>(builder.queueSize);diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientBuilderTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientBuilderTest.javaindex af120fc600a..282b88da189 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientBuilderTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientBuilderTest.java@@ -17,7 +17,13 @@package org.apache.solr.client.solrj.impl;+import java.io.IOException;+import java.net.InetAddress;+import java.net.ServerSocket;+import java.net.SocketTimeoutException;+import org.apache.solr.SolrTestCase;+import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Builder;import org.junit.Test;@@ -39,4 +45,27 @@ public class ConcurrentUpdateSolrClientBuilderTest extends SolrTestCase {// is the baseSolrUrl}}++ /**+ * Test that connection timeout information is passed to the HttpSolrClient that handles non add operations.+ */+ @Test(timeout = 10000)+ public void testSocketTimeoutOnCommit() throws IOException, SolrServerException {+ InetAddress localHost = InetAddress.getLocalHost();+ try (ServerSocket server = new ServerSocket(0, 1, localHost);+ ConcurrentUpdateSolrClient client = new ConcurrentUpdateSolrClient.Builder(+ "http://" + localHost.getHostAddress() + ":" + server.getLocalPort() + "/noOneThere")+ .withSocketTimeout(1)+ .build()){+ // Expecting an exception+ client.commit();+ fail();+ }+ catch (SolrServerException e) {+ if (!(e.getCause() instanceof SocketTimeoutException)) {+ throw e;+ }+ // else test passses+ }+ }}