SOLR-9632: Add deleteAllCollections method to MiniSolrCloudCluster

This commit is contained in:
Alan Woodward 2016-10-06 08:15:53 +01:00
parent f870c2069c
commit 20ea5355c9
3 changed files with 18 additions and 7 deletions

View File

@ -283,6 +283,8 @@ Other Changes
* SOLR-9627: Add QParser.getSortSpec, deprecate misleadingly named QParser.getSort (Judith Silverman, Christine Poerschke) * 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 ================== ================== 6.2.1 ==================
Bug Fixes Bug Fixes

View File

@ -29,6 +29,7 @@ import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.cloud.SolrCloudTestCase; import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.junit.After;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
@ -54,6 +55,11 @@ public class RulesTest extends SolrCloudTestCase {
@org.junit.Rule @org.junit.Rule
public ExpectedException expectedException = ExpectedException.none(); public ExpectedException expectedException = ExpectedException.none();
@After
public void removeCollections() throws Exception {
cluster.deleteAllCollections();
}
@Test @Test
public void doIntegrationTest() throws Exception { public void doIntegrationTest() throws Exception {
final long minGB = (random().nextBoolean() ? 1 : 0); final long minGB = (random().nextBoolean() ? 1 : 0);
@ -80,8 +86,6 @@ public class RulesTest extends SolrCloudTestCase {
CollectionAdminRequest.createShard(rulesColl, "shard2").process(cluster.getSolrClient()); CollectionAdminRequest.createShard(rulesColl, "shard2").process(cluster.getSolrClient());
CollectionAdminRequest.addReplicaToShard(rulesColl, "shard2").process(cluster.getSolrClient()); CollectionAdminRequest.addReplicaToShard(rulesColl, "shard2").process(cluster.getSolrClient());
CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient());
} }
@Test @Test
@ -105,7 +109,6 @@ public class RulesTest extends SolrCloudTestCase {
assertEquals(1, list.size()); assertEquals(1, list.size());
assertEquals ( "ImplicitSnitch", ((Map)list.get(0)).get("class")); assertEquals ( "ImplicitSnitch", ((Map)list.get(0)).get("class"));
CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient());
} }
@Test @Test
@ -134,7 +137,6 @@ public class RulesTest extends SolrCloudTestCase {
assertEquals(1, list.size()); assertEquals(1, list.size());
assertEquals("ImplicitSnitch", list.get(0).get("class")); 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") .setSnitch("class:ImplicitSnitch")
.process(cluster.getSolrClient()); .process(cluster.getSolrClient());
CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient());
} }
@ -201,6 +201,5 @@ public class RulesTest extends SolrCloudTestCase {
assertEquals(1, list.size()); assertEquals(1, list.size());
assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class")); assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class"));
CollectionAdminRequest.deleteCollection(rulesColl).process(cluster.getSolrClient());
} }
} }

View File

@ -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.embedded.SSLConfig;
import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; 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.client.solrj.request.QueryRequest;
import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.SolrZkClient;
@ -400,6 +401,15 @@ public class MiniSolrCloudCluster {
manager.uploadConfigDir(configDir.toPath(), configName); 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<Object> createCollection(String name, int numShards, int replicationFactor, public NamedList<Object> createCollection(String name, int numShards, int replicationFactor,
String configName, Map<String, String> collectionProperties) throws SolrServerException, IOException { String configName, Map<String, String> collectionProperties) throws SolrServerException, IOException {