You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2025/11/19 07:26:21 UTC
(lucene) branch branch_10x updated: Fix flaky TestParentsChildrenBlockJoinQuery (#15435)
This is an automated email from the ASF dual-hosted git repository.
tommaso pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_10x by this push:
new ce4fe966475 Fix flaky TestParentsChildrenBlockJoinQuery (#15435)
ce4fe966475 is described below
commit ce4fe966475b041481c9a946dd63e3630ed3d084
Author: Michael Froh <ms...@apache.org>
AuthorDate: Tue Nov 18 23:24:47 2025 -0800
Fix flaky TestParentsChildrenBlockJoinQuery (#15435)
These tests assumed that merges would preserve document order across
segments. Using some form of LogMergePolicy ensures that's true.
(cherry picked from commit 3e8c8797476416d1773241530abd43098bf366ed)
---
.../join/TestParentsChildrenBlockJoinQuery.java | 37 +++++++++++-----------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestParentsChildrenBlockJoinQuery.java b/lucene/join/src/test/org/apache/lucene/search/join/TestParentsChildrenBlockJoinQuery.java
index 40fb5ca4381..685263db398 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestParentsChildrenBlockJoinQuery.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestParentsChildrenBlockJoinQuery.java
@@ -16,15 +16,16 @@
*/
package org.apache.lucene.search.join;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.NoMergePolicy;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.store.Directory;
@@ -34,6 +35,15 @@ import org.junit.Test;
public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
+ private static RandomIndexWriter createIndexWriter(Directory dir) throws IOException {
+ // We need a merge policy that merges segments sequentially.
+ // Most tests here merge down to a single segment and assume the order of documents in the
+ // segment
+ // matches the order in which they were added.
+ return new RandomIndexWriter(
+ random(), dir, newIndexWriterConfig().setMergePolicy(newLogMergePolicy()));
+ }
+
@Test
public void testEmptyIndex() throws Exception {
// No documents to index, just test the query execution
@@ -65,7 +75,6 @@ public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
@Test
public void testWithRandomizedIndex() throws Exception {
-
for (int i = 0; i < 10; i++) {
// Run multiple iterations to ensure randomness
if (VERBOSE) {
@@ -149,9 +158,7 @@ public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
blocks[2][2] = new TestDoc("parent", true, 9); // docId=9
final Directory dir = newDirectory();
- final RandomIndexWriter writer =
- new RandomIndexWriter(
- random(), dir, newIndexWriterConfig().setMergePolicy(newMergePolicy(random(), false)));
+ final RandomIndexWriter writer = createIndexWriter(dir);
// Add documents
List<Document> docs = new ArrayList<>();
@@ -191,7 +198,7 @@ public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
Weight weight =
searcher.createWeight(
searcher.rewrite(query), org.apache.lucene.search.ScoreMode.COMPLETE, 1);
- Scorer scorer = weight.scorer(reader.leaves().get(0));
+ Scorer scorer = weight.scorer(reader.leaves().getFirst());
assert scorer != null;
DocIdSetIterator it = scorer.iterator();
@@ -211,9 +218,7 @@ public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
private void test(TestDoc[][] blocks, int[] expectedDocIds, int childLimitPerParent)
throws Exception {
final Directory dir = newDirectory();
- final RandomIndexWriter writer =
- new RandomIndexWriter(
- random(), dir, newIndexWriterConfig().setMergePolicy(newMergePolicy(random(), false)));
+ final RandomIndexWriter writer = createIndexWriter(dir);
// Add documents based on test case
final List<Document> docs = new ArrayList<>();
@@ -261,8 +266,8 @@ public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
// Verify the matching documents
for (ScoreDoc scoreDoc : results.scoreDocs) {
Document doc = reader.storedFields().document(scoreDoc.doc);
- String type = doc.getField("type").stringValue();
- Integer id = doc.getField("ID").numericValue().intValue();
+ String type = Objects.requireNonNull(doc.getField("type")).stringValue();
+ Integer id = Objects.requireNonNull(doc.getField("ID")).numericValue().intValue();
assertEquals("child", type); // All results should be children
assertTrue(expectedDocIdSet.contains(id));
}
@@ -279,7 +284,7 @@ public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
int i = 0;
for (ScoreDoc scoreDoc : results.scoreDocs) {
Document doc = reader.storedFields().document(scoreDoc.doc);
- int id = doc.getField("ID").numericValue().intValue();
+ int id = Objects.requireNonNull(doc.getField("ID")).numericValue().intValue();
actualDocIds[i++] = id;
}
System.out.println("Actual docIds: " + Arrays.toString(actualDocIds));
@@ -339,9 +344,7 @@ public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
blocks[1][2] = new TestDoc("parent", true, 5); // docId=5
Directory dir = newDirectory();
- final RandomIndexWriter writer =
- new RandomIndexWriter(
- random(), dir, newIndexWriterConfig().setMergePolicy(NoMergePolicy.INSTANCE));
+ final RandomIndexWriter writer = createIndexWriter(dir);
// Add documents
List<Document> docs = new ArrayList<>();
@@ -415,9 +418,7 @@ public class TestParentsChildrenBlockJoinQuery extends LuceneTestCase {
}
Directory dir = newDirectory();
- final RandomIndexWriter writer =
- new RandomIndexWriter(
- random(), dir, newIndexWriterConfig().setMergePolicy(newMergePolicy(random(), false)));
+ final RandomIndexWriter writer = createIndexWriter(dir);
// Add documents
List<Document> docs = new ArrayList<>();