mirror of https://github.com/apache/lucene.git
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:
parent
67141af6cd
commit
1de28d8c21
|
@ -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 ===================
|
||||
|
||||
|
||||
|
|
|
@ -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,6 +182,12 @@ 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;
|
||||
|
@ -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());
|
||||
|
|
|
@ -77,17 +77,30 @@ public class TestHarness {
|
|||
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
|
||||
* @param solrConfig solronfig instance
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue