From c3990c109113e2fcc2b6f697dcd7a06032644fee Mon Sep 17 00:00:00 2001 From: bowenlan-amzn Date: Wed, 24 May 2023 12:12:18 -0700 Subject: [PATCH] Fix tests Signed-off-by: bowenlan-amzn --- .../indexmanagement/IndexManagementRestTestCase.kt | 7 ++++++- .../rollup/resthandler/RestStopRollupActionIT.kt | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt index 4162f9964..8928b73a1 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexManagementRestTestCase.kt @@ -56,7 +56,7 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { // preemptively seems to give the job scheduler time to listen to operations. @Before fun initializeManagedIndex() { - if (!indexExists(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX)) { + if (!isIndexExists(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX)) { val request = Request("PUT", "/${IndexManagementPlugin.INDEX_MANAGEMENT_INDEX}") var entity = "{\"settings\": " + Strings.toString(XContentType.JSON, Settings.builder().put(INDEX_HIDDEN, true).build()) entity += ",\"mappings\" : ${IndexManagementIndices.indexManagementMappings}}" @@ -77,6 +77,11 @@ abstract class IndexManagementRestTestCase : ODFERestTestCase() { protected fun Response.restStatus(): RestStatus = RestStatus.fromCode(this.statusLine.statusCode) + protected fun isIndexExists(index: String): Boolean { + val response = client().makeRequest("HEAD", index) + return RestStatus.OK == response.restStatus() + } + protected fun assertIndexExists(index: String) { val response = client().makeRequest("HEAD", index) assertEquals("Index $index does not exist.", RestStatus.OK, response.restStatus()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt index e29b55a15..95d28756a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt @@ -310,6 +310,8 @@ class RestStopRollupActionIT : RollupRestTestCase() { assertEquals("Rollup is not STOPPED", RollupMetadata.Status.STOPPED, rollupMetadata.status) // clearing the config index to prevent other tests using this multi shard index + Thread.sleep(2000L) deleteIndex(IndexManagementPlugin.INDEX_MANAGEMENT_INDEX) + Thread.sleep(2000L) } }