diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupActionIT.kt index 7c871781c..67bab487c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestDeleteRollupActionIT.kt @@ -6,16 +6,14 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException -import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.INDEX_MANAGEMENT_INDEX import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.makeRequest -import org.opensearch.indexmanagement.rollup.RollupRestTestCase import org.opensearch.core.rest.RestStatus +import org.opensearch.indexmanagement.indexstatemanagement.wait import org.opensearch.test.junit.annotations.TestLogging @TestLogging(value = "level:DEBUG", reason = "Debugging tests") -@Suppress("UNCHECKED_CAST") -class RestDeleteRollupActionIT : RollupRestTestCase() { +class RestDeleteRollupActionIT : RollupRestAPITestCase() { @Throws(Exception::class) fun `test deleting a rollup`() { @@ -30,19 +28,21 @@ class RestDeleteRollupActionIT : RollupRestTestCase() { @Throws(Exception::class) fun `test deleting a rollup that doesn't exist in existing config index`() { - try { - createRandomRollup() - client().makeRequest("DELETE", "$ROLLUP_JOBS_BASE_URI/foobarbaz") - fail("expected 404 ResponseException") - } catch (e: ResponseException) { - assertEquals(RestStatus.NOT_FOUND, e.response.restStatus()) + createRandomRollup() + wait { + try { + client().makeRequest("DELETE", "$ROLLUP_JOBS_BASE_URI/foobarbaz") + fail("expected 404 ResponseException") + } catch (e: ResponseException) { + assertEquals(RestStatus.NOT_FOUND, e.response.restStatus()) + } } } @Throws(Exception::class) fun `test deleting a rollup that doesn't exist and config index doesnt exist`() { try { - deleteIndex(INDEX_MANAGEMENT_INDEX) + wipeAllIndices() client().makeRequest("DELETE", "$ROLLUP_JOBS_BASE_URI/foobarbaz") fail("expected 404 ResponseException") } catch (e: ResponseException) { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupActionIT.kt index 0f7fd50e9..8674b0445 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestExplainRollupActionIT.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.makeRequest -import org.opensearch.indexmanagement.rollup.RollupRestTestCase import org.opensearch.indexmanagement.rollup.model.RollupMetadata import org.opensearch.indexmanagement.rollup.randomRollup import org.opensearch.indexmanagement.waitFor @@ -20,7 +19,7 @@ import java.time.temporal.ChronoUnit @TestLogging(value = "level:DEBUG", reason = "Debugging tests") @Suppress("UNCHECKED_CAST") -class RestExplainRollupActionIT : RollupRestTestCase() { +class RestExplainRollupActionIT : RollupRestAPITestCase() { @Throws(Exception::class) fun `test explain rollup`() { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupActionIT.kt index 0f2897972..e02b7eafb 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestGetRollupActionIT.kt @@ -8,7 +8,6 @@ package org.opensearch.indexmanagement.rollup.resthandler import org.opensearch.client.ResponseException import org.opensearch.indexmanagement.IndexManagementPlugin.Companion.ROLLUP_JOBS_BASE_URI import org.opensearch.indexmanagement.makeRequest -import org.opensearch.indexmanagement.rollup.RollupRestTestCase import org.opensearch.indexmanagement.rollup.action.get.GetRollupsRequest.Companion.DEFAULT_SIZE import org.opensearch.indexmanagement.rollup.randomRollup import org.opensearch.core.rest.RestStatus @@ -17,7 +16,7 @@ import java.util.Locale @TestLogging(value = "level:DEBUG", reason = "Debugging tests") @Suppress("UNCHECKED_CAST") -class RestGetRollupActionIT : RollupRestTestCase() { +class RestGetRollupActionIT : RollupRestAPITestCase() { private val testName = javaClass.simpleName.lowercase(Locale.ROOT) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupActionIT.kt index 49a44b49b..4ae34eab6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestIndexRollupActionIT.kt @@ -14,7 +14,6 @@ import org.opensearch.indexmanagement.common.model.dimension.Dimension import org.opensearch.indexmanagement.common.model.dimension.Histogram import org.opensearch.indexmanagement.common.model.dimension.Terms import org.opensearch.indexmanagement.makeRequest -import org.opensearch.indexmanagement.rollup.RollupRestTestCase import org.opensearch.indexmanagement.rollup.model.RollupMetrics import org.opensearch.indexmanagement.rollup.model.metric.Average import org.opensearch.indexmanagement.rollup.model.metric.Max @@ -35,7 +34,7 @@ import java.util.Locale @TestLogging(value = "level:DEBUG", reason = "Debugging tests") @Suppress("UNCHECKED_CAST") -class RestIndexRollupActionIT : RollupRestTestCase() { +class RestIndexRollupActionIT : RollupRestAPITestCase() { private val testName = javaClass.simpleName.lowercase(Locale.ROOT) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt index e2654b105..d2442995d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStartRollupActionIT.kt @@ -14,7 +14,6 @@ import org.opensearch.indexmanagement.common.model.dimension.DateHistogram import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_NUMBER_OF_SHARDS import org.opensearch.indexmanagement.makeRequest -import org.opensearch.indexmanagement.rollup.RollupRestTestCase import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.rollup.model.RollupMetadata import org.opensearch.indexmanagement.rollup.randomRollup @@ -25,7 +24,7 @@ import java.time.Instant import java.time.temporal.ChronoUnit import java.util.Locale -class RestStartRollupActionIT : RollupRestTestCase() { +class RestStartRollupActionIT : RollupRestAPITestCase() { private val testName = javaClass.simpleName.lowercase(Locale.ROOT) 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 6a9a674e2..fb5154dbe 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RestStopRollupActionIT.kt @@ -5,7 +5,6 @@ package org.opensearch.indexmanagement.rollup.resthandler -import org.junit.After import org.opensearch.client.ResponseException import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.IndexManagementIndices @@ -17,7 +16,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_HIDDEN import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_NUMBER_OF_SHARDS import org.opensearch.indexmanagement.makeRequest import org.opensearch.indexmanagement.randomInstant -import org.opensearch.indexmanagement.rollup.RollupRestTestCase import org.opensearch.indexmanagement.rollup.model.Rollup import org.opensearch.indexmanagement.rollup.model.RollupMetadata import org.opensearch.indexmanagement.rollup.randomRollup @@ -28,18 +26,10 @@ import java.time.Instant import java.time.temporal.ChronoUnit import java.util.Locale -class RestStopRollupActionIT : RollupRestTestCase() { +class RestStopRollupActionIT : RollupRestAPITestCase() { private val testName = javaClass.simpleName.lowercase(Locale.ROOT) - @After - fun clearIndicesAfterEachTest() { - // Flaky could happen if config index not deleted - // metadata creation could cause the mapping to be auto set to - // a wrong type, namely, [rollup_metadata.continuous.next_window_end_time] to long - wipeAllIndices() - } - @Throws(Exception::class) fun `test stopping a started rollup`() { val rollup = createRollup(randomRollup().copy(enabled = true, jobEnabledTime = randomInstant(), metadataID = null), rollupId = "$testName-1") diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RollupRestAPITestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RollupRestAPITestCase.kt new file mode 100644 index 000000000..26d6f6e78 --- /dev/null +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/resthandler/RollupRestAPITestCase.kt @@ -0,0 +1,19 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.rollup.resthandler + +import org.junit.After +import org.opensearch.indexmanagement.rollup.RollupRestTestCase + +abstract class RollupRestAPITestCase : RollupRestTestCase() { + @After + fun clearIndicesAfterEachTest() { + // For API tests, flaky could happen if config index not deleted + // metadata creation could cause the mapping to be auto set to + // a wrong type, namely, [rollup_metadata.continuous.next_window_end_time] to long + wipeAllIndices() + } +}