Skip to content

Commit c03d83d

Browse files
committed
extend ESTestCase#newSearcher methods and add javadocs
1 parent 8e51178 commit c03d83d

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
import java.util.stream.LongStream;
209209
import java.util.stream.Stream;
210210

211+
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
211212
import static java.util.Collections.emptyMap;
212213
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
213214
import static org.hamcrest.Matchers.anyOf;
@@ -2573,9 +2574,42 @@ public static void ensureAllContextsReleased(SearchService searchService) {
25732574
}
25742575
}
25752576

2576-
// lucene 10 upgrade: this overwrites LuceneTestCase#newSearcher so we never get random INTRA_SEGMENT
2577-
// concurrency. We want to slowly migrate of stuff out of using this method after we got a working branch
2577+
/**
2578+
* Create a new searcher over the reader. This searcher might randomly use threads.
2579+
* Provides the same functionality as {@link LuceneTestCase#newSearcher(IndexReader)},
2580+
* with the only difference that concurrency will only ever be inter-segment and never intra-segment.
2581+
*/
25782582
public static IndexSearcher newSearcher(IndexReader r) {
2579-
return newSearcher(r, true, true, Concurrency.INTER_SEGMENT);
2583+
return newSearcher(r, true);
2584+
}
2585+
2586+
/**
2587+
* Create a new searcher over the reader. This searcher might randomly use threads.
2588+
* Provides the same functionality as {@link LuceneTestCase#newSearcher(IndexReader, boolean)},
2589+
* with the only difference that concurrency will only ever be inter-segment and never intra-segment.
2590+
*/
2591+
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap) {
2592+
return newSearcher(r, maybeWrap, true);
2593+
}
2594+
2595+
/**
2596+
* Create a new searcher over the reader. This searcher might randomly use threads.
2597+
* Provides the same functionality as {@link LuceneTestCase#newSearcher(IndexReader, boolean, boolean)},
2598+
* with the only difference that concurrency will only ever be inter-segment and never intra-segment.
2599+
*/
2600+
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions) {
2601+
return newSearcher(r, maybeWrap, wrapWithAssertions, randomBoolean());
2602+
}
2603+
2604+
/**
2605+
* Create a new searcher over the reader.
2606+
* Provides the same functionality as {@link LuceneTestCase#newSearcher(IndexReader, boolean, boolean, boolean)},
2607+
* with the only difference that concurrency will only ever be inter-segment and never intra-segment.
2608+
*/
2609+
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions, boolean useThreads) {
2610+
if (useThreads) {
2611+
return newSearcher(r, maybeWrap, wrapWithAssertions, Concurrency.INTER_SEGMENT);
2612+
}
2613+
return newSearcher(r, maybeWrap, wrapWithAssertions, Concurrency.NONE);
25802614
}
25812615
}

0 commit comments

Comments
 (0)