diff --git a/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt b/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt index 140a708d..51a0bd06 100644 --- a/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt +++ b/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt @@ -123,6 +123,7 @@ class TransportAutoFollowClusterManagerNodeAction @Inject constructor(transportS } catch(e: ResourceNotFoundException) { // Log warn as the task is already removed log.warn("Task already stopped for '$clusterAlias:$patternName'", e) + throw OpenSearchException("Autofollow replication rule $clusterAlias:$patternName does not exist") } catch (e: Exception) { log.error("Failed to stop auto follow task for cluster '$clusterAlias:$patternName'", e) throw OpenSearchException(AUTOFOLLOW_EXCEPTION_GENERIC_STRING) 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 57593241..78e4ead4 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt @@ -294,6 +294,22 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() { .hasMessageContaining(errorMsg) } + fun `test deletion of auto follow pattern`() { + val followerClient = getClientForCluster(FOLLOWER) + createConnectionBetweenClusters(FOLLOWER, LEADER, connectionAlias) + followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern) + //Delete a replication rule which does not exist + Assertions.assertThatThrownBy { + followerClient.deleteAutoFollowPattern(connectionAlias, "dummy_conn") + }.isInstanceOf(ResponseException::class.java) + .hasMessageContaining("does not exist") + //Delete a replication rule which exists + Assertions.assertThatCode { + followerClient.deleteAutoFollowPattern(connectionAlias, indexPatternName) + }.doesNotThrowAnyException() + + } + fun `test removing autofollow pattern stop autofollow task`() { val followerClient = getClientForCluster(FOLLOWER) val leaderClient = getClientForCluster(LEADER)