javanna commented on code in PR #16763:
URL: https://github.com/apache/lucene/pull/16763#discussion_r4183740277


##########
lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCaseParent.java:
##########
@@ -2534,95 +2524,29 @@ 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 LRUQueryCache classQueryCache;
+  /** A before-after hook providing {@link ExecutorService}. */
+  private static final SharedExecutorService sharedExecutor = new 
SharedExecutorService();
 
-  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 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
-    classQueryCache = createAndOverrideDefaultQueryCache();
-  }
-
-  @AfterClass
-  public static void resetClassDefaultQueryCache() throws IOException {
-    IndexSearcher.setDefaultQueryCache(DEFAULT_QUERY_CACHE);
-    IndexSearcher.setDefaultQueryCachingPolicy(DEFAULT_CACHING_POLICY);
-    if (classQueryCache != null) {
-      classQueryCache.clear();
-    }
-    IOUtils.close(classQueryCache);
-    classQueryCache = null;
-  }
-
-  private LRUQueryCache methodQueryCache;
-
-  @Before
-  public void overrideTestDefaultQueryCache() {
-    methodQueryCache = createAndOverrideDefaultQueryCache();
+  /**
+   * Suite-level setup and cleanup of the shared state used by this class. 
Test framework-specific
+   * subclasses must call these, in order, from their suite-level before/after 
hooks, after {@link
+   * #setTestFrameworkInfra} has been called.
+   */
+  static List<BeforeAfterCallback> suiteCallbacks() {
+    // we need to reset the query cache at suite level so that tests that 
instantiate an
+    // IndexSearcher in suite-level hooks use a fresh new cache
+    return List.of(
+        new SetupAndRestoreQueryCache(), new SetupAndRestoreCpuCoreCount(), 
sharedExecutor);
   }
 
-  @After
-  public void resetTestDefaultQueryCache() throws IOException {
-    // Restore the class-level cache so TestRules and @AfterClass still see a
+  /**
+   * Test-level setup and cleanup of the shared state used by this class. Test 
framework-specific
+   * subclasses must call these, in order, from their test-level before/after 
hooks.
+   */
+  static List<BeforeAfterCallback> testCallbacks() {
+    // restores the suite-level cache afterwards, so that suite-level hooks 
still see a
     // test-scoped cache rather than the process-wide production default.

Review Comment:
   this comment is perhaps outdated now and superseded by the method's javadocs?



-- 
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]

Reply via email to