Skip to content

Commit

Permalink
Fixing the flaky in rollup API test (#981) (#988)
Browse files Browse the repository at this point in the history
(cherry picked from commit 784ad4f)

Signed-off-by: bowenlan-amzn <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent d9811e6 commit 093d4ee
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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`() {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 093d4ee

Please sign in to comment.