Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,57 @@ public class TestSuiteBootstrap implements LauncherSessionListener {
private static final Integer ELASTIC_BATCH_SIZE = 10;
private static final IndexMappingLanguage ELASTIC_SEARCH_INDEX_MAPPING_LANGUAGE =
IndexMappingLanguage.EN;
private static final String ELASTIC_SEARCH_CLUSTER_ALIAS = "openmetadata";

/**
* Pattern allowed for {@code -DclusterAlias} overrides — must be a valid OpenSearch /
* Elasticsearch index name prefix (lowercase alphanumeric, underscore, or hyphen; must start
* with a letter or digit; max 63 chars).
*
* <p>Declared <em>before</em> {@link #ELASTIC_SEARCH_CLUSTER_ALIAS} on purpose: static fields
* initialize in declaration order, and {@link #resolveClusterAlias()} reads this pattern. If
* this declaration moved below, override validation would NPE on the only path that uses it.
*/
private static final java.util.regex.Pattern CLUSTER_ALIAS_PATTERN =
java.util.regex.Pattern.compile("[a-z0-9][a-z0-9_\\-]{0,62}");

/**
* Cluster alias used as the prefix for all search indices in this test session.
*
* <p>The OpenSearch / Elasticsearch testcontainer is shared across the entire JUnit launcher
* session (single static container, see {@link #SEARCH_CONTAINER}). When tests run in parallel
* (the {@code parallel-tests} profile sets {@code junit.jupiter.execution.parallel.enabled=true}
* and {@code reuseForks=true} keeps everything in one JVM), every test reads and writes against
* the same set of indices. {@link org.openmetadata.it.util.TestNamespace} only isolates entity
* FQNs in the database — it does not isolate documents in the search index.
*
* <p>To prevent cross-test pollution between concurrent CI runs that share the cluster, the alias
* is randomized per session by default so each session writes to its own {@code <alias>_*}
* indices. Set {@code -DclusterAlias=openmetadata} (or any fixed value matching {@link
* #CLUSTER_ALIAS_PATTERN}) to pin the alias for reproducible debugging.
*/
private static final String ELASTIC_SEARCH_CLUSTER_ALIAS = resolveClusterAlias();

Comment on lines +137 to +138
private static String resolveClusterAlias() {
String override = System.getProperty("clusterAlias");
if (override == null || override.isBlank()) {
return "omtest_" + java.util.UUID.randomUUID().toString().replace("-", "").substring(0, 8);
}
String normalized = override.trim().toLowerCase(java.util.Locale.ROOT);
if (!CLUSTER_ALIAS_PATTERN.matcher(normalized).matches()) {
throw new IllegalArgumentException(
"Invalid -DclusterAlias='"
+ override
+ "'. Must match "
+ CLUSTER_ALIAS_PATTERN.pattern()
+ " (lowercase alphanumeric, underscore, or hyphen; must start with a letter or"
+ " digit; max 63 chars) so it forms a valid OpenSearch/Elasticsearch index prefix.");
}
return normalized;
}
Comment on lines +139 to +155

public static String getClusterAlias() {
return ELASTIC_SEARCH_CLUSTER_ALIAS;
}
Comment on lines +110 to +159

// Default images (can be overridden by system properties)
private static final String DEFAULT_POSTGRES_IMAGE = "postgres:15";
Expand Down Expand Up @@ -164,6 +214,7 @@ public void launcherSessionOpened(LauncherSession session) {
LOG.info("=== TestSuiteBootstrap: Starting test infrastructure ===");
LOG.info("Database type: {}", databaseType);
LOG.info("Search type: {}", searchType);
LOG.info("Search cluster alias: {}", ELASTIC_SEARCH_CLUSTER_ALIAS);
LOG.info("RDF enabled: {}", rdfEnabled);
Comment thread
mohityadav766 marked this conversation as resolved.
LOG.info("Cache provider: {}", cacheProvider);
boolean k8sEnabled = isK8sTestsRequested();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class IndexTemplateIT {

private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String CLUSTER_ALIAS = "openmetadata";
private static final String CLUSTER_ALIAS = TestSuiteBootstrap.getClusterAlias();

@Test
void testIndexTemplatesExist(TestNamespace ns) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
@TestMethodOrder(OrderAnnotation.class)
public class OrphanedIndexCleanerScopedCleanupIT {

private static final String CLUSTER_ALIAS = "openmetadata";
private static final String CLUSTER_ALIAS = TestSuiteBootstrap.getClusterAlias();
private static final String FOREIGN_PREFIX = "foreigntenant_it_orphans";
private static final String OUR_PREFIX = CLUSTER_ALIAS + "_it_orphans";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public class SearchIndexFieldLimitIT {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final String TABLE_TYPE_NAME = "table";
private static final int NUM_CUSTOM_PROPERTIES = 50;
// Index name with cluster alias prefix (from TestSuiteBootstrap.ELASTIC_SEARCH_CLUSTER_ALIAS)
private static final String TABLE_INDEX = "openmetadata_table_search_index";
// Index name uses the cluster alias resolved by TestSuiteBootstrap (randomized per session by
// default; pin with -DclusterAlias=... for reproducible debugging).
private static final String TABLE_INDEX =
org.openmetadata.it.bootstrap.TestSuiteBootstrap.getClusterAlias() + "_table_search_index";

private static Type STRING_TYPE;
private static Type INTEGER_TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4586,11 +4586,13 @@ protected Table getEntityIncludeDeleted(String id) {
// ===================================================================

/**
* Get the full Elasticsearch index name with cluster alias prefix.
* In test environment, cluster alias is "openmetadata" so table index is "openmetadata_table_search_index"
* Get the full Elasticsearch index name with cluster alias prefix. The alias is randomized per
* JUnit session by default in {@link org.openmetadata.it.bootstrap.TestSuiteBootstrap}; it can
* be pinned via {@code -DclusterAlias=...} for reproducible debugging.
*/
private String getTableSearchIndexName() {
return "openmetadata_table_search_index";
return org.openmetadata.it.bootstrap.TestSuiteBootstrap.getClusterAlias()
+ "_table_search_index";
Comment on lines +4594 to +4595
Comment on lines +4594 to +4595
}

// ===================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,8 @@ private void putPipelineStatus(
}

private String getTestSuiteSearchIndexName() {
return "openmetadata_test_suite_search_index";
return org.openmetadata.it.bootstrap.TestSuiteBootstrap.getClusterAlias()
+ "_test_suite_search_index";
Comment on lines +1142 to +1143
Comment on lines +1142 to +1143
}

private void refreshTestSuiteSearchIndex(Rest5Client searchClient) throws Exception {
Expand Down
Loading