mirror of https://github.com/apache/lucene.git
SOLR-2299: enforce resource handling, prevent test interference by running in a jvm-unique CWD (under build/, same as tempDir)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1054164 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ffef43df4f
commit
cf43718bca
|
@ -361,6 +361,10 @@
|
|||
classpathref="test.compile.classpath">
|
||||
<src path="${src}/test" />
|
||||
</solr-javac>
|
||||
<!-- Copy any data files present to the classpath -->
|
||||
<copy todir="${dest}/tests">
|
||||
<fileset dir="${src}/test/test-files" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Run core unit tests. -->
|
||||
|
@ -421,7 +425,7 @@
|
|||
maxmemory="512M"
|
||||
errorProperty="tests.failed"
|
||||
failureProperty="tests.failed"
|
||||
dir="src/test/test-files/"
|
||||
dir="@{tempDir}/@{threadNum}"
|
||||
tempdir="@{tempDir}/@{threadNum}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
|
|
|
@ -118,6 +118,10 @@
|
|||
classpathref="test.classpath">
|
||||
<src path="src/test"/>
|
||||
</solr-javac>
|
||||
<!-- Copy any data files present to the classpath -->
|
||||
<copy todir="${dest}/test-classes">
|
||||
<fileset dir="src/test/test-files" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="example" depends="build,dist">
|
||||
|
@ -136,7 +140,7 @@
|
|||
maxmemory="512M"
|
||||
errorProperty="tests.failed"
|
||||
failureProperty="tests.failed"
|
||||
dir="src/test/test-files/"
|
||||
dir="${junit.output.dir}"
|
||||
tempdir="${junit.output.dir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
|
|
|
@ -90,6 +90,10 @@
|
|||
classpathref="test.classpath">
|
||||
<src path="src/test/java"/>
|
||||
</solr-javac>
|
||||
<!-- Copy any data files present to the classpath -->
|
||||
<copy todir="${dest}/test-classes">
|
||||
<fileset dir="src/test/resources" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="example" depends="build,dist">
|
||||
|
@ -108,7 +112,7 @@
|
|||
maxmemory="512M"
|
||||
errorProperty="tests.failed"
|
||||
failureProperty="tests.failed"
|
||||
dir="src/test/resources/"
|
||||
dir="${junit.output.dir}"
|
||||
tempdir="${junit.output.dir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
|
|
|
@ -28,7 +28,7 @@ public abstract class AbstractClusteringTestCase extends SolrTestCaseJ4 {
|
|||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig.xml", "schema.xml");
|
||||
initCore("solrconfig.xml", "schema.xml", "solr-clustering");
|
||||
numberOfDocs = 0;
|
||||
for (String[] doc : DOCUMENTS) {
|
||||
assertNull(h.validateUpdate(adoc("id", Integer.toString(numberOfDocs), "url", doc[0], "title", doc[1], "snippet", doc[2])));
|
||||
|
|
|
@ -123,6 +123,10 @@
|
|||
classpathref="test.classpath">
|
||||
<src path="src/test/java" />
|
||||
</solr-javac>
|
||||
<!-- Copy any data files present to the classpath -->
|
||||
<copy todir="target/test-classes">
|
||||
<fileset dir="src/test/resources" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="compileExtrasTests" depends="compileExtras">
|
||||
|
@ -130,6 +134,10 @@
|
|||
classpathref="test.classpath">
|
||||
<src path="src/extras/test/java" />
|
||||
</solr-javac>
|
||||
<!-- Copy any data files present to the classpath -->
|
||||
<copy todir="target/extras/test-classes">
|
||||
<fileset dir="src/extras/test/resources" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<property name="tempDir" value="${junit.output.dir}/temp" />
|
||||
|
@ -156,7 +164,7 @@
|
|||
maxmemory="512M"
|
||||
errorProperty="tests.failed"
|
||||
failureProperty="tests.failed"
|
||||
dir="src/test/resources/"
|
||||
dir="${tempDir}"
|
||||
tempdir="${tempDir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
|
@ -217,7 +225,7 @@
|
|||
maxmemory="512M"
|
||||
errorProperty="tests.failed"
|
||||
failureProperty="tests.failed"
|
||||
dir="src/extras/test/resources/"
|
||||
dir="${tempDir}"
|
||||
tempdir="${tempDir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
|||
public class TestTikaEntityProcessor extends AbstractDataImportHandlerTestCase {
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("dataimport-solrconfig.xml", "dataimport-schema-no-unique-key.xml");
|
||||
initCore("dataimport-solrconfig.xml", "dataimport-schema-no-unique-key.xml", "solr-dihextras");
|
||||
}
|
||||
|
||||
public void testIndexingWithTikaEntityProcessor() throws Exception {
|
||||
|
@ -33,7 +33,7 @@ public class TestTikaEntityProcessor extends AbstractDataImportHandlerTestCase {
|
|||
"<dataConfig>" +
|
||||
" <dataSource type=\"BinFileDataSource\"/>" +
|
||||
" <document>" +
|
||||
" <entity processor=\"TikaEntityProcessor\" url=\"../../../../../extraction/src/test/resources/solr-word.pdf\" >" +
|
||||
" <entity processor=\"TikaEntityProcessor\" url=\"" + getFile("solr-word.pdf").getAbsolutePath() + "\" >" +
|
||||
" <field column=\"Author\" meta=\"true\" name=\"author\"/>" +
|
||||
" <field column=\"title\" meta=\"true\" name=\"docTitle\"/>" +
|
||||
" <field column=\"text\"/>" +
|
||||
|
|
Binary file not shown.
|
@ -52,6 +52,11 @@ import java.util.Map;
|
|||
public abstract class AbstractDataImportHandlerTestCase extends
|
||||
SolrTestCaseJ4 {
|
||||
|
||||
// note, a little twisted that we shadow this static method
|
||||
public static void initCore(String config, String schema) throws Exception {
|
||||
initCore(config, schema, "solr-dih");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.List;
|
|||
* @since solr 1.4
|
||||
*/
|
||||
public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCase {
|
||||
private static final String CONF_DIR = "." + File.separator + "solr" + File.separator + "conf" + File.separator;
|
||||
private static final String CONF_DIR = "." + File.separator + "solr-dih" + File.separator + "conf" + File.separator;
|
||||
SolrInstance instance = null;
|
||||
JettySolrRunner jetty;
|
||||
|
||||
|
@ -129,12 +129,12 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
|
|||
confDir.mkdirs();
|
||||
|
||||
File f = new File(confDir, "solrconfig.xml");
|
||||
FileUtils.copyFile(new File(getSolrConfigFile()), f);
|
||||
FileUtils.copyFile(getFile(getSolrConfigFile()), f);
|
||||
f = new File(confDir, "schema.xml");
|
||||
|
||||
FileUtils.copyFile(new File(getSchemaFile()), f);
|
||||
FileUtils.copyFile(getFile(getSchemaFile()), f);
|
||||
f = new File(confDir, "data-config.xml");
|
||||
FileUtils.copyFile(new File(CONF_DIR + "dataconfig-contentstream.xml"), f);
|
||||
FileUtils.copyFile(getFile(CONF_DIR + "dataconfig-contentstream.xml"), f);
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
|
|
|
@ -79,6 +79,10 @@
|
|||
classpathref="test.classpath">
|
||||
<src path="src/test/java" />
|
||||
</solr-javac>
|
||||
<!-- Copy any data files present to the classpath -->
|
||||
<copy todir="${dest}/test-classes">
|
||||
<fileset dir="src/test/resources" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<property name="tempDir" value="${junit.output.dir}/temp" />
|
||||
|
@ -105,7 +109,7 @@
|
|||
maxmemory="512M"
|
||||
errorProperty="tests.failed"
|
||||
failureProperty="tests.failed"
|
||||
dir="src/test/resources/"
|
||||
dir="${tempDir}"
|
||||
tempdir="${tempDir}"
|
||||
forkmode="perBatch"
|
||||
>
|
||||
|
|
|
@ -43,7 +43,7 @@ import java.io.File;
|
|||
public class ExtractingRequestHandlerTest extends SolrTestCaseJ4 {
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig.xml", "schema.xml");
|
||||
initCore("solrconfig.xml", "schema.xml", "solr-extraction");
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -367,7 +367,7 @@ public class ExtractingRequestHandlerTest extends SolrTestCaseJ4 {
|
|||
// TODO: stop using locally defined streams once stream.file and
|
||||
// stream.body work everywhere
|
||||
List<ContentStream> cs = new ArrayList<ContentStream>();
|
||||
cs.add(new ContentStreamBase.FileStream(new File(filename)));
|
||||
cs.add(new ContentStreamBase.FileStream(getFile(filename)));
|
||||
req.setContentStreams(cs);
|
||||
return h.queryAndResponse("/update/extract", req);
|
||||
} finally {
|
||||
|
|
|
@ -84,7 +84,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
/** 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) throws Exception {
|
||||
initCore(config, schema, null);
|
||||
initCore(config, schema, TEST_HOME);
|
||||
}
|
||||
|
||||
/** Call initCore in @BeforeClass to instantiate a solr core in your test class.
|
||||
|
@ -1028,7 +1028,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
* if a real file is needed. To get a stream, code should prefer
|
||||
* {@link Class#getResourceAsStream} using {@code this.getClass()}.
|
||||
*/
|
||||
public static File getFile(String name) throws IOException {
|
||||
public static File getFile(String name) {
|
||||
try {
|
||||
File file = new File(name);
|
||||
if (!file.exists()) {
|
||||
|
@ -1036,7 +1036,26 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
}
|
||||
return file;
|
||||
} catch (Exception e) {
|
||||
throw new IOException("Cannot find resource: " + name);
|
||||
/* more friendly than NPE */
|
||||
throw new RuntimeException("Cannot find resource: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String SOURCE_HOME = determineSourceHome();
|
||||
public static String TEST_HOME = getFile("solr/conf").getParent();
|
||||
public static String WEBAPP_HOME = new File(SOURCE_HOME, "src/webapp/web").getAbsolutePath();
|
||||
public static String EXAMPLE_HOME = new File(SOURCE_HOME, "example/solr").getAbsolutePath();
|
||||
public static String EXAMPLE_MULTICORE_HOME = new File(SOURCE_HOME, "example/multicore").getAbsolutePath();
|
||||
public static String EXAMPLE_SCHEMA=EXAMPLE_HOME+"/conf/schema.xml";
|
||||
public static String EXAMPLE_CONFIG=EXAMPLE_HOME+"/conf/solrconfig.xml";
|
||||
|
||||
static String determineSourceHome() {
|
||||
// ugly, ugly hack to determine the example home without depending on the CWD
|
||||
// this is needed for example/multicore tests which reside outside the classpath
|
||||
File base = getFile("solr/conf/");
|
||||
while (!new File(base, "solr/CHANGES.txt").exists()) {
|
||||
base = base.getParentFile();
|
||||
}
|
||||
return new File(base, "solr/").getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,6 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
|
|||
// using configs in the test directory allows more flexibility to change "example"
|
||||
// without breaking configs.
|
||||
|
||||
private static final String SOURCE_HOME = determineSourceHome();
|
||||
public static String WEBAPP_HOME = new File(SOURCE_HOME, "src/webapp/web").getAbsolutePath();
|
||||
public static String EXAMPLE_HOME = new File(SOURCE_HOME, "example/solr").getAbsolutePath();
|
||||
public static String EXAMPLE_MULTICORE_HOME = new File(SOURCE_HOME, "example/multicore").getAbsolutePath();
|
||||
public static String EXAMPLE_SCHEMA=EXAMPLE_HOME+"/conf/schema.xml";
|
||||
public static String EXAMPLE_CONFIG=EXAMPLE_HOME+"/conf/solrconfig.xml";
|
||||
|
||||
public String getSolrHome() { return EXAMPLE_HOME; }
|
||||
|
||||
public static JettySolrRunner jetty;
|
||||
|
@ -29,23 +22,6 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
|
|||
public static SolrServer server;
|
||||
public static String context;
|
||||
|
||||
static String determineSourceHome() {
|
||||
// ugly, ugly hack to determine the example home without depending on the CWD
|
||||
try {
|
||||
File file = new File("../../../example/solr");
|
||||
if (file.exists())
|
||||
return new File("../../../").getAbsolutePath();
|
||||
// let the hacks begin
|
||||
File base = getFile("solr/conf/");
|
||||
while (!new File(base, "solr/CHANGES.txt").exists()) {
|
||||
base = base.getParentFile();
|
||||
}
|
||||
return new File(base, "solr/").getAbsolutePath();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Cannot determine example home!");
|
||||
}
|
||||
}
|
||||
|
||||
public static JettySolrRunner createJetty(String solrHome, String configFile, String context) throws Exception {
|
||||
// creates the data dir
|
||||
initCore(null, null);
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.solr.cloud;
|
|||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.client.solrj.impl.CloudSolrServer;
|
||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||
|
@ -59,7 +60,7 @@ public class BasicDistributedZkTest extends AbstractDistributedZkTestCase {
|
|||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
System.setProperty("solr.solr.home", SolrTestCaseJ4.TEST_HOME);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.apache.solr.core;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.util.AbstractSolrTestCase;
|
||||
import org.apache.solr.request.SolrRequestHandler;
|
||||
|
||||
|
@ -24,7 +27,9 @@ public class TestXIncludeConfig extends AbstractSolrTestCase {
|
|||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
|
||||
File dest = new File("solrconfig-reqHandler.incl");
|
||||
dest.deleteOnExit();
|
||||
FileUtils.copyFile(getFile("solr/conf/solrconfig-reqHandler.incl"), dest);
|
||||
supports = true;
|
||||
javax.xml.parsers.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
try {
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.junit.Test;
|
|||
public class NoCacheHeaderTest extends CacheHeaderTestBase {
|
||||
@BeforeClass
|
||||
public static void beforeTest() throws Exception {
|
||||
createJetty("solr/", "solr/conf/solrconfig-nocache.xml", null);
|
||||
createJetty(TEST_HOME, "solr/conf/solrconfig-nocache.xml", null);
|
||||
}
|
||||
|
||||
// The tests
|
||||
|
|
|
@ -84,6 +84,14 @@ public abstract class AbstractSolrTestCase extends LuceneTestCase {
|
|||
*/
|
||||
public abstract String getSolrConfigFile();
|
||||
|
||||
/**
|
||||
* Subclasses can override this to change a test's solr home
|
||||
* (default is in test-files)
|
||||
*/
|
||||
public String getSolrHome() {
|
||||
return SolrTestCaseJ4.TEST_HOME;
|
||||
}
|
||||
|
||||
/**
|
||||
* The directory used to story the index managed by the TestHarness h
|
||||
*/
|
||||
|
@ -114,8 +122,8 @@ public abstract class AbstractSolrTestCase extends LuceneTestCase {
|
|||
dataDir = new File(TEMP_DIR,
|
||||
getClass().getName() + "-" + System.currentTimeMillis());
|
||||
dataDir.mkdirs();
|
||||
|
||||
String configFile = getSolrConfigFile();
|
||||
System.setProperty("solr.solr.home", getSolrHome());
|
||||
if (configFile != null) {
|
||||
|
||||
solrConfig = h.createConfig(getSolrConfigFile());
|
||||
|
|
|
@ -19,5 +19,6 @@
|
|||
|
||||
<config>
|
||||
<luceneMatchVersion>${tests.luceneMatchVersion:LUCENE_CURRENT}</luceneMatchVersion>
|
||||
<xi:include href="solr/conf/solrconfig-reqHandler.incl" xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
<!-- FIXME: is there a way to make this test *not* depend on the CWD? -->
|
||||
<xi:include href="solrconfig-reqHandler.incl" xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
</config>
|
||||
|
|
Loading…
Reference in New Issue