Skip to content

Commit

Permalink
[7.17] Port QA projects to use javaRestTest and yamlRestTest (#86703) (
Browse files Browse the repository at this point in the history
…#86725)

Backports the following commits to 7.17:
 - Port QA projects to use javaRestTest and yamlRestTest (#86703)
  • Loading branch information
breskeby authored May 12, 2022
1 parent 0cb5108 commit c51abc6
Show file tree
Hide file tree
Showing 59 changed files with 48 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
package org.elasticsearch.gradle.internal.test;

import org.apache.commons.lang.StringUtils;
import org.elasticsearch.gradle.internal.test.rest.InternalJavaRestTestPlugin;
import org.elasticsearch.gradle.plugin.PluginBuildPlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.plugins.ExtraPropertiesExtension;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.Copy;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

import java.io.File;
Expand All @@ -31,8 +34,11 @@
* dependency to the test source set.
*/
public class TestWithDependenciesPlugin implements Plugin<Project> {
private Project project;

@Override
public void apply(final Project project) {
this.project = project;
ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
if (extraProperties.has("isEclipse") && Boolean.valueOf(extraProperties.get("isEclipse").toString())) {
/* The changes this plugin makes both break and aren't needed by
Expand All @@ -41,18 +47,29 @@ public void apply(final Project project) {
* "special".... */
return;
}
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
project.getPlugins()
.withType(
InternalJavaRestTestPlugin.class,
internalJavaRestTestPlugin -> processConfiguration(sourceSets.getByName(InternalJavaRestTestPlugin.SOURCE_SET_NAME))
);
sourceSets.matching(sourceSet -> sourceSet.getName().equals("test")).configureEach(sourceSet -> processConfiguration(sourceSet));

}

Configuration testImplementationConfig = project.getConfigurations().getByName("testImplementation");
testImplementationConfig.getDependencies().all(dep -> {
private void processConfiguration(SourceSet sourceSet) {
String implementationConfigurationName = sourceSet.getImplementationConfigurationName();
Configuration implementationConfig = project.getConfigurations().getByName(implementationConfigurationName);
implementationConfig.getDependencies().all(dep -> {
if (dep instanceof ProjectDependency
&& ((ProjectDependency) dep).getDependencyProject().getPlugins().hasPlugin(PluginBuildPlugin.class)) {
project.getGradle()
.projectsEvaluated(gradle -> addPluginResources(project, ((ProjectDependency) dep).getDependencyProject()));
.projectsEvaluated(gradle -> addPluginResources(sourceSet, project, ((ProjectDependency) dep).getDependencyProject()));
}
});
}

private static void addPluginResources(final Project project, final Project pluginProject) {
private static void addPluginResources(SourceSet sourceSet, final Project project, final Project pluginProject) {
final File outputDir = new File(project.getBuildDir(), "/generated-test-resources/" + pluginProject.getName());
String camelProjectName = stream(pluginProject.getName().split("-")).map(t -> StringUtils.capitalize(t))
.collect(Collectors.joining());
Expand All @@ -64,7 +81,6 @@ private static void addPluginResources(final Project project, final Project plug
});

Map<String, Object> map = Map.of("builtBy", taskName);
SourceSetContainer sourceSetContainer = project.getExtensions().getByType(SourceSetContainer.class);
sourceSetContainer.getByName("test").getOutput().dir(map, outputDir);
sourceSet.getOutput().dir(map, outputDir);
}
}
9 changes: 3 additions & 6 deletions qa/ccs-unavailable-clusters/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.test-with-dependencies'
apply plugin: 'elasticsearch.internal-java-rest-test'

testClusters.matching { it.name == "integTest" }.configureEach {
testClusters.matching { it.name == "javaRestTest" }.configureEach {
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
}

dependencies {
testImplementation project(":client:rest-high-level")
javaRestTestImplementation project(":client:rest-high-level")
}
12 changes: 5 additions & 7 deletions qa/smoke-test-http/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
* Side Public License, v 1.
*/

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.test-with-dependencies'

dependencies {
testImplementation project(':modules:transport-netty4') // for http
testImplementation project(':plugins:transport-nio') // for http
testImplementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
testImplementation project(':plugins:transport-nio') // for http
javaRestTestImplementation project(':modules:transport-netty4') // for http
javaRestTestImplementation project(':plugins:transport-nio') // for http
javaRestTestImplementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
javaRestTestImplementation project(':plugins:transport-nio') // for http
}

testClusters.configureEach {
Expand Down
11 changes: 2 additions & 9 deletions qa/smoke-test-ingest-disabled/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.rest-resources'
apply plugin: 'elasticsearch.internal-yaml-rest-test'

dependencies {
testImplementation project(':modules:ingest-common')
}

testClusters.configureEach {
testClusters.matching { it.name == "yamlRestTest" }.configureEach {
setting 'xpack.security.enabled', 'false'
}

testClusters.matching { it.name == "integTest" }.configureEach {
setting 'node.roles', '[data,master,remote_cluster_client]'
}
23 changes: 6 additions & 17 deletions qa/smoke-test-ingest-with-all-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,16 @@
* Side Public License, v 1.
*/

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.rest-resources'
apply plugin: 'elasticsearch.internal-yaml-rest-test'

dependencies {
testImplementation project(':modules:ingest-common')
testImplementation project(':modules:ingest-geoip')
testImplementation project(':modules:lang-mustache')
testImplementation project(':modules:lang-painless')
testImplementation project(':modules:reindex')
yamlRestTestImplementation project(':modules:ingest-common')
yamlRestTestImplementation project(':modules:ingest-geoip')
yamlRestTestImplementation project(':modules:lang-mustache')
yamlRestTestImplementation project(':modules:lang-painless')
yamlRestTestImplementation project(':modules:reindex')
}

testClusters.configureEach {
setting 'xpack.security.enabled', 'false'
}

tasks.named("testingConventions").configure {
naming {
IT {
baseClass 'org.elasticsearch.ingest.AbstractScriptTestCase'
}
}
}
9 changes: 3 additions & 6 deletions qa/smoke-test-multinode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
* Side Public License, v 1.
*/

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.rest-resources'
apply plugin: 'elasticsearch.internal-yaml-rest-test'

restResources {
restTests {
Expand All @@ -18,7 +15,7 @@ restResources {
}

File repo = file("$buildDir/testclusters/repo")
testClusters.matching { it.name == "integTest" }.configureEach {
testClusters.matching { it.name == "yamlRestTest" }.configureEach {
numberOfNodes = 2
setting 'path.repo', repo.absolutePath
}
Expand All @@ -27,7 +24,7 @@ testClusters.configureEach {
setting 'xpack.security.enabled', 'false'
}

tasks.named("integTest").configure {
tasks.named("yamlRestTest").configure {
doFirst {
project.delete(repo)
repo.mkdirs()
Expand Down
9 changes: 3 additions & 6 deletions qa/smoke-test-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import org.apache.tools.ant.filters.ReplaceTokens
import org.elasticsearch.gradle.internal.info.BuildParams

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.rest-resources'
apply plugin: 'elasticsearch.internal-yaml-rest-test'

ext.pluginPaths = []
project(':plugins').getChildProjects().each { pluginName, pluginProject ->
Expand All @@ -23,7 +20,7 @@ project(':plugins').getChildProjects().each { pluginName, pluginProject ->
pluginPaths << pluginProject.path
}

testClusters.matching { it.name == "integTest" }.configureEach {
testClusters.matching { it.name == "yamlRestTest" }.configureEach {
pluginPaths.each { pluginPath ->
plugin pluginPath
}
Expand All @@ -34,7 +31,7 @@ ext.expansions = [
'expected.plugins.count': pluginPaths.size()
]

tasks.named("processTestResources").configure {
tasks.named("processYamlRestTestResources").configure {
assert pluginPaths.size() > 0
inputs.properties(expansions)
filter("tokens" : expansions.collectEntries {k, v -> [k, v.toString()]} /* must be a map of strings */, ReplaceTokens.class)
Expand Down
10 changes: 4 additions & 6 deletions qa/unconfigured-node-name/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ import org.elasticsearch.gradle.OS
* Side Public License, v 1.
*/

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

testClusters.configureEach {
setting 'xpack.security.enabled', 'false'
}

testClusters.matching { it.name == "integTest" }.configureEach {
testClusters.matching { it.name == "javaRestTest" }.configureEach {
nameCustomization = { null }
}

tasks.named("integTest").configure {
tasks.named("javaRestTest").configure {
nonInputProperties.systemProperty 'tests.logfile',
"${-> testClusters.integTest.singleNode().getServerLog()}"
"${-> testClusters.javaRestTest.singleNode().getServerLog()}"
}

0 comments on commit c51abc6

Please sign in to comment.