Skip to content

Commit

Permalink
Allow parameterization of tests with OpenSearchIntegTestCase.SuiteSco…
Browse files Browse the repository at this point in the history
…peTestCase annotation

Signed-off-by: Neetika Singhal <neetiks@amazon.com>
  • Loading branch information
neetikasinghal committed Sep 7, 2023
1 parent bbe6b2d commit b62a9fb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Cleanup Unreferenced file on segment merge failure ([#9503](https://github.com/opensearch-project/OpenSearch/pull/9503))
- Move ZStd to a plugin ([#9658](https://github.com/opensearch-project/OpenSearch/pull/9658))
- [Remote Store] Add support for Remote Translog Store upload stats in `_nodes/stats/` API ([#8908](https://github.com/opensearch-project/OpenSearch/pull/8908))
- Allow parameterization of tests with OpenSearchIntegTestCase.SuiteScopeTestCase annotation ([#9916](https://github.com/opensearch-project/OpenSearch/pull/9916))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@

package org.opensearch.search.aggregations;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.action.search.SearchResponse;
import org.opensearch.common.geo.GeoPoint;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.opensearch.search.aggregations.bucket.histogram.Histogram;
import org.opensearch.search.aggregations.bucket.terms.Terms;
Expand All @@ -43,7 +47,12 @@
import org.opensearch.search.aggregations.metrics.Percentiles;
import org.opensearch.search.aggregations.metrics.Stats;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.ParameterizedOpenSearchIntegTestCase;

import java.util.Arrays;
import java.util.Collection;

import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;
import static org.opensearch.search.aggregations.AggregationBuilders.cardinality;
import static org.opensearch.search.aggregations.AggregationBuilders.dateHistogram;
import static org.opensearch.search.aggregations.AggregationBuilders.geoCentroid;
Expand All @@ -55,8 +64,25 @@
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse;
import static org.hamcrest.Matchers.closeTo;

@OpenSearchIntegTestCase.SuiteScopeTestCase
public class MissingValueIT extends OpenSearchIntegTestCase {
@OpenSearchIntegTestCase.SuiteScopeTestCase(isParameterized = true)
public class MissingValueIT extends ParameterizedOpenSearchIntegTestCase {

public MissingValueIT(Settings dynamicSettings) {
super(dynamicSettings);
}

@ParametersFactory
public static Collection<Object[]> parameters() {
return Arrays.asList(
new Object[] { Settings.builder().put(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey(), false).build() },
new Object[] { Settings.builder().put(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey(), true).build() }
);
}

@Override
protected Settings featureFlagSettings() {
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.CONCURRENT_SEGMENT_SEARCH, "true").build();
}

@Override
protected int maximumNumberOfShards() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,11 @@ private static void initializeSuiteScope() throws Exception {
assert INSTANCE == null;
if (isSuiteScopedTest(targetClass)) {
// note we need to do this this way to make sure this is reproducible
INSTANCE = (OpenSearchIntegTestCase) targetClass.getConstructor().newInstance();
if (targetClass.getAnnotation(SuiteScopeTestCase.class).isParameterized()) {
INSTANCE = (OpenSearchIntegTestCase) targetClass.getConstructor(Settings.class).newInstance(Settings.EMPTY);
} else {
INSTANCE = (OpenSearchIntegTestCase) targetClass.getConstructor().newInstance();
}
boolean success = false;
try {
INSTANCE.printTestMessage("setup");
Expand Down Expand Up @@ -2422,6 +2426,7 @@ private static boolean isSuiteScopedTest(Class<?> clazz) {
@Inherited
@Target(ElementType.TYPE)
public @interface SuiteScopeTestCase {
boolean isParameterized() default false;
}

public static Index resolveIndex(String index) {
Expand Down

0 comments on commit b62a9fb

Please sign in to comment.