Apache Lucene open-source search software
LUCENE-2768: add support to LuceneTestCase for @Nightly annotated tests
Robert Muire60764241b2e
diff --git a/lucene/common-build.xml b/lucene/common-build.xmlindex 2b93e19c5c2..78e84f59502 100644--- a/lucene/common-build.xml+++ b/lucene/common-build.xml@@ -72,6 +72,7 @@<property name="tests.seed" value="random" /><property name="tests.userdir" value="."/><property name="tests.loggingfile" value="/dev/null"/>+ <property name="tests.nightly" value="false" /><property name="javac.deprecation" value="off"/><property name="javac.debug" value="on"/>@@ -462,7 +463,9 @@<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/><!-- logging config file --><sysproperty key="java.util.logging.config.file" value="${tests.loggingfile}"/>-+ <!-- set whether or not nightly tests should run -->+ <sysproperty key="tests.nightly" value="${tests.nightly}"/>+<!-- TODO: create propertyset for test properties, so each project can have its own set --><sysproperty key="tests.multiplier" value="${tests.multiplier}"/><sysproperty key="tempDir" file="@{tempDir}/@{threadNum}"/>diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.javaindex 986877bbc77..fff097cc159 100644--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java@@ -63,6 +63,10 @@ import org.junit.runners.model.InitializationError;import java.io.File;import java.io.IOException;import java.io.PrintStream;+import java.lang.annotation.Documented;+import java.lang.annotation.Inherited;+import java.lang.annotation.Retention;+import java.lang.annotation.RetentionPolicy;import java.lang.reflect.Constructor;import java.lang.reflect.Method;import java.lang.reflect.Modifier;@@ -152,6 +156,8 @@ public abstract class LuceneTestCase extends Assert {static final int TEST_ITER = Integer.parseInt(System.getProperty("tests.iter", "1"));/** Get the random seed for tests */static final String TEST_SEED = System.getProperty("tests.seed", "random");+ /** whether or not nightly tests should run */+ static final boolean TEST_NIGHTLY = Boolean.parseBoolean(System.getProperty("tests.nightly", "false"));private static final Pattern codecWithParam = Pattern.compile("(.*)\\(\\s*(\\d+)\\s*\\)");@@ -843,6 +849,14 @@ public abstract class LuceneTestCase extends Assert {private String name = "<unknown>";+ /**+ * Annotation for tests that should only be run during nightly builds.+ */+ @Documented+ @Inherited+ @Retention(RetentionPolicy.RUNTIME)+ public @interface Nightly {}+/** optionally filters the tests to be run by TEST_METHOD */public static class LuceneTestCaseRunner extends BlockJUnit4ClassRunner {private List<FrameworkMethod> testMethods;@@ -856,7 +870,7 @@ public abstract class LuceneTestCase extends Assert {for (Method m : getTestClass().getJavaClass().getMethods()) {// check if the current test's class has methods annotated with @Ignorefinal Ignore ignored = m.getAnnotation(Ignore.class);- if (ignored != null) {+ if (ignored != null && !m.getName().equals("alwaysIgnoredTestMethod")) {System.err.println("NOTE: Ignoring test method '" + m.getName() + "': " + ignored.value());}// add methods starting with "test"@@ -872,6 +886,34 @@ public abstract class LuceneTestCase extends Assert {testMethods.add(new FrameworkMethod(m));}}++ if (testMethods.isEmpty()) {+ throw new RuntimeException("No runnable methods!");+ }++ if (TEST_NIGHTLY == false) {+ if (getTestClass().getJavaClass().isAnnotationPresent(Nightly.class)) {+ /* the test class is annotated with nightly, remove all methods */+ String className = getTestClass().getJavaClass().getSimpleName();+ System.err.println("NOTE: Ignoring nightly-only test class '" + className + "'");+ testMethods.clear();+ } else {+ /* remove all nightly-only methods */+ for (int i = 0; i < testMethods.size(); i++) {+ final FrameworkMethod m = testMethods.get(i);+ if (m.getAnnotation(Nightly.class) != null) {+ System.err.println("NOTE: Ignoring nightly-only test method '" + m.getName() + "'");+ testMethods.remove(i--);+ }+ }+ }+ /* dodge a possible "no-runnable methods" exception by adding a fake ignored test */+ if (testMethods.isEmpty()) {+ try {+ testMethods.add(new FrameworkMethod(LuceneTestCase.class.getMethod("alwaysIgnoredTestMethod")));+ } catch (Exception e) { throw new RuntimeException(e); }+ }+ }return testMethods;}@@ -901,4 +943,7 @@ public abstract class LuceneTestCase extends Assert {}}}++ @Ignore("just a hack")+ public final void alwaysIgnoredTestMethod() {}}diff --git a/solr/build.xml b/solr/build.xmlindex 81e66356c10..60199cfb420 100644--- a/solr/build.xml+++ b/solr/build.xml@@ -436,6 +436,8 @@<sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="@{tempDir}/@{threadNum}"/><sysproperty key="testmethod" value="${testmethod}"/>+ <!-- set whether or not nightly tests should run -->+ <sysproperty key="tests.nightly" value="${tests.nightly}"/><!-- TODO: why is this unconditionally set to "" above? disable for now<jvmarg line="${dir.prop}"/>-->diff --git a/solr/common-build.xml b/solr/common-build.xmlindex d95925c2d26..8e77e8a1881 100644--- a/solr/common-build.xml+++ b/solr/common-build.xml@@ -61,6 +61,7 @@<property name="tests.timezone" value="random" /><property name="tests.iter" value="1" /><property name="tests.seed" value="random" />+ <property name="tests.nightly" value="false" /><condition property="dir.prop" value="-Dsolr.directoryFactory=solr.StandardDirectoryFactory"><isset property="use.fsdir"/>diff --git a/solr/contrib/analysis-extras/build.xml b/solr/contrib/analysis-extras/build.xmlindex a58a4967462..9857db8ba5e 100644--- a/solr/contrib/analysis-extras/build.xml+++ b/solr/contrib/analysis-extras/build.xml@@ -148,6 +148,8 @@<sysproperty key="tests.multiplier" value="${tests.multiplier}"/><sysproperty key="tests.seed" value="${tests.seed}"/><sysproperty key="tests.iter" value="${tests.iter}"/>+ <!-- set whether or not nightly tests should run -->+ <sysproperty key="tests.nightly" value="${tests.nightly}"/><sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${junit.output.dir}"/><sysproperty key="testmethod" value="${testmethod}"/>diff --git a/solr/contrib/clustering/build.xml b/solr/contrib/clustering/build.xmlindex db024434f5f..62f5ce11e73 100644--- a/solr/contrib/clustering/build.xml+++ b/solr/contrib/clustering/build.xml@@ -116,6 +116,8 @@<sysproperty key="tests.multiplier" value="${tests.multiplier}"/><sysproperty key="tests.seed" value="${tests.seed}"/><sysproperty key="tests.iter" value="${tests.iter}"/>+ <!-- set whether or not nightly tests should run -->+ <sysproperty key="tests.nightly" value="${tests.nightly}"/><sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${junit.output.dir}"/><sysproperty key="testmethod" value="${testmethod}"/>diff --git a/solr/contrib/dataimporthandler/build.xml b/solr/contrib/dataimporthandler/build.xmlindex 164536af4da..49d57cf452a 100644--- a/solr/contrib/dataimporthandler/build.xml+++ b/solr/contrib/dataimporthandler/build.xml@@ -168,6 +168,8 @@<sysproperty key="tests.multiplier" value="${tests.multiplier}"/><sysproperty key="tests.iter" value="${tests.iter}"/><sysproperty key="tests.seed" value="${tests.seed}"/>+ <!-- set whether or not nightly tests should run -->+ <sysproperty key="tests.nightly" value="${tests.nightly}"/><sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${tempDir}"/><sysproperty key="testmethod" value="${testmethod}"/>@@ -226,6 +228,8 @@<sysproperty key="tests.multiplier" value="${tests.multiplier}"/><sysproperty key="tests.iter" value="${tests.iter}"/><sysproperty key="tests.seed" value="${tests.seed}"/>+ <!-- set whether or not nightly tests should run -->+ <sysproperty key="tests.nightly" value="${tests.nightly}"/><sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${tempDir}"/><sysproperty key="testmethod" value="${testmethod}"/>diff --git a/solr/contrib/extraction/build.xml b/solr/contrib/extraction/build.xmlindex bfc15782f10..114f72a3b3b 100644--- a/solr/contrib/extraction/build.xml+++ b/solr/contrib/extraction/build.xml@@ -117,6 +117,8 @@<sysproperty key="tests.multiplier" value="${tests.multiplier}"/><sysproperty key="tests.iter" value="${tests.iter}"/><sysproperty key="tests.seed" value="${tests.seed}"/>+ <!-- set whether or not nightly tests should run -->+ <sysproperty key="tests.nightly" value="${tests.nightly}"/><sysproperty key="jetty.testMode" value="1"/><sysproperty key="tempDir" file="${tempDir}"/><sysproperty key="testmethod" value="${testmethod}"/>