forked from opensearch-project/index-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Successful deletes of an index still adds history document (opensearc…
…h-project#160) Signed-off-by: Drew Baugher <[email protected]>
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
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
76 changes: 76 additions & 0 deletions
76
src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/DeleteActionIT.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,76 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.indexstatemanagement.action | ||
|
||
import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase | ||
import org.opensearch.indexmanagement.indexstatemanagement.model.Policy | ||
import org.opensearch.indexmanagement.indexstatemanagement.model.State | ||
import org.opensearch.indexmanagement.indexstatemanagement.model.action.DeleteActionConfig | ||
import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification | ||
import org.opensearch.indexmanagement.waitFor | ||
import java.time.Instant | ||
import java.time.temporal.ChronoUnit | ||
import java.util.Locale | ||
|
||
class DeleteActionIT : IndexStateManagementRestTestCase() { | ||
|
||
private val testIndexName = javaClass.simpleName.toLowerCase(Locale.ROOT) | ||
|
||
fun `test basic`() { | ||
val indexName = "${testIndexName}_index_1" | ||
val policyID = "${testIndexName}_testPolicyName_1" | ||
val actionConfig = DeleteActionConfig(0) | ||
val states = listOf( | ||
State("DeleteState", listOf(actionConfig), listOf()) | ||
) | ||
|
||
val policy = Policy( | ||
id = policyID, | ||
description = "$testIndexName description", | ||
schemaVersion = 1L, | ||
lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), | ||
errorNotification = randomErrorNotification(), | ||
defaultState = states[0].name, | ||
states = states | ||
) | ||
createPolicy(policy, policyID) | ||
createIndex(indexName, policyID) | ||
|
||
waitFor { assertIndexExists(indexName) } | ||
|
||
val managedIndexConfig = getExistingManagedIndexConfig(indexName) | ||
// Change the start time so the job will trigger in 2 seconds. | ||
updateManagedIndexConfigStartTime(managedIndexConfig) | ||
|
||
waitFor { assertEquals(policyID, getExplainManagedIndexMetaData(indexName).policyID) } | ||
|
||
// Need to wait two cycles. | ||
// Change the start time so the job will trigger in 2 seconds. | ||
updateManagedIndexConfigStartTime(managedIndexConfig) | ||
|
||
// confirm index does not exist anymore | ||
waitFor { assertIndexDoesNotExist(indexName) } | ||
|
||
// confirm we added a history document that says we did a successful delete operation | ||
waitFor { | ||
val response = getHistorySearchResponse(indexName) | ||
assertTrue( | ||
response.hits.hits | ||
.map { it.sourceAsMap } | ||
.any { | ||
val metadata = it["managed_index_meta_data"] as Map<*, *> | ||
val index = metadata["index"] as String | ||
val action = metadata["action"] as Map<*, *> | ||
val actionName = action["name"] as String | ||
val step = metadata["step"] as Map<*, *> | ||
val stepName = step["name"] as String | ||
val stepStatus = step["step_status"] as String | ||
index == indexName && actionName == "delete" && stepName == "attempt_delete" && stepStatus == "completed" | ||
} | ||
) | ||
} | ||
} | ||
} |