Apache Lucene open-source search software
SOLR-10065: The Nightly test ConcurrentDeleteAndCreateCollectionTest appears to be too fragile.
markrmillerbc02b0f70d34
diff --git a/solr/core/src/test/org/apache/solr/cloud/ConcurrentDeleteAndCreateCollectionTest.java b/solr/core/src/test/org/apache/solr/cloud/ConcurrentDeleteAndCreateCollectionTest.javaindex 3e90759bc31..151230dc69b 100644--- a/solr/core/src/test/org/apache/solr/cloud/ConcurrentDeleteAndCreateCollectionTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ConcurrentDeleteAndCreateCollectionTest.java@@ -17,6 +17,7 @@package org.apache.solr.cloud;import java.io.IOException;+import java.lang.invoke.MethodHandles;import java.nio.file.Path;import java.util.concurrent.TimeUnit;import java.util.concurrent.atomic.AtomicReference;@@ -27,14 +28,19 @@ import org.apache.solr.client.solrj.SolrClient;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.request.CollectionAdminRequest;import org.apache.solr.client.solrj.response.CollectionAdminResponse;+import org.apache.solr.common.util.IOUtils;import org.apache.solr.util.TimeOut;import org.apache.zookeeper.KeeperException;import org.junit.After;import org.junit.Before;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;@Nightlypublic class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());+private MiniSolrCloudCluster solrCluster;@Override@@ -54,7 +60,7 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {public void testConcurrentCreateAndDeleteDoesNotFail() {final AtomicReference<Exception> failure = new AtomicReference<>();final int timeToRunSec = 30;- final Thread[] threads = new Thread[10];+ final CreateDeleteCollectionThread[] threads = new CreateDeleteCollectionThread[10];for (int i = 0; i < threads.length; i++) {final String collectionName = "collection" + i;uploadConfig(configset("configset-2"), collectionName);@@ -74,12 +80,12 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {final String configName = "testconfig";uploadConfig(configset("configset-2"), configName); // upload config once, to be used by all collectionsfinal String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();- final SolrClient solrClient = getHttpSolrClient(baseUrl);final AtomicReference<Exception> failure = new AtomicReference<>();final int timeToRunSec = 30;- final Thread[] threads = new Thread[2];+ final CreateDeleteCollectionThread[] threads = new CreateDeleteCollectionThread[2];for (int i = 0; i < threads.length; i++) {final String collectionName = "collection" + i;+ final SolrClient solrClient = getHttpSolrClient(baseUrl);threads[i] = new CreateDeleteCollectionThread("create-delete-" + i, collectionName, configName,timeToRunSec, solrClient, failure);}@@ -88,12 +94,6 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {joinAll(threads);assertNull("concurrent create and delete collection failed: " + failure.get(), failure.get());-- try {- solrClient.close();- } catch (IOException e) {- throw new RuntimeException(e);- }}private void uploadConfig(Path configDir, String configName) {@@ -104,10 +104,10 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {}}- private void joinAll(final Thread[] threads) {- for (Thread t : threads) {+ private void joinAll(final CreateDeleteCollectionThread[] threads) {+ for (CreateDeleteCollectionThread t : threads) {try {- t.join();+ t.joinAndClose();} catch (InterruptedException e) {Thread.interrupted();throw new RuntimeException(e);@@ -152,6 +152,7 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {}protected void addFailure(Exception e) {+ log.error("Add Failure", e);synchronized (failure) {if (failure.get() != null) {failure.get().addSuppressed(e);@@ -190,6 +191,14 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {addFailure(e);}}++ public void joinAndClose() throws InterruptedException {+ try {+ super.join(60000);+ } finally {+ IOUtils.closeQuietly(solrClient);+ }+ }}private static class CreateDeleteSearchCollectionThread extends CreateDeleteCollectionThread {