Index: lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (revision 1177807) +++ lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (working copy) @@ -303,6 +303,32 @@ swapCodec(new PulsingCodec(), cp); cp.setDefaultFieldCodec(savedDefaultCodec); } + + // Support for @UseNoMemoryExpensiveCodec (called from LuceneTestCaseRunner): + + private static final List disabledCodecs = new ArrayList(); + + static synchronized void disableMemoryExpensiveCodecs() { + final CodecProvider cp = CodecProvider.getDefault(); + if (cp instanceof RandomCodecProvider) { + final RandomCodecProvider rcp = (RandomCodecProvider) cp; + disabledCodecs.add(rcp.lookup("Memory")); + disabledCodecs.add(rcp.lookup("SimpleText")); + for (final Codec c : disabledCodecs) { + rcp.unregister(c); + } + } + } + + static synchronized void reenableMemoryExpensiveCodecs() { + final CodecProvider cp = CodecProvider.getDefault(); + if (cp instanceof RandomCodecProvider) { + for (final Codec c : disabledCodecs) { + ((RandomCodecProvider) cp).register(c); + } + } + disabledCodecs.clear(); + } // randomly picks from core and test codecs static String pickRandomCodec(Random rnd) { @@ -1418,6 +1444,14 @@ @Retention(RetentionPolicy.RUNTIME) public @interface Nightly {} + /** + * Annotation for tests that should only use codecs that are not memory expensive (avoid SimpleText, MemoryCodec). + */ + @Documented + @Inherited + @Retention(RetentionPolicy.RUNTIME) + public @interface UseNoMemoryExpensiveCodec {} + @Ignore("just a hack") public final void alwaysIgnoredTestMethod() {} } Index: lucene/src/test-framework/org/apache/lucene/util/LuceneTestCaseRunner.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/util/LuceneTestCaseRunner.java (revision 1177807) +++ lucene/src/test-framework/org/apache/lucene/util/LuceneTestCaseRunner.java (working copy) @@ -26,6 +26,7 @@ import java.util.Random; import org.apache.lucene.util.LuceneTestCase.Nightly; +import org.apache.lucene.util.LuceneTestCase.UseNoMemoryExpensiveCodec; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.Description; @@ -131,26 +132,36 @@ // only print iteration info if the user requested more than one iterations final boolean verbose = VERBOSE && TEST_ITER > 1; - final int currentIter[] = new int[1]; - arg1.addListener(new RunListener() { - @Override - public void testFailure(Failure failure) throws Exception { + // avoid some codecs if annotation present + final boolean useNoMemoryExpensiveCodec = arg0.getAnnotation(UseNoMemoryExpensiveCodec.class) != null; + try { + if (useNoMemoryExpensiveCodec) { + System.err.println("NOTE: Using no memory-expensive random codecs for '" + arg0.getName() + "' unless explicitely selected."); + LuceneTestCase.disableMemoryExpensiveCodecs(); + } + final int currentIter[] = new int[1]; + arg1.addListener(new RunListener() { + @Override + public void testFailure(Failure failure) throws Exception { + if (verbose) { + System.out.println("\nNOTE: iteration " + currentIter[0] + " failed! "); + } + } + }); + for (int i = 0; i < TEST_ITER; i++) { + currentIter[0] = i; if (verbose) { - System.out.println("\nNOTE: iteration " + currentIter[0] + " failed! "); + System.out.println("\nNOTE: running iter=" + (1+i) + " of " + TEST_ITER); } - } - }); - for (int i = 0; i < TEST_ITER; i++) { - currentIter[0] = i; - if (verbose) { - System.out.println("\nNOTE: running iter=" + (1+i) + " of " + TEST_ITER); - } - super.runChild(arg0, arg1); - if (LuceneTestCase.testsFailed) { - if (i >= TEST_ITER_MIN - 1) { // XXX is this still off-by-one? - break; + super.runChild(arg0, arg1); + if (LuceneTestCase.testsFailed) { + if (i >= TEST_ITER_MIN - 1) { // XXX is this still off-by-one? + break; + } } } + } finally { + LuceneTestCase.reenableMemoryExpensiveCodecs(); } } Index: lucene/src/test/org/apache/lucene/index/TestLongPostings.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestLongPostings.java (revision 1177807) +++ lucene/src/test/org/apache/lucene/index/TestLongPostings.java (working copy) @@ -75,6 +75,7 @@ } } + @UseNoMemoryExpensiveCodec public void testLongPostings() throws Exception { assumeFalse("Too slow with SimpleText codec at night", TEST_NIGHTLY && CodecProvider.getDefault().getFieldCodec("field").equals("SimpleText")); assumeFalse("Too slow with Memory codec at night", TEST_NIGHTLY && CodecProvider.getDefault().getFieldCodec("field").equals("Memory")); Index: lucene/src/test/org/apache/lucene/index/TestTermsEnum.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestTermsEnum.java (revision 1177807) +++ lucene/src/test/org/apache/lucene/index/TestTermsEnum.java (working copy) @@ -184,6 +184,7 @@ } // Tests Terms.intersect + @UseNoMemoryExpensiveCodec public void testIntersectRandom() throws IOException { final Directory dir = newDirectory(); Index: lucene/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java =================================================================== --- lucene/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java (revision 1177807) +++ lucene/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java (working copy) @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -30,12 +31,20 @@ public class TestCompiledAutomaton extends LuceneTestCase { private CompiledAutomaton build(String... strings) { + final List terms = new ArrayList(); + for(String s : strings) { + terms.add(new BytesRef(s)); + } + Collections.sort(terms); + final Automaton a = DaciukMihovAutomatonBuilder.build(terms); + /* final List as = new ArrayList(); for(String s : strings) { as.add(BasicAutomata.makeString(s)); } Automaton a = BasicOperations.union(as); a.determinize(); + */ return new CompiledAutomaton(a, true, false); } @@ -93,7 +102,7 @@ } public void testRandom() throws Exception { - final int numTerms = atLeast(1000); + final int numTerms = atLeast(400); final Set terms = new HashSet(); while(terms.size() != numTerms) { terms.add(randomString()); @@ -107,7 +116,7 @@ } public void testBasic() throws Exception { - CompiledAutomaton c = build("foo", "fob", "goo"); + CompiledAutomaton c = build("fob", "foo", "goo"); testFloor(c, "goo", "goo"); testFloor(c, "ga", "foo"); testFloor(c, "g", "foo"); Index: lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java =================================================================== --- lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java (revision 1177807) +++ lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java (working copy) @@ -1009,6 +1009,7 @@ // Build FST for all unique terms in the test line docs // file, up until a time limit + @UseNoMemoryExpensiveCodec public void testRealTerms() throws Exception { final String defaultCodec = CodecProvider.getDefault().getDefaultFieldCodec();