Apache Lucene open-source search software
SOLR-11425: SolrClientBuilder does not allow infinite timeout (value 0).
markrmillerfc429399ecd9
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 177cdf74c4f..c14c9b6e358 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -156,6 +156,7 @@ Bug Fixes* SOLR-11278: Fix a race condition in the CDCR bootstrap process which could lead to bootstraps cancelling itself(Amrit Sarkar, shalin, Varun Thacker)+* SOLR-11425: SolrClientBuilder does not allow infinite timeout (value 0). (Peter Szantai-Kis via Mark Miller)Optimizations----------------------diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.javaindex ec149bd39fb..74e981dbd3e 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java@@ -48,10 +48,13 @@ public abstract class SolrClientBuilder<B extends SolrClientBuilder<B>> {/*** Tells {@link Builder} that created clients should obey the following timeout when connecting to Solr servers.+ * <p>+ * For valid values see {@link org.apache.http.client.config.RequestConfig#getConnectTimeout()}+ * </p>*/public B withConnectionTimeout(int connectionTimeoutMillis) {- if (connectionTimeoutMillis <= 0) {- throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");+ if (connectionTimeoutMillis < 0) {+ throw new IllegalArgumentException("connectionTimeoutMillis must be a non-negative integer.");}this.connectionTimeoutMillis = connectionTimeoutMillis;@@ -60,10 +63,13 @@ public abstract class SolrClientBuilder<B extends SolrClientBuilder<B>> {/*** Tells {@link Builder} that created clients should set the following read timeout on all sockets.+ * <p>+ * For valid values see {@link org.apache.http.client.config.RequestConfig#getSocketTimeout()}+ * </p>*/public B withSocketTimeout(int socketTimeoutMillis) {- if (socketTimeoutMillis <= 0) {- throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");+ if (socketTimeoutMillis < 0) {+ throw new IllegalArgumentException("socketTimeoutMillis must be a non-negative integer.");}this.socketTimeoutMillis = socketTimeoutMillis;diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientBuilderTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientBuilderTest.javaindex 4c385546ea0..97b79eff173 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientBuilderTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientBuilderTest.java@@ -97,4 +97,15 @@ public class CloudSolrClientBuilderTest extends LuceneTestCase {assertFalse(createdClient.isDirectUpdatesToLeadersOnly());}}++ @Test+ public void test0Timeouts() throws IOException {+ try(CloudSolrClient createdClient = new Builder()+ .withZkHost(ANY_ZK_HOST)+ .withZkChroot(ANY_CHROOT)+ .withSocketTimeout(0)+ .withConnectionTimeout(0)+ .build()) {+ }+ }}