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; @@ -340,13 +342,17 @@ System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockDirectoryFactory"); } + if (useNoMemoryExpensiveCodec) { + System.err.println("NOTE: Using no memory expensive codecs."); + } + savedCodecProvider = CodecProvider.getDefault(); if ("random".equals(TEST_CODECPROVIDER)) { if ("randomPerField".equals(TEST_CODEC)) { 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 +1403,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 +1424,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,12 @@ 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."); + } + // evil we cannot init our random here, because super() calls computeTestMethods!!!!; Filter f = new Filter() { @@ -173,5 +180,8 @@ } catch (NoTestsRemainException e) { throw new RuntimeException(e); } + + LuceneTestCase.useNoMemoryExpensiveCodec = + getTestClass().getJavaClass().isAnnotationPresent(UseNoMemoryExpensiveCodec.class); } } 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) @@ -36,6 +36,7 @@ import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util._TestUtil; +@LuceneTestCase.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) @@ -46,6 +46,7 @@ import org.apache.lucene.util.automaton.CompiledAutomaton; import org.apache.lucene.util.automaton.DaciukMihovAutomatonBuilder; +@LuceneTestCase.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,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 1177870) +++ lucene/src/test/org/apache/lucene/util/fst/TestFSTs.java (working copy) @@ -57,6 +57,7 @@ import org.apache.lucene.util._TestUtil; import org.apache.lucene.util.fst.FST.Arc; +@LuceneTestCase.UseNoMemoryExpensiveCodec public class TestFSTs extends LuceneTestCase { private MockDirectoryWrapper dir;