Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6fb168d
introduce plugin
jakelandis May 15, 2020
87ae362
clean up
jakelandis May 15, 2020
9baf839
add another todo
jakelandis May 15, 2020
76cf101
clean up comment
jakelandis May 15, 2020
7e92d81
fix runner setup
jakelandis May 15, 2020
d6ef96f
Merge remote-tracking branch 'upstream/master' into yamlTest_part1
jakelandis Jun 8, 2020
84939b2
review changes and move core tests
jakelandis Jun 8, 2020
b815cce
checkstlyle and spotless
jakelandis Jun 8, 2020
d3a71bc
minor text changes
jakelandis Jun 8, 2020
7fc8f3e
remove temp code infavor explicit config
jakelandis Jun 8, 2020
3ccd5d8
remove rest-resources from build plugin
jakelandis Jun 8, 2020
35f3736
update the example projects
jakelandis Jun 8, 2020
282c160
more missed locations
jakelandis Jun 8, 2020
a97896f
fix docker tests
jakelandis Jun 9, 2020
a43d3e7
fix s3 tests
jakelandis Jun 9, 2020
4b11a42
fix some x-pack tests
jakelandis Jun 9, 2020
c7b2189
Merge branch 'master' into yamlTest_part1
jakelandis Jun 23, 2020
53ae393
Merge branch 'master' into yamlTest_part1
elasticmachine Jun 23, 2020
6289b00
review changes
jakelandis Jul 1, 2020
02afa30
minor review comments
jakelandis Jul 1, 2020
ceaeca3
Merge branch 'master' into yamlTest_part1
elasticmachine Jul 1, 2020
a7a6f9e
ensure core specs are copied for x-pack
jakelandis Jul 1, 2020
22c55da
remove gymnastics
jakelandis Jul 1, 2020
db94130
fix checkstyle
jakelandis Jul 1, 2020
b20a166
fix newly introduced project
jakelandis Jul 1, 2020
01990fa
Merge branch 'master' into yamlTest_part1
elasticmachine Jul 1, 2020
07ddee5
Merge remote-tracking branch 'upstream/master' into yamlTest_part1
jakelandis Jul 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions TESTING.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,21 @@ restResources {
}
---------------------------------------------------------------------------

YAML tests that include x-pack specific APIs need to explicitly declare
YAML REST tests that include x-pack specific APIs need to explicitly declare
which APIs are required through a similar `includeXpack` configuration.

The REST tests are run automatically when executing the "./gradlew check" command. To run only the
REST tests use the following command:
YAML REST tests use the following command (modules and plugins may also include YAML REST tests):

---------------------------------------------------------------------------
./gradlew :distribution:archives:integ-test-zip:integTestRunner \
--tests "org.elasticsearch.test.rest.IntegTestZipClientYamlTestSuiteIT"
./gradlew :rest-api-spec:yamlRestTest
---------------------------------------------------------------------------

A specific test case can be run with the following command:

