forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce javaRestTest source set/task and convert modules (elastic#5…
…9939) Introduce a javaRestTest source set and task to compliment the yamlRestTest. javaRestTest differs such that the code is sourced from Java and may have different dependencies and setup requirements for the test clusters. This also allows the tests to run in parallel in different cluster instances to prevent any cross test contamination between the two types of tests. Included in this PR is all :modules no longer use the integTest task. The tests are now driven by test, yamlRestTest, javaRestTest, and internalClusterTest. Since only :modules (and :rest-api-spec) have been converted to yamlRestTest we can now disable the integTest task if either yamlRestTest or javaRestTest have been applied. Once all projects are converted, we can delete the integTest task. related: elastic#56841 related: elastic#59444
- Loading branch information
1 parent
293cb8d
commit 07fde36
Showing
48 changed files
with
260 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/JavaRestTestPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.test.rest; | ||
|
||
import org.elasticsearch.gradle.ElasticsearchJavaPlugin; | ||
import org.elasticsearch.gradle.test.RestIntegTestTask; | ||
import org.elasticsearch.gradle.testclusters.TestClustersPlugin; | ||
import org.elasticsearch.gradle.util.GradleUtils; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.plugins.JavaBasePlugin; | ||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradle.api.tasks.SourceSetContainer; | ||
|
||
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupDependencies; | ||
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupRunnerTask; | ||
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupTask; | ||
|
||
/** | ||
* Apply this plugin to run the Java based REST tests. | ||
*/ | ||
public class JavaRestTestPlugin implements Plugin<Project> { | ||
|
||
public static final String SOURCE_SET_NAME = "javaRestTest"; | ||
|
||
@Override | ||
public void apply(Project project) { | ||
|
||
project.getPluginManager().apply(ElasticsearchJavaPlugin.class); | ||
project.getPluginManager().apply(TestClustersPlugin.class); | ||
|
||
// create source set | ||
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); | ||
SourceSet javaTestSourceSet = sourceSets.create(SOURCE_SET_NAME); | ||
|
||
// setup the javaRestTest task | ||
RestIntegTestTask javaRestTestTask = setupTask(project, SOURCE_SET_NAME); | ||
|
||
// setup the runner task | ||
setupRunnerTask(project, javaRestTestTask, javaTestSourceSet); | ||
|
||
// setup dependencies | ||
setupDependencies(project, javaTestSourceSet); | ||
|
||
// setup IDE | ||
GradleUtils.setupIdeForTestSourceSet(project, javaTestSourceSet); | ||
|
||
// wire this task into check | ||
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure(check -> check.dependsOn(javaRestTestTask)); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/RestTestUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.test.rest; | ||
|
||
import org.elasticsearch.gradle.VersionProperties; | ||
import org.elasticsearch.gradle.info.BuildParams; | ||
import org.elasticsearch.gradle.plugin.PluginPropertiesExtension; | ||
import org.elasticsearch.gradle.test.RestIntegTestTask; | ||
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.plugins.JavaBasePlugin; | ||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradle.api.tasks.bundling.Zip; | ||
|
||
/** | ||
* Utility class to configure the necessary tasks and dependencies. | ||
*/ | ||
public class RestTestUtil { | ||
|
||
private RestTestUtil() {} | ||
|
||
/** | ||
* Creates a task with the source set name of type {@link RestIntegTestTask} | ||
*/ | ||
static RestIntegTestTask setupTask(Project project, String sourceSetName) { | ||
// create task - note can not use .register due to the work in RestIntegTestTask's constructor :( | ||
// see: https://github.com/elastic/elasticsearch/issues/47804 | ||
RestIntegTestTask testTask = project.getTasks().create(sourceSetName, RestIntegTestTask.class); | ||
testTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP); | ||
testTask.setDescription("Runs the REST tests against an external cluster"); | ||
// make the new test run after unit tests | ||
testTask.mustRunAfter(project.getTasks().named("test")); | ||
return testTask; | ||
} | ||
|
||
/** | ||
* Creates the runner task and configures the test clusters | ||
*/ | ||
static RestTestRunnerTask setupRunnerTask(Project project, RestIntegTestTask testTask, SourceSet sourceSet) { | ||
RestTestRunnerTask runner = testTask.getRunner(); | ||
runner.setTestClassesDirs(sourceSet.getOutput().getClassesDirs()); | ||
runner.setClasspath(sourceSet.getRuntimeClasspath()); | ||
|
||
// if this a module or plugin, it may have an associated zip file with it's contents, add that to the test cluster | ||
project.getPluginManager().withPlugin("elasticsearch.esplugin", plugin -> { | ||
Zip bundle = (Zip) project.getTasks().getByName("bundlePlugin"); | ||
testTask.dependsOn(bundle); | ||
if (project.getPath().startsWith(":modules:")) { | ||
runner.getClusters().forEach(c -> c.module(bundle.getArchiveFile())); | ||
} else { | ||
runner.getClusters().forEach(c -> c.plugin(project.getObjects().fileProperty().value(bundle.getArchiveFile()))); | ||
} | ||
}); | ||
|
||
// es-plugins may declare dependencies on additional modules, add those to the test cluster too. | ||
project.afterEvaluate(p -> { | ||
PluginPropertiesExtension pluginPropertiesExtension = project.getExtensions().findByType(PluginPropertiesExtension.class); | ||
if (pluginPropertiesExtension != null) { // not all projects are defined as plugins | ||
pluginPropertiesExtension.getExtendedPlugins().forEach(pluginName -> { | ||
Project extensionProject = project.getProject().findProject(":modules:" + pluginName); | ||
if (extensionProject != null) { // extension plugin may be defined, but not required to be a module | ||
Zip extensionBundle = (Zip) extensionProject.getTasks().getByName("bundlePlugin"); | ||
testTask.dependsOn(extensionBundle); | ||
runner.getClusters().forEach(c -> c.module(extensionBundle.getArchiveFile())); | ||
} | ||
}); | ||
} | ||
}); | ||
return runner; | ||
} | ||
|
||
/** | ||
* Setup the dependencies needed for the REST tests. | ||
*/ | ||
static void setupDependencies(Project project, SourceSet sourceSet) { | ||
if (BuildParams.isInternal()) { | ||
project.getDependencies().add(sourceSet.getImplementationConfigurationName(), project.project(":test:framework")); | ||
} else { | ||
project.getDependencies() | ||
.add( | ||
sourceSet.getImplementationConfigurationName(), | ||
"org.elasticsearch.test:framework:" + VersionProperties.getElasticsearch() | ||
); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.java-rest-test.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Licensed to Elasticsearch under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
implementation-class=org.elasticsearch.gradle.test.rest.JavaRestTestPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.