Skip to content

Commit

Permalink
rebased commit
Browse files Browse the repository at this point in the history
Signed-off-by: Sanjay Kumar <[email protected]>
  • Loading branch information
skumarp7 committed Apr 23, 2024
1 parent cf3d699 commit 8f17c16
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,50 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {
fun getIndexReplicationTasks(clusterName: String): List<TaskInfo> {
return getReplicationTaskList(clusterName, IndexReplicationExecutor.TASK_NAME + "*")
}
fun `test auto follow should fail on indexPattern validation failure`() {
val followerClient = getClientForCluster(FOLLOWER)
createConnectionBetweenClusters(FOLLOWER, LEADER, connectionAlias)
assertPatternValidation(followerClient, "testPattern,",
"Autofollow pattern: testPattern, must not contain the following characters")
assertPatternValidation(followerClient, "testPat?",
"Autofollow pattern: testPat? must not contain the following characters")
assertPatternValidation(followerClient, "test#",
"Autofollow pattern: test# must not contain '#' or ':'")
assertPatternValidation(followerClient, "test:",
"Autofollow pattern: test: must not contain '#' or ':'")
assertPatternValidation(followerClient, "_test",
"Autofollow pattern: _test must not start with '_' or '-'")
assertPatternValidation(followerClient, "-leader",
"Autofollow pattern: -leader must not start with '_' or '-'")
assertPatternValidation(followerClient, "",
"Autofollow pattern: must not be empty")

}
private fun assertPatternValidation(followerClient: RestHighLevelClient, pattern: String,
errorMsg: String) {
Assertions.assertThatThrownBy {
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, pattern)
}.isInstanceOf(ResponseException::class.java)
.hasMessageContaining(errorMsg)
}

fun `test auto follow should succeed on valid indexPatterns`() {
val followerClient = getClientForCluster(FOLLOWER)
createConnectionBetweenClusters(FOLLOWER, LEADER, connectionAlias)
assertValidPatternValidation(followerClient, "test-leader")
assertValidPatternValidation(followerClient, "test*")
assertValidPatternValidation(followerClient, "leader-*")
assertValidPatternValidation(followerClient, "leader_test")
assertValidPatternValidation(followerClient, "Leader_Test-*")
assertValidPatternValidation(followerClient, "Leader_*")

}

private fun assertValidPatternValidation(followerClient: RestHighLevelClient, pattern: String) {
Assertions.assertThatCode {
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, pattern)
}.doesNotThrowAnyException()
}

fun createDummyConnection(fromClusterName: String, connectionName: String="source") {
val fromCluster = getNamedCluster(fromClusterName)
Expand Down

0 comments on commit 8f17c16

Please sign in to comment.