---------------------------------------------------------------------------
./gradlew ':distribution:archives:integ-test-zip:integTestRunner' \
--tests "org.elasticsearch.test.rest.IntegTestZipClientYamlTestSuiteIT" \
./gradlew ':rest-api-spec:yamlRestTestRunner' \
--tests "org.elasticsearch.test.rest.ClientYamlTestSuiteIT" \
-Dtests.method="test {p0=cat.segments/10_basic/Help}"
---------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin
import org.elasticsearch.gradle.info.BuildParams
import org.elasticsearch.gradle.test.rest.RestResourcesPlugin
import org.elasticsearch.gradle.test.RestIntegTestTask
import org.elasticsearch.gradle.testclusters.RunTask
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
Expand Down Expand Up @@ -55,7 +54,6 @@ class PluginBuildPlugin implements Plugin<Project> {
void apply(Project project) {
project.pluginManager.apply(BuildPlugin)
project.pluginManager.apply(TestClustersPlugin)
project.pluginManager.apply(RestResourcesPlugin)
project.pluginManager.apply(CompileOnlyResolvePlugin.class);

PluginPropertiesExtension extension = project.extensions.create(PLUGIN_EXTENSION_NAME, PluginPropertiesExtension, project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask
import org.elasticsearch.gradle.info.BuildParams
import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.elasticsearch.gradle.test.rest.RestResourcesPlugin
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Plugin
Expand Down Expand Up @@ -73,8 +72,6 @@ class StandaloneRestTestPlugin implements Plugin<Project> {
// only setup tests to build
SourceSetContainer sourceSets = project.extensions.getByType(SourceSetContainer)
SourceSet testSourceSet = sourceSets.create('test')
// need to apply plugin after test source sets are created
project.pluginManager.apply(RestResourcesPlugin)

project.tasks.withType(Test).configureEach { Test test ->
test.testClassesDirs = testSourceSet.output.classesDirs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.tasks.Internal;

public class RestIntegTestTask extends DefaultTask {

Expand All @@ -36,6 +37,9 @@ public class RestIntegTestTask extends DefaultTask {
private static final String TESTS_CLUSTER = "tests.cluster";
private static final String TESTS_CLUSTER_NAME = "tests.clustername";

// TODO: refactor this so that work is not done in constructor and find usages and register them, not create them
// See: https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, there's an open issue for this. Perhaps we can link it here.

#47804

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

// See: https://github.com/elastic/elasticsearch/issues/47804
public RestIntegTestTask() {
Project project = getProject();
String name = getName();
Expand Down Expand Up @@ -101,4 +105,9 @@ public void setDependsOn(Iterable<?> dependencies) {
public void runner(Action<? super RestTestRunnerTask> configure) {
configure.execute(runner);
}

@Internal
public RestTestRunnerTask getRunner() {
return runner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
Expand All @@ -41,6 +42,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -54,7 +57,7 @@ public class CopyRestApiTask extends DefaultTask {
private static final String REST_API_PREFIX = "rest-api-spec/api";
final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);

String sourceSetName;
Configuration coreConfig;
Configuration xpackConfig;

Expand All @@ -81,6 +84,11 @@ public ListProperty<String> getIncludeXpack() {
return includeXpack;
}

@Input
String getSourceSetName() {
return sourceSetName;
}

@SkipWhenEmpty
@InputFiles
public FileTree getInputDir() {
Expand Down Expand Up @@ -109,7 +117,12 @@ public FileTree getInputDir() {

@OutputDirectory
public File getOutputDir() {
return new File(getTestSourceSet().getOutput().getResourcesDir(), REST_API_PREFIX);
return new File(
getSourceSet().orElseThrow(() -> new IllegalArgumentException("could not find source set [" + sourceSetName + "]"))
.getOutput()
.getResourcesDir(),
REST_API_PREFIX
);
}

@TaskAction
Expand All @@ -131,7 +144,8 @@ void copy() {
);
project.copy(c -> {
c.from(project.zipTree(coreConfig.getSingleFile()));
c.into(getTestSourceSet().getOutput().getResourcesDir()); // this ends up as the same dir as outputDir
// this ends up as the same dir as outputDir
c.into(Objects.requireNonNull(getSourceSet().orElseThrow().getOutput().getResourcesDir()));
if (includeCore.get().isEmpty()) {
c.include(REST_API_PREFIX + "/**");
} else {
Expand Down Expand Up @@ -178,31 +192,33 @@ private boolean projectHasYamlRestTests() {
}

private File getTestSourceResourceDir() {
SourceSet testSources = getTestSourceSet();
if (testSources == null) {
return null;
}
Set<File> resourceDir = testSources.getResources()
.getSrcDirs()
.stream()
.filter(f -> f.isDirectory() && f.getParentFile().getName().equals("test") && f.getName().equals("resources"))
.collect(Collectors.toSet());
assert resourceDir.size() <= 1;
if (resourceDir.size() == 0) {
Optional<SourceSet> testSourceSet = getSourceSet();
if (testSourceSet.isPresent()) {
SourceSet testSources = testSourceSet.get();
Set<File> resourceDir = testSources.getResources()
.getSrcDirs()
.stream()
.filter(f -> f.isDirectory() && f.getParentFile().getName().equals("test") && f.getName().equals("resources"))
.collect(Collectors.toSet());
assert resourceDir.size() <= 1;
if (resourceDir.size() == 0) {
return null;
}
return resourceDir.iterator().next();
} else {
return null;
}
return resourceDir.iterator().next();
}

private File getTestOutputResourceDir() {
SourceSet testSources = getTestSourceSet();
if (testSources == null) {
return null;
}
return testSources.getOutput().getResourcesDir();
Optional<SourceSet> testSourceSet = getSourceSet();
return testSourceSet.map(sourceSet -> sourceSet.getOutput().getResourcesDir()).orElse(null);
}

private SourceSet getTestSourceSet() {
return GradleUtils.getJavaSourceSets(getProject()).findByName("test");
private Optional<SourceSet> getSourceSet() {
Project project = getProject();
return project.getConvention().findPlugin(JavaPluginConvention.class) == null
? Optional.empty()
: Optional.ofNullable(GradleUtils.getJavaSourceSets(project).findByName(getSourceSetName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
Expand All @@ -39,6 +40,8 @@

import javax.inject.Inject;
import java.io.File;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
Expand All @@ -52,6 +55,7 @@ public class CopyRestTestsTask extends DefaultTask {
final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);

String sourceSetName;
Configuration coreConfig;
Configuration xpackConfig;

Expand All @@ -78,6 +82,11 @@ public ListProperty<String> getIncludeXpack() {
return includeXpack;
}

@Input
String getSourceSetName() {
return sourceSetName;
}

@SkipWhenEmpty
@InputFiles
public FileTree getInputDir() {
Expand All @@ -103,7 +112,12 @@ public FileTree getInputDir() {

@OutputDirectory
public File getOutputDir() {
return new File(getTestSourceSet().getOutput().getResourcesDir(), REST_TEST_PREFIX);
return new File(
getSourceSet().orElseThrow(() -> new IllegalArgumentException("could not find source set [" + sourceSetName + "]"))
.getOutput()
.getResourcesDir(),
REST_TEST_PREFIX
);
}

@TaskAction
Expand All @@ -127,7 +141,8 @@ void copy() {
);
project.copy(c -> {
c.from(project.zipTree(coreConfig.getSingleFile()));
c.into(getTestSourceSet().getOutput().getResourcesDir()); // this ends up as the same dir as outputDir
// this ends up as the same dir as outputDir
c.into(Objects.requireNonNull(getSourceSet().orElseThrow().getOutput().getResourcesDir()));
c.include(
includeCore.get().stream().map(prefix -> REST_TEST_PREFIX + "/" + prefix + "*/**").collect(Collectors.toList())
);
Expand All @@ -145,7 +160,10 @@ void copy() {
}
}

private SourceSet getTestSourceSet() {
return GradleUtils.getJavaSourceSets(getProject()).findByName("test");
private Optional<SourceSet> getSourceSet() {
Project project = getProject();
return project.getConvention().findPlugin(JavaPluginConvention.class) == null
? Optional.empty()
: Optional.ofNullable(GradleUtils.getJavaSourceSets(project).findByName(getSourceSetName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

import java.util.Map;

Expand Down Expand Up @@ -76,6 +78,7 @@
* Will copy any of the the x-pack tests that start with graph, and will copy the X-pack graph specification, as well as the full core
* Rest API specification.
*
* Additionally you can specify which sourceSetName resources should be copied to. The default is the yamlRestTest source set.
* @see CopyRestApiTask
* @see CopyRestTestsTask
*/
Expand All @@ -97,6 +100,7 @@ public void apply(Project project) {
task.includeCore.set(extension.restTests.getIncludeCore());
task.includeXpack.set(extension.restTests.getIncludeXpack());
task.coreConfig = testConfig;
task.sourceSetName = SourceSet.TEST_SOURCE_SET_NAME;
if (BuildParams.isInternal()) {
// core
Dependency restTestdependency = project.getDependencies()
Expand Down Expand Up @@ -127,6 +131,7 @@ public void apply(Project project) {
task.includeXpack.set(extension.restApi.getIncludeXpack());
task.dependsOn(copyRestYamlTestTask);
task.coreConfig = specConfig;
task.sourceSetName = SourceSet.TEST_SOURCE_SET_NAME;
if (BuildParams.isInternal()) {
Dependency restSpecDependency = project.getDependencies()
.project(Map.of("path", ":rest-api-spec", "configuration", "restSpecs"));
Expand All @@ -144,6 +149,12 @@ public void apply(Project project) {
task.dependsOn(task.coreConfig);
});

project.getTasks().named("processTestResources").configure(t -> t.dependsOn(copyRestYamlSpecTask));
project.afterEvaluate(p -> {
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
SourceSet testSourceSet = sourceSets.findByName(SourceSet.TEST_SOURCE_SET_NAME);
if (testSourceSet != null) {
project.getTasks().named(testSourceSet.getProcessResourcesTaskName()).configure(t -> t.dependsOn(copyRestYamlSpecTask));
}
});
}
}
Loading