diff --git a/src/test/kotlin/org/opensearch/replication/ReplicationHelpers.kt b/src/test/kotlin/org/opensearch/replication/ReplicationHelpers.kt index 6640f911..e538657e 100644 --- a/src/test/kotlin/org/opensearch/replication/ReplicationHelpers.kt +++ b/src/test/kotlin/org/opensearch/replication/ReplicationHelpers.kt @@ -325,7 +325,8 @@ fun RestHighLevelClient.waitForReplicationStop(index: String, waitFor : TimeValu fun RestHighLevelClient.updateAutoFollowPattern(connection: String, patternName: String, pattern: String, settings: Settings = Settings.EMPTY, useRoles: UseRoles = UseRoles(), - requestOptions: RequestOptions = RequestOptions.DEFAULT) { + requestOptions: RequestOptions = RequestOptions.DEFAULT, + ignoreIfExists: Boolean = false) { val lowLevelRequest = Request("POST", REST_AUTO_FOLLOW_PATTERN) if (settings == Settings.EMPTY) { lowLevelRequest.setJsonEntity("""{ @@ -350,9 +351,14 @@ fun RestHighLevelClient.updateAutoFollowPattern(connection: String, patternName: }""") } lowLevelRequest.setOptions(requestOptions) - val lowLevelResponse = lowLevelClient.performRequest(lowLevelRequest) - val response = getAckResponse(lowLevelResponse) - assertThat(response.isAcknowledged).isTrue() + try { + val lowLevelResponse = lowLevelClient.performRequest(lowLevelRequest) + val response = getAckResponse(lowLevelResponse) + assertThat(response.isAcknowledged).isTrue() + } catch (e: ResponseException) { + // Skip if ignoreIfExists is true and exception contains resource_already_exists_exception + if ((ignoreIfExists == true && e.message?.contains("resource_already_exists_exception")!!) == false) throw e + } } fun RestHighLevelClient.AutoFollowStats() : Map { diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt index d1f884fe..a65bc348 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt @@ -376,7 +376,7 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() { // Add replication start block followerClient.updateReplicationStartBlockSetting(true) createRandomIndex(leaderClient) - followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern) + followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern, ignoreIfExists=true) sleep(95000) // wait for auto follow trigger in the worst case // verify both index replication tasks and autofollow tasks // Replication shouldn't have been started - (repeat-1) tasks as for current loop index shouldn't be