Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index refresh after config creation and deletion in integration tests #590

Merged
merged 5 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,59 @@ abstract class PluginRestTestCase : OpenSearchRestTestCase() {
RestStatus.OK.status,
client
)
refreshAllIndices()
val configId = createResponse.get("config_id").asString
Assert.assertNotNull(configId)
Thread.sleep(100)
qreshi marked this conversation as resolved.
Show resolved Hide resolved
return configId
}

fun createConfigWithRequestJsonString(
createRequestJsonString: String,
client: RestClient = client()
): String {
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
createRequestJsonString,
RestStatus.OK.status,
client
)
refreshAllIndices()
Thread.sleep(100)
return createResponse.get("config_id").asString
}

fun deleteConfig(
configId: String,
client: RestClient = client()
): JsonObject {
val deleteResponse = executeRequest(
RestRequest.Method.DELETE.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs/$configId",
"",
RestStatus.OK.status,
client
)
refreshAllIndices()
return deleteResponse
}

fun deleteConfigs(
configIds: Set<String>,
client: RestClient = client()
): JsonObject {
val deleteResponse = executeRequest(
RestRequest.Method.DELETE.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs?config_id_list=${configIds.joinToString(separator = ",")}",
"",
RestStatus.OK.status,
client
)
refreshAllIndices()
return deleteResponse
}

@After
open fun wipeAllSettings() {
wipeAllClusterSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ class SecurityNotificationIT : PluginRestTestCase() {
}
""".trimIndent()
try {
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
createRequestJsonString,
RestStatus.OK.status,
userClient!!
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString, userClient!!)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down Expand Up @@ -159,13 +152,7 @@ class SecurityNotificationIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down Expand Up @@ -278,13 +265,7 @@ class SecurityNotificationIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down Expand Up @@ -340,24 +321,12 @@ class SecurityNotificationIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

// Delete Slack notification config
executeRequest(
RestRequest.Method.DELETE.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs/$configId",
"",
RestStatus.OK.status,
userClient!!
)
deleteConfig(configId, userClient!!)

// Should not be able to find config
executeRequest(
Expand Down Expand Up @@ -477,13 +446,7 @@ class SecurityNotificationIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down Expand Up @@ -521,13 +484,7 @@ class SecurityNotificationIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,7 @@ class NotificationsBackwardsCompatibilityIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"${NotificationPlugin.PLUGIN_BASE_URI}/configs",
requestJsonString,
RestStatus.OK.status
)
val createdConfigId = createResponse.get("config_id").asString
val createdConfigId = createConfigWithRequestJsonString(requestJsonString)
assertNotNull(createdConfigId)
Thread.sleep(100)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"$PLUGIN_BASE_URI/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down Expand Up @@ -114,12 +108,7 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
Thread.sleep(100)

// Delete chime notification config
val deleteResponse = executeRequest(
RestRequest.Method.DELETE.name,
"$PLUGIN_BASE_URI/configs/$configId",
"",
RestStatus.OK.status
)
val deleteResponse = deleteConfig(configId)
Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString)
Thread.sleep(1000)

Expand Down Expand Up @@ -189,13 +178,7 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"$PLUGIN_BASE_URI/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down Expand Up @@ -283,13 +266,7 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"$PLUGIN_BASE_URI/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ class CreateNotificationConfigIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"$PLUGIN_BASE_URI/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

Expand Down Expand Up @@ -90,13 +84,8 @@ class CreateNotificationConfigIT : PluginRestTestCase() {
}
}
""".trimIndent()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"$PLUGIN_BASE_URI/configs",
createRequestJsonString,
RestStatus.OK.status
)
Assert.assertEquals(configId, createResponse.get("config_id").asString)
val createdConfigId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertEquals(configId, createdConfigId)
Thread.sleep(1000)

// Get chime notification config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,10 @@ import org.opensearch.notifications.verifyMultiConfigIdEquals
import org.opensearch.notifications.verifySingleConfigIdEquals
import org.opensearch.rest.RestRequest
import org.opensearch.rest.RestStatus
import kotlin.random.Random

class DeleteNotificationConfigIT : PluginRestTestCase() {
private val charPool: List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9')

private fun getCreateRequestJsonString(): String {
val randomString = (1..20)
.map { Random.nextInt(0, charPool.size) }
.map(charPool::get)
.joinToString("")
return """
{
"config_id":"$randomString",
"config":{
"name":"this is a sample config name $randomString",
"description":"this is a sample config description $randomString",
"config_type":"slack",
"is_enabled":true,
"slack":{"url":"https://domain.com/sample_slack_url#$randomString"}
}
}
""".trimIndent()
}

private fun createConfig(): String {
val createRequestJsonString = getCreateRequestJsonString()
val createResponse = executeRequest(
RestRequest.Method.POST.name,
"$PLUGIN_BASE_URI/configs",
createRequestJsonString,
RestStatus.OK.status
)
val configId = createResponse.get("config_id").asString
Assert.assertNotNull(configId)
Thread.sleep(100)
return configId
}

fun `test Delete single notification config`() {
val configId = createConfig()
Thread.sleep(1000)
Expand All @@ -65,12 +31,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
Thread.sleep(100)

// Delete notification config
val deleteResponse = executeRequest(
RestRequest.Method.DELETE.name,
"$PLUGIN_BASE_URI/configs/$configId",
"",
RestStatus.OK.status
)
val deleteResponse = deleteConfig(configId)
Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString)
Thread.sleep(100)

Expand Down Expand Up @@ -122,12 +83,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
Thread.sleep(100)

// Delete notification config
val deleteResponse = executeRequest(
RestRequest.Method.DELETE.name,
"$PLUGIN_BASE_URI/configs?config_id_list=${configIds.joinToString(separator = ",")}",
"",
RestStatus.OK.status
)
val deleteResponse = deleteConfigs(configIds)
val deletedObject = deleteResponse.get("delete_response_list").asJsonObject
configIds.forEach {
Assert.assertEquals("OK", deletedObject.get(it).asString)
Expand Down Expand Up @@ -203,12 +159,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
val remainingIds = partitions.second.toSet()

// Delete notification config
val deleteResponse = executeRequest(
RestRequest.Method.DELETE.name,
"$PLUGIN_BASE_URI/configs?config_id_list=${deletedIds.joinToString(separator = ",")}",
"",
RestStatus.OK.status
)
val deleteResponse = deleteConfigs(deletedIds)
val deletedObject = deleteResponse.get("delete_response_list").asJsonObject
deletedIds.forEach {
Assert.assertEquals("OK", deletedObject.get(it).asString)
Expand Down
Loading