From 04a531dcfa6c77305a05d97d6477fc553b666cde Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 8 Jul 2020 15:23:59 -0700 Subject: [PATCH] Use consistent system jdk in 7.x packaging tests (#59257) In 7.x, we have java 8 as minimum jdk version. In the past, for packaging tests, we relied on the system to provide an alternative jdk to be used by the no-jdk distributions. Master switched to using a build provided jdk, but 7.x was stuck relying on the system because it needed a java 8 jdk. The jdk download plugin was updated a while ago to support jdk 8, and so this PR converts the distro tests to use the build provided jdk just as master branch does. Note also this fixes a failure that would sometimes occur on older jdks in windows where the expected gc filename can be different. --- .../org/elasticsearch/gradle/test/DistroTestPlugin.java | 6 +++++- .../org/elasticsearch/packaging/test/ArchiveTests.java | 5 +++-- .../elasticsearch/packaging/test/PackagingTestCase.java | 8 ++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java index 321929819a6..bd635a4f673 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java @@ -71,6 +71,8 @@ import static org.elasticsearch.gradle.vagrant.VagrantMachine.convertLinuxPath; import static org.elasticsearch.gradle.vagrant.VagrantMachine.convertWindowsPath; public class DistroTestPlugin implements Plugin { + private static final String SYSTEM_JDK_VERSION = "8u242+b08"; + private static final String SYSTEM_JDK_VENDOR = "adoptopenjdk"; private static final String GRADLE_JDK_VERSION = "14+36@076bab302c7b4508975440c56f6cc26a"; private static final String GRADLE_JDK_VENDOR = "openjdk"; @@ -231,11 +233,13 @@ public class DistroTestPlugin implements Plugin { NamedDomainObjectContainer jdksContainer = JdkDownloadPlugin.getContainer(project); String platform = box.contains("windows") ? "windows" : "linux"; + Jdk systemJdk = createJdk(jdksContainer, "system", SYSTEM_JDK_VENDOR, SYSTEM_JDK_VERSION, platform, "x64"); Jdk gradleJdk = createJdk(jdksContainer, "gradle", GRADLE_JDK_VENDOR, GRADLE_JDK_VERSION, platform, "x64"); // setup VM used by these tests VagrantExtension vagrant = project.getExtensions().getByType(VagrantExtension.class); vagrant.setBox(box); + vagrant.vmEnv("SYSTEM_JAVA_HOME", convertPath(project, vagrant, systemJdk, "", "")); vagrant.vmEnv("PATH", convertPath(project, vagrant, gradleJdk, "/bin:$PATH", "\\bin;$Env:PATH")); // pass these along to get correct build scans if (System.getenv("JENKINS_URL") != null) { @@ -243,7 +247,7 @@ public class DistroTestPlugin implements Plugin { } vagrant.setIsWindowsVM(isWindows(project)); - return Arrays.asList(gradleJdk); + return Arrays.asList(systemJdk, gradleJdk); } private static Object convertPath(Project project, VagrantExtension vagrant, Jdk jdk, String additionaLinux, String additionalWindows) { diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java b/qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java index 4a0281dd48c..786bce6d471 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java @@ -46,6 +46,7 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assume.assumeThat; @@ -134,8 +135,8 @@ public class ArchiveTests extends PackagingTestCase { throw e; } - final String gcLogName = distribution().hasJdk == false ? "gc.log.0.current" : "gc.log"; - assertThat(installation.logs.resolve(gcLogName), fileExists()); + List gcLogs = FileUtils.lsGlob(installation.logs, "gc.log*"); + assertThat(gcLogs, is(not(empty()))); ServerUtils.runElasticsearchTests(); stopElasticsearch(); diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/test/PackagingTestCase.java b/qa/os/src/test/java/org/elasticsearch/packaging/test/PackagingTestCase.java index 5097f17b565..eed0d13e317 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/test/PackagingTestCase.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/test/PackagingTestCase.java @@ -176,11 +176,15 @@ public abstract class PackagingTestCase extends Assert { @After public void teardown() throws Exception { - // move log file so we can avoid false positives when grepping for - // messages in logs during test if (installation != null && failed == false) { if (Files.exists(installation.logs)) { Path logFile = installation.logs.resolve("elasticsearch.log"); + if (Files.exists(logFile)) { + logger.warn("Elasticsearch log:\n" + FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz")); + } + + // move log file so we can avoid false positives when grepping for + // messages in logs during test String prefix = this.getClass().getSimpleName() + "." + testNameRule.getMethodName(); if (Files.exists(logFile)) { Path newFile = installation.logs.resolve(prefix + ".elasticsearch.log");