Apache Lucene open-source search software
SOLR-2002: add support for -Dtestmethod=xxx when running tests
Robert Muir40a3eb4fd3a9
diff --git a/lucene/common-build.xml b/lucene/common-build.xmlindex fe9bd0d730d..711a0c1e48a 100644--- a/lucene/common-build.xml+++ b/lucene/common-build.xml@@ -53,6 +53,7 @@</path><!-- default arguments to pass to JVM executing tests -->+ <property name="testmethod" value=""/><property name="args" value=""/><property name="threadsPerProcessor" value="1" /><property name="random.multiplier" value="1" />@@ -449,6 +450,8 @@<sysproperty key="tempDir" file="@{tempDir}/@{threadNum}"/><sysproperty key="lucene.version" value="${dev.version}"/>++ <sysproperty key="testmethod" value="${testmethod}"/><formatter type="xml"/><formatter classname="${junit.details.formatter}" usefile="false"/>diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.javaindex 0cca68c66ef..371bad0902f 100644--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java@@ -30,6 +30,7 @@ import java.util.Collections;import java.util.TimeZone;import junit.framework.TestCase;+import junit.framework.TestResult;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.index.ConcurrentMergeScheduler;@@ -324,6 +325,14 @@ public abstract class LuceneTestCase extends TestCase {}}++ @Override+ public void run(TestResult result) {+ if (LuceneTestCaseJ4.TEST_METHOD == null ||+ getName().equals(LuceneTestCaseJ4.TEST_METHOD))+ super.run(result);+ }+@Overridepublic void runBare() throws Throwable {//long t0 = System.currentTimeMillis();diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.javaindex 71ffba36d6f..bb4b8ff318c 100644--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java@@ -44,7 +44,13 @@ import org.junit.BeforeClass;import org.junit.Rule;import org.junit.Test;import org.junit.rules.TestWatchman;+import org.junit.runner.Description;+import org.junit.runner.RunWith;+import org.junit.runner.manipulation.Filter;+import org.junit.runner.manipulation.NoTestsRemainException;+import org.junit.runners.BlockJUnit4ClassRunner;import org.junit.runners.model.FrameworkMethod;+import org.junit.runners.model.InitializationError;import java.io.File;import java.io.PrintStream;@@ -101,6 +107,7 @@ import static org.junit.Assert.fail;// every test. But the functionality we used to// get from that override is provided by InterceptTestCaseEvents//@RunWith(RunBareWrapper.class)+@RunWith(LuceneTestCaseJ4.LuceneTestCaseRunner.class)public class LuceneTestCaseJ4 {/**@@ -114,9 +121,16 @@ public class LuceneTestCaseJ4 {*/public static final Version TEST_VERSION_CURRENT = Version.LUCENE_40;+ /**+ * If this is set, it is the only method that should run.+ */+ static final String TEST_METHOD;+/** Create indexes in this directory, optimally use a subdir, named after the test */public static final File TEMP_DIR;static {+ String method = System.getProperty("testmethod", "").trim();+ TEST_METHOD = method.length() == 0 ? null : method;String s = System.getProperty("tempDir", System.getProperty("java.io.tmpdir"));if (s == null)throw new RuntimeException("To run tests, you need to define system property 'tempDir' or 'java.io.tmpdir'.");@@ -615,4 +629,27 @@ public class LuceneTestCaseJ4 {private static final Random seedRnd = new Random();private String name = "<unknown>";++ /** optionally filters the tests to be run by TEST_METHOD */+ public static class LuceneTestCaseRunner extends BlockJUnit4ClassRunner {+ public LuceneTestCaseRunner(Class<?> clazz) throws InitializationError {+ super(clazz);+ Filter f = new Filter() {++ @Override+ public String describe() { return "filters according to TEST_METHOD"; }++ @Override+ public boolean shouldRun(Description d) {+ return TEST_METHOD == null || d.getMethodName().equals(TEST_METHOD);+ }+ };++ try {+ f.apply(this);+ } catch (NoTestsRemainException e) {+ throw new RuntimeException(e);+ }+ }+ }}diff --git a/solr/build.xml b/solr/build.xmlindex 6a6893356eb..975c85678b6 100644--- a/solr/build.xml+++ b/solr/build.xml@@ -445,6 +445,7 @@<sysproperty key="tests.timezone" value="${tests.timezone}"/><sysproperty key="jetty.insecurerandom" value="1"/><sysproperty key="tempDir" file="@{tempDir}/@{threadNum}"/>+ <sysproperty key="testmethod" value="${testmethod}"/><jvmarg line="${dir.prop}"/><jvmarg line="${args}"/>diff --git a/solr/common-build.xml b/solr/common-build.xmlindex 489b040ae57..79e4cb4e6a1 100644--- a/solr/common-build.xml+++ b/solr/common-build.xml@@ -109,6 +109,7 @@<property name="build.javadoc.solrj" value="${build.docs}/api-solrj"/><!-- JUnit properties -->+ <property name="testmethod" value=""/><property name="junit.includes" value="**/Test*.java,**/*Test.java"/><property name="junit.output.dir" location="${common-solr.dir}/${dest}/test-results"/><property name="junit.reports" location="${common-solr.dir}/${dest}/test-results/reports"/>diff --git a/solr/contrib/dataimporthandler/build.xml b/solr/contrib/dataimporthandler/build.xmlindex 0595f3bae11..e7af9418f69 100644--- a/solr/contrib/dataimporthandler/build.xml+++ b/solr/contrib/dataimporthandler/build.xml@@ -157,6 +157,7 @@><sysproperty key="jetty.insecurerandom" value="1"/><sysproperty key="tempDir" file="${tempDir}"/>+ <sysproperty key="testmethod" value="${testmethod}"/><formatter type="brief" usefile="false" if="junit.details"/><classpath refid="test.classpath"/><formatter type="xml"/>@@ -204,6 +205,7 @@><sysproperty key="jetty.insecurerandom" value="1"/><sysproperty key="tempDir" file="${tempDir}"/>+ <sysproperty key="testmethod" value="${testmethod}"/><formatter type="brief" usefile="false" if="junit.details"/><classpath refid="test.extras.classpath"/><assertions>diff --git a/solr/contrib/extraction/build.xml b/solr/contrib/extraction/build.xmlindex 1b3d58f33ac..e6734f30fc0 100644--- a/solr/contrib/extraction/build.xml+++ b/solr/contrib/extraction/build.xml@@ -105,6 +105,7 @@><sysproperty key="jetty.insecurerandom" value="1"/><sysproperty key="tempDir" file="${tempDir}"/>+ <sysproperty key="testmethod" value="${testmethod}"/><formatter type="brief" usefile="false" if="junit.details"/><classpath refid="test.classpath"/><assertions>