Skip to content

Commit

Permalink
Fix SM IT
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Jun 28, 2022
1 parent b651e32 commit 9d0ce75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ fun generateSnapshotName(policy: SMPolicy): String {
dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
}
val dateValue = if (policy.snapshotConfig[DATE_FORMAT_TIMEZONE_FIELD] != null) {
generateFormatTime(
generateFormatDate(
dateFormat,
ZoneId.of(policy.snapshotConfig[DATE_FORMAT_TIMEZONE_FIELD] as String),
)
} else {
generateFormatTime(dateFormat)
}
generateFormatDate(dateFormat)
}.lowercase()
result += "-$dateValue"
return result + "-${getRandomString(RANDOM_STRING_LENGTH)}"
}
Expand All @@ -167,7 +167,7 @@ fun getRandomString(length: Int): String {
/**
* For the supporting formats, refer to [DateFormatters]
*/
fun generateFormatTime(dateFormat: String, timezone: ZoneId = ZoneId.of("UTC")): String {
fun generateFormatDate(dateFormat: String, timezone: ZoneId = ZoneId.of("UTC")): String {
val dateFormatter = DateFormatter.forPattern(dateFormat).withZone(timezone)
return dateFormatter.format(now())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.apache.http.HttpHeaders
import org.apache.http.entity.ContentType.APPLICATION_JSON
import org.apache.http.entity.StringEntity
import org.apache.http.message.BasicHeader
import org.junit.Before
import org.opensearch.client.Response
import org.opensearch.client.ResponseException
import org.opensearch.common.xcontent.XContentParser
Expand All @@ -30,10 +31,24 @@ import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule
import org.opensearch.rest.RestStatus
import java.io.InputStream
import java.time.Duration
import java.time.Instant
import java.time.Instant.now

abstract class SnapshotManagementRestTestCase : IndexManagementRestTestCase() {

var timeout: Instant = Instant.ofEpochSecond(20)

/**
* For multi node test, if the shard of config index is moving, then the job scheduler
* could miss the execution after [updateSMPolicyStartTime]
* Extending this to be more than 1 minute, so even missed at first place, it could still be
* picked up to run in the next scheduled job.
*/
@Before
fun timeoutForMultiNode() {
if (isMultiNode) timeout = Instant.ofEpochSecond(70)
}

protected fun createSMPolicy(
smPolicy: SMPolicy,
refresh: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.opensearch.indexmanagement.snapshotmanagement.randomSMPolicy
import org.opensearch.indexmanagement.waitFor
import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule
import org.opensearch.rest.RestStatus
import java.time.Instant
import java.time.Instant.now
import java.time.temporal.ChronoUnit

Expand All @@ -32,7 +33,7 @@ class RestExplainSnapshotManagementIT : SnapshotManagementRestTestCase() {
)
)
updateSMPolicyStartTime(smPolicy)
waitFor {
waitFor(timeout = timeout) {
val explainResponse = explainSMPolicy(smPolicy.policyName)
val responseMap = createParser(XContentType.JSON.xContent(), explainResponse.entity.content).map() as Map<String, Any>
assertTrue(responseMap.containsKey(ExplainSMPolicyResponse.SM_POLICIES_FIELD))
Expand Down Expand Up @@ -76,7 +77,7 @@ class RestExplainSnapshotManagementIT : SnapshotManagementRestTestCase() {
}
// if this proves to be flaky, just index the metadata directly instead of executing to generate metadata
smPolicies.forEach { updateSMPolicyStartTime(it) }
waitFor {
waitFor(timeout = timeout) {
val explainResponse = explainSMPolicy(smPolicies.joinToString(",") { it.policyName })
val responseMap = createParser(XContentType.JSON.xContent(), explainResponse.entity.content).map() as Map<String, Any>
assertTrue(responseMap.containsKey(ExplainSMPolicyResponse.SM_POLICIES_FIELD))
Expand Down Expand Up @@ -104,7 +105,7 @@ class RestExplainSnapshotManagementIT : SnapshotManagementRestTestCase() {
}
// if this proves to be flaky, just index the metadata directly instead of executing to generate metadata
smPolicies.forEach { updateSMPolicyStartTime(it) }
waitFor {
waitFor(timeout = timeout) {
val explainResponse = explainSMPolicy("")
val responseMap = createParser(XContentType.JSON.xContent(), explainResponse.entity.content).map() as Map<String, Any>
assertTrue(responseMap.containsKey(ExplainSMPolicyResponse.SM_POLICIES_FIELD))
Expand Down

0 comments on commit 9d0ce75

Please sign in to comment.