From 20ea5355c91e61617d59310ea51ca5cb5383c490 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 6 Oct 2016 08:15:53 +0100 Subject: [PATCH] SOLR-9632: Add deleteAllCollections method to MiniSolrCloudCluster --- solr/CHANGES.txt | 2 ++ .../test/org/apache/solr/cloud/rule/RulesTest.java | 13 ++++++------- .../org/apache/solr/cloud/MiniSolrCloudCluster.java | 10 ++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index a3c14b098ba..281140a48a5 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -283,6 +283,8 @@ Other Changes * SOLR-9627: Add QParser.getSortSpec, deprecate misleadingly named QParser.getSort (Judith Silverman, Christine Poerschke) +* SOLR-9632: Add MiniSolrCloudCluster#deleteAllCollections() method (Alan Woodward) + ================== 6.2.1 ================== Bug Fixes diff --git a/solr/core/src/test/org/apache/solr/cloud/rule/RulesTest.java b/solr/core/src/test/org/apache/solr/cloud/rule/RulesTest.java index eec3d93bc22..6955418b6f5 100644 --- a/solr/core/src/test/org/apache/solr/cloud/rule/RulesTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/rule/RulesTest.java @@ -29,6 +29,7 @@ import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.cloud.SolrCloudTestCase; import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.params.ModifiableSolrParams; +import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -54,6 +55,11 @@ public class RulesTest extends SolrCloudTestCase { @org.junit.Rule public ExpectedException expectedException = ExpectedException.none(); + @After + public void removeCollections() throws Exception { + cluster.deleteAllCollections(); + } + @Test public void doIntegrationTest() throws Exception { final long minGB = (random().nextBoolean() ? 1 : 0); @@ -80,8 +86,6 @@ public class RulesTest extends SolrCloudTestCase { CollectionAdminRequest.createShard(rulesColl, "shard2").process(cluster.getSolrClient()); CollectionAdminRequest.addReplicaToShard(rulesColl, "shard2").process(cluster.getSolrClient()); - CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient()); - } @Test @@ -105,7 +109,6 @@ public class RulesTest extends SolrCloudTestCase { assertEquals(1, list.size()); assertEquals ( "ImplicitSnitch", ((Map)list.get(0)).get("class")); - CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient()); } @Test @@ -134,7 +137,6 @@ public class RulesTest extends SolrCloudTestCase { assertEquals(1, list.size()); assertEquals("ImplicitSnitch", list.get(0).get("class")); - CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient()); } @@ -157,8 +159,6 @@ public class RulesTest extends SolrCloudTestCase { .setSnitch("class:ImplicitSnitch") .process(cluster.getSolrClient()); - CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient()); - } @@ -201,6 +201,5 @@ public class RulesTest extends SolrCloudTestCase { assertEquals(1, list.size()); assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class")); - CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient()); } } 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 74cae539e60..7e809c7614d 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 @@ -46,6 +46,7 @@ import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.embedded.SSLConfig; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.SolrZkClient; @@ -400,6 +401,15 @@ public class MiniSolrCloudCluster { manager.uploadConfigDir(configDir.toPath(), configName); } } + + public void deleteAllCollections() throws Exception { + try (ZkStateReader reader = new ZkStateReader(solrClient.getZkStateReader().getZkClient())) { + reader.createClusterStateWatchersAndUpdate(); + for (String collection : reader.getClusterState().getCollectionStates().keySet()) { + CollectionAdminRequest.deleteCollection(collection).process(solrClient); + } + } + } public NamedList createCollection(String name, int numShards, int replicationFactor, String configName, Map collectionProperties) throws SolrServerException, IOException {