From 60824c852ceb39f3a8c64f4db310c0d0b156d173 Mon Sep 17 00:00:00 2001 From: owenhalpert Date: Tue, 14 Jan 2025 13:08:39 -0800 Subject: [PATCH] Fix sequence of test setup/teardown (#2387) Signed-off-by: owenhalpert --- .../index/memory/NativeMemoryCacheManagerTests.java | 11 ++--------- .../QuantizationStateCacheTests.java | 6 ++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/opensearch/knn/index/memory/NativeMemoryCacheManagerTests.java b/src/test/java/org/opensearch/knn/index/memory/NativeMemoryCacheManagerTests.java index 8a46a781e..5cdedf11b 100644 --- a/src/test/java/org/opensearch/knn/index/memory/NativeMemoryCacheManagerTests.java +++ b/src/test/java/org/opensearch/knn/index/memory/NativeMemoryCacheManagerTests.java @@ -12,7 +12,6 @@ package org.opensearch.knn.index.memory; import com.google.common.cache.CacheStats; -import org.junit.After; import org.junit.Before; import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.opensearch.common.settings.Settings; @@ -41,18 +40,11 @@ public class NativeMemoryCacheManagerTests extends OpenSearchSingleNodeTestCase private ThreadPool threadPool; @Before - public void setUp() throws Exception { - super.setUp(); + public void setThreadPool() { threadPool = new ThreadPool(Settings.builder().put("node.name", "NativeMemoryCacheManagerTests").build()); NativeMemoryCacheManager.setThreadPool(threadPool); } - @After - public void shutdown() throws Exception { - super.tearDown(); - terminate(threadPool); - } - @Override public void tearDown() throws Exception { // Clear out persistent metadata @@ -61,6 +53,7 @@ public void tearDown() throws Exception { clusterUpdateSettingsRequest.persistentSettings(circuitBreakerSettings); client().admin().cluster().updateSettings(clusterUpdateSettingsRequest).get(); NativeMemoryCacheManager.getInstance().close(); + terminate(threadPool); super.tearDown(); } diff --git a/src/test/java/org/opensearch/knn/quantization/models/quantizationState/QuantizationStateCacheTests.java b/src/test/java/org/opensearch/knn/quantization/models/quantizationState/QuantizationStateCacheTests.java index 1a3c56e9a..3886e0c9a 100644 --- a/src/test/java/org/opensearch/knn/quantization/models/quantizationState/QuantizationStateCacheTests.java +++ b/src/test/java/org/opensearch/knn/quantization/models/quantizationState/QuantizationStateCacheTests.java @@ -36,15 +36,13 @@ public class QuantizationStateCacheTests extends KNNTestCase { private ThreadPool threadPool; @Before - public void setUp() throws Exception { - super.setUp(); + public void setThreadPool() { threadPool = new ThreadPool(Settings.builder().put("node.name", "QuantizationStateCacheTests").build()); QuantizationStateCache.setThreadPool(threadPool); } @After - public void shutdown() throws Exception { - super.tearDown(); + public void terminateThreadPool() { terminate(threadPool); }