-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Abstraction for BWC tests with a basic test (#367)
Signed-off-by: Naveen Tatikonda <[email protected]>
- Loading branch information
1 parent
faea575
commit ccedc8d
Showing
9 changed files
with
267 additions
and
340 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
qa/restart-upgrade/src/test/java/org/opensearch/knn/bwc/AbstractRestartUpgradeTestCase.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,62 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.bwc; | ||
|
||
import org.junit.Before; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.knn.KNNRestTestCase; | ||
import org.opensearch.test.rest.OpenSearchRestTestCase; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
import static org.opensearch.knn.TestUtils.*; | ||
|
||
public abstract class AbstractRestartUpgradeTestCase extends KNNRestTestCase { | ||
protected String testIndex; | ||
|
||
@Before | ||
protected void setIndex() { | ||
// Creating index name by concatenating "knn-bwc-" prefix with test method name | ||
// for all the tests in this sub-project | ||
testIndex = KNN_BWC_PREFIX + getTestName().toLowerCase(Locale.ROOT); | ||
} | ||
|
||
@Override | ||
protected final boolean preserveIndicesUponCompletion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected final boolean preserveReposUponCompletion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected boolean preserveTemplatesUponCompletion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected final Settings restClientSettings() { | ||
return Settings.builder() | ||
.put(super.restClientSettings()) | ||
// increase the timeout here to 90 seconds to handle long waits for a green | ||
// cluster health. the waits for green need to be longer than a minute to | ||
// account for delayed shards | ||
.put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, CLIENT_TIMEOUT_VALUE) | ||
.build(); | ||
} | ||
|
||
protected final boolean isRunningAgainstOldCluster() { | ||
return Boolean.parseBoolean(System.getProperty(RESTART_UPGRADE_OLD_CLUSTER)); | ||
} | ||
|
||
protected final Optional<String> getBWCVersion() { | ||
return Optional.ofNullable(System.getProperty(BWC_VERSION, null)); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
qa/restart-upgrade/src/test/java/org/opensearch/knn/bwc/IndexingIT.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,32 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.bwc; | ||
|
||
import static org.opensearch.knn.TestUtils.NODES_BWC_CLUSTER; | ||
|
||
public class IndexingIT extends AbstractRestartUpgradeTestCase { | ||
private static final String TEST_FIELD = "test-field"; | ||
private static final int DIMENSIONS = 5; | ||
private static final int K = 5; | ||
private static final int ADD_DOCS_CNT = 10; | ||
|
||
public void testKnnDefaultIndexSettings() throws Exception { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
|
||
if (isRunningAgainstOldCluster()) { | ||
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS)); | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, ADD_DOCS_CNT); | ||
} else { | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 10, K); | ||
cleanUpCache(); | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 10, ADD_DOCS_CNT); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 20, K); | ||
forceMergeKnnIndex(testIndex); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 20, K); | ||
deleteKNNIndex(testIndex); | ||
} | ||
} | ||
} |
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
85 changes: 85 additions & 0 deletions
85
qa/rolling-upgrade/src/test/java/org/opensearch/knn/bwc/AbstractRollingUpgradeTestCase.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,85 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.bwc; | ||
|
||
import org.junit.Before; | ||
import org.opensearch.knn.KNNRestTestCase; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.test.rest.OpenSearchRestTestCase; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
import static org.opensearch.knn.TestUtils.*; | ||
|
||
public abstract class AbstractRollingUpgradeTestCase extends KNNRestTestCase { | ||
protected String testIndex; | ||
|
||
@Before | ||
protected void setIndex() { | ||
// Creating index name by concatenating "knn-bwc-" prefix with test method name | ||
// for all the tests in this sub-project | ||
testIndex = KNN_BWC_PREFIX + getTestName().toLowerCase(Locale.ROOT); | ||
} | ||
|
||
@Override | ||
protected final boolean preserveIndicesUponCompletion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected final boolean preserveReposUponCompletion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected boolean preserveTemplatesUponCompletion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected final Settings restClientSettings() { | ||
return Settings.builder() | ||
.put(super.restClientSettings()) | ||
// increase the timeout here to 90 seconds to handle long waits for a green | ||
// cluster health. the waits for green need to be longer than a minute to | ||
// account for delayed shards | ||
.put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, CLIENT_TIMEOUT_VALUE) | ||
.build(); | ||
} | ||
|
||
protected enum ClusterType { | ||
OLD, | ||
MIXED, | ||
UPGRADED; | ||
|
||
public static ClusterType instance(String value) { | ||
switch (value) { | ||
case OLD_CLUSTER: | ||
return OLD; | ||
case MIXED_CLUSTER: | ||
return MIXED; | ||
case UPGRADED_CLUSTER: | ||
return UPGRADED; | ||
default: | ||
throw new IllegalArgumentException("unknown cluster type: " + value); | ||
} | ||
} | ||
} | ||
|
||
protected final ClusterType getClusterType() { | ||
return ClusterType.instance(System.getProperty(BWCSUITE_CLUSTER)); | ||
} | ||
|
||
protected final boolean isFirstMixedRound() { | ||
return Boolean.parseBoolean(System.getProperty(ROLLING_UPGRADE_FIRST_ROUND, "false")); | ||
} | ||
|
||
protected final Optional<String> getBWCVersion() { | ||
return Optional.ofNullable(System.getProperty(BWC_VERSION, null)); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
qa/rolling-upgrade/src/test/java/org/opensearch/knn/bwc/IndexingIT.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,43 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.bwc; | ||
|
||
import static org.opensearch.knn.TestUtils.*; | ||
|
||
public class IndexingIT extends AbstractRollingUpgradeTestCase { | ||
private static final String TEST_FIELD = "test-field"; | ||
private static final int DIMENSIONS = 5; | ||
private static final int K = 5; | ||
private static final int ADD_DOCS_CNT = 10; | ||
|
||
public void testKnnDefaultIndexSettings() throws Exception { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
switch (getClusterType()) { | ||
case OLD: | ||
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS)); | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 0, ADD_DOCS_CNT); | ||
break; | ||
case MIXED: | ||
if (isFirstMixedRound()) { | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 10, K); | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 10, ADD_DOCS_CNT); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 20, K); | ||
} else { | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 20, K); | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 20, ADD_DOCS_CNT); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 30, K); | ||
} | ||
break; | ||
case UPGRADED: | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 30, K); | ||
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, 30, ADD_DOCS_CNT); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 40, K); | ||
forceMergeKnnIndex(testIndex); | ||
validateKNNSearch(testIndex, TEST_FIELD, DIMENSIONS, 40, K); | ||
deleteKNNIndex(testIndex); | ||
} | ||
} | ||
} |
Oops, something went wrong.