Apache Lucene open-source search software
SOLR-3826: Test framework improvements for specifying coreName on initCore
Chris M. Hostetter1de28d8c2114
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 478fabdd754..f461f7c9240 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -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 ===================diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex c50732e2b63..5fdf8122e37 100755--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -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());diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.javaindex 551e2674792..36cb1fe52f4 100644--- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java+++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java@@ -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 testsSystem.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);}};