Apache Lucene open-source search software
make tests.verbose only include relevant output, fix non-reproducibility (!) of QueryUtils
Robert Muirb67473ea85e4
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java b/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.javaindex cd5c18c3946..d35939a7941 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java@@ -100,8 +100,7 @@ public class RandomIndexWriter implements Closeable {}codec = w.getConfig().getCodec();if (LuceneTestCase.VERBOSE) {- System.out.println("RIW dir=" + dir + " config=" + w.getConfig());- System.out.println("codec default=" + codec.getName());+ System.out.println("RIW dir=" + dir);}// Make sure we sometimes test indices that don't getdiff --git a/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java b/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.javaindex aa53d17a597..b5a4caf02e4 100644--- a/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java+++ b/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java@@ -18,24 +18,27 @@ package org.apache.lucene.search;*/import java.io.IOException;+import java.util.Collections;+import java.util.Iterator;import java.util.List;import java.util.Random;import junit.framework.Assert;-import org.apache.lucene.analysis.MockAnalyzer;-import org.apache.lucene.document.Document;-import org.apache.lucene.index.AllDeletedFilterReader;-import org.apache.lucene.index.DirectoryReader;+import org.apache.lucene.index.BinaryDocValues;+import org.apache.lucene.index.FieldInfo;+import org.apache.lucene.index.FieldInfos;+import org.apache.lucene.index.Fields;import org.apache.lucene.index.IndexReader;-import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.LeafReader;import org.apache.lucene.index.LeafReaderContext;import org.apache.lucene.index.MultiReader;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockDirectoryWrapper;-import org.apache.lucene.store.RAMDirectory;+import org.apache.lucene.index.NumericDocValues;+import org.apache.lucene.index.SortedDocValues;+import org.apache.lucene.index.SortedNumericDocValues;+import org.apache.lucene.index.SortedSetDocValues;+import org.apache.lucene.index.StoredFieldVisitor;+import org.apache.lucene.index.Terms;import org.apache.lucene.util.Bits;import org.apache.lucene.util.LuceneTestCase;@@ -166,16 +169,16 @@ public class QueryUtils {// we can't put deleted docs before the nested reader, because// it will throw off the docIdsIndexReader[] readers = new IndexReader[] {- edge < 0 ? r : emptyReaders[0],- emptyReaders[0],- new FCInvisibleMultiReader(edge < 0 ? emptyReaders[4] : emptyReaders[0],- emptyReaders[0],- 0 == edge ? r : emptyReaders[0]),- 0 < edge ? emptyReaders[0] : emptyReaders[7],- emptyReaders[0],- new FCInvisibleMultiReader(0 < edge ? emptyReaders[0] : emptyReaders[5],- emptyReaders[0],- 0 < edge ? r : emptyReaders[0])+ edge < 0 ? r : new MultiReader(),+ new MultiReader(),+ new FCInvisibleMultiReader(edge < 0 ? emptyReader(4) : new MultiReader(),+ new MultiReader(),+ 0 == edge ? r : new MultiReader()),+ 0 < edge ? new MultiReader() : emptyReader(7),+ new MultiReader(),+ new FCInvisibleMultiReader(0 < edge ? new MultiReader() : emptyReader(5),+ new MultiReader(),+ 0 < edge ? r : new MultiReader())};IndexSearcher out = LuceneTestCase.newSearcher(new FCInvisibleMultiReader(readers));@@ -183,35 +186,105 @@ public class QueryUtils {return out;}- static final IndexReader[] emptyReaders = new IndexReader[8];- static {- try {- emptyReaders[0] = new MultiReader();- emptyReaders[4] = makeEmptyIndex(new Random(0), 4);- emptyReaders[5] = makeEmptyIndex(new Random(0), 5);- emptyReaders[7] = makeEmptyIndex(new Random(0), 7);- } catch (IOException ex) {- throw new RuntimeException(ex);- }- }+ private static IndexReader emptyReader(final int maxDoc) {+ return new LeafReader() {- private static IndexReader makeEmptyIndex(Random random, final int numDocs) throws IOException {- assert numDocs > 0;- Directory d = new MockDirectoryWrapper(random, new RAMDirectory());- if (LuceneTestCase.VERBOSE) {- System.out.println("NOTE: QueryUtils: now create empty index");- }- IndexWriter w = new IndexWriter(d, new IndexWriterConfig(new MockAnalyzer(random)));- for (int i = 0; i < numDocs; i++) {- w.addDocument(new Document());- }- w.forceMerge(1);- w.close();- if (LuceneTestCase.VERBOSE) {- System.out.println("NOTE: QueryUtils: done create empty index");- }- DirectoryReader reader = DirectoryReader.open(d);- return new AllDeletedFilterReader(LuceneTestCase.getOnlySegmentReader(reader));+ @Override+ public void addCoreClosedListener(CoreClosedListener listener) {}++ @Override+ public void removeCoreClosedListener(CoreClosedListener listener) {}++ @Override+ public Fields fields() throws IOException {+ return new Fields() {+ @Override+ public Iterator<String> iterator() {+ return Collections.<String>emptyList().iterator();+ }++ @Override+ public Terms terms(String field) throws IOException {+ return null;+ }++ @Override+ public int size() {+ return 0;+ }+ };+ }++ @Override+ public NumericDocValues getNumericDocValues(String field) throws IOException {+ return null;+ }++ @Override+ public BinaryDocValues getBinaryDocValues(String field) throws IOException {+ return null;+ }++ @Override+ public SortedDocValues getSortedDocValues(String field) throws IOException {+ return null;+ }++ @Override+ public SortedNumericDocValues getSortedNumericDocValues(String field) throws IOException {+ return null;+ }++ @Override+ public SortedSetDocValues getSortedSetDocValues(String field) throws IOException {+ return null;+ }++ @Override+ public Bits getDocsWithField(String field) throws IOException {+ return null;+ }++ @Override+ public NumericDocValues getNormValues(String field) throws IOException {+ return null;+ }++ @Override+ public FieldInfos getFieldInfos() {+ return new FieldInfos(new FieldInfo[0]);+ }++ final Bits liveDocs = new Bits.MatchNoBits(maxDoc);+ @Override+ public Bits getLiveDocs() {+ return liveDocs;+ }++ @Override+ public void checkIntegrity() throws IOException {}++ @Override+ public Fields getTermVectors(int docID) throws IOException {+ return null;+ }++ @Override+ public int numDocs() {+ return 0;+ }++ @Override+ public int maxDoc() {+ return maxDoc;+ }++ @Override+ public void document(int docID, StoredFieldVisitor visitor) throws IOException {}++ @Override+ protected void doClose() throws IOException {}+ };}/** alternate scorer advance(),advance(),next(),next(),advance(),advance(), etcdiff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.javaindex e9af82ec9a6..69b00df85d1 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java@@ -114,15 +114,9 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {// if verbose: print some debugging stuff about which codecs are loaded.if (VERBOSE) {- Set<String> codecs = Codec.availableCodecs();- for (String codec : codecs) {- System.out.println("Loaded codec: '" + codec + "': " + Codec.forName(codec).getClass().getName());- }-- Set<String> postingsFormats = PostingsFormat.availablePostingsFormats();- for (String postingsFormat : postingsFormats) {- System.out.println("Loaded postingsFormat: '" + postingsFormat + "': " + PostingsFormat.forName(postingsFormat).getClass().getName());- }+ System.out.println("Loaded codecs: " + Codec.availableCodecs());+ System.out.println("Loaded postingsFormats: " + PostingsFormat.availablePostingsFormats());+}savedInfoStream = InfoStream.getDefault();