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 (opensearch-project#9916)

Signed-off-by: Neetika Singhal <neetiks@amazon.com>
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Co-authored-by: Andriy Redko <andriy.redko@aiven.io>
(cherry picked from commit 8e5e54b)
  • Loading branch information
neetikasinghal committed Sep 8, 2023
1 parent 529a5b8 commit 24cb7bf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 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))
- [Remote Store] Removing feature flag to mark feature GA ([#9761](https://github.com/opensearch-project/OpenSearch/pull/9761))
- 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 @@ -56,7 +65,24 @@
import static org.hamcrest.Matchers.closeTo;

@OpenSearchIntegTestCase.SuiteScopeTestCase
public class MissingValueIT extends OpenSearchIntegTestCase {
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 @@ -2361,8 +2361,12 @@ 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();
// note we need to do this way to make sure this is reproducible
if (isSuiteScopedTestParameterized(targetClass)) {
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 @@ -2457,6 +2461,16 @@ private static boolean isSuiteScopedTest(Class<?> clazz) {
return clazz.getAnnotation(SuiteScopeTestCase.class) != null;
}

/*
* For tests defined with, SuiteScopeTestCase return true if the
* class has a constructor that takes a single Settings parameter
* */
private static boolean isSuiteScopedTestParameterized(Class<?> clazz) {
return Arrays.stream(clazz.getConstructors())
.filter(x -> x.getParameterTypes().length == 1)
.anyMatch(x -> x.getParameterTypes()[0].equals(Settings.class));
}

/**
* If a test is annotated with {@link SuiteScopeTestCase}
* the checks and modifications that are applied to the used test cluster are only done after all tests
Expand Down

0 comments on commit 24cb7bf

Please sign in to comment.