Skip to content

Commit

Permalink
Add Abstraction for BWC tests with a basic test (#367)
Browse files Browse the repository at this point in the history
Signed-off-by: Naveen Tatikonda <navtat@amazon.com>
  • Loading branch information
naveentatikonda committed May 5, 2022
1 parent 771d5d8 commit afe3feb
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 340 deletions.
6 changes: 3 additions & 3 deletions qa/restart-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ testClusters {
}

// Task to run BWC tests against the old cluster
task "testAgainstOldCluster"(type: StandaloneRestIntegTestTask) {
task testAgainstOldCluster(type: StandaloneRestIntegTestTask) {
dependsOn "zipBwcPlugin"
useCluster testClusters."${baseName}"
systemProperty 'tests.rest.bwcsuite_cluster', 'old_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'old'
systemProperty 'tests.is_old_cluster', 'true'
systemProperty 'tests.plugin_bwc_version', knn_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
Expand All @@ -48,7 +48,7 @@ task testRestartUpgrade(type: StandaloneRestIntegTestTask) {
testClusters."${baseName}".upgradeAllNodesAndPluginsToNextVersion([rootProject.tasks.bundlePlugin.archiveFile])
}
systemProperty 'tests.rest.bwcsuite_cluster', 'upgraded_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'fullrestart'
systemProperty 'tests.is_old_cluster', 'false'
systemProperty 'tests.plugin_bwc_version', knn_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
Expand Down
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));
}

}
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);
}
}
}
8 changes: 3 additions & 5 deletions qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ task testAgainstOldCluster(type: StandaloneRestIntegTestTask) {
dependsOn "zipBwcPlugin"
useCluster testClusters."${baseName}"
systemProperty 'tests.rest.bwcsuite_cluster', 'old_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'old'
systemProperty 'tests.plugin_bwc_version', knn_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
Expand All @@ -51,7 +50,7 @@ task testAgainstOneThirdUpgradedCluster(type: StandaloneRestIntegTestTask) {
testClusters."${baseName}".upgradeNodeAndPluginToNextVersion([rootProject.tasks.bundlePlugin.archiveFile])
}
systemProperty 'tests.rest.bwcsuite_cluster', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'first'
systemProperty 'tests.rest.first_round', 'true'
systemProperty 'tests.plugin_bwc_version', knn_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
Expand All @@ -69,7 +68,7 @@ task testAgainstTwoThirdsUpgradedCluster(type: StandaloneRestIntegTestTask) {
testClusters."${baseName}".upgradeNodeAndPluginToNextVersion([rootProject.tasks.bundlePlugin.archiveFile])
}
systemProperty 'tests.rest.bwcsuite_cluster', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'second'
systemProperty 'tests.rest.first_round', 'false'
systemProperty 'tests.plugin_bwc_version', knn_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
Expand All @@ -87,8 +86,7 @@ task testRollingUpgrade(type: StandaloneRestIntegTestTask) {
testClusters."${baseName}".upgradeNodeAndPluginToNextVersion([rootProject.tasks.bundlePlugin.archiveFile])
}
mustRunAfter "testAgainstOneThirdUpgradedCluster"
systemProperty 'tests.rest.bwcsuite_cluster', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'third'
systemProperty 'tests.rest.bwcsuite_cluster', 'upgraded_cluster'
systemProperty 'tests.plugin_bwc_version', knn_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName()}")
Expand Down
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));
}

}
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);
}
}
}
Loading

0 comments on commit afe3feb

Please sign in to comment.