Apache Solr open-source search software
SOLR-16185: CloudSolrClientCacheTest leaks threads (#839)
Kevin Risden26b29d4df41e
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.javaindex a1f0222709b..7794818e89c 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java@@ -99,7 +99,7 @@ public abstract class CloudSolrClient extends SolrClient {// no of times collection state to be reloaded if stale state error is receivedprivate static final int MAX_STALE_RETRIES =Integer.parseInt(System.getProperty("cloudSolrClientMaxStaleRetries", "5"));- private Random rand = new Random();+ private final Random rand = new Random();private final boolean updatesToLeaders;private final boolean directUpdatesToLeadersOnly;@@ -304,7 +304,8 @@ public abstract class CloudSolrClient extends SolrClient {@Overridepublic void close() throws IOException {if (this.threadPool != null && !this.threadPool.isShutdown()) {- this.threadPool.shutdown();+ ExecutorUtil.shutdownAndAwaitTermination(this.threadPool);+ this.threadPool = null;}}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.javaindex 4c9bebf369f..35c404d33a3 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java@@ -78,10 +78,11 @@ public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {LBHttpSolrClient mockLbclient = getMockLbHttpSolrClient(responses);AtomicInteger lbhttpRequestCount = new AtomicInteger();- try (CloudSolrClient cloudClient =- new CloudSolrClientBuilder(getStateProvider(livenodes, refs))- .withLBHttpSolrClient(mockLbclient)- .build()) {+ try (ClusterStateProvider clusterStateProvider = getStateProvider(livenodes, refs);+ CloudSolrClient cloudClient =+ new CloudSolrClientBuilder(clusterStateProvider)+ .withLBHttpSolrClient(mockLbclient)+ .build()) {livenodes.addAll(ImmutableSet.of("192.168.1.108:7574_solr", "192.168.1.108:8983_solr"));ClusterState cs =ClusterState.createFromJson(1, coll1State.getBytes(UTF_8), Collections.emptySet());@@ -91,9 +92,15 @@ public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {"request",o -> {int i = lbhttpRequestCount.incrementAndGet();- if (i == 1) return new ConnectException("TEST");- if (i == 2) return new SocketException("TEST");- if (i == 3) return new NoHttpResponseException("TEST");+ if (i == 1) {+ return new ConnectException("TEST");+ }+ if (i == 2) {+ return new SocketException("TEST");+ }+ if (i == 3) {+ return new NoHttpResponseException("TEST");+ }return okResponse;});UpdateRequest update = new UpdateRequest().add("id", "123", "desc", "Something 0");