sgup432 commented on code in PR #16740:
URL: https://github.com/apache/lucene/pull/16740#discussion_r4138359763
##########
lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCaseParent.java:
##########
@@ -2536,36 +2537,46 @@ public static IOContext newIOContext(Random random,
IOContext oldContext) {
private static final QueryCache DEFAULT_QUERY_CACHE =
IndexSearcher.getDefaultQueryCache();
private static final QueryCachingPolicy DEFAULT_CACHING_POLICY =
IndexSearcher.getDefaultQueryCachingPolicy();
- private static final List<LRUQueryCache> queryCacheList = new ArrayList<>();
+ private static LRUQueryCache classQueryCache;
- @Before
- public void overrideTestDefaultQueryCache() {
- // Make sure each test method has its own cache
- overrideDefaultQueryCache();
+ private static LRUQueryCache createAndOverrideDefaultQueryCache() {
+ LRUQueryCache lruQueryCache =
+ new LRUQueryCache(10000, 1 << 25, _ -> true, Float.POSITIVE_INFINITY);
+ IndexSearcher.setDefaultQueryCache(lruQueryCache);
+ IndexSearcher.setDefaultQueryCachingPolicy(MAYBE_CACHE_POLICY);
+ return lruQueryCache;
}
@BeforeClass
- public static void overrideDefaultQueryCache() {
+ public static void overrideClassDefaultQueryCache() {
// we need to reset the query cache in an @BeforeClass so that tests that
// instantiate an IndexSearcher in an @BeforeClass method use a fresh new
cache
- LRUQueryCache queryCacheTemp =
- new LRUQueryCache(10000, 1 << 25, _ -> true, Float.POSITIVE_INFINITY);
- queryCacheList.add(queryCacheTemp);
- IndexSearcher.setDefaultQueryCache(queryCacheTemp);
- IndexSearcher.setDefaultQueryCachingPolicy(MAYBE_CACHE_POLICY);
+ classQueryCache = createAndOverrideDefaultQueryCache();
}
@AfterClass
- public static void resetDefaultQueryCache() {
+ public static void resetClassDefaultQueryCache() throws IOException {
IndexSearcher.setDefaultQueryCache(DEFAULT_QUERY_CACHE);
IndexSearcher.setDefaultQueryCachingPolicy(DEFAULT_CACHING_POLICY);
- for (int i = 0; i < queryCacheList.size(); i++) {
- try {
- queryCacheList.get(i).close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ IOUtils.close(classQueryCache);
+ classQueryCache = null;
+ }
+
+ private LRUQueryCache methodQueryCache;
+
+ @Before
+ public void overrideTestDefaultQueryCache() {
+ methodQueryCache = createAndOverrideDefaultQueryCache();
+ }
+
+ @After
+ public void resetTestDefaultQueryCache() throws IOException {
+ // Restore the class-level cache so TestRules and @AfterClass still see a
+ // test-scoped cache rather than the process-wide production default.
+ IndexSearcher.setDefaultQueryCache(classQueryCache);
+ IndexSearcher.setDefaultQueryCachingPolicy(MAYBE_CACHE_POLICY);
+ IOUtils.close(methodQueryCache);
Review Comment:
The LRUQueryCache.close() actually doesn't do any resource freeing but just
closes the background scheduled cleaner(this was introduced as part of recent
refactoring), in this it is a no-op.
I think we should also call methodQueryCache.clear() before this close()
call.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]