mirror of https://github.com/apache/lucene.git
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:
parent
054b3be627
commit
051133c13f
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue