From 4018db4bcdd406f64d033ada54ec84cfa153e891 Mon Sep 17 00:00:00 2001 From: Lorenzo Dematte Date: Mon, 25 Aug 2025 16:21:04 +0200 Subject: [PATCH 1/2] Make ESClientYamlSuiteTestCase#createParameters paths argument variadic --- .../s3/RepositoryS3ClientYamlTestSuiteIT.java | 2 +- ...oryS3RegionalStsClientYamlTestSuiteIT.java | 2 +- .../RepositoryHdfsClientYamlTestSuiteIT.java | 2 +- ...reRepositoryHdfsClientYamlTestSuiteIT.java | 2 +- .../rest/yaml/ESClientYamlSuiteTestCase.java | 61 ++++++++++++------- .../xpack/downsample/DownsampleRestIT.java | 2 +- .../downsample/DownsampleWithBasicRestIT.java | 2 +- .../DownsampleWithSecurityRestIT.java | 2 +- .../rrf/LicenseClientYamlTestSuiteIT.java | 2 +- .../rrf/LinearRankClientYamlTestSuiteIT.java | 2 +- .../rrf/RRFRankClientYamlTestSuiteIT.java | 2 +- ...rchBusinessRulesClientYamlTestSuiteIT.java | 2 +- 12 files changed, 49 insertions(+), 34 deletions(-) diff --git a/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java b/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java index a3210868ec245..89b03dcb71d03 100644 --- a/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java +++ b/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java @@ -52,7 +52,7 @@ public class RepositoryS3ClientYamlTestSuiteIT extends AbstractRepositoryS3Clien @ParametersFactory public static Iterable parameters() throws Exception { - return createParameters(new String[] { "repository_s3/10_basic", "repository_s3/20_repository_permanent_credentials" }); + return createParameters("repository_s3/10_basic", "repository_s3/20_repository_permanent_credentials"); } public RepositoryS3ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { diff --git a/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3RegionalStsClientYamlTestSuiteIT.java b/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3RegionalStsClientYamlTestSuiteIT.java index ac356083983eb..e80e46494cb58 100644 --- a/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3RegionalStsClientYamlTestSuiteIT.java +++ b/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3RegionalStsClientYamlTestSuiteIT.java @@ -37,7 +37,7 @@ public static Iterable parameters() throws Exception { // Run just the basic sanity test to make sure ES starts up and loads the S3 repository with a regional endpoint without an error. // It would be great to make actual requests against a test fixture, but setting the region means using a production endpoint. // See #102230 for more details. - return createParameters(new String[] { "repository_s3/10_basic" }); + return createParameters("repository_s3/10_basic"); } public RepositoryS3RegionalStsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { diff --git a/plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/RepositoryHdfsClientYamlTestSuiteIT.java b/plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/RepositoryHdfsClientYamlTestSuiteIT.java index 6a91cc51a564a..1ca86bac479ec 100644 --- a/plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/RepositoryHdfsClientYamlTestSuiteIT.java +++ b/plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/RepositoryHdfsClientYamlTestSuiteIT.java @@ -52,6 +52,6 @@ protected String getTestRestCluster() { @ParametersFactory public static Iterable parameters() throws Exception { - return createParameters(new String[] { "hdfs_repository" }, Map.of("hdfs_port", hdfsFixture.getPort())); + return createParameters(Map.of("hdfs_port", hdfsFixture.getPort()), "hdfs_repository"); } } diff --git a/plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/SecureRepositoryHdfsClientYamlTestSuiteIT.java b/plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/SecureRepositoryHdfsClientYamlTestSuiteIT.java index f238a17993856..3e2f28b095275 100644 --- a/plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/SecureRepositoryHdfsClientYamlTestSuiteIT.java +++ b/plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/SecureRepositoryHdfsClientYamlTestSuiteIT.java @@ -58,6 +58,6 @@ protected String getTestRestCluster() { @ParametersFactory public static Iterable parameters() throws Exception { - return createParameters(new String[] { "secure_hdfs_repository" }, Map.of("secure_hdfs_port", hdfsFixture.getPort())); + return createParameters(Map.of("secure_hdfs_port", hdfsFixture.getPort()), "secure_hdfs_repository"); } } diff --git a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index 087feadfb84a3..62f34bd5dd8d4 100644 --- a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java +++ b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -59,8 +59,9 @@ /** * Runs a suite of yaml tests shared with all the official Elasticsearch * clients against an elasticsearch cluster. - * + *

* The suite timeout is extended to account for projects with a large number of tests. + *

