From 3d908079efd781c37574e59058c2ac29db0d3290 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 13 Jan 2022 16:33:10 -0800 Subject: [PATCH] Run LoaderIntegrationTests against multiple JDKs Update `LoaderIntegrationTests` to run against OpenJDK 8, 11 and 17 as well as Oracle JDK 17. Closes gh-29385 --- .../boot/loader/LoaderIntegrationTests.java | 76 ++++++++++++++----- .../resources/conf/oracle-jdk-17/Dockerfile | 8 ++ .../resources/conf/oracle-jdk-17/README.adoc | 5 ++ 3 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile create mode 100644 spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/README.adoc diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java index 1abe0c519c..ae80cbc280 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,17 @@ package org.springframework.boot.loader; import java.io.File; import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Stream; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.output.ToStringConsumer; import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.utility.DockerImageName; import org.testcontainers.utility.MountableFile; @@ -37,31 +41,67 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Phillip Webb */ -@Testcontainers(disabledWithoutDocker = true) class LoaderIntegrationTests { - private static final DockerImageName JRE = DockerImageName.parse("adoptopenjdk:15-jre-hotspot"); + private final ToStringConsumer output = new ToStringConsumer(); - private static ToStringConsumer output = new ToStringConsumer(); + @ParameterizedTest + @MethodSource("javaRuntimes") + void readUrlsWithoutWarning(JavaRuntime javaRuntime) { + try (GenericContainer container = createContainer(javaRuntime)) { + container.start(); + System.out.println(this.output.toUtf8String()); + assertThat(this.output.toUtf8String()).contains(">>>>> 287649 BYTES from").doesNotContain("WARNING:") + .doesNotContain("illegal").doesNotContain("jar written to temp"); + } + } - @Container - public static GenericContainer container = new GenericContainer<>(JRE).withLogConsumer(output) - .withCopyFileToContainer(MountableFile.forHostPath(findApplication().toPath()), "/app.jar") - .withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5))) - .withCommand("java", "-jar", "app.jar"); + private GenericContainer createContainer(JavaRuntime javaRuntime) { + return javaRuntime.getContainer().withLogConsumer(this.output) + .withCopyFileToContainer(MountableFile.forHostPath(findApplication().toPath()), "/app.jar") + .withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5))) + .withCommand("java", "-jar", "app.jar"); + } - private static File findApplication() { + private File findApplication() { String name = String.format("build/%1$s/build/libs/%1$s.jar", "spring-boot-loader-tests-app"); File jar = new File(name); Assert.state(jar.isFile(), () -> "Could not find " + name + ". Have you built it?"); return jar; } - @Test - void readUrlsWithoutWarning() { - System.out.println(output.toUtf8String()); - assertThat(output.toUtf8String()).contains(">>>>> 287649 BYTES from").doesNotContain("WARNING:") - .doesNotContain("illegal").doesNotContain("jar written to temp"); + static Stream javaRuntimes() { + List javaRuntimes = new ArrayList<>(); + javaRuntimes.add(JavaRuntime.openJdk("8")); + javaRuntimes.add(JavaRuntime.openJdk("11")); + javaRuntimes.add(JavaRuntime.openJdk("17")); + javaRuntimes.add(JavaRuntime.oracleJdk17()); + return javaRuntimes.stream(); + } + + static final class JavaRuntime { + + private final Supplier> container; + + private JavaRuntime(Supplier> container) { + this.container = container; + } + + GenericContainer getContainer() { + return this.container.get(); + } + + static JavaRuntime openJdk(String version) { + DockerImageName image = DockerImageName.parse("bellsoft/liberica-openjdk-debian:" + version); + return new JavaRuntime(() -> new GenericContainer<>(image)); + } + + static JavaRuntime oracleJdk17() { + ImageFromDockerfile image = new ImageFromDockerfile("spring-boot-loader/oracle-jdk-17") + .withFileFromFile("Dockerfile", new File("src/intTest/resources/conf/oracle-jdk-17/Dockerfile")); + return new JavaRuntime(() -> new GenericContainer<>(image)); + } + } } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile new file mode 100644 index 0000000000..18106a8864 --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:focal-20211006 +RUN apt-get update && \ + apt-get install -y software-properties-common curl && \ + mkdir -p /opt/oraclejdk && \ + cd /opt/oraclejdk && \ + curl -L https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz | tar zx --strip-components=1 +ENV JAVA_HOME /opt/oraclejdk +ENV PATH $JAVA_HOME/bin:$PATH diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/README.adoc b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/README.adoc new file mode 100644 index 0000000000..28704af225 --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/README.adoc @@ -0,0 +1,5 @@ +This folder contains a Dockerfile that will create an Oracle JDK instance for use in integration tests. +The resulting Docker image should not be published. + +Oracle JDK is subject to the https://www.oracle.com/downloads/licenses/no-fee-license.html["Oracle No-Fee Terms and Conditions" License (NFTC)] license. +We are specifically using the unmodified JDK for the purposes of developing and testing.