SOLR-7081: TestMiniSolrCloudCluster.testBasics tidies up after itself, adds collection create/delete/create test case.

TestMiniSolrCloudCluster.testBasics now re-creates the server it removed for test purposes,
thus restoring the original NUM_SERVERS count. TestMiniSolrCloudCluster.testBasics now also deletes
the collection it created for test purposes (this revision adds MiniSolrCloudCluster.deleteCollection
and AbstractDistribZkTestBase.waitForCollectionToDisappear methods).

Sometimes TestMiniSolrCloudCluster.testBasics runs its create-collection/search-collection/delete-collection
logic twice, thus creating a create/delete/create-collection test case.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1675590 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ramkumar Aiyengar 2015-04-23 12:29:52 +00:00
parent 9d1c2019a8
commit 852e04e3d0
4 changed files with 68 additions and 4 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -284,7 +284,7 @@ public class MiniSolrCloudCluster {
public NamedList<Object> createCollection(String name, int numShards, int replicationFactor,
String configName, Map<String, String> 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<Object> 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<Object> makeCollectionsRequest(final ModifiableSolrParams params) throws SolrServerException, IOException {
final QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
return solrClient.request(request);