LUCENE-3615: add slow, weekly annotations, mark Test2B as slow

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1210033 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2011-12-04 00:20:23 +00:00
parent d4c9e4d6e6
commit f4aabde43b
4 changed files with 76 additions and 31 deletions

View File

@ -94,10 +94,13 @@
<property name="tests.seed" value="random" />
<property name="tests.loggingfile" value="/dev/null"/>
<property name="tests.nightly" value="false" />
<property name="tests.weekly" value="false" />
<property name="tests.slow" value="false" />
<property name="tests.cleanthreads.sysprop" value="perMethod"/>
<property name="tests.asserts.gracious" value="false"/>
<property name="tests.verbose" value="false"/>
<property name="tests.infostream" value="${tests.verbose}"/>
<property name="tests.heapsize" value="512M"/>
<property name="javac.deprecation" value="off"/>
<property name="javac.debug" value="on"/>
@ -527,8 +530,10 @@
<attribute name="tempDir" default="${build.dir}/test"/>
<attribute name="threadNum" default="1"/>
<attribute name="threadTotal" default="1"/>
<attribute name="tests.nightly" default="${tests.nightly}"/>
<attribute name="tests.multiplier" default="${tests.multiplier}"/>
<attribute name="tests.nightly" default="${tests.nightly}"/>
<attribute name="tests.weekly" default="${tests.weekly}"/>
<attribute name="tests.slow" default="${tests.slow}"/>
<attribute name="tests.multiplier" default="${tests.multiplier}"/>
<sequential>
<condition property="runall">
@ -542,7 +547,7 @@
This is very loud and obnoxious. abuse touch instead for a "quiet" mkdir
-->
<touch file="@{tempDir}/@{threadNum}/quiet.ant" verbose="false" mkdirs="true"/>
<junit printsummary="off" haltonfailure="no" maxmemory="512M" tempdir="@{tempDir}/@{threadNum}"
<junit printsummary="off" haltonfailure="no" maxmemory="${tests.heapsize}" tempdir="@{tempDir}/@{threadNum}"
errorProperty="tests.failed" failureProperty="tests.failed" forkmode="perBatch" dir="@{tempDir}/@{threadNum}">
<classpath refid="@{junit.classpath}"/>
<assertions>
@ -584,6 +589,10 @@
<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}"/>
<!-- set whether or not weekly tests should run -->
<sysproperty key="tests.weekly" value="@{tests.weekly}"/>
<!-- set whether or not slow tests should run -->
<sysproperty key="tests.slow" value="@{tests.slow}"/>
<!-- set whether tests framework should not require java assertions enabled -->
<sysproperty key="tests.asserts.gracious" value="${tests.asserts.gracious}"/>

View File

