Index: lucene/src/test-framework/org/apache/lucene/index/RandomCodecProvider.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/index/RandomCodecProvider.java (revision 1177870) +++ lucene/src/test-framework/org/apache/lucene/index/RandomCodecProvider.java (working copy) @@ -48,7 +48,7 @@ private Map previousMappings = new HashMap(); private final int perFieldSeed; - public RandomCodecProvider(Random random) { + public RandomCodecProvider(Random random, boolean useNoMemoryExpensiveCodec) { this.perFieldSeed = random.nextInt(); // TODO: make it possible to specify min/max iterms per // block via CL: @@ -61,8 +61,10 @@ minItemsPerBlock = _TestUtil.nextInt(random, 2, 100); maxItemsPerBlock = 2*(Math.max(1, minItemsPerBlock-1)) + random.nextInt(100); register(new PulsingCodec( 1 + random.nextInt(20), minItemsPerBlock, maxItemsPerBlock)); - register(new SimpleTextCodec()); - register(new MemoryCodec()); + if (!useNoMemoryExpensiveCodec) { + register(new SimpleTextCodec()); + register(new MemoryCodec()); + } Collections.shuffle(knownCodecs, random); } Index: lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java =================================================================== --- lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (revision 1177870) +++ lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (working copy) @@ -21,9 +21,11 @@ import java.io.IOException; import java.io.PrintStream; import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.lang.reflect.Constructor; import java.util.*; import java.util.Map.Entry; @@ -346,7 +348,7 @@ if (random.nextInt(4) == 0) { // preflex-only setup codec = installTestCodecs("PreFlex", CodecProvider.getDefault()); } else { // per-field setup - CodecProvider.setDefault(new RandomCodecProvider(random)); + CodecProvider.setDefault(new RandomCodecProvider(random, useNoMemoryExpensiveCodec)); codec = installTestCodecs(TEST_CODEC, CodecProvider.getDefault()); } } else { // ordinary setup @@ -1397,6 +1399,9 @@ return context; } + // initialized by the TestRunner + static boolean useNoMemoryExpensiveCodec; + // recorded seed: for beforeClass private static long staticSeed; // seed for individual test methods, changed in @before @@ -1415,6 +1420,15 @@ @Retention(RetentionPolicy.RUNTIME) public @interface Nightly {} + /** + * Annotation for test classes that should only use codecs that are not memory expensive (avoid SimpleText, MemoryCodec). + */ + @Documented + @Inherited + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + 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 1177870) +++ 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; @@ -156,6 +157,18 @@ public LuceneTestCaseRunner(Class clazz) throws InitializationError { super(clazz); + + // This TestRunner can handle only LuceneTestCase subclasses + if (!LuceneTestCase.class.isAssignableFrom(clazz)) { + throw new UnsupportedOperationException("LuceneTestCaseRunner can only be used with LuceneTestCase."); + } + + final boolean useNoMemoryExpensiveCodec = LuceneTestCase.useNoMemoryExpensiveCodec = + clazz.isAnnotationPresent(UseNoMemoryExpensiveCodec.class); + if (useNoMemoryExpensiveCodec) { + System.err.println("NOTE: Using no memory expensive codecs unless otherwise specified."); + } + // evil we cannot init our random here, because super() calls computeTestMethods!!!!; Filter f = new Filter() { Index: lucene/src/test/org/apache/lucene/index/TestLongPostings.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestLongPostings.java (revision 1177870) +++ lucene/src/test/org/apache/lucene/index/TestLongPostings.java (working copy) @@ -33,9 +33,11 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCase.UseNoMemoryExpensiveCodec; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util._TestUtil; +@UseNoMemoryExpensiveCodec public class TestLongPostings extends LuceneTestCase { // Produces a realistic unicode random string that Index: lucene/src/test/org/apache/lucene/index/TestTermsEnum.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestTermsEnum.java (revision 1177870) +++ lucene/src/test/org/apache/lucene/index/TestTermsEnum.java (working copy) @@ -40,12 +40,14 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LineFileDocs; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCase.UseNoMemoryExpensiveCodec; import org.apache.lucene.util._TestUtil; import org.apache.lucene.util.automaton.Automaton; import org.apache.lucene.util.automaton.BasicAutomata; import org.apache.lucene.util.automaton.CompiledAutomaton; import org.apache.lucene.util.automaton.DaciukMihovAutomatonBuilder; +@UseNoMemoryExpensiveCodec public class TestTermsEnum extends LuceneTestCase { public void test() throws Exception { Index: lucene/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java =================================================================== --- lucene/src/test/org/apache/lucene/util/automaton/TestCompiledAutomaton.java (revision 1177870) +++ 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,12 @@ public class TestCompiledAutomaton extends LuceneTestCase { private CompiledAutomaton build(String... strings) { - final List as = new ArrayList(); + final List terms = new ArrayList(); for(String s : strings) { - as.add(BasicAutomata.makeString(s)); + terms.add(new BytesRef(s)); } - Automaton a = BasicOperations.union(as); - a.determinize(); + Collections.sort(terms); + final Automaton a = DaciukMihovAutomatonBuilder.build(terms); return new CompiledAutomaton(a, true, false); } @@ -93,7 +94,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 +108,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 1177870) +++ lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java (working copy) @@ -53,10 +53,12 @@ import org.apache.lucene.util.IntsRef; import org.apache.lucene.util.LineFileDocs; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCase.UseNoMemoryExpensiveCodec; import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util._TestUtil; import org.apache.lucene.util.fst.FST.Arc; +@UseNoMemoryExpensiveCodec public class TestFSTs extends LuceneTestCase { private MockDirectoryWrapper dir;