diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java b/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java index 91584fb45cf..066ab054e00 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java @@ -77,6 +77,16 @@ public abstract class OpenSearchSQLRestTestCase extends OpenSearchRestTestCase { + "}"; private static final String SCRIPT_CONTEXT_MAX_COMPILATIONS_RATE_PATTERN = "script.context.*.max_compilations_rate"; + // Per-class cleanup must not delete shared plugin state or force managed indices to be recreated. + private static final List PLUGIN_MANAGED_INDEX_PREFIXES = + List.of( + ".opensearch", + ".opendistro", + ".ql", + ".plugins", + ".scheduler", + ".geospatial", + "security-auditlog-"); private static RestClient remoteClient; /** @@ -212,11 +222,7 @@ protected static void wipeAllOpenSearchIndices(RestClient client) throws IOExcep JSONObject jsonObject = (JSONObject) object; String indexName = jsonObject.getString("index"); try { - // System index, mostly named .opensearch-xxx or .opendistro-xxx, are not allowed to - // delete - if (!indexName.startsWith(".opensearch") - && !indexName.startsWith(".opendistro") - && !indexName.startsWith(".ql")) { + if (!isPluginManagedIndex(indexName)) { client.performRequest(new Request("DELETE", "/" + indexName)); } } catch (Exception e) { @@ -230,6 +236,10 @@ protected static void wipeAllOpenSearchIndices(RestClient client) throws IOExcep } } + static boolean isPluginManagedIndex(String indexName) { + return PLUGIN_MANAGED_INDEX_PREFIXES.stream().anyMatch(indexName::startsWith); + } + /** * Configure authentication and pass builder to superclass to configure other stuff.
* By default, auth is configure when https is set only. diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCaseIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCaseIT.java new file mode 100644 index 00000000000..195cd6b2004 --- /dev/null +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCaseIT.java @@ -0,0 +1,34 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.sql.legacy; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class OpenSearchSQLRestTestCaseIT { + + @Test + public void identifiesPluginManagedIndices() { + assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex(".opensearch-observability")); + assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex(".opendistro_security")); + assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex(".ql-datasources")); + assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex(".plugins-ml-config")); + assertTrue( + OpenSearchSQLRestTestCase.isPluginManagedIndex(".scheduler-geospatial-ip2geo-datasource")); + assertTrue( + OpenSearchSQLRestTestCase.isPluginManagedIndex(".geospatial-ip2geo-data.datasource")); + assertTrue(OpenSearchSQLRestTestCase.isPluginManagedIndex("security-auditlog-2026.07.15")); + } + + @Test + public void leavesTestIndicesEligibleForCleanup() { + assertFalse(OpenSearchSQLRestTestCase.isPluginManagedIndex("opensearch-sql_test_index_bank")); + assertFalse(OpenSearchSQLRestTestCase.isPluginManagedIndex("security-test-index")); + assertFalse(OpenSearchSQLRestTestCase.isPluginManagedIndex(".test-hidden-index")); + } +}