Skip to content

Apache Lucene open-source search software

Avoid thread contention in LRUQueryCache test

Alan Woodwarda2fdbc935342
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
index f6b1c7375f0..eac8b4ec129 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
@@ -1475,7 +1475,11 @@ public class TestLRUQueryCache extends LuceneTestCase {
w.addDocument(new Document());
w.commit();
DirectoryReader reader = DirectoryReader.open(w);
- IndexSearcher searcher = newSearcher(reader);
+
+ // Don't use newSearcher(), because that will sometimes use an ExecutorService, and
+ // we need to be single threaded to ensure that LRUQueryCache doesn't skip the cache
+ // due to thread contention
+ IndexSearcher searcher = new AssertingIndexSearcher(random(), reader);
searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
LRUQueryCache cache = new LRUQueryCache(1, 10000, context -> true, Float.POSITIVE_INFINITY);