Merge branch '2.5.x' into 2.6.x

Closes gh-29462
pull/30003/head
Phillip Webb 3 years ago
commit 44537d4494

@ -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<JavaRuntime> javaRuntimes() {
List<JavaRuntime> 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<GenericContainer<?>> container;
private JavaRuntime(Supplier<GenericContainer<?>> 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));
}
}
}

@ -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

@ -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.
Loading…
Cancel
Save