Fix intermittently failing TestSortedSetFieldSource (#12850)

This commit fixes the intermittently failing TestSortedSetFieldSource.

The test assertions depend on doc order which may be affected by merging. The fix is to trivially avoid merging for the very small index, with just two docs.
This commit is contained in:
Chris Hegarty 2023-11-30 08:39:26 +00:00 committed by GitHub
parent 6ba38c13eb
commit 7919133858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -22,7 +22,9 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource; import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource;
import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
@ -31,13 +33,17 @@ import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortedSetSortField; import org.apache.lucene.search.SortedSetSortField;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.analysis.MockAnalyzer;
import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
public class TestSortedSetFieldSource extends LuceneTestCase { public class TestSortedSetFieldSource extends LuceneTestCase {
public void testSimple() throws Exception { public void testSimple() throws Exception {
Directory dir = newDirectory(); Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(null)); IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
conf.setMaxBufferedDocs(2); // generate few segments
conf.setMergePolicy(NoMergePolicy.INSTANCE); // prevent merges for this test
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document(); Document doc = new Document();
doc.add(new SortedSetDocValuesField("value", new BytesRef("baz"))); doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
doc.add(newStringField("id", "2", Field.Store.YES)); doc.add(newStringField("id", "2", Field.Store.YES));
@ -47,7 +53,6 @@ public class TestSortedSetFieldSource extends LuceneTestCase {
doc.add(new SortedSetDocValuesField("value", new BytesRef("bar"))); doc.add(new SortedSetDocValuesField("value", new BytesRef("bar")));
doc.add(newStringField("id", "1", Field.Store.YES)); doc.add(newStringField("id", "1", Field.Store.YES));
writer.addDocument(doc); writer.addDocument(doc);
writer.forceMerge(1);
writer.close(); writer.close();
DirectoryReader ir = DirectoryReader.open(dir); DirectoryReader ir = DirectoryReader.open(dir);