Don't wrap readers when checking for term vector access in test (#12136)

In TestUnifiedHighlighterTermVec, we have a special reader which counts the
number of times term vectors are accessed, so that we can assert that caching
works correctly here. There is some special logic in place to skip the check
when the test framework wraps readers with CheckIndex or ParallelReader;
however, this logic no longer works with ParallelReader in particular, because
term vectors are now accessed through an anonymous class.

A simpler solution here is to call newSearcher(reader, false), which disables
wrapping, meaning that we can remove this extra logic entirely.

Fixes #12115
This commit is contained in:
Alan Woodward 2023-02-09 09:29:41 +00:00 committed by GitHub
parent 776149f0f6
commit f38d51ee89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 15 deletions

View File

@ -28,14 +28,12 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType; import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.CheckIndex;
import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Fields; import org.apache.lucene.index.Fields;
import org.apache.lucene.index.FilterDirectoryReader; import org.apache.lucene.index.FilterDirectoryReader;
import org.apache.lucene.index.FilterLeafReader; import org.apache.lucene.index.FilterLeafReader;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.ParallelLeafReader;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermVectors; import org.apache.lucene.index.TermVectors;
import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause;
@ -66,7 +64,7 @@ public class TestUnifiedHighlighterTermVec extends LuceneTestCase {
private Directory dir; private Directory dir;
@Before @Before
public void doBefore() throws IOException { public void doBefore() {
indexAnalyzer = indexAnalyzer =
new MockAnalyzer( new MockAnalyzer(
random(), MockTokenizer.SIMPLE, true); // whitespace, punctuation, lowercase random(), MockTokenizer.SIMPLE, true); // whitespace, punctuation, lowercase
@ -107,7 +105,8 @@ public class TestUnifiedHighlighterTermVec extends LuceneTestCase {
IndexReader ir = new AssertOnceTermVecDirectoryReader(originalReader); IndexReader ir = new AssertOnceTermVecDirectoryReader(originalReader);
iw.close(); iw.close();
IndexSearcher searcher = newSearcher(ir); IndexSearcher searcher =
newSearcher(ir, false); // wrapping the reader messes up our counting logic
UnifiedHighlighter highlighter = UnifiedHighlighter.builder(searcher, indexAnalyzer).build(); UnifiedHighlighter highlighter = UnifiedHighlighter.builder(searcher, indexAnalyzer).build();
BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
for (String field : fields) { for (String field : fields) {
@ -134,7 +133,7 @@ public class TestUnifiedHighlighterTermVec extends LuceneTestCase {
@Override @Override
public LeafReader wrap(LeafReader reader) { public LeafReader wrap(LeafReader reader) {
return new FilterLeafReader(reader) { return new FilterLeafReader(reader) {
BitSet seenDocIDs = new BitSet(); final BitSet seenDocIDs = new BitSet();
@Override @Override
public TermVectors termVectors() throws IOException { public TermVectors termVectors() throws IOException {
@ -142,16 +141,9 @@ public class TestUnifiedHighlighterTermVec extends LuceneTestCase {
return new TermVectors() { return new TermVectors() {
@Override @Override
public Fields get(int docID) throws IOException { public Fields get(int docID) throws IOException {
// if we're invoked by ParallelLeafReader then we can't do our assertion. TODO
// see
// LUCENE-6868
if (callStackContains(ParallelLeafReader.class) == false
&& callStackContains(CheckIndex.class) == false) {
assertFalse( assertFalse(
"Should not request TVs for doc more than once.", seenDocIDs.get(docID)); "Should not request TVs for doc more than once.", seenDocIDs.get(docID));
seenDocIDs.set(docID); seenDocIDs.set(docID);
}
return orig.get(docID); return orig.get(docID);
} }
}; };