diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 97a5947e7aa..704ebca4d6c 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -124,7 +124,7 @@ dependencies { compile "org.elasticsearch:jna:4.5.1" compile 'com.github.jengelman.gradle.plugins:shadow:2.0.4' compile 'de.thetaphi:forbiddenapis:2.6' - compile 'com.avast.gradle:docker-compose-gradle-plugin:0.4.5' + compile 'com.avast.gradle:gradle-docker-compose-plugin:0.8.12' testCompile "junit:junit:${props.getProperty('junit')}" } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testfixtures/TestFixturesPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testfixtures/TestFixturesPlugin.java index 26f99a9d62e..73b3baf66dd 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testfixtures/TestFixturesPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testfixtures/TestFixturesPlugin.java @@ -27,12 +27,15 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.plugins.BasePlugin; +import org.gradle.api.plugins.ExtraPropertiesExtension; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskContainer; +import org.gradle.internal.os.OperatingSystem; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collections; +import java.util.function.BiConsumer; public class TestFixturesPlugin implements Plugin { @@ -54,7 +57,16 @@ public class TestFixturesPlugin implements Plugin { disableTaskByType(tasks, ThirdPartyAuditTask.class); disableTaskByType(tasks, JarHellTask.class); + Task buildFixture = project.getTasks().create("buildFixture"); + Task preProcessFixture = project.getTasks().create("preProcessFixture"); + buildFixture.dependsOn(preProcessFixture); + Task postProcessFixture = project.getTasks().create("postProcessFixture"); + buildFixture.dependsOn(postProcessFixture); + if (dockerComposeSupported(project) == false) { + preProcessFixture.setEnabled(false); + postProcessFixture.setEnabled(false); + buildFixture.setEnabled(false); return; } @@ -68,8 +80,18 @@ public class TestFixturesPlugin implements Plugin { "/usr/local/bin/docker-compose" : "/usr/bin/docker-compose" ); - project.getTasks().getByName("clean").dependsOn("composeDown"); + buildFixture.dependsOn(tasks.getByName("composeUp")); + tasks.getByName("composeUp").mustRunAfter(preProcessFixture); + postProcessFixture.dependsOn("composeUp"); + + configureServiceInfoForTask( + postProcessFixture, + project, + (name, port) -> postProcessFixture.getExtensions() + .getByType(ExtraPropertiesExtension.class).set(name, port) + ); } else { + extension.fixtures.all(fixtureProject -> project.evaluationDependsOn(fixtureProject.getPath())); if (dockerComposeSupported(project) == false) { project.getLogger().warn( "Tests for {} require docker-compose at /usr/local/bin/docker-compose or /usr/bin/docker-compose " + @@ -82,27 +104,54 @@ public class TestFixturesPlugin implements Plugin { } tasks.withType(getTaskClass("com.carrotsearch.gradle.junit4.RandomizedTestingTask"), task -> extension.fixtures.all(fixtureProject -> { - task.dependsOn(fixtureProject.getTasks().getByName("composeUp")); - task.finalizedBy(fixtureProject.getTasks().getByName("composeDown")); - // Configure ports for the tests as system properties. - // We only know these at execution time so we need to do it in doFirst - task.doFirst(it -> - fixtureProject.getExtensions().getByType(ComposeExtension.class).getServicesInfos() - .forEach((service, infos) -> - infos.getPorts() - .forEach((container, host) -> setSystemProperty( - it, - "test.fixtures." + fixtureProject.getName() + "." + service + "." + container, - host - )) - )); - })); + fixtureProject.getTasks().matching(it->it.getName().equals("buildFixture")).all(buildFixture -> + task.dependsOn(buildFixture) + ); + fixtureProject.getTasks().matching(it->it.getName().equals("composeDown")).all(composeDown -> + task.finalizedBy(composeDown) + ); + configureServiceInfoForTask( + task, + fixtureProject, + (name, port) -> setSystemProperty(task, name, port) + ); + }) + ); } } + private void configureServiceInfoForTask(Task task, Project fixtureProject, BiConsumer consumer) { + // Configure ports for the tests as system properties. + // We only know these at execution time so we need to do it in doFirst + task.doFirst(theTask -> + fixtureProject.getExtensions().getByType(ComposeExtension.class).getServicesInfos() + .forEach((service, infos) -> { + theTask.getLogger().info( + "Port maps for {}\nTCP:{}\nUDP:{}\nexposed to {}", + fixtureProject.getPath(), + infos.getTcpPorts(), + infos.getUdpPorts(), + theTask.getPath() + ); + infos.getTcpPorts() + .forEach((container, host) -> consumer.accept( + "test.fixtures." + service + ".tcp." + container, + host + )); + infos.getUdpPorts() + .forEach((container, host) -> consumer.accept( + "test.fixtures." + service + ".udp." + container, + host + )); + }) + ); + } + @Input public boolean dockerComposeSupported(Project project) { - // Don't look for docker-compose on the PATH yet that would pick up on Windows as well + if (OperatingSystem.current().isWindows()) { + return false; + } final boolean hasDockerCompose = project.file("/usr/local/bin/docker-compose").exists() || project.file("/usr/bin/docker-compose").exists(); return hasDockerCompose && Boolean.parseBoolean(System.getProperty("tests.fixture.enabled", "true")); diff --git a/test/fixtures/hdfs-fixture/docker-compose.yml b/test/fixtures/hdfs-fixture/docker-compose.yml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/x-pack/qa/third-party/active-directory/src/test/java/org/elasticsearch/xpack/security/authc/ldap/AbstractActiveDirectoryTestCase.java b/x-pack/qa/third-party/active-directory/src/test/java/org/elasticsearch/xpack/security/authc/ldap/AbstractActiveDirectoryTestCase.java index 11fe23501c4..5c4df3eedb8 100644 --- a/x-pack/qa/third-party/active-directory/src/test/java/org/elasticsearch/xpack/security/authc/ldap/AbstractActiveDirectoryTestCase.java +++ b/x-pack/qa/third-party/active-directory/src/test/java/org/elasticsearch/xpack/security/authc/ldap/AbstractActiveDirectoryTestCase.java @@ -154,9 +154,9 @@ public abstract class AbstractActiveDirectoryTestCase extends ESTestCase { } private static String getFromProperty(String port) { - String key = "test.fixtures.smb-fixture.fixture." + port; + String key = "test.fixtures.smb-fixture.tcp." + port; final String value = System.getProperty(key); - assertNotNull("Expected the actual value for " + port + " to be in system property " + key, value); + assertNotNull("Expected the actual value for port " + port + " to be in system property " + key, value); return value; } } diff --git a/x-pack/test/smb-fixture/docker-compose.yml b/x-pack/test/smb-fixture/docker-compose.yml index a2c11cb5012..51a76fd42b4 100644 --- a/x-pack/test/smb-fixture/docker-compose.yml +++ b/x-pack/test/smb-fixture/docker-compose.yml @@ -1,6 +1,6 @@ version: '3' services: - fixture: + smb-fixture: build: context: . dockerfile: Dockerfile