Skip to content

Commit

Permalink
Addition of test case on valid indexPatterns and Addresal of review c…
Browse files Browse the repository at this point in the history
…omments

Signed-off-by: Sanjay Kumar <[email protected]>
  • Loading branch information
skumarp7 committed Apr 12, 2024
1 parent 3d55296 commit 80cd1be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package org.opensearch.replication.action.autofollow
import org.opensearch.replication.action.index.ReplicateIndexRequest
import org.opensearch.replication.metadata.store.KEY_SETTINGS
import org.opensearch.replication.util.ValidationUtil.validateName
import org.opensearch.replication.util.ValidationUtil.validatePattern
import org.opensearch.replication.util.ValidationUtil.validateAutoFollowPattern
import org.opensearch.action.ActionRequestValidationException
import org.opensearch.action.support.master.AcknowledgedRequest
import org.opensearch.core.ParseField
Expand Down Expand Up @@ -118,7 +118,7 @@ class UpdateAutoFollowPatternRequest: AcknowledgedRequest<UpdateAutoFollowPatter
if(pattern == null)
validationException.addValidationError("Missing pattern")
else
validatePattern(pattern, validationException)
validateAutoFollowPattern(pattern, validationException)
}

return if(validationException.validationErrors().isEmpty()) return null else validationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ object ValidationUtil {
* Validate the pattern against the rules that we have for indexPattern name.
*/

fun validatePattern(pattern: String?, validationException: ValidationException) {
fun validateAutoFollowPattern(pattern: String?, validationException: ValidationException) {

if (!Strings.validFileNameExcludingAstrix(pattern))
validationException.addValidationError("Autofollow pattern: $pattern must not contain the following characters ${Strings.INVALID_FILENAME_CHARS}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {
"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) {
Expand All @@ -320,6 +321,24 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {
.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 `test removing autofollow pattern stop autofollow task`() {
val followerClient = getClientForCluster(FOLLOWER)
val leaderClient = getClientForCluster(LEADER)
Expand Down

0 comments on commit 80cd1be

Please sign in to comment.