Avoid thread contention in LRUQueryCache test

This commit is contained in:
Alan Woodward 2018-02-19 09:48:32 +00:00
parent 34d3282ede
commit a2fdbc9353
1 changed files with 5 additions and 1 deletions

View File

@ -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);