SOLR-3826: Test framework improvements for specifying coreName on initCore

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1384872 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2012-09-14 18:07:23 +00:00
parent 67141af6cd
commit 1de28d8c21
3 changed files with 34 additions and 7 deletions

View File

@ -214,6 +214,10 @@ Other Changes
* SOLR-3824: Velocity: Error messages from search not displayed (janhoy)
* SOLR-3826: Test framework improvements for specifying coreName on initCore
(Amit Nithian, hossman)
================== 4.0.0-BETA ===================

View File

@ -30,6 +30,7 @@ import org.apache.solr.common.*;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.params.*;
import org.apache.solr.common.util.XML;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.JsonUpdateRequestHandler;
@ -52,7 +53,9 @@ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
/**
* A junit4 Solr test harness that extends LuceneTestCaseJ4.
* A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply
* invoke the {@link #initCore(String, String, String, String)} method.
*
* Unlike {@link AbstractSolrTestCase}, a new core is not created for each test method.
*/
@ThreadLeakFilters(defaultFilters = true, filters = {
@ -60,6 +63,7 @@ import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
QuickPatchThreadsFilter.class
})
public abstract class SolrTestCaseJ4 extends LuceneTestCase {
private static String coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
public static int DEFAULT_CONNECTION_TIMEOUT = 1000; // default socket connection timeout in ms
@ -178,7 +182,13 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
initCore();
}
/** Call initCore in @BeforeClass to instantiate a solr core in your test class.
* deleteCore will be called for you via SolrTestCaseJ4 @AfterClass */
public static void initCore(String config, String schema, String solrHome, String pCoreName) throws Exception {
coreName=pCoreName;
initCore(config,schema,solrHome);
}
static long numOpens;
static long numCloses;
public static void startTrackingSearchers() {
@ -358,7 +368,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
}
public static void createCore() {
solrConfig = TestHarness.createConfig(testSolrHome, getSolrConfigFile());
solrConfig = TestHarness.createConfig(testSolrHome, coreName, getSolrConfigFile());
h = new TestHarness( dataDir.getAbsolutePath(),
solrConfig,
getSchemaFile());

View File

@ -76,17 +76,30 @@ public class TestHarness {
private final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<DocumentBuilder>();
private final ThreadLocal<XPath> xpathTL = new ThreadLocal<XPath>();
public UpdateRequestHandler updater;
public static SolrConfig createConfig(String solrHome, String confFile) {
/**
* Creates a SolrConfig object for the specified coreName assuming it
* follows the basic conventions of being a relative path in the solrHome
* dir. (ie: <code>${solrHome}/${coreName}/conf/${confFile}</code>
*/
public static SolrConfig createConfig(String solrHome, String coreName, String confFile) {
// set some system properties for use by tests
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
try {
return new SolrConfig(solrHome + File.separator + "collection1", confFile, null);
return new SolrConfig(solrHome + File.separator + coreName, confFile, null);
} catch (Exception xany) {
throw new RuntimeException(xany);
}
}
/**
* Creates a SolrConfig object for the
* {@link CoreContainer#DEFAULT_DEFAULT_CORE_NAME} core using {@link #createConfig(String,String,String)}
*/
public static SolrConfig createConfig(String solrHome, String confFile) {
return createConfig(solrHome, CoreContainer.DEFAULT_DEFAULT_CORE_NAME, confFile);
}
/**
* @param dataDirectory path for index data, will not be cleaned up
@ -176,7 +189,7 @@ public class TestHarness {
{
hostPort = System.getProperty("hostPort");
hostContext = "solr";
defaultCoreName = "collection1";
defaultCoreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
initZooKeeper(System.getProperty("zkHost"), 10000);
}
};