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

Commit

Permalink
FIX: Added resetState for uTs so state does not spill over (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmazanec15 committed Aug 12, 2020
1 parent f345ac1 commit 73f2896
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
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

0 comments on commit 73f2896

Please sign in to comment.