@ -148,8 +148,12 @@ public abstract class LuceneTestCase extends Assert {
public static final int TEST_ITER_MIN = Integer.parseInt(System.getProperty("tests.iter.min", Integer.toString(TEST_ITER)));
/** Get the random seed for tests */
public static final String TEST_SEED = System.getProperty("tests.seed", "random");
/** whether or not nightly tests should run */
/** whether or not @nightly tests should run */
public static final boolean TEST_NIGHTLY = Boolean.parseBoolean(System.getProperty("tests.nightly", "false"));
/** whether or not @weekly tests should run */
public static final boolean TEST_WEEKLY = Boolean.parseBoolean(System.getProperty("tests.weekly", "false"));
/** whether or not @slow tests should run */
public static final boolean TEST_SLOW = Boolean.parseBoolean(System.getProperty("tests.slow", "false"));
/** the line file used by LineFileDocs */
public static final String TEST_LINE_DOCS_FILE = System.getProperty("tests.linedocsfile", "europarl.lines.txt.gz");
/** whether or not to clean threads between test invocations: "false", "perMethod", "perClass" */
@ -1349,6 +1353,22 @@ public abstract class LuceneTestCase extends Assert {
@Retention(RetentionPolicy.RUNTIME)
public @interface Nightly {}
/**
* Annotation for tests that should only be run during weekly builds
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface Weekly{}
/**
* Annotation for tests that are slow and should be run only when specifically asked to run
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface Slow{}
/**
* Annotation for test classes that should only use codecs that are not memory expensive (avoid SimpleText, MemoryCodec).
*/

View File

@ -17,6 +17,7 @@ package org.apache.lucene.util;
* limitations under the License.
*/
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
@ -26,6 +27,8 @@ import java.util.List;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase.Nightly;
import org.apache.lucene.util.LuceneTestCase.Weekly;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.LuceneTestCase.UseNoMemoryExpensiveCodec;
import org.junit.Ignore;
import org.junit.Test;
@ -45,8 +48,11 @@ import static org.apache.lucene.util.LuceneTestCase.TEST_ITER_MIN;
import static org.apache.lucene.util.LuceneTestCase.TEST_METHOD;
import static org.apache.lucene.util.LuceneTestCase.TEST_SEED;
import static org.apache.lucene.util.LuceneTestCase.TEST_NIGHTLY;
import static org.apache.lucene.util.LuceneTestCase.TEST_WEEKLY;
import static org.apache.lucene.util.LuceneTestCase.TEST_SLOW;
import static org.apache.lucene.util.LuceneTestCase.VERBOSE;
/** optionally filters the tests to be run by TEST_METHOD */
public class LuceneTestCaseRunner extends BlockJUnit4ClassRunner {
private List<FrameworkMethod> testMethods;
@ -89,27 +95,13 @@ public class LuceneTestCaseRunner extends BlockJUnit4ClassRunner {
}
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); }
}
removeAnnotatedTests(Nightly.class, "@nightly");
}
if (TEST_WEEKLY == false) {
removeAnnotatedTests(Weekly.class, "@weekly");
}
if (TEST_SLOW == false) {
removeAnnotatedTests(Slow.class, "@slow");
}
// sort the test methods first before shuffling them, so that the shuffle is consistent
// across different implementations that might order the methods different originally.
@ -122,7 +114,31 @@ public class LuceneTestCaseRunner extends BlockJUnit4ClassRunner {
Collections.shuffle(testMethods, r);
return testMethods;
}
private void removeAnnotatedTests(Class<? extends Annotation> annotation, String userFriendlyName) {
if (getTestClass().getJavaClass().isAnnotationPresent(annotation)) {
/* the test class is annotated with the annotation, remove all methods */
String className = getTestClass().getJavaClass().getSimpleName();
System.err.println("NOTE: Ignoring " + userFriendlyName + " test class '" + className + "'");
testMethods.clear();
} else {
/* remove all methods with the annotation*/
for (int i = 0; i < testMethods.size(); i++) {
final FrameworkMethod m = testMethods.get(i);
if (m.getAnnotation(annotation) != null) {
System.err.println("NOTE: Ignoring " + userFriendlyName + " 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); }
}
}
@Override
protected void runChild(FrameworkMethod arg0, RunNotifier arg1) {
if (VERBOSE) {

View File

@ -41,11 +41,11 @@ import org.junit.Ignore;
// disk (but, should run successfully). Best to run w/
// -Dtests.codec=Standard, and w/ plenty of RAM, eg:
//
// ant compile-test
// ant test -Dtest.weekly=true -Dtest.slow=true -Dtests.heapsize=8g
//
// java -server -Xmx8g -d64 -cp .:lib/junit-4.7.jar:./build/classes/test:./build/classes/test-framework:./build/classes/java -Dlucene.version=4.0-dev -Dtests.directory=MMapDirectory -DtempDir=build -ea org.junit.runner.JUnitCore org.apache.lucene.index.Test2BTerms
//
@LuceneTestCase.UseNoMemoryExpensiveCodec
public class Test2BTerms extends LuceneTestCase {
private final static int TOKEN_LEN = 10;
@ -140,13 +140,13 @@ public class Test2BTerms extends LuceneTestCase {
}
}
@Ignore("Takes ~4 hours to run on a fast machine!! And requires that you don't use PreFlex codec.")
@Slow
public void test2BTerms() throws IOException {
if ("Lucene3x".equals(Codec.getDefault().getName())) {
throw new RuntimeException("thist test cannot run with PreFlex codec");
throw new RuntimeException("this test cannot run with PreFlex codec");
}
System.out.println("Starting Test2B");
final long TERM_COUNT = ((long) Integer.MAX_VALUE) + 100000000;
final int TERMS_PER_DOC = _TestUtil.nextInt(random, 100000, 1000000);