From a4a1ff51c291807e4616f07e85be487ddaf45e17 Mon Sep 17 00:00:00 2001 From: monusingh-1 Date: Sun, 23 Jul 2023 13:41:25 +0530 Subject: [PATCH] Fix test for single test Signed-off-by: monusingh-1 --- build.gradle | 3 +++ .../replication/MultiClusterRestTestCase.kt | 18 +++++++++++----- .../integ/rest/ClusterRerouteFollowerIT.kt | 2 +- .../integ/rest/ClusterRerouteLeaderIT.kt | 2 +- .../integ/rest/ResumeReplicationIT.kt | 13 ++++-------- .../integ/rest/StartReplicationIT.kt | 21 ++++++++----------- .../integ/rest/StopReplicationIT.kt | 5 ++--- 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/build.gradle b/build.gradle index 426993aac..aa4422a7b 100644 --- a/build.gradle +++ b/build.gradle @@ -931,6 +931,9 @@ task integTestRemote (type: RestIntegTestTask) { systemProperty "tests.cluster.leaderCluster.security_enabled", System.getProperty("security_enabled") nonInputProperties.systemProperty('tests.integTestRemote', "true") + var numberOfNodes = findProperty('numNodes') as Integer + systemProperty "tests.cluster.followCluster.total_nodes", "${-> numberOfNodes.toString()}" + systemProperty "tests.cluster.leaderCluster.total_nodes", "${-> numberOfNodes.toString()}" systemProperty "build.dir", "${buildDir}" } diff --git a/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt b/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt index d6981ad23..f79819d0d 100644 --- a/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt @@ -120,7 +120,6 @@ abstract class MultiClusterRestTestCase : OpenSearchTestCase() { lateinit var testClusters : Map var isSecurityPropertyEnabled = false var forceInitSecurityConfiguration = false - var isMultiNodeClusterConfiguration = true internal fun createTestCluster(configuration: ClusterConfiguration) : TestCluster { return createTestCluster(configuration.clusterName, configuration.preserveSnapshots, configuration.preserveIndices, @@ -133,7 +132,6 @@ abstract class MultiClusterRestTestCase : OpenSearchTestCase() { val httpHostsProp = systemProperties.get("tests.cluster.${cluster}.http_hosts") as String? val transportHostsProp = systemProperties.get("tests.cluster.${cluster}.transport_hosts") as String? val securityEnabled = systemProperties.get("tests.cluster.${cluster}.security_enabled") as String? - val totalNodes = systemProperties.get("tests.cluster.${cluster}.total_nodes") as String? requireNotNull(httpHostsProp) { "Missing http hosts property for cluster: $cluster."} requireNotNull(transportHostsProp) { "Missing transport hosts property for cluster: $cluster."} @@ -145,9 +143,6 @@ abstract class MultiClusterRestTestCase : OpenSearchTestCase() { isSecurityPropertyEnabled = true } - if(totalNodes != null && totalNodes < "2") { - isMultiNodeClusterConfiguration = false - } forceInitSecurityConfiguration = isSecurityPropertyEnabled && initSecurityConfiguration @@ -667,6 +662,19 @@ abstract class MultiClusterRestTestCase : OpenSearchTestCase() { return integTestRemote.equals("true") } + protected fun isMultiNodeClusterConfiguration(leaderCluster: String, followerCluster: String): Boolean{ + val systemProperties = BootstrapInfo.getSystemProperties() + val totalLeaderNodes = systemProperties.get("tests.cluster.${leaderCluster}.total_nodes") as String + val totalFollowerNodes = systemProperties.get("tests.cluster.${followerCluster}.total_nodes") as String + + assertNotNull(totalLeaderNodes) + assertNotNull(totalFollowerNodes) + if(totalLeaderNodes < "2" || totalFollowerNodes < "2" ) { + return false + } + return true + } + protected fun docCount(cluster: RestHighLevelClient, indexName: String) : Int { val persistentConnectionRequest = Request("GET", "/$indexName/_search?pretty&q=*") diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/ClusterRerouteFollowerIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/ClusterRerouteFollowerIT.kt index 77cb164e6..189fa9fa3 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/ClusterRerouteFollowerIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/ClusterRerouteFollowerIT.kt @@ -25,7 +25,7 @@ class ClusterRerouteFollowerIT : MultiClusterRestTestCase() { @Before fun beforeTest() { - Assume.assumeTrue(isMultiNodeClusterConfiguration) + Assume.assumeTrue(isMultiNodeClusterConfiguration(LEADER, FOLLOWER)) } fun `test replication works after rerouting a shard from one node to another in follower cluster`() { diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/ClusterRerouteLeaderIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/ClusterRerouteLeaderIT.kt index 36fce5a55..03747f9a0 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/ClusterRerouteLeaderIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/ClusterRerouteLeaderIT.kt @@ -30,7 +30,7 @@ class ClusterRerouteLeaderIT : MultiClusterRestTestCase() { @Before fun beforeTest() { - Assume.assumeTrue(isMultiNodeClusterConfiguration) + Assume.assumeTrue(isMultiNodeClusterConfiguration(LEADER, FOLLOWER)) } fun `test replication works after rerouting a shard from one node to another in leader cluster`() { diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/ResumeReplicationIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/ResumeReplicationIT.kt index 2a3b3bae8..79839d35f 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/ResumeReplicationIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/ResumeReplicationIT.kt @@ -40,6 +40,7 @@ import org.opensearch.client.indices.GetMappingsRequest import org.opensearch.common.io.PathUtils import org.opensearch.common.settings.Settings import org.junit.Assert +import org.junit.Assume import java.nio.file.Files import java.util.concurrent.TimeUnit import org.opensearch.bootstrap.BootstrapInfo @@ -165,9 +166,7 @@ class ResumeReplicationIT: MultiClusterRestTestCase() { fun `test that replication fails to resume when custom analyser is not present in follower`() { - if(checkifIntegTestRemote()){ - return; - } + Assume.assumeTrue(checkifIntegTestRemote()) val synonyms = javaClass.getResourceAsStream("/analyzers/synonyms.txt") val config = PathUtils.get(buildDir, leaderClusterPath, "config") @@ -202,9 +201,7 @@ class ResumeReplicationIT: MultiClusterRestTestCase() { fun `test that replication resumes when custom analyser is present in follower`() { - if(checkifIntegTestRemote()){ - return; - } + Assume.assumeTrue(checkifIntegTestRemote()) val synonyms = javaClass.getResourceAsStream("/analyzers/synonyms.txt") val config = PathUtils.get(buildDir, leaderClusterPath, "config") @@ -246,9 +243,7 @@ class ResumeReplicationIT: MultiClusterRestTestCase() { fun `test that replication resumes when custom analyser is overridden and present in follower`() { - if(checkifIntegTestRemote()){ - return; - } + Assume.assumeTrue(checkifIntegTestRemote()) val synonyms = javaClass.getResourceAsStream("/analyzers/synonyms.txt") val config = PathUtils.get(buildDir, leaderClusterPath, "config") diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/StartReplicationIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/StartReplicationIT.kt index d4737c61c..db036bc84 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/StartReplicationIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/StartReplicationIT.kt @@ -66,6 +66,7 @@ import org.opensearch.index.mapper.MapperService import org.opensearch.repositories.fs.FsRepository import org.opensearch.test.OpenSearchTestCase.assertBusy import org.junit.Assert +import org.junit.Assume import org.opensearch.cluster.metadata.AliasMetadata import org.opensearch.core.xcontent.DeprecationHandler import org.opensearch.core.xcontent.NamedXContentRegistry @@ -585,9 +586,7 @@ class StartReplicationIT: MultiClusterRestTestCase() { fun `test that replication fails to start when custom analyser is not present in follower`() { - if(checkifIntegTestRemote()){ - return; - } + Assume.assumeTrue(checkifIntegTestRemote()) val synonyms = javaClass.getResourceAsStream("/analyzers/synonyms.txt") val config = PathUtils.get(buildDir, leaderClusterPath, "config") @@ -620,9 +619,7 @@ class StartReplicationIT: MultiClusterRestTestCase() { fun `test that replication starts successfully when custom analyser is present in follower`() { - if(checkifIntegTestRemote()){ - return; - } + Assume.assumeTrue(checkifIntegTestRemote()) val synonyms = javaClass.getResourceAsStream("/analyzers/synonyms.txt") val leaderConfig = PathUtils.get(buildDir, leaderClusterPath, "config") @@ -662,9 +659,7 @@ class StartReplicationIT: MultiClusterRestTestCase() { fun `test that replication starts successfully when custom analyser is overridden and present in follower`() { - if(checkifIntegTestRemote()){ - return; - } + Assume.assumeTrue(checkifIntegTestRemote()) val synonyms = javaClass.getResourceAsStream("/analyzers/synonyms.txt") val leaderConfig = PathUtils.get(buildDir, leaderClusterPath, "config") @@ -801,9 +796,7 @@ class StartReplicationIT: MultiClusterRestTestCase() { fun `test that snapshot on leader does not affect replication during bootstrap`() { - if(checkifIntegTestRemote()){ - return; - } + Assume.assumeTrue(checkifIntegTestRemote()) val settings = Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 20) @@ -1147,6 +1140,10 @@ class StartReplicationIT: MultiClusterRestTestCase() { } fun `test that wait_for_active_shards setting is updated on follower through start replication api`() { + + //Ignore this test if clusters dont have multiple nodes + Assume.assumeTrue(isMultiNodeClusterConfiguration(LEADER, FOLLOWER)) + val followerClient = getClientForCluster(FOLLOWER) val leaderClient = getClientForCluster(LEADER) diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/StopReplicationIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/StopReplicationIT.kt index f2f0a09e0..edbef1662 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/StopReplicationIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/StopReplicationIT.kt @@ -24,6 +24,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Assert +import org.junit.Assume import org.opensearch.OpenSearchStatusException import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest @@ -243,9 +244,7 @@ class StopReplicationIT: MultiClusterRestTestCase() { fun `test stop replication with stale replication settings at leader cluster`() { - if(checkifIntegTestRemote()){ - return; - } + Assume.assumeTrue(checkifIntegTestRemote()) val followerClient = getClientForCluster(FOLLOWER) val leaderClient = getClientForCluster(LEADER)