SOLR-12550: ConcurrentUpdateSolrClient doesn't respect timeouts for commits and optimize (#417)

ConcurrentUpdateSolrClient now propagates its connection and read timeouts to the private HttpSolrClient used to commit and optimize.
This commit is contained in:
Marc A. Morissette 2020-02-20 07:29:20 -05:00 committed by GitHub
parent 054b3be627
commit 051133c13f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -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);

View File

@ -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
}
}
}