Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Reset state for uTs so tests run independently #159

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,28 @@

package com.amazon.opendistroforelasticsearch.knn;

import com.amazon.opendistroforelasticsearch.knn.index.KNNIndexCache;
import com.amazon.opendistroforelasticsearch.knn.plugin.stats.KNNCounter;
import org.elasticsearch.test.ESTestCase;
import org.junit.Before;

/**
* Base class for integration tests for KNN plugin. Contains several methods for testing KNN ES functionality.
*/
public class KNNTestCase extends ESTestCase {
@Before
public void resetCounters() {
@Override
public void tearDown() throws Exception {
super.tearDown();
resetState();
}

public static void resetState() {
// Reset all of the counters
for (KNNCounter knnCounter : KNNCounter.values()) {
knnCounter.set(0L);
}

// Clean up the cache
KNNIndexCache.getInstance().evictAllGraphsFromCache();
KNNIndexCache.getInstance().close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package com.amazon.opendistroforelasticsearch.knn.index;

import com.amazon.opendistroforelasticsearch.knn.KNNTestCase;
import com.amazon.opendistroforelasticsearch.knn.plugin.KNNPlugin;
import com.amazon.opendistroforelasticsearch.knn.plugin.stats.KNNCounter;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
Expand All @@ -42,15 +42,6 @@ public class KNNIndexCacheTests extends ESSingleNodeTestCase {
private final String testIndexName = "test_index";
private final String testFieldName = "test_field";

@Override
public void setUp() throws Exception {
// Reset all of the counters
for (KNNCounter knnCounter : KNNCounter.values()) {
knnCounter.set(0L);
}
super.setUp();
}

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Collections.singletonList(KNNPlugin.class);
Expand All @@ -64,8 +55,7 @@ protected boolean resetNodeAfterTest() {
@Override
public void tearDown() throws Exception {
super.tearDown();
KNNIndexCache.getInstance().evictAllGraphsFromCache();
KNNIndexCache.getInstance().close();
KNNTestCase.resetState();
}

public void testGetIndicesCacheStats() throws IOException, InterruptedException, ExecutionException {
Expand Down