*/ @TimeoutSuite(millis = 30 * TimeUnits.MINUTE) public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { @@ -91,11 +92,11 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { /** * This separator pattern matches ',' except it is preceded by a '\'. * This allows us to support ',' within paths when it is escaped with a slash. - * + *

* For example, the path string "/a/b/c\,d/e/f,/foo/bar,/baz" is separated to "/a/b/c\,d/e/f", "/foo/bar" and "/baz". - * + *

* For reference, this regular expression feature is known as zero-width negative look-behind. - * + *

*/ private static final String PATHS_SEPARATOR = "(? createParameters() throws Exception { * Create parameters for this parameterized test. */ public static Iterable createParameters(NamedXContentRegistry executeableSectionRegistry) throws Exception { - return createParameters(executeableSectionRegistry, null); + return createParameters(executeableSectionRegistry, resolvePathsProperty(REST_TESTS_SUITE, "")); } /** * Create parameters for this parameterized test. + * @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time. */ - public static Iterable createParameters(String[] testPaths, Map yamlParameters) throws Exception { - return createParameters(ExecutableSection.XCONTENT_REGISTRY, testPaths, yamlParameters); + public static Iterable createParameters(Map yamlParameters) throws Exception { + return createParameters(ExecutableSection.XCONTENT_REGISTRY, yamlParameters, resolvePathsProperty(REST_TESTS_SUITE, "")); } /** * Create parameters for this parameterized test. + * @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time. + * @param testPaths list of paths to explicitly search for tests. */ - public static Iterable createParameters(String[] testPaths) throws Exception { - return createParameters(testPaths, Collections.emptyMap()); + public static Iterable createParameters(Map yamlParameters, String... testPaths) throws Exception { + if (System.getProperty(REST_TESTS_SUITE) != null) { + throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths."); + } + return createParameters(ExecutableSection.XCONTENT_REGISTRY, yamlParameters, testPaths); + } + + /** + * Create parameters for this parameterized test. + * @param testPaths list of paths to explicitly search for tests. + */ + public static Iterable createParameters(String... testPaths) throws Exception { + return createParameters(Map.of(), testPaths); } /** * Create parameters for this parameterized test. * * @param executeableSectionRegistry registry of executable sections - * @param testPaths list of paths to explicitly search for tests. If null then include all tests in root path. + * @param testPaths list of paths to explicitly search for tests. * @return list of test candidates. - * @throws Exception */ - public static Iterable createParameters(NamedXContentRegistry executeableSectionRegistry, String[] testPaths) + public static Iterable createParameters(NamedXContentRegistry executeableSectionRegistry, String... testPaths) throws Exception { - return createParameters(executeableSectionRegistry, testPaths, Collections.emptyMap()); + if (System.getProperty(REST_TESTS_SUITE) != null) { + throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths."); + } + return createParameters(executeableSectionRegistry, Map.of(), testPaths); } /** * Create parameters for this parameterized test. * * @param executeableSectionRegistry registry of executable sections - * @param testPaths list of paths to explicitly search for tests. If null then include all tests in root path. - * @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time. + * @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time. + * @param testPaths list of paths to explicitly search for tests. If {@code null} then include all tests in root path. * @return list of test candidates. - * @throws Exception */ public static Iterable createParameters( NamedXContentRegistry executeableSectionRegistry, - String[] testPaths, - Map yamlParameters + Map yamlParameters, + String... testPaths ) throws Exception { - if (testPaths != null && System.getProperty(REST_TESTS_SUITE) != null) { - throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths."); + + if (testPaths == null) { + throw new IllegalArgumentException("testPaths cannot be null"); } - // default to all tests under the test root - String[] paths = testPaths == null ? resolvePathsProperty(REST_TESTS_SUITE, "") : testPaths; - Map> yamlSuites = loadSuites(paths); + Map> yamlSuites = loadSuites(testPaths); List suites = new ArrayList<>(); IllegalArgumentException validationException = null; // yaml suites are grouped by directory (effectively by api) diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleRestIT.java b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleRestIT.java index dfef469a27812..9b86ff9cf3483 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleRestIT.java +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleRestIT.java @@ -35,7 +35,7 @@ public DownsampleRestIT(final ClientYamlTestCandidate testCandidate) { @ParametersFactory public static Iterable parameters() throws Exception { - return ESClientYamlSuiteTestCase.createParameters(new String[] { "downsample" }); + return ESClientYamlSuiteTestCase.createParameters("downsample"); } } diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithBasicRestIT.java b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithBasicRestIT.java index d9a44ab1508d6..080374bb73476 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithBasicRestIT.java +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithBasicRestIT.java @@ -34,7 +34,7 @@ public DownsampleWithBasicRestIT(final ClientYamlTestCandidate testCandidate) { @ParametersFactory public static Iterable parameters() throws Exception { - return ESClientYamlSuiteTestCase.createParameters(new String[] { "downsample" }); + return ESClientYamlSuiteTestCase.createParameters("downsample"); } } diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithSecurityRestIT.java b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithSecurityRestIT.java index afde47b377400..01038754cdd34 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithSecurityRestIT.java +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithSecurityRestIT.java @@ -48,6 +48,6 @@ protected Settings restClientSettings() { @ParametersFactory public static Iterable parameters() throws Exception { - return ESClientYamlSuiteTestCase.createParameters(new String[] { "downsample-with-security" }); + return ESClientYamlSuiteTestCase.createParameters("downsample-with-security"); } } diff --git a/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LicenseClientYamlTestSuiteIT.java b/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LicenseClientYamlTestSuiteIT.java index b4828e2cf9b9b..9c43658340551 100644 --- a/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LicenseClientYamlTestSuiteIT.java +++ b/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LicenseClientYamlTestSuiteIT.java @@ -33,7 +33,7 @@ public LicenseClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCa @ParametersFactory public static Iterable parameters() throws Exception { - return ESClientYamlSuiteTestCase.createParameters(new String[] { "license" }); + return ESClientYamlSuiteTestCase.createParameters("license"); } @Override diff --git a/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LinearRankClientYamlTestSuiteIT.java b/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LinearRankClientYamlTestSuiteIT.java index 00f756ff6ee3f..5a1a51ad40122 100644 --- a/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LinearRankClientYamlTestSuiteIT.java +++ b/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LinearRankClientYamlTestSuiteIT.java @@ -40,7 +40,7 @@ public LinearRankClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate tes @ParametersFactory public static Iterable parameters() throws Exception { - return ESClientYamlSuiteTestCase.createParameters(new String[] { "linear" }); + return ESClientYamlSuiteTestCase.createParameters("linear"); } @Override diff --git a/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/RRFRankClientYamlTestSuiteIT.java b/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/RRFRankClientYamlTestSuiteIT.java index f2a8f7f38bb06..51189c4939827 100644 --- a/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/RRFRankClientYamlTestSuiteIT.java +++ b/x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/RRFRankClientYamlTestSuiteIT.java @@ -40,7 +40,7 @@ public RRFRankClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCa @ParametersFactory public static Iterable parameters() throws Exception { - return ESClientYamlSuiteTestCase.createParameters(new String[] { "rrf" }); + return ESClientYamlSuiteTestCase.createParameters("rrf"); } @Override diff --git a/x-pack/plugin/search-business-rules/src/yamlRestTest/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRulesClientYamlTestSuiteIT.java b/x-pack/plugin/search-business-rules/src/yamlRestTest/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRulesClientYamlTestSuiteIT.java index 59971598269fa..47b1474e4d4d2 100644 --- a/x-pack/plugin/search-business-rules/src/yamlRestTest/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRulesClientYamlTestSuiteIT.java +++ b/x-pack/plugin/search-business-rules/src/yamlRestTest/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRulesClientYamlTestSuiteIT.java @@ -32,7 +32,7 @@ public SearchBusinessRulesClientYamlTestSuiteIT(final ClientYamlTestCandidate te @ParametersFactory public static Iterable parameters() throws Exception { - return ESClientYamlSuiteTestCase.createParameters(new String[] { "search-business-rules/10_pinned_retriever" }); + return ESClientYamlSuiteTestCase.createParameters("search-business-rules/10_pinned_retriever"); } @Override From 74b2b21f8a6ed83667eac2c9b6e7cc2881ac07b7 Mon Sep 17 00:00:00 2001 From: Lorenzo Dematte Date: Tue, 26 Aug 2025 12:07:25 +0200 Subject: [PATCH 2/2] Fix --- .../test/rest/yaml/ESClientYamlSuiteTestCase.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index 62f34bd5dd8d4..aade3c0e86cde 100644 --- a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java +++ b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -227,7 +227,7 @@ public static Iterable createParameters() throws Exception { * Create parameters for this parameterized test. */ public static Iterable createParameters(NamedXContentRegistry executeableSectionRegistry) throws Exception { - return createParameters(executeableSectionRegistry, resolvePathsProperty(REST_TESTS_SUITE, "")); + return createParameters(executeableSectionRegistry, Map.of(), resolvePathsProperty(REST_TESTS_SUITE, "")); } /** @@ -255,7 +255,10 @@ public static Iterable createParameters(Map yamlParame * @param testPaths list of paths to explicitly search for tests. */ public static Iterable createParameters(String... testPaths) throws Exception { - return createParameters(Map.of(), testPaths); + if (System.getProperty(REST_TESTS_SUITE) != null) { + throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths."); + } + return createParameters(ExecutableSection.XCONTENT_REGISTRY, Map.of(), testPaths); } /**