forked from opensearch-project/neural-search
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatting of Test folder and Initial BWC Test Commit
Signed-off-by: Varun Jain <[email protected]>
- Loading branch information
1 parent
81b9333
commit bf264ed
Showing
21 changed files
with
804 additions
and
770 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
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
...ade/src/test/java/org/opensearch/neuralsearch/bwc/AbstractRestartUpgradeRestTestCase.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.neuralsearch.bwc; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
import org.junit.Before; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.neuralsearch.BaseNeuralSearchIT; | ||
import static org.opensearch.neuralsearch.TestUtils.CLIENT_TIMEOUT_VALUE; | ||
import static org.opensearch.neuralsearch.TestUtils.RESTART_UPGRADE_OLD_CLUSTER; | ||
import static org.opensearch.neuralsearch.TestUtils.BWC_VERSION; | ||
import static org.opensearch.neuralsearch.TestUtils.NEURAL_SEARCH_BWC_PREFIX; | ||
import org.opensearch.test.rest.OpenSearchRestTestCase; | ||
|
||
public abstract class AbstractRestartUpgradeRestTestCase extends BaseNeuralSearchIT { | ||
protected static 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 = NEURAL_SEARCH_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 static 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)); | ||
} | ||
} |
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,67 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.bwc; | ||
|
||
import java.util.Map; | ||
import lombok.SneakyThrows; | ||
import static org.opensearch.neuralsearch.TestUtils.*; | ||
import static org.opensearch.neuralsearch.TestUtils.objectToFloat; | ||
import org.opensearch.neuralsearch.query.NeuralQueryBuilder; | ||
|
||
public class TextSearchIT extends AbstractRestartUpgradeRestTestCase { | ||
|
||
// @Before | ||
// public void setUp() throws Exception { | ||
// super.setUp(); | ||
// updateClusterSettings(); | ||
// prepareModel(); | ||
// } | ||
|
||
@SneakyThrows | ||
public void textSearch() { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
|
||
|
||
if(isRunningAgainstOldCluster()){ | ||
updateClusterSettings(); | ||
prepareModel(); | ||
initializeBasicIndexIfNotExist(TEST_BASIC_INDEX_NAME); | ||
// String modelId = getDeployedModelId(); | ||
// | ||
// NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder( | ||
// TEST_KNN_VECTOR_FIELD_NAME_1, | ||
// TEST_QUERY_TEXT8, | ||
// "", | ||
// modelId, | ||
// 1, | ||
// null, | ||
// null | ||
// ); | ||
|
||
}else { | ||
String modelId = getDeployedModelId(); | ||
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder( | ||
TEST_KNN_VECTOR_FIELD_NAME_1, | ||
TEST_QUERY_TEXT8, | ||
"", | ||
modelId, | ||
1, | ||
null, | ||
null | ||
); | ||
Map<String, Object> searchResponseAsMap = search(TEST_BASIC_INDEX_NAME, neuralQueryBuilder, 1); | ||
Map<String, Object> firstInnerHit = getFirstInnerHit(searchResponseAsMap); | ||
|
||
assertEquals("1", firstInnerHit.get("_id")); | ||
float expectedScore = computeExpectedScore(modelId, testVector, TEST_SPACE_TYPE, TEST_QUERY_TEXT8); | ||
assertEquals(expectedScore, objectToFloat(firstInnerHit.get("_score")), 0.0); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...upgrade/src/test/java/org/opensearch/neuralsearch/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,90 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.bwc; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
import org.junit.Before; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.neuralsearch.BaseNeuralSearchIT; | ||
import org.opensearch.test.rest.OpenSearchRestTestCase; | ||
import static org.opensearch.neuralsearch.TestUtils.CLIENT_TIMEOUT_VALUE; | ||
import static org.opensearch.neuralsearch.TestUtils.OLD_CLUSTER; | ||
import static org.opensearch.neuralsearch.TestUtils.MIXED_CLUSTER; | ||
import static org.opensearch.neuralsearch.TestUtils.UPGRADED_CLUSTER; | ||
import static org.opensearch.neuralsearch.TestUtils.BWC_VERSION; | ||
import static org.opensearch.neuralsearch.TestUtils.ROLLING_UPGRADE_FIRST_ROUND; | ||
import static org.opensearch.neuralsearch.TestUtils.BWCSUITE_CLUSTER; | ||
import static org.opensearch.neuralsearch.TestUtils.NEURAL_SEARCH_BWC_PREFIX; | ||
|
||
public abstract class AbstractRollingUpgradeTestCase extends BaseNeuralSearchIT { | ||
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 = NEURAL_SEARCH_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)); | ||
} | ||
|
||
} |
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,11 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
repositories { | ||
mavenLocal() | ||
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } | ||
mavenCentral() | ||
maven { url "https://plugins.gradle.org/m2/" } | ||
} |
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
Oops, something went wrong.