Skip to content

Commit

Permalink
Formatting of Test folder and Initial BWC Test Commit
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Nov 29, 2023
1 parent 81b9333 commit bf264ed
Show file tree
Hide file tree
Showing 21 changed files with 804 additions and 770 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.opensearch.gradle.test.RestIntegTestTask
import java.util.concurrent.Callable

apply plugin: 'java'
apply plugin: 'java-test-fixtures'
apply plugin: 'idea'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.pluginzip'
Expand Down Expand Up @@ -123,6 +124,7 @@ allprojects {
version = "${opensearch_build}"
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_11
apply from: rootProject.file('repositories.gradle').absoluteFile
}

repositories {
Expand All @@ -145,6 +147,7 @@ dependencies {
compileOnly fileTree(dir: knnJarDirectory, include: '*.jar')
api group: 'org.opensearch', name:'opensearch-ml-client', version: "${opensearch_build}"
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
testFixturesImplementation "org.opensearch.test:framework:${opensearch_version}"
// ml-common excluded reflection for runtime so we need to add it by ourselves.
// https://github.com/opensearch-project/ml-commons/commit/464bfe34c66d7a729a00dd457f03587ea4e504d9
// TODO: Remove following three lines of dependencies if ml-common include them in their jar
Expand All @@ -154,6 +157,10 @@ dependencies {
runtimeOnly group: 'org.apache.commons', name: 'commons-text', version: '1.10.0'
runtimeOnly group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
runtimeOnly group: 'org.json', name: 'json', version: '20231013'
testFixturesImplementation "org.opensearch:common-utils:${version}"
testFixturesImplementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
testFixturesCompileOnly group: 'com.google.guava', name: 'guava', version:'32.0.1-jre'
testFixturesCompileOnly fileTree(dir: knnJarDirectory, include: '*.jar')
}

// In order to add the jar to the classpath, we need to unzip the
Expand All @@ -173,6 +180,9 @@ compileJava {
compileTestJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
}
compileTestFixturesJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
}

def opensearch_tmp_dir = rootProject.file('build/private/opensearch_tmp').absoluteFile
opensearch_tmp_dir.mkdirs()
Expand Down
6 changes: 3 additions & 3 deletions qa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.nio.file.Files
apply plugin: 'opensearch.testclusters'
apply plugin: 'opensearch.build'
apply plugin: 'opensearch.rest-test'
apply plugin: 'io.freefair.lombok'

// Disable a few tasks that come with build
build.enabled = false
Expand All @@ -19,11 +20,10 @@ dependenciesInfo.enabled = false

dependencies {
api "org.opensearch:opensearch:${opensearch_version}"
//compileOnly "org.opensearch.plugin:opensearch-scripting-painless-spi:${versions.opensearch}"
//api group: 'commons-lang', name: 'commons-lang', version: '2.6'

api group: 'commons-lang', name: 'commons-lang', version: '2.6'
api "org.apache.logging.log4j:log4j-api:${versions.log4j}"
api "org.apache.logging.log4j:log4j-core:${versions.log4j}"
api "junit:junit:${versions.junit}"

testImplementation "org.opensearch.test:framework:${opensearch_version}"
testImplementation(testFixtures(rootProject))
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.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));
}
}
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);
}

}



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

}
11 changes: 11 additions & 0 deletions repositories.gradle
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/" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Map;
import java.util.Optional;

import org.opensearch.indices.IndicesService;
import org.opensearch.ingest.IngestService;
import org.opensearch.ingest.Processor;
import org.opensearch.neuralsearch.processor.NeuralQueryEnricherProcessor;
Expand Down Expand Up @@ -66,7 +67,8 @@ public void testProcessors() {
null,
mock(IngestService.class),
null,
null
null,
mock(IndicesService.class)
);
Map<String, Processor.Factory> processors = plugin.getProcessors(processorParams);
assertNotNull(processors);
Expand Down
Loading

0 comments on commit bf264ed

Please sign in to comment.