Skip to content

Commit

Permalink
Added & fixed test cases for shrink action
Browse files Browse the repository at this point in the history
Signed-off-by: Angie Zhang <[email protected]>
  • Loading branch information
Angie Zhang committed Mar 24, 2023
1 parent 0e7f320 commit 4539d24
Showing 1 changed file with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() {
}
""".trimIndent()
val res = client().makeRequest(
"PUT", "_cluster/settings", emptyMap(),
"PUT",
"_cluster/settings",
emptyMap(),
StringEntity(request, ContentType.APPLICATION_JSON)
)
assertEquals("Request failed", RestStatus.OK, res.restStatus())
Expand Down Expand Up @@ -447,7 +449,6 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() {
val indexName = "${testIndexName}_index_shard_noop"
val policyID = "${testIndexName}_testPolicyName_shard_noop"

// Create a Policy with one State that only preforms a force_merge Action
val shrinkAction = ShrinkAction(
numNewShards = null,
maxShardSize = null,
Expand Down Expand Up @@ -500,6 +501,63 @@ class ShrinkActionIT : IndexStateManagementRestTestCase() {
}
}

fun `test source index already has target number of shard`() {
val logger = LogManager.getLogger(::ShrinkActionIT)
val indexName = "${testIndexName}_index_shard_noop"
val policyID = "${testIndexName}_testPolicyName_shard_noop"

val shrinkAction = ShrinkAction(
numNewShards = 2,
maxShardSize = null,
percentageOfSourceShards = null,
targetIndexTemplate = Script(ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, "{{ctx.index}}$testIndexSuffix", mapOf()),
aliases = null,
forceUnsafe = true,
index = 0
)
val states = listOf(State("ShrinkState", listOf(shrinkAction), listOf()))

val policy = Policy(
id = policyID,
description = "$testIndexName description",
schemaVersion = 11L,
lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS),
errorNotification = randomErrorNotification(),
defaultState = states[0].name,
states = states
)

createPolicy(policy, policyID)
createIndex(indexName, policyID, null, "0", "2", "")

insertSampleData(indexName, 3)

// Will change the startTime each execution so that it triggers in 2 seconds
// First execution: Policy is initialized
val managedIndexConfig = getExistingManagedIndexConfig(indexName)

updateManagedIndexConfigStartTime(managedIndexConfig)
waitFor(Instant.ofEpochSecond(60)) { assertEquals(policyID, getExplainManagedIndexMetaData(indexName).policyID) }
logger.info("before attempt move shards")
// Starts AttemptMoveShardsStep
updateManagedIndexConfigStartTime(managedIndexConfig)

// The action should be done after the no-op
waitFor(Instant.ofEpochSecond(60)) {
val metadata = getExplainManagedIndexMetaData(indexName)
assertEquals(
"Did not get the no-op due to no shard count change",
AttemptMoveShardsStep.NO_SHARD_COUNT_CHANGE_MESSAGE,
metadata.info?.get("message")
)
assertEquals(
"Was not on the last step after no-op due to no shard count change",
WaitForShrinkStep.name,
metadata.stepMetaData?.name
)
}
}

@Suppress("UNCHECKED_CAST")
fun `test shrink with replicas`() {
val logger = LogManager.getLogger(::ShrinkActionIT)
Expand Down

0 comments on commit 4539d24

Please sign in to comment.