Index: common-build.xml =================================================================== --- common-build.xml (revision 1035418) +++ common-build.xml (working copy) @@ -65,6 +65,7 @@ + Index: src/test/org/apache/lucene/util/LuceneTestCase.java =================================================================== --- src/test/org/apache/lucene/util/LuceneTestCase.java (revision 1035418) +++ src/test/org/apache/lucene/util/LuceneTestCase.java (working copy) @@ -35,6 +35,8 @@ import org.apache.lucene.index.codecs.preflex.PreFlexCodec; import org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec; import org.apache.lucene.index.codecs.pulsing.PulsingCodec; +import org.apache.lucene.index.codecs.simpletext.SimpleTextCodec; +import org.apache.lucene.index.codecs.standard.StandardCodec; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache.CacheEntry; @@ -69,6 +71,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; @@ -142,6 +145,8 @@ // tests) /** Gets the codec to run tests with. */ static final String TEST_CODEC = System.getProperty("tests.codec", "random"); + /** Get if a random codec per field should be used */ // only use random per field if no explicit codec is set + static final boolean TEST_RAMDOM_CODEC_PER_FIELD = "random".equals(TEST_CODEC) && Boolean.parseBoolean(System.getProperty("tests.randomCodecPerField", "true")); /** Gets the locale to run tests with */ static final String TEST_LOCALE = System.getProperty("tests.locale", "random"); /** Gets the timezone to run tests with */ @@ -316,6 +321,7 @@ timeZone = TEST_TIMEZONE.equals("random") ? randomTimeZone(random) : TimeZone.getTimeZone(TEST_TIMEZONE); TimeZone.setDefault(timeZone); testsFailed = false; + randomCodecProvider = new RandomCodecProvider(random); } @AfterClass @@ -336,11 +342,11 @@ } stores = null; // if tests failed, report some information back - if (testsFailed) + if (testsFailed) { System.out.println("NOTE: test params are: codec=" + codec + ", locale=" + locale + - ", timezone=" + (timeZone == null ? "(null)" : timeZone.getID())); - if (testsFailed) { + ", timezone=" + (timeZone == null ? "(null)" : timeZone.getID()) + + (TEST_RAMDOM_CODEC_PER_FIELD?", "+randomCodecProvider.toString():"")); System.err.println("NOTE: all tests run in this JVM:"); System.err.println(Arrays.toString(testClassesRun.toArray())); } @@ -636,7 +642,9 @@ logmp.setCalibrateSizeByDeletes(r.nextBoolean()); logmp.setMergeFactor(_TestUtil.nextInt(r, 2, 20)); } - + if (TEST_RAMDOM_CODEC_PER_FIELD) { + c.setCodecProvider(randomCodecProvider); + } c.setReaderPooling(r.nextBoolean()); c.setReaderTermsIndexDivisor(_TestUtil.nextInt(r, 1, 4)); return c; @@ -838,6 +846,8 @@ // seed for individual test methods, changed in @before private long seed; + protected static CodecProvider randomCodecProvider; + private static final Random seedRand = new Random(); protected static final Random random = new Random(); @@ -901,4 +911,45 @@ } } } + + static class RandomCodecProvider extends CodecProvider { + + private final Codec[] codecs; + private final Map perFieldMap = new HashMap(); + private final Random random; + + RandomCodecProvider(Random random) { + this.codecs = new Codec[] { new StandardCodec(), new SimpleTextCodec(), + new MockSepCodec(), new PulsingCodec(1 + random.nextInt(10)), + new MockVariableIntBlockCodec(1 + random.nextInt(10)), + new MockFixedIntBlockCodec(1 + random.nextInt(10)) }; + for (int i = 0; i < codecs.length; i++) { + super.register(codecs[i]); + } + // register preflex to support reading of old indexes + this.register(new PreFlexCodec()); + this.random = random; + } + + @Override + public synchronized String getFieldCodec(String name) { + if (!perFieldMap.containsKey(name)) { // select a codec at random + setFieldCodec(name, codecs[random.nextInt(codecs.length)].name); + } + return super.getFieldCodec(name); + } + + @Override + public synchronized void setFieldCodec(String field, String codec) { + if (!perFieldMap.containsKey(field)) { + perFieldMap.put(field, codec); + } + super.setFieldCodec(field, codec); + } + + @Override + public String toString() { + return "RandomCodecProvider [perFieldMap=" + perFieldMap + "]"; + } + } }