From 3822541d8952da50ca71c37eb0e64383aa259f97 Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Fri, 25 Jun 2021 17:24:24 +0100 Subject: [PATCH] SOLR-15485: discourage Collections.singleton.forEach use (#179) Resolved Conflicts: gradle/validation/validate-source-patterns.gradle solr/core/src/java/org/apache/solr/core/CoreContainer.java --- .../java/org/apache/solr/core/CoreContainer.java | 4 +--- .../solr/BaseDistributedSearchTestCase.java | 4 +--- .../cloud/AbstractFullDistribZkTestBase.java | 16 ++++------------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index 2388d38e2086..2c4ab4cad088 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -1138,9 +1138,7 @@ public void shutdown() { } finally { try { if (updateShardHandler != null) { - customThreadPool.submit(() -> Collections.singleton(shardHandlerFactory).parallelStream().forEach(c -> { - updateShardHandler.close(); - })); + customThreadPool.submit(() -> updateShardHandler.close()); } } finally { try { diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java index 66c1974a7262..26f90b2d7ea8 100644 --- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java +++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java @@ -414,9 +414,7 @@ protected String getShardsString() { protected void destroyServers() throws Exception { ExecutorService customThreadPool = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool")); - customThreadPool.submit(() -> Collections.singleton(controlClient).parallelStream().forEach(c -> { - IOUtils.closeQuietly(c); - })); + customThreadPool.submit(() -> IOUtils.closeQuietly(controlClient)); customThreadPool.submit(() -> { try { diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index 1fb1efb49d24..3976adb05dac 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -1732,25 +1732,17 @@ public void distribTearDown() throws Exception { protected void destroyServers() throws Exception { ExecutorService customThreadPool = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool")); - customThreadPool.submit(() -> Collections.singleton(commonCloudSolrClient).parallelStream().forEach(c -> { - IOUtils.closeQuietly(c); - })); + customThreadPool.submit(() -> IOUtils.closeQuietly(commonCloudSolrClient)); - customThreadPool.submit(() -> Collections.singleton(controlClient).parallelStream().forEach(c -> { - IOUtils.closeQuietly(c); - })); + customThreadPool.submit(() -> IOUtils.closeQuietly(controlClient)); customThreadPool.submit(() -> coreClients.parallelStream().forEach(c -> { IOUtils.closeQuietly(c); })); - customThreadPool.submit(() -> Collections.singletonList(controlClientCloud).parallelStream().forEach(c -> { - IOUtils.closeQuietly(c); - })); + customThreadPool.submit(() -> IOUtils.closeQuietly(controlClientCloud)); - customThreadPool.submit(() -> Collections.singletonList(cloudClient).parallelStream().forEach(c -> { - IOUtils.closeQuietly(c); - })); + customThreadPool.submit(() -> IOUtils.closeQuietly(cloudClient)); ExecutorUtil.shutdownAndAwaitTermination(customThreadPool);