Apache Solr open-source search software
don't lose coverage for memory / mix up dv formats in tests
Robert Muir6acc61da2d27
diff --git a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.javaindex 9945c8eb3b0..ff18f998329 100644--- a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java+++ b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java@@ -52,7 +52,7 @@ import org.apache.lucene.util.LuceneTestCase;* to this class.*/// nocommit don't suppress any:-@SuppressCodecs({"Asserting", "Direct", "Memory", "MockRandom", "Lucene40", "Compressing"})+@SuppressCodecs({"Asserting", "Direct", "MockRandom", "Lucene40", "Compressing"})public class TestDemoDocValue extends LuceneTestCase {public void testDemoNumber() throws IOException {diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java b/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.javaindex 61de20efe1f..d46f8efc643 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java@@ -28,12 +28,15 @@ import java.util.Random;import java.util.Set;import org.apache.lucene.codecs.PostingsFormat;+import org.apache.lucene.codecs.SimpleDocValuesFormat;import org.apache.lucene.codecs.asserting.AssertingPostingsFormat;import org.apache.lucene.codecs.lucene41.Lucene41Codec;import org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat;+import org.apache.lucene.codecs.lucene41.Lucene41SimpleDocValuesFormat;import org.apache.lucene.codecs.lucene41ords.Lucene41WithOrds;import org.apache.lucene.codecs.bloom.TestBloomFilteredLucene41Postings;import org.apache.lucene.codecs.memory.DirectPostingsFormat;+import org.apache.lucene.codecs.memory.MemoryDocValuesFormat;import org.apache.lucene.codecs.memory.MemoryPostingsFormat;import org.apache.lucene.codecs.mockintblock.MockFixedIntBlockPostingsFormat;import org.apache.lucene.codecs.mockintblock.MockVariableIntBlockPostingsFormat;@@ -42,6 +45,7 @@ import org.apache.lucene.codecs.mocksep.MockSepPostingsFormat;import org.apache.lucene.codecs.nestedpulsing.NestedPulsingPostingsFormat;import org.apache.lucene.codecs.pulsing.Pulsing41PostingsFormat;import org.apache.lucene.codecs.simpletext.SimpleTextPostingsFormat;+import org.apache.lucene.codecs.simpletext.SimpleTextSimpleDocValuesFormat;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util._TestUtil;@@ -58,14 +62,21 @@ public class RandomCodec extends Lucene41Codec {/** Shuffled list of postings formats to use for new mappings */private List<PostingsFormat> formats = new ArrayList<PostingsFormat>();+ /** Shuffled list of docvalues formats to use for new mappings */+ private List<SimpleDocValuesFormat> dvFormats = new ArrayList<SimpleDocValuesFormat>();+/** unique set of format names this codec knows about */public Set<String> formatNames = new HashSet<String>();++ /** unique set of docvalues format names this codec knows about */+ public Set<String> dvFormatNames = new HashSet<String>();/** memorized field->postingsformat mappings */// note: we have to sync this map even though its just for debugging/toString,// otherwise DWPT's .toString() calls that iterate over the map can// cause concurrentmodificationexception if indexwriter's infostream is onprivate Map<String,PostingsFormat> previousMappings = Collections.synchronizedMap(new HashMap<String,PostingsFormat>());+ private Map<String,SimpleDocValuesFormat> previousDVMappings = Collections.synchronizedMap(new HashMap<String,SimpleDocValuesFormat>());private final int perFieldSeed;@Override@@ -84,6 +95,22 @@ public class RandomCodec extends Lucene41Codec {return codec;}+ @Override+ public SimpleDocValuesFormat getDocValuesFormatForField(String name) {+ SimpleDocValuesFormat codec = previousDVMappings.get(name);+ if (codec == null) {+ codec = dvFormats.get(Math.abs(perFieldSeed ^ name.hashCode()) % dvFormats.size());+ if (codec instanceof SimpleTextSimpleDocValuesFormat && perFieldSeed % 5 != 0) {+ // make simpletext rarer, choose again+ codec = dvFormats.get(Math.abs(perFieldSeed ^ name.toUpperCase(Locale.ROOT).hashCode()) % dvFormats.size());+ }+ previousDVMappings.put(name, codec);+ // Safety:+ assert previousDVMappings.size() < 10000: "test went insane";+ }+ return codec;+ }+public RandomCodec(Random random, Set<String> avoidCodecs) {this.perFieldSeed = random.nextInt();// TODO: make it possible to specify min/max iterms per@@ -113,11 +140,18 @@ public class RandomCodec extends Lucene41Codec {new AssertingPostingsFormat(),new MemoryPostingsFormat(true, random.nextFloat()),new MemoryPostingsFormat(false, random.nextFloat()));++ addDocValues(avoidCodecs,+ new Lucene41SimpleDocValuesFormat(),+ new SimpleTextSimpleDocValuesFormat(),+ new MemoryDocValuesFormat());Collections.shuffle(formats, random);+ Collections.shuffle(dvFormats, random);// Avoid too many open files:formats = formats.subList(0, 4);+ // only if we get big dvFormats = dvFormats.subList(0, 4);}public RandomCodec(Random random) {@@ -132,9 +166,18 @@ public class RandomCodec extends Lucene41Codec {}}}++ private final void addDocValues(Set<String> avoidCodecs, SimpleDocValuesFormat... docvalues) {+ for (SimpleDocValuesFormat d : docvalues) {+ if (!avoidCodecs.contains(d.getName())) {+ dvFormats.add(d);+ dvFormatNames.add(d.getName());+ }+ }+ }@Overridepublic String toString() {- return super.toString() + ": " + previousMappings.toString();+ return super.toString() + ": " + previousMappings.toString() + ", docValues:" + previousDVMappings.toString();}}