diff --git a/lucene/src/test/org/apache/lucene/codecs/lucene40/TestReuseDocsEnum.java b/lucene/src/test/org/apache/lucene/codecs/lucene40/TestReuseDocsEnum.java index d3e778dcf93..1a78346c019 100644 --- a/lucene/src/test/org/apache/lucene/codecs/lucene40/TestReuseDocsEnum.java +++ b/lucene/src/test/org/apache/lucene/codecs/lucene40/TestReuseDocsEnum.java @@ -22,6 +22,8 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.codecs.Codec; import org.apache.lucene.codecs.lucene40.Lucene40PostingsFormat; +import org.apache.lucene.index.AtomicIndexReader; +import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; @@ -34,6 +36,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LineFileDocs; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.ReaderUtil; import org.apache.lucene.util._TestUtil; public class TestReuseDocsEnum extends LuceneTestCase { @@ -48,19 +51,21 @@ public class TestReuseDocsEnum extends LuceneTestCase { writer.commit(); IndexReader open = IndexReader.open(dir); - IndexReader[] sequentialSubReaders = open.getSequentialSubReaders(); - for (IndexReader indexReader : sequentialSubReaders) { - Terms terms = indexReader.terms("body"); - TermsEnum iterator = terms.iterator(null); - IdentityHashMap enums = new IdentityHashMap(); - MatchNoBits bits = new Bits.MatchNoBits(open.maxDoc()); - while ((iterator.next()) != null) { - DocsEnum docs = iterator.docs(random.nextBoolean() ? bits : new Bits.MatchNoBits(open.maxDoc()), null, random.nextBoolean()); - enums.put(docs, true); + new ReaderUtil.Gather(open) { + @Override + protected void add(int base, AtomicIndexReader r) throws IOException { + Terms terms = r.terms("body"); + TermsEnum iterator = terms.iterator(null); + IdentityHashMap enums = new IdentityHashMap(); + MatchNoBits bits = new Bits.MatchNoBits(r.maxDoc()); + while ((iterator.next()) != null) { + DocsEnum docs = iterator.docs(random.nextBoolean() ? bits : new Bits.MatchNoBits(r.maxDoc()), null, random.nextBoolean()); + enums.put(docs, true); + } + + assertEquals(terms.getUniqueTermCount(), enums.size()); } - - assertEquals(terms.getUniqueTermCount(), enums.size()); - } + }.run(); IOUtils.close(writer, open, dir); }