-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic sanity tests for single cluster scenario. (#393)
Signed-off-by: Naveen Pajjuri <nppajjur@amazon.com> Co-authored-by: Naveen Pajjuri <nppajjur@amazon.com>
- Loading branch information
1 parent
500a50a
commit 9c4f7e2
Showing
2 changed files
with
115 additions
and
1 deletion.
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
89 changes: 89 additions & 0 deletions
89
src/test/kotlin/org/opensearch/replication/singleCluster/SingleClusterSanityIT.kt
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,89 @@ | ||
package org.opensearch.replication.singleCluster | ||
|
||
|
||
import org.apache.logging.log4j.LogManager | ||
import org.junit.BeforeClass | ||
import org.opensearch.client.ResponseException | ||
import org.opensearch.replication.MultiClusterRestTestCase | ||
import org.opensearch.replication.StartReplicationRequest | ||
import org.opensearch.replication.startReplication | ||
import org.assertj.core.api.Assertions.assertThatThrownBy | ||
import org.junit.Assert | ||
import org.opensearch.replication.stopReplication | ||
import java.util.stream.Collectors | ||
|
||
|
||
|
||
|
||
class SingleClusterSanityIT : MultiClusterRestTestCase() { | ||
|
||
companion object { | ||
private val log = LogManager.getLogger(SingleClusterSanityIT::class.java) | ||
private const val standaloneClusterName = "singleCluster" | ||
private const val REPLICATION_PLUGIN_NAME = "opensearch-cross-cluster-replication" | ||
private const val NUM_NODES = 3 | ||
private const val SAMPLE_INDEX = "sample_test_index" | ||
|
||
@BeforeClass | ||
@JvmStatic | ||
fun setupTestClusters() { | ||
val clusters = HashMap<String, TestCluster>() | ||
clusters.put(standaloneClusterName, createTestCluster(standaloneClusterName, true, true, true, false)) | ||
testClusters = clusters | ||
} | ||
|
||
enum class ClusterState(val value: String) { | ||
SINGLE_CLUSTER_SANITY_SUITE("integTestSingleCluster"); | ||
|
||
companion object { | ||
fun from(s: String): ClusterState? = values().find { it.value == s } | ||
} | ||
} | ||
} | ||
|
||
@Throws(Exception::class) | ||
fun testReplicationPluginWithSingleCluster() { | ||
when(ClusterState.from(System.getProperty("tests.sanitySingleCluster"))) { | ||
ClusterState.SINGLE_CLUSTER_SANITY_SUITE -> basicReplicationSanityWithSingleCluster() | ||
} | ||
} | ||
|
||
fun basicReplicationSanityWithSingleCluster() { | ||
verifyReplicationPluginInstallationOnAllNodes(standaloneClusterName) | ||
VerifyReplicationApis(standaloneClusterName) | ||
} | ||
|
||
@Throws(java.lang.Exception::class) | ||
private fun verifyReplicationPluginInstallationOnAllNodes(clusterName: String) { | ||
val restClient = getClientForCluster(clusterName) | ||
for (i in 0 until NUM_NODES) { | ||
val responseMap = getAsMap(restClient.lowLevelClient, "_nodes/$clusterName-$i/plugins")["nodes"] | ||
as Map<String, Map<String, Any>>? | ||
Assert.assertTrue(responseMap!!.values.isNotEmpty()) | ||
for (response in responseMap!!.values) { | ||
val plugins = response["plugins"] as List<Map<String, Any>>? | ||
val pluginNames: Set<Any?> = plugins!!.stream().map { map: Map<String, Any> -> | ||
map["name"] | ||
}.collect(Collectors.toSet()).orEmpty() | ||
Assert.assertTrue(pluginNames.contains(REPLICATION_PLUGIN_NAME)) | ||
} | ||
} | ||
} | ||
|
||
@Throws(java.lang.Exception::class) | ||
private fun VerifyReplicationApis(clusterName: String) { | ||
val follower = getClientForCluster(standaloneClusterName) | ||
assertThatThrownBy { | ||
follower.startReplication( | ||
StartReplicationRequest("sample_connection", SAMPLE_INDEX, SAMPLE_INDEX), | ||
waitForRestore = true | ||
) | ||
}.isInstanceOf(ResponseException::class.java).hasMessageContaining("no such remote cluster") | ||
assertThatThrownBy { | ||
follower.stopReplication(standaloneClusterName) | ||
}.isInstanceOf(ResponseException::class.java) | ||
.hasMessageContaining("No replication in progress for index:"+standaloneClusterName) | ||
} | ||
|
||
} | ||
|