30
30
import org .apache .lucene .index .Term ;
31
31
import org .apache .lucene .search .Explanation ;
32
32
import org .apache .lucene .search .IndexSearcher ;
33
+ import org .apache .lucene .search .LRUQueryCache ;
33
34
import org .apache .lucene .search .LeafCollector ;
34
35
import org .apache .lucene .search .Query ;
35
36
import org .apache .lucene .search .QueryCachingPolicy ;
47
48
import org .elasticsearch .search .internal .ContextIndexSearcher ;
48
49
import org .elasticsearch .search .profile .ProfileResult ;
49
50
import org .elasticsearch .test .ESTestCase ;
51
+ import org .junit .After ;
50
52
import org .junit .AfterClass ;
51
53
import org .junit .BeforeClass ;
52
54
@@ -81,7 +83,16 @@ public static void setup() throws IOException {
81
83
reader = w .getReader ();
82
84
w .close ();
83
85
searcher = new ContextIndexSearcher (reader , IndexSearcher .getDefaultSimilarity (),
84
- IndexSearcher .getDefaultQueryCache (), MAYBE_CACHE_POLICY );
86
+ IndexSearcher .getDefaultQueryCache (), ALWAYS_CACHE_POLICY );
87
+ }
88
+
89
+ @ After
90
+ public void checkNoCache () {
91
+ LRUQueryCache cache = (LRUQueryCache ) searcher .getQueryCache ();
92
+ assertThat (cache .getHitCount (), equalTo (0L ));
93
+ assertThat (cache .getCacheCount (), equalTo (0L ));
94
+ assertThat (cache .getTotalCount (), equalTo (cache .getMissCount ()));
95
+ assertThat (cache .getCacheSize (), equalTo (0L ));
85
96
}
86
97
87
98
@ AfterClass
@@ -158,10 +169,6 @@ public void testUseIndexStats() throws IOException {
158
169
159
170
public void testApproximations () throws IOException {
160
171
QueryProfiler profiler = new QueryProfiler ();
161
- // disable query caching since we want to test approximations, which won't
162
- // be exposed on a cached entry
163
- ContextIndexSearcher searcher = new ContextIndexSearcher (reader , IndexSearcher .getDefaultSimilarity (),
164
- null , MAYBE_CACHE_POLICY );
165
172
searcher .setProfiler (profiler );
166
173
Query query = new RandomApproximationQuery (new TermQuery (new Term ("foo" , "bar" )), random ());
167
174
searcher .count (query );
@@ -184,7 +191,6 @@ public void testApproximations() throws IOException {
184
191
185
192
long rewriteTime = profiler .getRewriteTime ();
186
193
assertThat (rewriteTime , greaterThan (0L ));
187
-
188
194
}
189
195
190
196
public void testCollector () throws IOException {
@@ -288,17 +294,4 @@ public boolean shouldCache(Query query) throws IOException {
288
294
}
289
295
290
296
};
291
-
292
- private static final QueryCachingPolicy NEVER_CACHE_POLICY = new QueryCachingPolicy () {
293
-
294
- @ Override
295
- public void onUse (Query query ) {}
296
-
297
- @ Override
298
- public boolean shouldCache (Query query ) throws IOException {
299
- return false ;
300
- }
301
-
302
- };
303
-
304
297
}
0 commit comments