diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 8ad9808154a..0efe45eb3d7 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -207,6 +207,9 @@ Other Changes * SOLR-7421: RecoveryAfterSoftCommitTest fails frequently on Jenkins due to full index replication taking longer than 30 seconds. (Timothy Potter, shalin) +* SOLR-7081: Add new test case to test if create/delete/re-create collections work. + (Christine Poerschke via Ramkumar Aiyengar) + ================== 5.1.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release diff --git a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java index 56c11ffaced..04849cbd1af 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java @@ -74,6 +74,12 @@ public class TestMiniSolrCloudCluster extends LuceneTestCase { @Test public void testBasics() throws Exception { + testCollectionCreateSearchDelete(); + // sometimes run a second test e.g. to test collection create-delete-create scenario + if (random().nextBoolean()) testCollectionCreateSearchDelete(); + } + + private void testCollectionCreateSearchDelete() throws Exception { File solrXml = new File(SolrTestCaseJ4.TEST_HOME(), "solr-no-core.xml"); MiniSolrCloudCluster miniCluster = new MiniSolrCloudCluster(NUM_SERVERS, null, createTempDir().toFile(), solrXml, null, null); @@ -114,8 +120,8 @@ public class TestMiniSolrCloudCluster extends LuceneTestCase { miniCluster.createCollection(collectionName, NUM_SHARDS, REPLICATION_FACTOR, configName, collectionProperties); try (SolrZkClient zkClient = new SolrZkClient - (miniCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null)) { - ZkStateReader zkStateReader = new ZkStateReader(zkClient); + (miniCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null); + ZkStateReader zkStateReader = new ZkStateReader(zkClient)) { AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330); // modify/query collection @@ -155,6 +161,17 @@ public class TestMiniSolrCloudCluster extends LuceneTestCase { assertEquals(NUM_SERVERS - 1, miniCluster.getJettySolrRunners().size()); } } + + // now restore the original state so that this function could be called multiple times + + // re-create a server (to restore original NUM_SERVERS count) + startedServer = miniCluster.startJettySolrRunner(null, null, null); + assertTrue(startedServer.isRunning()); + assertEquals(NUM_SERVERS, miniCluster.getJettySolrRunners().size()); + + // delete the collection we created earlier + miniCluster.deleteCollection(collectionName); + AbstractDistribZkTestBase.waitForCollectionToDisappear(collectionName, zkStateReader, true, true, 330); } } finally { diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java index fbbf6cbbd0c..f035fe492e8 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java @@ -184,6 +184,37 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes log.info("Recoveries finished - collection: " + collection); } + public static void waitForCollectionToDisappear(String collection, + ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, int timeoutSeconds) + throws Exception { + log.info("Wait for collection to disappear - collection: " + collection + " failOnTimeout:" + failOnTimeout + " timeout (sec):" + timeoutSeconds); + boolean cont = true; + int cnt = 0; + + while (cont) { + if (verbose) System.out.println("-"); + zkStateReader.updateClusterState(true); + ClusterState clusterState = zkStateReader.getClusterState(); + if (!clusterState.hasCollection(collection)) break; + if (cnt == timeoutSeconds) { + if (verbose) System.out.println("Gave up waiting for "+collection+" to disappear.."); + if (failOnTimeout) { + Diagnostics.logThreadDumps("Gave up waiting for "+collection+" to disappear. THREAD DUMP:"); + zkStateReader.getZkClient().printLayoutToStdOut(); + fail("The collection ("+collection+") is still present - waited for " + timeoutSeconds + " seconds"); + // won't get here + return; + } + cont = false; + } else { + Thread.sleep(1000); + } + cnt++; + } + + log.info("Collection has disappeared - collection: " + collection); + } + protected void assertAllActive(String collection,ZkStateReader zkStateReader) throws KeeperException, InterruptedException { diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java index d6663932025..51f12c419b2 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java @@ -284,7 +284,7 @@ public class MiniSolrCloudCluster { public NamedList createCollection(String name, int numShards, int replicationFactor, String configName, Map collectionProperties) throws SolrServerException, IOException { - ModifiableSolrParams params = new ModifiableSolrParams(); + final ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CoreAdminParams.ACTION, CollectionAction.CREATE.name()); params.set(CoreAdminParams.NAME, name); params.set("numShards", numShards); @@ -296,7 +296,20 @@ public class MiniSolrCloudCluster { } } - QueryRequest request = new QueryRequest(params); + return makeCollectionsRequest(params); + } + + public NamedList deleteCollection(String name) throws SolrServerException, IOException { + final ModifiableSolrParams params = new ModifiableSolrParams(); + params.set(CoreAdminParams.ACTION, CollectionAction.DELETE.name()); + params.set(CoreAdminParams.NAME, name); + + return makeCollectionsRequest(params); + } + + private NamedList makeCollectionsRequest(final ModifiableSolrParams params) throws SolrServerException, IOException { + + final QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); return solrClient.request(request);