This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new e7e487e1694 SOLR-16590: Standardize Builder method names in solr
clients (#1334)
e7e487e1694 is described below
commit e7e487e1694231b6e586276742e598de06acd9bf
Author: Eric Pugh <[email protected]>
AuthorDate: Mon Feb 6 14:51:55 2023 -0500
SOLR-16590: Standardize Builder method names in solr clients (#1334)
Use the with pattern for methods unless another one makes sense, like
keeping useHttp1_1().
---
solr/CHANGES.txt | 2 +
.../handler/component/HttpShardHandlerFactory.java | 6 +--
.../org/apache/solr/update/UpdateShardHandler.java | 6 +--
.../apache/solr/update/MockingHttp2SolrClient.java | 4 +-
.../prometheus/exporter/SolrClientFactory.java | 8 ++--
.../client/solrj/impl/CloudHttp2SolrClient.java | 25 ++++++++++++
.../solr/client/solrj/impl/Http2SolrClient.java | 44 +++++++++++++++++++++-
.../client/solrj/SolrExampleBinaryHttp2Test.java | 2 +-
.../solr/client/solrj/TestLBHttp2SolrClient.java | 3 +-
.../solrj/embedded/SolrExampleXMLHttp2Test.java | 2 +-
.../client/solrj/impl/Http2SolrClientTest.java | 6 +--
11 files changed, 89 insertions(+), 19 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 78c87769d21..174c88d8283 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -138,6 +138,8 @@ Improvements
* SOLR-16618: Admin UI Analysis page should include dynamic fields (Alex
Deparvu via Eric Pugh)
+* SOLR-16590: Standardize Builder method names on SolrClient's to use the with
pattern, deprecating the use of set or bare property name. (Eric Pugh)
+
Optimizations
---------------------
diff --git
a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
index 25aac2e5620..0a31ce29fab 100644
---
a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
+++
b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
@@ -282,10 +282,10 @@ public class HttpShardHandlerFactory extends
ShardHandlerFactory
this.defaultClient =
new Http2SolrClient.Builder()
- .connectionTimeout(connectionTimeout)
- .idleTimeout(soTimeout)
+ .withConnectionTimeout(connectionTimeout)
+ .withIdleTimeout(soTimeout)
.withExecutor(commExecutor)
- .maxConnectionsPerHost(maxConnectionsPerHost)
+ .withMaxConnectionsPerHost(maxConnectionsPerHost)
.build();
this.defaultClient.addListenerFactory(this.httpListenerFactory);
this.loadbalancer = new LBHttp2SolrClient.Builder(defaultClient).build();
diff --git a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
index 4ce3d9d9e71..d52bda8506d 100644
--- a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
+++ b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
@@ -144,9 +144,9 @@ public class UpdateShardHandler implements SolrInfoBean {
Http2SolrClient.Builder updateOnlyClientBuilder = new
Http2SolrClient.Builder();
if (cfg != null) {
updateOnlyClientBuilder
- .connectionTimeout(cfg.getDistributedConnectionTimeout())
- .idleTimeout(cfg.getDistributedSocketTimeout())
- .maxConnectionsPerHost(cfg.getMaxUpdateConnectionsPerHost());
+ .withConnectionTimeout(cfg.getDistributedConnectionTimeout())
+ .withIdleTimeout(cfg.getDistributedSocketTimeout())
+ .withMaxConnectionsPerHost(cfg.getMaxUpdateConnectionsPerHost());
}
updateOnlyClientBuilder.withTheseParamNamesInTheUrl(urlParamNames);
updateOnlyClient = updateOnlyClientBuilder.build();
diff --git
a/solr/core/src/test/org/apache/solr/update/MockingHttp2SolrClient.java
b/solr/core/src/test/org/apache/solr/update/MockingHttp2SolrClient.java
index 12bfcacf605..6e17ba2ed98 100644
--- a/solr/core/src/test/org/apache/solr/update/MockingHttp2SolrClient.java
+++ b/solr/core/src/test/org/apache/solr/update/MockingHttp2SolrClient.java
@@ -54,8 +54,8 @@ public class MockingHttp2SolrClient extends Http2SolrClient {
public Builder(UpdateShardHandlerConfig config) {
super();
- this.connectionTimeout(config.getDistributedConnectionTimeout());
- this.idleTimeout(config.getDistributedSocketTimeout());
+ this.withConnectionTimeout(config.getDistributedConnectionTimeout());
+ this.withIdleTimeout(config.getDistributedSocketTimeout());
}
@Override
diff --git
a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrClientFactory.java
b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrClientFactory.java
index f325808bee0..abe0f63a35d 100644
---
a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrClientFactory.java
+++
b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrClientFactory.java
@@ -36,8 +36,8 @@ public class SolrClientFactory {
public Http2SolrClient createStandaloneSolrClient(String solrHost) {
Http2SolrClient http2SolrClient =
new Http2SolrClient.Builder(solrHost)
- .idleTimeout(settings.getHttpReadTimeout())
- .connectionTimeout(settings.getHttpConnectionTimeout())
+ .withIdleTimeout(settings.getHttpReadTimeout())
+ .withConnectionTimeout(settings.getHttpConnectionTimeout())
.withResponseParser(new NoOpResponseParser("json"))
.build();
@@ -55,8 +55,8 @@ public class SolrClientFactory {
Optional.ofNullable(parser.getChrootPath()))
.withInternalClientBuilder(
new Http2SolrClient.Builder()
- .idleTimeout(settings.getHttpReadTimeout())
- .connectionTimeout(settings.getHttpConnectionTimeout()))
+ .withIdleTimeout(settings.getHttpReadTimeout())
+
.withConnectionTimeout(settings.getHttpConnectionTimeout()))
.withResponseParser(new NoOpResponseParser("json"))
.build();
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
index 89a08280535..65f539cb672 100644
---
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java
@@ -292,16 +292,41 @@ public class CloudHttp2SolrClient extends CloudSolrClient
{
* number of locks.
*
* <p>Defaults to 3.
+ *
+ * @deprecated Please use {@link #withParallelCacheRefreshes(int)}
*/
+ @Deprecated(since = "9.2")
public Builder setParallelCacheRefreshes(int parallelCacheRefreshesLocks) {
+ this.withParallelCacheRefreshes(parallelCacheRefreshesLocks);
+ return this;
+ }
+
+ /**
+ * When caches are expired then they are refreshed after acquiring a lock.
Use this to set the
+ * number of locks.
+ *
+ * <p>Defaults to 3.
+ */
+ public Builder withParallelCacheRefreshes(int parallelCacheRefreshesLocks)
{
this.parallelCacheRefreshesLocks = parallelCacheRefreshesLocks;
return this;
}
/**
* This is the time to wait to refetch the state after getting the same
state version from ZK
+ *
+ * @deprecated Please use {@link #withRetryExpiryTime(int)} *
*/
+ @Deprecated(since = "9.2")
public Builder setRetryExpiryTime(int secs) {
+ this.withRetryExpiryTime(secs);
+ return this;
+ }
+
+ /**
+ * This is the time to wait to refetch the state after getting the same
state version from ZK
+ */
+ public Builder withRetryExpiryTime(int secs) {
this.retryExpiryTime = TimeUnit.NANOSECONDS.convert(secs,
TimeUnit.SECONDS);
return this;
}
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index 71553756a5b..1b3b7ff4048 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -1096,14 +1096,34 @@ public class Http2SolrClient extends SolrClient {
/**
* Set maxConnectionsPerHost for http1 connections, maximum number http2
connections is limited
- * by 4
+ * to 4
+ *
+ * @deprecated Please use {@link #withMaxConnectionsPerHost(int)}
*/
+ @Deprecated(since = "9.2")
public Builder maxConnectionsPerHost(int max) {
+ withMaxConnectionsPerHost(max);
+ return this;
+ }
+ /**
+ * Set maxConnectionsPerHost for http1 connections, maximum number http2
connections is limited
+ * to 4
+ */
+ public Builder withMaxConnectionsPerHost(int max) {
this.maxConnectionsPerHost = max;
return this;
}
+ /**
+ * @deprecated Please use {@link #withIdleTimeout(int)}
+ */
+ @Deprecated(since = "9.2")
public Builder idleTimeout(int idleConnectionTimeout) {
+ withIdleTimeout(idleConnectionTimeout);
+ return this;
+ }
+
+ public Builder withIdleTimeout(int idleConnectionTimeout) {
this.idleTimeout = idleConnectionTimeout;
return this;
}
@@ -1113,7 +1133,16 @@ public class Http2SolrClient extends SolrClient {
return this;
}
+ /**
+ * @deprecated Please use {@link #withConnectionTimeout(int)}
+ */
+ @Deprecated(since = "9.2")
public Builder connectionTimeout(int connectionTimeout) {
+ withConnectionTimeout(connectionTimeout);
+ return this;
+ }
+
+ public Builder withConnectionTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
return this;
}
@@ -1121,13 +1150,26 @@ public class Http2SolrClient extends SolrClient {
/**
* Set a timeout in milliseconds for requests issued by this client.
*
+ * @deprecated Please use {@link #withRequestTimeout(int)}
* @param requestTimeout The timeout in milliseconds
* @return this Builder.
*/
+ @Deprecated(since = "9.2")
public Builder requestTimeout(int requestTimeout) {
this.requestTimeout = requestTimeout;
return this;
}
+
+ /**
+ * Set a timeout in milliseconds for requests issued by this client.
+ *
+ * @param requestTimeout The timeout in milliseconds
+ * @return this Builder.
+ */
+ public Builder withRequestTimeout(int requestTimeout) {
+ this.requestTimeout = requestTimeout;
+ return this;
+ }
}
/**
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java
index e5a1008e081..e482a9f43cc 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java
@@ -38,7 +38,7 @@ public class SolrExampleBinaryHttp2Test extends
SolrExampleTests {
@Override
public SolrClient createNewSolrClient() {
return new Http2SolrClient.Builder(getServerUrl())
- .connectionTimeout(DEFAULT_CONNECTION_TIMEOUT)
+ .withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT)
.withRequestWriter(new BinaryRequestWriter())
// where the magic happens
.withResponseParser(new BinaryResponseParser())
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttp2SolrClient.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttp2SolrClient.java
index c54c2b60a07..cb4d88237d4 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttp2SolrClient.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttp2SolrClient.java
@@ -78,7 +78,8 @@ public class TestLBHttp2SolrClient extends SolrTestCaseJ4 {
@Override
public void setUp() throws Exception {
super.setUp();
- httpClient = new
Http2SolrClient.Builder().connectionTimeout(1000).idleTimeout(2000).build();
+ httpClient =
+ new
Http2SolrClient.Builder().withConnectionTimeout(1000).withIdleTimeout(2000).build();
for (int i = 0; i < solr.length; i++) {
solr[i] =
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleXMLHttp2Test.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleXMLHttp2Test.java
index 94c8789fb77..ddd20f4a270 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleXMLHttp2Test.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleXMLHttp2Test.java
@@ -39,7 +39,7 @@ public class SolrExampleXMLHttp2Test extends SolrExampleTests
{
Http2SolrClient client =
new Http2SolrClient.Builder(getServerUrl())
- .connectionTimeout(DEFAULT_CONNECTION_TIMEOUT)
+ .withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT)
.withRequestWriter(new RequestWriter())
.withResponseParser(new XMLResponseParser())
.build();
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
index 57636345077..06a2931962b 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
@@ -191,8 +191,8 @@ public class Http2SolrClientTest extends SolrJettyTestBase {
private Http2SolrClient.Builder getHttp2SolrClientBuilder(
String url, int connectionTimeOut, int socketTimeout) {
return new Http2SolrClient.Builder(url)
- .connectionTimeout(connectionTimeOut)
- .idleTimeout(socketTimeout);
+ .withConnectionTimeout(connectionTimeOut)
+ .withIdleTimeout(socketTimeout);
}
@Test
@@ -229,7 +229,7 @@ public class Http2SolrClientTest extends SolrJettyTestBase {
try (Http2SolrClient client =
getHttp2SolrClientBuilder(
jetty.getBaseUrl().toString() + "/slow/foo",
DEFAULT_CONNECTION_TIMEOUT, 0)
- .requestTimeout(500)
+ .withRequestTimeout(500)
.build()) {
client.query(q, SolrRequest.METHOD.GET);
fail("No exception thrown.");