diff --git a/testing/elasticsearch-dao-integ-testing-7/src/main/java/com/linkedin/metadata/testing/ElasticsearchIntegrationTestExtension.java b/testing/elasticsearch-dao-integ-testing-7/src/main/java/com/linkedin/metadata/testing/ElasticsearchIntegrationTestExtension.java index 471cc039a..0f01e8573 100644 --- a/testing/elasticsearch-dao-integ-testing-7/src/main/java/com/linkedin/metadata/testing/ElasticsearchIntegrationTestExtension.java +++ b/testing/elasticsearch-dao-integ-testing-7/src/main/java/com/linkedin/metadata/testing/ElasticsearchIntegrationTestExtension.java @@ -72,13 +72,15 @@ public void beforeAll(ExtensionContext context) throws Exception { }, ReflectionUtils.HierarchyTraversalMode.TOP_DOWN); final SearchIndexFactory indexFactory = new SearchIndexFactory(_connection); - final List> indices = createIndices(indexFactory, context.getRequiredTestClass(), fields, - fieldName -> String.format("%s_%s_%s", fieldName, testClass.getSimpleName(), System.currentTimeMillis())); + final List> indices = + createIndices(indexFactory, context.getRequiredTestClass(), context.getRequiredTestClass(), fields, + fieldName -> String.format("%s_%s_%s", fieldName, testClass.getSimpleName(), System.currentTimeMillis())); store.put(STATIC_INDICIES, indices); } - private List> createIndices(@Nonnull SearchIndexFactory indexFactory, @Nonnull Object testInstance, - @Nonnull List fields, @Nonnull Function nameFn) throws Exception { + private List> createIndices(@Nonnull SearchIndexFactory indexFactory, @Nonnull Class testClass, + @Nonnull Object testInstance, @Nonnull List fields, @Nonnull Function nameFn) + throws Exception { final List> indices = new ArrayList<>(); for (Field field : fields) { @@ -92,10 +94,10 @@ private List> createIndices(@Nonnull SearchIndexFactory indexFact final String indexName = nameFn.apply(field.getName()).replaceAll("^_*", "").toLowerCase(); final SearchIndexSettings settings = field.getAnnotation(SearchIndexSettings.class); - final String settingsJson = settings == null ? null : loadResource(testInstance.getClass(), settings.value()); + final String settingsJson = settings == null ? null : loadResource(testClass, settings.value()); final SearchIndexMappings mappings = field.getAnnotation(SearchIndexMappings.class); - final String mappingsJson = mappings == null ? null : loadResource(testInstance.getClass(), mappings.value()); + final String mappingsJson = mappings == null ? null : loadResource(testClass, mappings.value()); final SearchIndex index = indexFactory.createIndex(searchIndexType.value(), indexName, settingsJson, mappingsJson); @@ -164,9 +166,10 @@ public void beforeEach(ExtensionContext context) throws Exception { }, ReflectionUtils.HierarchyTraversalMode.TOP_DOWN); final SearchIndexFactory indexFactory = new SearchIndexFactory(_connection); - final List> indices = createIndices(indexFactory, context.getRequiredTestInstance(), fields, - fieldName -> String.format("%s_%s_%s_%s", fieldName, context.getRequiredTestMethod().getName(), - context.getRequiredTestClass().getSimpleName(), System.currentTimeMillis())); + final List> indices = + createIndices(indexFactory, context.getRequiredTestClass(), context.getRequiredTestInstance(), fields, + fieldName -> String.format("%s_%s_%s_%s", fieldName, context.getRequiredTestMethod().getName(), + context.getRequiredTestClass().getSimpleName(), System.currentTimeMillis())); store.put(INDICIES, indices); } diff --git a/testing/elasticsearch-dao-integ-testing/src/main/java/com/linkedin/metadata/testing/ElasticsearchIntegrationTestExtension.java b/testing/elasticsearch-dao-integ-testing/src/main/java/com/linkedin/metadata/testing/ElasticsearchIntegrationTestExtension.java index 975bece77..2f975b40d 100644 --- a/testing/elasticsearch-dao-integ-testing/src/main/java/com/linkedin/metadata/testing/ElasticsearchIntegrationTestExtension.java +++ b/testing/elasticsearch-dao-integ-testing/src/main/java/com/linkedin/metadata/testing/ElasticsearchIntegrationTestExtension.java @@ -71,13 +71,15 @@ public void beforeAll(ExtensionContext context) throws Exception { }, ReflectionUtils.HierarchyTraversalMode.TOP_DOWN); final SearchIndexFactory indexFactory = new SearchIndexFactory(_connection); - final List> indices = createIndices(indexFactory, context.getRequiredTestClass(), fields, - fieldName -> String.format("%s_%s_%s", fieldName, testClass.getSimpleName(), System.currentTimeMillis())); + final List> indices = + createIndices(indexFactory, context.getRequiredTestClass(), context.getRequiredTestClass(), fields, + fieldName -> String.format("%s_%s_%s", fieldName, testClass.getSimpleName(), System.currentTimeMillis())); store.put(STATIC_INDICIES, indices); } - private List> createIndices(@Nonnull SearchIndexFactory indexFactory, @Nonnull Object testInstance, - @Nonnull List fields, @Nonnull Function nameFn) throws Exception { + private List> createIndices(@Nonnull SearchIndexFactory indexFactory, + @Nonnull Class testClass, @Nonnull Object testInstance, @Nonnull List fields, + @Nonnull Function nameFn) throws Exception { final List> indices = new ArrayList<>(); for (Field field : fields) { @@ -91,10 +93,10 @@ private List> createIndices(@Nonnull SearchIndexFactory indexFact final String indexName = nameFn.apply(field.getName()).replaceAll("^_*", "").toLowerCase(); final SearchIndexSettings settings = field.getAnnotation(SearchIndexSettings.class); - final String settingsJson = settings == null ? null : loadResource(testInstance.getClass(), settings.value()); + final String settingsJson = settings == null ? null : loadResource(testClass, settings.value()); final SearchIndexMappings mappings = field.getAnnotation(SearchIndexMappings.class); - final String mappingsJson = mappings == null ? null : loadResource(testInstance.getClass(), mappings.value()); + final String mappingsJson = mappings == null ? null : loadResource(testClass, mappings.value()); final DocType docType = field.getAnnotation(DocType.class); final String docTypeStr = docType == null ? null : docType.value(); @@ -166,9 +168,10 @@ public void beforeEach(ExtensionContext context) throws Exception { }, ReflectionUtils.HierarchyTraversalMode.TOP_DOWN); final SearchIndexFactory indexFactory = new SearchIndexFactory(_connection); - final List> indices = createIndices(indexFactory, context.getRequiredTestInstance(), fields, - fieldName -> String.format("%s_%s_%s_%s", fieldName, context.getRequiredTestMethod().getName(), - context.getRequiredTestClass().getSimpleName(), System.currentTimeMillis())); + final List> indices = + createIndices(indexFactory, context.getRequiredTestClass(), context.getRequiredTestInstance(), fields, + fieldName -> String.format("%s_%s_%s_%s", fieldName, context.getRequiredTestMethod().getName(), + context.getRequiredTestClass().getSimpleName(), System.currentTimeMillis())); store.put(INDICIES, indices); }