mirror of https://github.com/apache/lucene.git
LUCENE-6303: Make tests reproducible again.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1663106 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b985737d1f
commit
4f3d2aeae5
|
@ -75,8 +75,8 @@ import org.apache.lucene.util.ThreadInterruptedException;
|
|||
public class IndexSearcher {
|
||||
|
||||
// 32MB and at most 10,000 queries
|
||||
private static final QueryCache DEFAULT_QUERY_CACHE = new LRUQueryCache(10000, 1 << 25);
|
||||
private static final QueryCachingPolicy DEFAULT_CACHING_POLICY = new UsageTrackingQueryCachingPolicy();
|
||||
private static QueryCache DEFAULT_QUERY_CACHE = new LRUQueryCache(10000, 1 << 25);
|
||||
private static QueryCachingPolicy DEFAULT_CACHING_POLICY = new UsageTrackingQueryCachingPolicy();
|
||||
|
||||
final IndexReader reader; // package private for testing!
|
||||
|
||||
|
@ -106,7 +106,23 @@ public class IndexSearcher {
|
|||
public static Similarity getDefaultSimilarity() {
|
||||
return defaultSimilarity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expert: set the default {@link QueryCache} instance.
|
||||
* @lucene.internal
|
||||
*/
|
||||
public static void setDefaultQueryCache(QueryCache defaultQueryCache) {
|
||||
DEFAULT_QUERY_CACHE = defaultQueryCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expert: set the default {@link QueryCachingPolicy} instance.
|
||||
* @lucene.internal
|
||||
*/
|
||||
public static void setDefaultQueryCachingPolicy(QueryCachingPolicy defaultQueryCachingPolicy) {
|
||||
DEFAULT_CACHING_POLICY = defaultQueryCachingPolicy;
|
||||
}
|
||||
|
||||
/** The Similarity implementation used by this searcher. */
|
||||
private Similarity similarity = defaultSimilarity;
|
||||
|
||||
|
|
|
@ -602,7 +602,8 @@ public class TestBooleanQuery extends LuceneTestCase {
|
|||
w.commit();
|
||||
|
||||
DirectoryReader reader = w.getReader();
|
||||
final IndexSearcher searcher = new IndexSearcher(reader);
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
searcher.setQueryCache(null); // to still have approximations
|
||||
|
||||
PhraseQuery pq = new PhraseQuery();
|
||||
pq.add(new Term("field", "a"));
|
||||
|
@ -633,6 +634,7 @@ public class TestBooleanQuery extends LuceneTestCase {
|
|||
|
||||
DirectoryReader reader = w.getReader();
|
||||
final IndexSearcher searcher = new IndexSearcher(reader);
|
||||
searcher.setQueryCache(null); // to still have approximations
|
||||
|
||||
PhraseQuery pq = new PhraseQuery();
|
||||
pq.add(new Term("field", "a"));
|
||||
|
@ -662,7 +664,8 @@ public class TestBooleanQuery extends LuceneTestCase {
|
|||
w.commit();
|
||||
|
||||
DirectoryReader reader = w.getReader();
|
||||
final IndexSearcher searcher = new IndexSearcher(reader);
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
searcher.setQueryCache(null); // to still have approximations
|
||||
|
||||
PhraseQuery pq = new PhraseQuery();
|
||||
pq.add(new Term("field", "a"));
|
||||
|
@ -693,6 +696,7 @@ public class TestBooleanQuery extends LuceneTestCase {
|
|||
|
||||
DirectoryReader reader = w.getReader();
|
||||
final IndexSearcher searcher = new IndexSearcher(reader);
|
||||
searcher.setQueryCache(null); // to still have approximations
|
||||
|
||||
PhraseQuery pq = new PhraseQuery();
|
||||
pq.add(new Term("field", "a"));
|
||||
|
@ -723,6 +727,7 @@ public class TestBooleanQuery extends LuceneTestCase {
|
|||
|
||||
DirectoryReader reader = w.getReader();
|
||||
final IndexSearcher searcher = new IndexSearcher(reader);
|
||||
searcher.setQueryCache(null); // to still have approximations
|
||||
|
||||
PhraseQuery pq = new PhraseQuery();
|
||||
pq.add(new Term("field", "a"));
|
||||
|
|
|
@ -214,7 +214,8 @@ public class TestConstantScoreQuery extends LuceneTestCase {
|
|||
w.commit();
|
||||
|
||||
DirectoryReader reader = w.getReader();
|
||||
final IndexSearcher searcher = new IndexSearcher(reader);
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
searcher.setQueryCache(null); // to still have approximations
|
||||
|
||||
PhraseQuery pq = new PhraseQuery();
|
||||
pq.add(new Term("field", "a"));
|
||||
|
|
|
@ -203,6 +203,7 @@ public class TestQueryWrapperFilter extends LuceneTestCase {
|
|||
final IndexReader reader = writer.getReader();
|
||||
writer.close();
|
||||
final IndexSearcher searcher = new IndexSearcher(reader);
|
||||
searcher.setQueryCache(null); // to still have approximations
|
||||
final Query query = new QueryWrapperFilter(new RandomApproximationQuery(new TermQuery(new Term("foo", "bar")), random()));
|
||||
final Weight weight = searcher.createNormalizedWeight(query, random().nextBoolean());
|
||||
final Scorer scorer = weight.scorer(reader.leaves().get(0), null);
|
||||
|
|
|
@ -95,6 +95,7 @@ import org.apache.lucene.index.IndexReader.ReaderClosedListener;
|
|||
import org.apache.lucene.index.TermsEnum.SeekStatus;
|
||||
import org.apache.lucene.search.AssertingIndexSearcher;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.LRUQueryCache;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.QueryCachingPolicy;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
|
@ -1649,6 +1650,12 @@ public abstract class LuceneTestCase extends Assert {
|
|||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void resetDefaultQueryCache() {
|
||||
IndexSearcher.setDefaultQueryCache(new LRUQueryCache(10000, 1 << 25));
|
||||
IndexSearcher.setDefaultQueryCachingPolicy(MAYBE_CACHE_POLICY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new searcher over the reader. This searcher might randomly use
|
||||
* threads.
|
||||
|
@ -1700,7 +1707,6 @@ public abstract class LuceneTestCase extends Assert {
|
|||
ret = random.nextBoolean() ? new IndexSearcher(r) : new IndexSearcher(r.getContext());
|
||||
}
|
||||
ret.setSimilarity(classEnvRule.similarity);
|
||||
ret.setQueryCachingPolicy(MAYBE_CACHE_POLICY);
|
||||
return ret;
|
||||
} else {
|
||||
int threads = 0;
|
||||
|
|
Loading…
Reference in New Issue