Replace heavy weight build-tools integ tests with a simple unit test. (#44056)

Remove heavy build-tool integ test.
Add a  unit test for the plugin builder plugin.

Closes #41256 #41256
This commit is contained in:
Alpar Torok 2019-09-30 10:23:04 +03:00
parent 1c7dc3a5bf
commit 3648481eb2
20 changed files with 115 additions and 737 deletions

View File

@ -16,9 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import org.gradle.util.GradleVersion
import java.util.regex.Matcher
import org.gradle.util.GradleVersion
plugins {
id 'java-gradle-plugin'
@ -109,8 +108,9 @@ dependencies {
compile 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3'
compile 'com.netflix.nebula:nebula-publishing-plugin:4.4.4'
compile 'com.netflix.nebula:gradle-info-plugin:3.0.3'
compile 'com.netflix.nebula:gradle-info-plugin:5.1.0'
compile 'org.eclipse.jgit:org.eclipse.jgit:5.5.0.201909110433-r'
compile 'com.netflix.nebula:gradle-info-plugin:3.0.3'
compile 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE....
compile 'org.apache.rat:apache-rat:0.11'
compile "org.elasticsearch:jna:4.5.1"
@ -120,6 +120,7 @@ dependencies {
testCompile "junit:junit:${props.getProperty('junit')}"
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"
testCompile 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
testCompile 'org.mockito:mockito-core:1.9.5'
minimumRuntimeCompile "junit:junit:${props.getProperty('junit')}"
minimumRuntimeCompile localGroovy()
minimumRuntimeCompile gradleApi()
@ -194,40 +195,6 @@ if (project != rootProject) {
}
}
String localDownloads = "${rootProject.buildDir}/local-downloads"
task setupLocalDownloads(type:Copy) {
from configurations.distribution
into localDownloads
}
task integTest(type: Test) {
// integration test requires the local testing repo for example plugin builds
dependsOn project.rootProject.allprojects.collect {
it.tasks.matching { it.name == 'publishNebulaPublicationToTestRepository'}
}
dependsOn setupLocalDownloads
exclude "**/*Tests.class"
inputs.dir(file("src/testKit"))
// tell BuildExamplePluginsIT where to find the example plugins
systemProperty (
'test.build-tools.plugin.examples',
files(
project(':example-plugins').subprojects.collect { it.projectDir }
).asPath,
)
systemProperty 'test.local-test-repo-path', "${rootProject.buildDir}/local-test-repo"
systemProperty 'test.local-test-downloads-path', localDownloads
systemProperty 'test.version_under_test', version
Matcher isLuceneSnapshot = (/\w+-snapshot-([a-z0-9]+)/ =~ versions.lucene)
if (isLuceneSnapshot) {
systemProperty 'test.lucene-snapshot-revision', isLuceneSnapshot[0][1]
}
maxParallelForks System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel.toString()) as Integer
// These tests run Gradle which doesn't have FIPS support
onlyIf { project.inFipsJvm == false }
}
check.dependsOn(integTest)
// TODO: re-enable once randomizedtesting gradle code is published and removed from here
licenseHeaders.enabled = false
@ -250,6 +217,14 @@ if (project != rootProject) {
}
}
task integTest(type: Test) {
inputs.dir(file("src/testKit")).withPropertyName("testkit dir").withPathSensitivity(PathSensitivity.RELATIVE)
systemProperty 'test.version_under_test', version
onlyIf { project.inFipsJvm == false }
maxParallelForks = System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel.toString()) as Integer
}
check.dependsOn(integTest)
/*
* We alread configure publication and we don't need or want this one that
* comes from the java-gradle-plugin.

View File

@ -62,14 +62,11 @@ class PluginBuildPlugin implements Plugin<Project> {
project.afterEvaluate {
boolean isXPackModule = project.path.startsWith(':x-pack:plugin')
boolean isModule = project.path.startsWith(':modules:') || isXPackModule
String name = extension.name
PluginPropertiesExtension extension1 = project.getExtensions().getByType(PluginPropertiesExtension.class)
String name = extension1.name
project.archivesBaseName = name
// set the project description so it will be picked up by publishing
project.description = extension.description
configurePublishing(project, extension)
project.description = extension1.description
configurePublishing(project, extension1)
if (project.plugins.hasPlugin(TestClustersPlugin.class) == false) {
project.integTestCluster.dependsOn(project.tasks.bundlePlugin)
if (isModule) {
@ -99,7 +96,29 @@ class PluginBuildPlugin implements Plugin<Project> {
}
}
}
if (extension1.name == null) {
throw new InvalidUserDataException('name is a required setting for esplugin')
}
if (extension1.description == null) {
throw new InvalidUserDataException('description is a required setting for esplugin')
}
if (extension1.classname == null) {
throw new InvalidUserDataException('classname is a required setting for esplugin')
}
Copy buildProperties = project.tasks.getByName('pluginProperties')
Map<String, String> properties = [
'name' : extension1.name,
'description' : extension1.description,
'version' : extension1.version,
'elasticsearchVersion': Version.fromString(VersionProperties.elasticsearch).toString(),
'javaVersion' : project.targetCompatibility as String,
'classname' : extension1.classname,
'extendedPlugins' : extension1.extendedPlugins.join(','),
'hasNativeController' : extension1.hasNativeController,
'requiresKeystore' : extension1.requiresKeystore
]
buildProperties.expand(properties)
buildProperties.inputs.properties(properties)
project.tasks.run.dependsOn(project.tasks.bundlePlugin)
if (isModule) {
project.tasks.run.clusterConfig.distribution = System.getProperty(
@ -108,9 +127,8 @@ class PluginBuildPlugin implements Plugin<Project> {
} else {
project.tasks.run.clusterConfig.plugin(project.path)
}
if (isModule == false || isXPackModule) {
addNoticeGeneration(project, extension)
addNoticeGeneration(project, extension1)
}
}
project.tasks.named('testingConventions').configure {
@ -150,7 +168,6 @@ class PluginBuildPlugin implements Plugin<Project> {
if (project.plugins.hasPlugin(MavenPublishPlugin)) {
project.publishing.publications.nebula(MavenPublication).artifactId(extension.name)
}
}
}
@ -207,36 +224,6 @@ class PluginBuildPlugin implements Plugin<Project> {
into("${project.buildDir}/generated-resources")
}
project.afterEvaluate {
// check require properties are set
if (extension.name == null) {
throw new InvalidUserDataException('name is a required setting for esplugin')
}
if (extension.description == null) {
throw new InvalidUserDataException('description is a required setting for esplugin')
}
if (extension.classname == null) {
throw new InvalidUserDataException('classname is a required setting for esplugin')
}
Map<String, String> properties = [
'name': extension.name,
'description': extension.description,
'version': extension.version,
'elasticsearchVersion': Version.fromString(VersionProperties.elasticsearch).toString(),
'javaVersion': project.targetCompatibility as String,
'classname': extension.classname,
'extendedPlugins': extension.extendedPlugins.join(','),
'hasNativeController': extension.hasNativeController,
'requiresKeystore': extension.requiresKeystore
]
buildProperties.configure {
expand(properties)
inputs.properties(properties)
}
}
// add the plugin properties and metadata to test resources, so unit tests can
// know about the plugin (used by test security code to statically initialize the plugin in unit tests)
SourceSet testSourceSet = project.sourceSets.test
@ -291,7 +278,7 @@ class PluginBuildPlugin implements Plugin<Project> {
/** Configure the pom for the main jar of this plugin */
protected void addNoticeGeneration(Project project, PluginPropertiesExtension extension) {
protected static void addNoticeGeneration(Project project, PluginPropertiesExtension extension) {
File licenseFile = extension.licenseFile
if (licenseFile != null) {
project.tasks.bundlePlugin.from(licenseFile.parentFile) {

View File

@ -57,7 +57,7 @@ public class TestClustersPlugin implements Plugin<Project> {
// provide a task to be able to list defined clusters.
createListClustersTask(project, container);
if (project.getRootProject().getExtensions().findByType(TestClustersRegistry.class) == null) {
if (project.getRootProject().getExtensions().findByName("testClusters") == null) {
TestClustersRegistry registry = project.getRootProject().getExtensions()
.create("testClusters", TestClustersRegistry.class);

View File

@ -1,161 +0,0 @@
/*
* 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;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.apache.commons.io.FileUtils;
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Ignore("https://github.com/elastic/elasticsearch/issues/42453")
public class BuildExamplePluginsIT extends GradleIntegrationTestCase {
private static final List<File> EXAMPLE_PLUGINS = Collections.unmodifiableList(
Arrays.stream(
Objects.requireNonNull(System.getProperty("test.build-tools.plugin.examples"))
.split(File.pathSeparator)
).map(File::new).collect(Collectors.toList())
);
private static final String BUILD_TOOLS_VERSION = Objects.requireNonNull(System.getProperty("test.version_under_test"));
@Rule
public TemporaryFolder tmpDir = new TemporaryFolder();
public final File examplePlugin;
public BuildExamplePluginsIT(File examplePlugin) {
this.examplePlugin = examplePlugin;
}
@BeforeClass
public static void assertProjectsExist() {
assertEquals(
EXAMPLE_PLUGINS,
EXAMPLE_PLUGINS.stream().filter(File::exists).collect(Collectors.toList())
);
}
@ParametersFactory
public static Iterable<Object[]> parameters() {
return EXAMPLE_PLUGINS
.stream()
.map(each -> new Object[] {each})
.collect(Collectors.toList());
}
public void testCurrentExamplePlugin() throws IOException {
FileUtils.copyDirectory(examplePlugin, tmpDir.getRoot(), pathname -> pathname.getPath().contains("/build/") == false);
adaptBuildScriptForTest();
Files.write(
tmpDir.newFile("NOTICE.txt").toPath(),
"dummy test notice".getBytes(StandardCharsets.UTF_8)
);
GradleRunner.create()
.withProjectDir(tmpDir.getRoot())
.withArguments("clean", "check", "-s", "-i", "--warning-mode=all", "--scan")
.withPluginClasspath()
.build();
}
private void adaptBuildScriptForTest() throws IOException {
// Add the local repo as a build script URL so we can pull in build-tools and apply the plugin under test
// we need to specify the exact version of build-tools because gradle automatically adds its plugin portal
// which appears to mirror jcenter, opening us up to pulling a "later" version of build-tools
writeBuildScript(
"buildscript {\n" +
" repositories {\n" +
" maven {\n" +
" name = \"test\"\n" +
" url = '" + getLocalTestRepoPath() + "'\n" +
" }\n" +
" }\n" +
" dependencies {\n" +
" classpath \"org.elasticsearch.gradle:build-tools:" + BUILD_TOOLS_VERSION + "\"\n" +
" }\n" +
"}\n"
);
// get the original file
Files.readAllLines(getTempPath("build.gradle"), StandardCharsets.UTF_8)
.stream()
.map(line -> line + "\n")
.forEach(this::writeBuildScript);
// Add a repositories section to be able to resolve dependencies
String luceneSnapshotRepo = "";
String luceneSnapshotRevision = System.getProperty("test.lucene-snapshot-revision");
if (luceneSnapshotRepo != null) {
luceneSnapshotRepo = " maven {\n" +
" name \"lucene-snapshots\"\n" +
" url \"https://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/" + luceneSnapshotRevision + "\"\n" +
" }\n";
}
writeBuildScript("\n" +
"repositories {\n" +
" maven {\n" +
" name \"test\"\n" +
" url \"" + getLocalTestRepoPath() + "\"\n" +
" }\n" +
" flatDir {\n" +
" dir '" + getLocalTestDownloadsPath() + "'\n" +
" }\n" +
luceneSnapshotRepo +
"}\n"
);
Files.delete(getTempPath("build.gradle"));
Files.move(getTempPath("build.gradle.new"), getTempPath("build.gradle"));
System.err.print("Generated build script is:");
Files.readAllLines(getTempPath("build.gradle")).forEach(System.err::println);
}
private Path getTempPath(String fileName) {
return new File(tmpDir.getRoot(), fileName).toPath();
}
private Path writeBuildScript(String script) {
try {
Path path = getTempPath("build.gradle.new");
return Files.write(
path,
script.getBytes(StandardCharsets.UTF_8),
Files.exists(path) ? StandardOpenOption.APPEND : StandardOpenOption.CREATE_NEW
);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -51,7 +51,7 @@ public class BuildPluginIT extends GradleIntegrationTestCase {
public void testCheckTask() {
BuildResult result = getGradleRunner("elasticsearch.build")
.withArguments("check", "assemble", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath())
.withArguments("check", "assemble", "-s")
.build();
assertTaskSuccessful(result, ":check");
}
@ -103,7 +103,7 @@ public class BuildPluginIT extends GradleIntegrationTestCase {
public void testLicenseAndNotice() throws IOException {
BuildResult result = getGradleRunner("elasticsearch.build")
.withArguments("clean", "assemble", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath())
.withArguments("clean", "assemble")
.build();
assertTaskSuccessful(result, ":assemble");

View File

@ -99,7 +99,6 @@ public class DistributionDownloadPluginIT extends GradleIntegrationTestCase {
assert sysProps.length % 2 == 0;
List<String> args = new ArrayList<>();
args.add(taskname);
args.add("-Dlocal.repo.path=" + getLocalTestRepoPath());
for (int i = 0; i < sysProps.length; i += 2) {
args.add("-D" + sysProps[i] + "=" + sysProps[i + 1]);
}

View File

@ -109,7 +109,6 @@ public abstract class JdkDownloadPluginIT extends GradleIntegrationTestCase {
GradleRunner runner = GradleRunner.create().withProjectDir(getProjectDir("jdk-download"))
.withArguments(taskname,
"-Dlocal.repo.path=" + getLocalTestRepoPath(),
"-Dtests.jdk_vendor=" + vendor,
"-Dtests.jdk_version=" + version,
"-Dtests.jdk_repo=" + wireMock.baseUrl(),

View File

@ -0,0 +1,69 @@
package org.elasticsearch.gradle.plugin;
import org.elasticsearch.gradle.BwcVersions;
import org.elasticsearch.gradle.test.GradleUnitTestCase;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.Before;
import org.junit.Ignore;
import org.mockito.Mockito;
import java.util.stream.Collectors;
public class PluginBuildPluginTests extends GradleUnitTestCase {
private Project project;
@Before
public void setUp() throws Exception {
project = ProjectBuilder.builder()
.withName(getClass().getName())
.build();
}
public void testApply() {
// FIXME: distribution download plugin doesn't support running externally
project.getExtensions().getExtraProperties().set(
"bwcVersions", Mockito.mock(BwcVersions.class)
);
project.getPlugins().apply(PluginBuildPlugin.class);
assertNotNull(
"plugin extension created with the right name",
project.getExtensions().findByName(PluginBuildPlugin.PLUGIN_EXTENSION_NAME)
);
assertNotNull(
"plugin extensions has the right type",
project.getExtensions().findByType(PluginPropertiesExtension.class)
);
assertNotNull(
"plugin created an integTest class",
project.getTasks().findByName("integTest")
);
}
@Ignore("https://github.com/elastic/elasticsearch/issues/47123")
public void testApplyWithAfterEvaluate() {
project.getExtensions().getExtraProperties().set(
"bwcVersions", Mockito.mock(BwcVersions.class)
);
project.getPlugins().apply(PluginBuildPlugin.class);
PluginPropertiesExtension extension = project.getExtensions().getByType(PluginPropertiesExtension.class);
extension.setNoticeFile(project.file("test.notice"));
extension.setLicenseFile(project.file("test.license"));
extension.setDescription("just a test");
extension.setClassname(getClass().getName());
((ProjectInternal) project).evaluate();
assertNotNull(
"Task to generate notice not created: " + project.getTasks().stream()
.map(Task::getPath)
.collect(Collectors.joining(", ")),
project.getTasks().findByName("generateNotice")
);
}
}

View File

@ -1,39 +0,0 @@
package org.elasticsearch.gradle.precommit;
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
/*
* 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.
*/
public class JarHellTaskIT extends GradleIntegrationTestCase {
public void testJarHellDetected() {
BuildResult result = getGradleRunner("jarHell")
.withArguments("clean", "precommit", "-s", "-Dlocal.repo.path=" + getLocalTestRepoPath())
.buildAndFail();
assertTaskFailed(result, ":jarHell");
assertOutputContains(
result.getOutput(),
"java.lang.IllegalStateException: jar hell!",
"class: org.apache.logging.log4j.Logger"
);
}
}

View File

@ -157,10 +157,6 @@ public abstract class GradleIntegrationTestCase extends GradleUnitTestCase {
);
}
protected String getLocalTestRepoPath() {
return getLocalTestPath("test.local-test-repo-path");
}
protected String getLocalTestDownloadsPath() {
return getLocalTestPath("test.local-test-downloads-path");
}

View File

@ -1,219 +0,0 @@
/*
* 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.testclusters;
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Before;
import org.junit.Ignore;
import java.util.Arrays;
@Ignore("https://github.com/elastic/elasticsearch/issues/42453")
public class TestClustersPluginIT extends GradleIntegrationTestCase {
private GradleRunner runner;
@Before
public void setUp() throws Exception {
runner = getGradleRunner("testclusters");
}
public void testListClusters() {
BuildResult result = getTestClustersRunner("listTestClusters").build();
assertTaskSuccessful(result, ":listTestClusters");
assertOutputContains(
result.getOutput(),
" * myTestCluster:"
);
}
public void testUseClusterByOne() {
BuildResult result = getTestClustersRunner(":user1").build();
assertTaskSuccessful(result, ":user1");
assertStartedAndStoppedOnce(result);
}
public void testUseClusterByOneWithDryRun() {
BuildResult result = getTestClustersRunner("--dry-run", ":user1").build();
assertNull(result.task(":user1"));
assertNotStarted(result);
}
public void testUseClusterByTwo() {
BuildResult result = getTestClustersRunner(":user1", ":user2").build();
assertTaskSuccessful(result, ":user1", ":user2");
assertStartedAndStoppedOnce(result);
}
public void testUseClusterByUpToDateTask() {
// Run it once, ignoring the result and again to make sure it's considered up to date.
// Gradle randomly considers tasks without inputs and outputs as as up-to-date or success on the first run
getTestClustersRunner(":upToDate1").build();
BuildResult result = getTestClustersRunner(":upToDate1").build();
assertTaskUpToDate(result, ":upToDate1");
assertNotStarted(result);
}
public void testUseClusterBySkippedTask() {
BuildResult result = getTestClustersRunner(":skipped1", ":skipped2").build();
assertTaskSkipped(result, ":skipped1", ":skipped2");
assertNotStarted(result);
}
public void testUseClusterBySkippedAndWorkingTask() {
BuildResult result = getTestClustersRunner("skipped1", "user1").build();
assertTaskSkipped(result, ":skipped1");
assertTaskSuccessful(result, ":user1");
assertOutputContains(
result.getOutput(),
"> Task :user1",
"Starting `node{::myTestCluster-0}`",
"Stopping `node{::myTestCluster-0}`"
);
}
@Ignore // https://github.com/elastic/elasticsearch/issues/41256
public void testMultiProject() {
BuildResult result = getTestClustersRunner(
"user1", "user2", "-s", "-i", "--parallel", "-Dlocal.repo.path=" + getLocalTestRepoPath()
).build();
assertTaskSuccessful(
result,
":user1", ":user2", ":alpha:user1", ":alpha:user2", ":bravo:user1", ":bravo:user2"
);
assertStartedAndStoppedOnce(result);
assertOutputOnlyOnce(
result.getOutput(),
"Starting `node{:alpha:myTestCluster-0}`",
"Stopping `node{::myTestCluster-0}`"
);
assertOutputOnlyOnce(
result.getOutput(),
"Starting `node{::myTestCluster-0}`",
"Stopping `node{:bravo:myTestCluster-0}`"
);
}
public void testReleased() {
BuildResult result = getTestClustersRunner("testReleased").build();
assertTaskSuccessful(result, ":testReleased");
assertStartedAndStoppedOnce(result, "releasedVersionDefault-0");
assertStartedAndStoppedOnce(result, "releasedVersionOSS-0");
assertStartedAndStoppedOnce(result, "releasedVersionIntegTest-0");
}
public void testIncremental() {
BuildResult result = getTestClustersRunner("clean", ":user1").build();
assertTaskSuccessful(result, ":user1");
assertStartedAndStoppedOnce(result);
result = getTestClustersRunner(":user1").build();
assertTaskSuccessful(result, ":user1");
assertStartedAndStoppedOnce(result);
result = getTestClustersRunner("clean", ":user1").build();
assertTaskSuccessful(result, ":user1");
assertStartedAndStoppedOnce(result);
assertStartedAndStoppedOnce(result);
}
public void testUseClusterByFailingOne() {
BuildResult result = getTestClustersRunner(":itAlwaysFails").buildAndFail();
assertTaskFailed(result, ":itAlwaysFails");
assertStartedAndStoppedOnce(result);
assertOutputContains(
result.getOutput(),
"Stopping `node{::myTestCluster-0}`, tailLogs: true",
"Execution failed for task ':itAlwaysFails'."
);
}
public void testUseClusterByFailingDependency() {
BuildResult result = getTestClustersRunner(":dependsOnFailed").buildAndFail();
assertTaskFailed(result, ":itAlwaysFails");
assertNull(result.task(":dependsOnFailed"));
assertStartedAndStoppedOnce(result);
assertOutputContains(
result.getOutput(),
"Stopping `node{::myTestCluster-0}`, tailLogs: true",
"Execution failed for task ':itAlwaysFails'."
);
}
public void testConfigurationLocked() {
BuildResult result = getTestClustersRunner(":illegalConfigAlter").buildAndFail();
assertTaskFailed(result, ":illegalConfigAlter");
assertOutputContains(
result.getOutput(),
"Configuration for node{::myTestCluster-0} can not be altered, already locked"
);
}
@Ignore // https://github.com/elastic/elasticsearch/issues/41256
public void testMultiNode() {
BuildResult result = getTestClustersRunner(":multiNode").build();
assertTaskSuccessful(result, ":multiNode");
assertStartedAndStoppedOnce(result, "multiNode-0");
assertStartedAndStoppedOnce(result, "multiNode-1");
assertStartedAndStoppedOnce(result, "multiNode-2");
}
public void testPluginInstalled() {
BuildResult result = getTestClustersRunner(":printLog").build();
assertTaskSuccessful(result, ":printLog");
assertStartedAndStoppedOnce(result);
assertOutputContains(result.getOutput(), "-> Installed dummy");
assertOutputContains(result.getOutput(), "loaded plugin [dummy]");
}
private void assertNotStarted(BuildResult result) {
assertOutputDoesNotContain(
result.getOutput(),
"Starting ",
"Stopping "
);
}
private GradleRunner getTestClustersRunner(String... tasks) {
String[] arguments = Arrays.copyOf(tasks, tasks.length + 3);
arguments[tasks.length] = "-s";
arguments[tasks.length + 1] = "-i";
arguments[tasks.length + 2] = "-Dlocal.repo.path=" + getLocalTestRepoPath();
return runner.withArguments(arguments);
}
private void assertStartedAndStoppedOnce(BuildResult result, String nodeName) {
assertOutputOnlyOnce(
result.getOutput(),
"Starting `node{::" + nodeName + "}`",
"Stopping `node{::" + nodeName + "}`"
);
}
private void assertStartedAndStoppedOnce(BuildResult result) {
assertStartedAndStoppedOnce(result, "myTestCluster-0");
}
}

View File

@ -14,12 +14,6 @@ dependencies {
repositories {
jcenter()
repositories {
maven {
name "local-repo"
url System.getProperty("local.repo.path")
}
}
}
// todo remove offending rules
@ -30,6 +24,8 @@ jarHell.enabled = false
// we don't have tests for now
test.enabled = false
thirdPartyAudit.enabled = false
// This requires an additional Jar not part of build-tools
loggerUsageCheck.enabled = false
task hello {
doFirst {

View File

@ -1,29 +0,0 @@
plugins {
id 'java'
id 'elasticsearch.build'
}
dependencyLicenses.enabled = false
dependenciesInfo.enabled = false
forbiddenApisMain.enabled = false
forbiddenApisTest.enabled = false
thirdPartyAudit.enabled = false
ext.licenseFile = file("$buildDir/dummy/license")
ext.noticeFile = file("$buildDir/dummy/notice")
repositories {
jcenter()
repositories {
maven {
name "local"
url System.getProperty("local.repo.path")
}
}
}
dependencies {
// Needed for the JarHell task
testCompile ("org.elasticsearch.test:framework:${versions.elasticsearch}")
// causes jar hell with local sources
compile "org.apache.logging.log4j:log4j-api:${versions.log4j}"
}

View File

@ -1,7 +0,0 @@
package org.apache.logging.log4j;
// Jar Hell !
public class Logger {
}

View File

@ -1,142 +0,0 @@
plugins {
id 'elasticsearch.testclusters'
id 'base'
}
allprojects { all ->
repositories {
flatDir {
dir System.getProperty("test.local-test-downloads-path")
}
maven {
name "local"
url System.getProperty("local.repo.path")
}
String luceneSnapshotRevision = System.getProperty("test.lucene-snapshot-revision")
if (luceneSnapshotRevision != null) {
maven {
name "lucene-snapshots"
url "https://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/" + luceneSnapshotRevision
}
}
}
if (project == rootProject || project.name == "alpha" || project.name == "bravo") {
apply plugin: 'elasticsearch.testclusters'
all.testClusters {
myTestCluster {
testDistribution = 'DEFAULT'
version = System.getProperty("test.version_under_test")
javaHome = file(System.getProperty('java.home'))
plugin file("${project(":dummyPlugin").buildDir}/distributions/dummy-${System.getProperty("test.version_under_test")}.zip")
}
}
task user1 {
useCluster testClusters.myTestCluster
doFirst {
println "$path: Cluster running @ ${testClusters.myTestCluster.httpSocketURI}"
}
}
task user2 {
useCluster testClusters.myTestCluster
doFirst {
println "$path: Cluster running @ ${testClusters.myTestCluster.httpSocketURI}"
}
}
syncTestClustersArtifacts {
dependsOn ":dummyPlugin:bundlePlugin"
}
}
}
testClusters {
multiNode {
version = System.getProperty("test.version_under_test")
testDistribution = 'DEFAULT'
javaHome = file(System.getProperty('java.home'))
numberOfNodes = 3
}
releasedVersionDefault {
version = "7.0.0"
testDistribution = 'DEFAULT'
javaHome = file(System.getProperty('java.home'))
}
releasedVersionOSS {
version = "7.0.0"
testDistribution = 'OSS'
javaHome = file(System.getProperty('java.home'))
}
releasedVersionIntegTest {
version = "7.0.0"
testDistribution = 'INTEG_TEST'
javaHome = file(System.getProperty('java.home'))
}
}
task multiNode {
useCluster testClusters.multiNode
doFirst {
println "$path: Cluster running @ ${testClusters.multiNode.httpSocketURI}"
}
}
task testReleased {
useCluster testClusters.releasedVersionDefault
useCluster testClusters.releasedVersionOSS
useCluster testClusters.releasedVersionIntegTest
doFirst {
println "$path: Cluster running @ ${testClusters.releasedVersionDefault.httpSocketURI}"
println "$path: Cluster running @ ${testClusters.releasedVersionOSS.httpSocketURI}"
println "$path: Cluster running @ ${testClusters.releasedVersionIntegTest.httpSocketURI}"
}
}
task printLog {
useCluster testClusters.myTestCluster
doFirst {
println "$path: Cluster running @ ${testClusters.myTestCluster.httpSocketURI}"
testClusters.myTestCluster.singleNode().logLines().each {
println it
}
}
}
task upToDate1 {
useCluster testClusters.myTestCluster
outputs.upToDateWhen { true }
doLast {
println "Some task action"
}
}
task skipped1 {
enabled = false
useCluster testClusters.myTestCluster
}
task skipped2 {
enabled = false
useCluster testClusters.myTestCluster
}
task itAlwaysFails {
doLast {
throw new GradleException("Task 1 failed!")
}
useCluster testClusters.myTestCluster
}
task dependsOnFailed {
dependsOn itAlwaysFails
useCluster testClusters.myTestCluster
}
task illegalConfigAlter {
useCluster testClusters.myTestCluster
doFirst {
println "Going to alter configuration after use"
testClusters.myTestCluster.testDistribution = 'OSS'
}
}

View File

@ -1,11 +0,0 @@
apply plugin: 'elasticsearch.esplugin'
version = System.getProperty("test.version_under_test")
esplugin {
name 'dummy'
description 'A dummy plugin used for testing'
classname 'DummyPlugin'
licenseFile rootProject.file('empty.txt')
noticeFile rootProject.file('empty.txt')
}

View File

@ -1,30 +0,0 @@
/*
* 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.
*/
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.common.settings.Settings;
import java.nio.file.Path;
public class DummyPlugin extends Plugin {
public DummyPlugin(final Settings settings, final Path configPath) {
}
}

View File

@ -1,5 +0,0 @@
include 'dummyPlugin'
include ':alpha'
include ':bravo'
include ':charlie'
include 'dummyPlugin'