-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Naveen Tatikonda <[email protected]>
- Loading branch information
1 parent
9174a9f
commit f373209
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
qa/restart-upgrade/src/test/java/org/opensearch/knn/bwc/ClearCacheIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.bwc; | ||
|
||
import java.util.Collections; | ||
import static org.opensearch.knn.TestUtils.NODES_BWC_CLUSTER; | ||
|
||
public class ClearCacheIT extends AbstractRestartUpgradeTestCase { | ||
private static final String TEST_FIELD = "test-field"; | ||
private static final int DIMENSIONS = 5; | ||
private static int docId = 0; | ||
private static final int NUM_DOCS = 10; | ||
private static int queryCnt = 0; | ||
private static final int K = 5; | ||
|
||
// Restart Upgrade BWC Tests to validate Clear Cache API | ||
public void testClearCache() throws Exception { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
if (isRunningAgainstOldCluster()) { | ||
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS)); | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, docId, NUM_DOCS); | ||
} else { | ||
queryCnt = NUM_DOCS; | ||
validateClearCacheOnUpgrade(queryCnt); | ||
|
||
docId = NUM_DOCS; | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, docId, NUM_DOCS); | ||
|
||
queryCnt = queryCnt + NUM_DOCS; | ||
validateClearCacheOnUpgrade(queryCnt); | ||
deleteKNNIndex(testIndex); | ||
} | ||
} | ||
|
||
// validation steps for Clear Cache API after upgrading node to new version | ||
private void validateClearCacheOnUpgrade(int queryCount) throws Exception { | ||
int graphCount = getTotalGraphsInCache(); | ||
knnWarmup(Collections.singletonList(testIndex)); | ||
assertTrue(getTotalGraphsInCache() > graphCount); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, queryCount, K); | ||
|
||
clearCache(Collections.singletonList(testIndex)); | ||
assertEquals(0, getTotalGraphsInCache()); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, queryCount, K); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
qa/rolling-upgrade/src/test/java/org/opensearch/knn/bwc/ClearCacheIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.bwc; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.opensearch.knn.TestUtils.NODES_BWC_CLUSTER; | ||
|
||
public class ClearCacheIT extends AbstractRollingUpgradeTestCase { | ||
private static final String TEST_FIELD = "test-field"; | ||
private static final int DIMENSIONS = 5; | ||
private static int docId = 0; | ||
private static final int K = 5; | ||
private static final int NUM_DOCS = 10; | ||
private static int queryCnt = 0; | ||
|
||
// Rolling Upgrade BWC Tests to validate Clear Cache API | ||
public void testClearCache() throws Exception { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
switch (getClusterType()) { | ||
case OLD: | ||
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS)); | ||
int docIdOld = 0; | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, docIdOld, NUM_DOCS); | ||
break; | ||
case UPGRADED: | ||
queryCnt = NUM_DOCS; | ||
validateClearCacheOnUpgrade(queryCnt); | ||
|
||
docId = NUM_DOCS; | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, docId, NUM_DOCS); | ||
|
||
queryCnt = queryCnt + NUM_DOCS; | ||
validateClearCacheOnUpgrade(queryCnt); | ||
deleteKNNIndex(testIndex); | ||
} | ||
|
||
} | ||
|
||
// validation steps for Clear Cache API after upgrading all nodes from old version to new version | ||
public void validateClearCacheOnUpgrade(int queryCount) throws Exception { | ||
int graphCount = getTotalGraphsInCache(); | ||
knnWarmup(Collections.singletonList(testIndex)); | ||
assertTrue(getTotalGraphsInCache() > graphCount); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, queryCount, K); | ||
|
||
clearCache(Collections.singletonList(testIndex)); | ||
assertEquals(0, getTotalGraphsInCache()); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, queryCount, K); | ||
} | ||
|
||
} |