diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java index 79400a0a71..14df5ee402 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java @@ -156,6 +156,7 @@ class JavaConventions { project.getTasks().withType(Test.class, (test) -> { test.useJUnitPlatform(); test.setMaxHeapSize("1024M"); + test.setMaxParallelForks(project.getGradle().getStartParameter().getMaxWorkerCount()); project.getTasks().withType(Checkstyle.class, (checkstyle) -> test.mustRunAfter(checkstyle)); project.getTasks().withType(CheckFormat.class, (checkFormat) -> test.mustRunAfter(checkFormat)); }); diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java index b87a2cf294..b60b41e220 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java @@ -29,8 +29,8 @@ import org.awaitility.Awaitility; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; -import org.springframework.boot.testsupport.BuildOutput; import org.springframework.util.FileCopyUtils; +import org.springframework.util.FileSystemUtils; import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; @@ -43,15 +43,15 @@ abstract class AbstractApplicationLauncher implements BeforeEachCallback { private final Application application; - private final BuildOutput buildOutput; + private final File outputLocation; private Process process; private int httpPort; - protected AbstractApplicationLauncher(Application application, BuildOutput buildOutput) { + protected AbstractApplicationLauncher(Application application, File outputLocation) { this.application = application; - this.buildOutput = buildOutput; + this.outputLocation = outputLocation; } @Override @@ -71,6 +71,7 @@ abstract class AbstractApplicationLauncher implements BeforeEachCallback { Thread.currentThread().interrupt(); } } + FileSystemUtils.deleteRecursively(this.outputLocation); } final int getHttpPort() { @@ -85,7 +86,7 @@ abstract class AbstractApplicationLauncher implements BeforeEachCallback { private Process startApplication() throws Exception { File workingDirectory = getWorkingDirectory(); - File serverPortFile = new File(this.buildOutput.getRootLocation(), "server.port"); + File serverPortFile = new File(this.outputLocation, "server.port"); serverPortFile.delete(); File archive = new File("build/spring-boot-server-tests-app/build/libs/spring-boot-server-tests-app-" + this.application.getContainer() + "." + this.application.getPackaging()); diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java index 740eb7b3c9..35f5a9f7ea 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import org.springframework.boot.testsupport.BuildOutput; import org.springframework.util.FileCopyUtils; import org.springframework.util.FileSystemUtils; import org.springframework.util.StreamUtils; @@ -43,9 +42,9 @@ class BootRunApplicationLauncher extends AbstractApplicationLauncher { private final File exploded; - BootRunApplicationLauncher(Application application, BuildOutput buildOutput) { - super(application, buildOutput); - this.exploded = new File(buildOutput.getRootLocation(), "run"); + BootRunApplicationLauncher(Application application, File outputLocation) { + super(application, outputLocation); + this.exploded = new File(outputLocation, "run"); } @Override diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java index a867f5f22a..4f883f866d 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java @@ -16,6 +16,7 @@ package org.springframework.boot.context.embedded; +import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.file.Files; @@ -26,6 +27,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.stream.Stream; import org.apache.http.impl.client.HttpClients; @@ -110,7 +112,8 @@ class EmbeddedServerContainerInvocationContextProvider if (this.launcherCache.containsKey(cacheKey)) { return this.launcherCache.get(cacheKey); } - AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, application, buildOutput); + AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, application, + new File(buildOutput.getRootLocation(), "app-launcher-" + UUID.randomUUID())); this.launcherCache.put(cacheKey, launcher); return launcher; } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java index d9e2eb1cd2..dc8fb37a0c 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java @@ -22,11 +22,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.Enumeration; import java.util.List; -import java.util.function.Supplier; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import org.springframework.boot.testsupport.BuildOutput; import org.springframework.util.FileSystemUtils; import org.springframework.util.StreamUtils; @@ -38,16 +36,16 @@ import org.springframework.util.StreamUtils; */ class ExplodedApplicationLauncher extends AbstractApplicationLauncher { - private final Supplier exploded; + private final File exploded; - ExplodedApplicationLauncher(Application application, BuildOutput buildOutput) { - super(application, buildOutput); - this.exploded = () -> new File(buildOutput.getRootLocation(), "exploded"); + ExplodedApplicationLauncher(Application application, File outputLocation) { + super(application, outputLocation); + this.exploded = new File(outputLocation, "exploded"); } @Override protected File getWorkingDirectory() { - return this.exploded.get(); + return this.exploded; } @Override @@ -61,8 +59,7 @@ class ExplodedApplicationLauncher extends AbstractApplicationLauncher { : "org.springframework.boot.loader.JarLauncher"); try { explodeArchive(archive); - return Arrays.asList("-cp", this.exploded.get().getAbsolutePath(), mainClass, - serverPortFile.getAbsolutePath()); + return Arrays.asList("-cp", this.exploded.getAbsolutePath(), mainClass, serverPortFile.getAbsolutePath()); } catch (IOException ex) { throw new RuntimeException(ex); @@ -70,12 +67,12 @@ class ExplodedApplicationLauncher extends AbstractApplicationLauncher { } private void explodeArchive(File archive) throws IOException { - FileSystemUtils.deleteRecursively(this.exploded.get()); + FileSystemUtils.deleteRecursively(this.exploded); JarFile jarFile = new JarFile(archive); Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); - File extracted = new File(this.exploded.get(), jarEntry.getName()); + File extracted = new File(this.exploded, jarEntry.getName()); if (jarEntry.isDirectory()) { extracted.mkdirs(); } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java index b2320d06a2..29f7fad067 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import org.springframework.boot.testsupport.BuildOutput; import org.springframework.util.FileCopyUtils; import org.springframework.util.FileSystemUtils; import org.springframework.util.StreamUtils; @@ -43,9 +42,9 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher { private final File exploded; - IdeApplicationLauncher(Application application, BuildOutput buildOutput) { - super(application, buildOutput); - this.exploded = new File(buildOutput.getRootLocation(), "the+ide application"); + IdeApplicationLauncher(Application application, File outputLocation) { + super(application, outputLocation); + this.exploded = new File(outputLocation, "the+ide application"); } @Override diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java index 84a3d5325d..5d68fea058 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java @@ -20,8 +20,6 @@ import java.io.File; import java.util.Arrays; import java.util.List; -import org.springframework.boot.testsupport.BuildOutput; - /** * {@link AbstractApplicationLauncher} that launches a packaged Spring Boot application * using {@code java -jar}. @@ -30,8 +28,8 @@ import org.springframework.boot.testsupport.BuildOutput; */ class PackagedApplicationLauncher extends AbstractApplicationLauncher { - PackagedApplicationLauncher(Application application, BuildOutput buildOutput) { - super(application, buildOutput); + PackagedApplicationLauncher(Application application, File outputLocation) { + super(application, outputLocation); } @Override