From 025841567a2d6ae671a34be31f088f291ffc8a3c Mon Sep 17 00:00:00 2001 From: Martin Gaievski Date: Tue, 25 Jan 2022 10:29:02 -0800 Subject: [PATCH] Adding gradle task for running integ tests in remote cluster (#266) * Adding gradle task for running integ tests in remote cluster Signed-off-by: Martin Gaievski --- DEVELOPER_GUIDE.md | 12 +++++++++++ build.gradle | 20 +++++++++++++++++++ .../knn/index/KNNCircuitBreakerIT.java | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 302fd2983..28484f61b 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -178,6 +178,18 @@ In order to run the integration tests with a 3 node cluster, run this command: ./gradlew :integTest -PnumNodes=3 ``` +Integration tests can be run with remote cluster. For that run the following command and replace host/port/cluster name values with ones for the target cluster: + +``` +./gradlew :integTestRemote -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="integTest-0" -Dhttps=false -PnumNodes=1 +``` + +In case remote cluster is secured it's possible to pass username and password with the following command: + +``` +./gradlew :integTestRemote -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="integTest-0" -Dhttps=true -Duser=admin -Dpassword=admin +``` + ### Debugging Sometimes it is useful to attach a debugger to either the OpenSearch cluster or the integration test runner to see what's going on. For running unit tests, hit **Debug** from the IDE's gutter to debug the tests. For the OpenSearch cluster, first, make sure that the debugger is listening on port `5005`. Then, to debug the cluster code, run: diff --git a/build.gradle b/build.gradle index b5b1ae5fe..4f6562941 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ import java.util.concurrent.Callable import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask +import org.opensearch.gradle.test.RestIntegTestTask buildscript { ext { @@ -217,6 +218,25 @@ testClusters.integTest { systemProperty("java.library.path", "$rootDir/jni/release") } +task integTestRemote(type: RestIntegTestTask) { + testClassesDirs = sourceSets.test.output.classesDirs + classpath = sourceSets.test.runtimeClasspath + + systemProperty "https", System.getProperty("https") + systemProperty "user", System.getProperty("user") + systemProperty "password", System.getProperty("password") + + systemProperty 'cluster.number_of_nodes', "${_numNodes}" + + // Run tests with remote cluster only if rest case is defined + if (System.getProperty("tests.rest.cluster") != null) { + filter { + includeTestsMatching "org.opensearch.knn.*IT" + excludeTestsMatching "org.opensearch.knn.bwc.*IT" + } + } +} + // bwcFilePath contains the gradlew assemble binary files of k-NN plugins String baseName = "knnBwcCluster" String bwcFilePath = "src/test/resources/org/opensearch/knn/bwc/" diff --git a/src/test/java/org/opensearch/knn/index/KNNCircuitBreakerIT.java b/src/test/java/org/opensearch/knn/index/KNNCircuitBreakerIT.java index f5a360e2d..1e0f94c42 100644 --- a/src/test/java/org/opensearch/knn/index/KNNCircuitBreakerIT.java +++ b/src/test/java/org/opensearch/knn/index/KNNCircuitBreakerIT.java @@ -33,7 +33,7 @@ private void tripCb() throws Exception { updateClusterSettings("knn.memory.circuit_breaker.limit", "1kb"); // Create index with 1 primary and numNodes-1 replicas so that the data will be on every node in the cluster - int numNodes = Integer.parseInt(System.getProperty("cluster.number_of_nodes")); + int numNodes = Integer.parseInt(System.getProperty("cluster.number_of_nodes", "1")); Settings settings = Settings.builder() .put("number_of_shards", 1) .put("number_of_replicas", numNodes - 1)