You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ch...@apache.org on 2023/11/30 08:40:33 UTC

(lucene) branch branch_9x updated: [9.x] Fix intermittently failing TestSortedSetFieldSource (#12851)(#12850)

This is an automated email from the ASF dual-hosted git repository.

chegar pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 2b320e12693 [9.x] Fix intermittently failing TestSortedSetFieldSource (#12851)(#12850)
2b320e12693 is described below

commit 2b320e1269300c06ac81b71d7e94ca61b617bad9
Author: Chris Hegarty <62...@users.noreply.github.com>
AuthorDate: Thu Nov 30 08:40:27 2023 +0000

    [9.x] Fix intermittently failing TestSortedSetFieldSource (#12851)(#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.
---
 .../apache/lucene/queries/function/TestSortedSetFieldSource.java | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java
index 27bd2192a9d..3245ec8d40f 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java
@@ -22,7 +22,9 @@ import org.apache.lucene.document.Field;
 import org.apache.lucene.document.SortedSetDocValuesField;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.LeafReader;
+import org.apache.lucene.index.NoMergePolicy;
 import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource;
 import org.apache.lucene.search.DocIdSetIterator;
 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.SortedSetSortField;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.tests.analysis.MockAnalyzer;
 import org.apache.lucene.tests.util.LuceneTestCase;
 import org.apache.lucene.util.BytesRef;
 
 public class TestSortedSetFieldSource extends LuceneTestCase {
   public void testSimple() throws Exception {
     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();
     doc.add(new SortedSetDocValuesField("value", new BytesRef("baz")));
     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(newStringField("id", "1", Field.Store.YES));
     writer.addDocument(doc);
-    writer.forceMerge(1);
     writer.close();
 
     DirectoryReader ir = DirectoryReader.open(dir);