Skip to content

Commit 22d85e6

Browse files
committed
Allow tests to be run in parallel across multiple workers
Closes gh-19876
1 parent 2462f67 commit 22d85e6

File tree

7 files changed

+27
-29
lines changed

7 files changed

+27
-29
lines changed

buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private void configureTestConventions(Project project) {
156156
project.getTasks().withType(Test.class, (test) -> {
157157
test.useJUnitPlatform();
158158
test.setMaxHeapSize("1024M");
159+
test.setMaxParallelForks(project.getGradle().getStartParameter().getMaxWorkerCount());
159160
project.getTasks().withType(Checkstyle.class, (checkstyle) -> test.mustRunAfter(checkstyle));
160161
project.getTasks().withType(CheckFormat.class, (checkFormat) -> test.mustRunAfter(checkFormat));
161162
});

spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import org.junit.jupiter.api.extension.BeforeEachCallback;
3030
import org.junit.jupiter.api.extension.ExtensionContext;
3131

32-
import org.springframework.boot.testsupport.BuildOutput;
3332
import org.springframework.util.FileCopyUtils;
33+
import org.springframework.util.FileSystemUtils;
3434
import org.springframework.util.StreamUtils;
3535
import org.springframework.util.StringUtils;
3636

@@ -43,15 +43,15 @@ abstract class AbstractApplicationLauncher implements BeforeEachCallback {
4343

4444
private final Application application;
4545

46-
private final BuildOutput buildOutput;
46+
private final File outputLocation;
4747

4848
private Process process;
4949

5050
private int httpPort;
5151

52-
protected AbstractApplicationLauncher(Application application, BuildOutput buildOutput) {
52+
protected AbstractApplicationLauncher(Application application, File outputLocation) {
5353
this.application = application;
54-
this.buildOutput = buildOutput;
54+
this.outputLocation = outputLocation;
5555
}
5656

5757
@Override
@@ -71,6 +71,7 @@ void destroyProcess() {
7171
Thread.currentThread().interrupt();
7272
}
7373
}
74+
FileSystemUtils.deleteRecursively(this.outputLocation);
7475
}
7576

7677
final int getHttpPort() {
@@ -85,7 +86,7 @@ final int getHttpPort() {
8586

8687
private Process startApplication() throws Exception {
8788
File workingDirectory = getWorkingDirectory();
88-
File serverPortFile = new File(this.buildOutput.getRootLocation(), "server.port");
89+
File serverPortFile = new File(this.outputLocation, "server.port");
8990
serverPortFile.delete();
9091
File archive = new File("build/spring-boot-server-tests-app/build/libs/spring-boot-server-tests-app-"
9192
+ this.application.getContainer() + "." + this.application.getPackaging());

spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.jar.JarEntry;
2828
import java.util.jar.JarFile;
2929

30-
import org.springframework.boot.testsupport.BuildOutput;
3130
import org.springframework.util.FileCopyUtils;
3231
import org.springframework.util.FileSystemUtils;
3332
import org.springframework.util.StreamUtils;
@@ -43,9 +42,9 @@ class BootRunApplicationLauncher extends AbstractApplicationLauncher {
4342

4443
private final File exploded;
4544

46-
BootRunApplicationLauncher(Application application, BuildOutput buildOutput) {
47-
super(application, buildOutput);
48-
this.exploded = new File(buildOutput.getRootLocation(), "run");
45+
BootRunApplicationLauncher(Application application, File outputLocation) {
46+
super(application, outputLocation);
47+
this.exploded = new File(outputLocation, "run");
4948
}
5049

5150
@Override

spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.context.embedded;
1818

19+
import java.io.File;
1920
import java.io.IOException;
2021
import java.net.URI;
2122
import java.nio.file.Files;
@@ -26,6 +27,7 @@
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.Set;
30+
import java.util.UUID;
2931
import java.util.stream.Stream;
3032

3133
import org.apache.http.impl.client.HttpClients;
@@ -110,7 +112,8 @@ private AbstractApplicationLauncher getAbstractApplicationLauncher(Application a
110112
if (this.launcherCache.containsKey(cacheKey)) {
111113
return this.launcherCache.get(cacheKey);
112114
}
113-
AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, application, buildOutput);
115+
AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, application,
116+
new File(buildOutput.getRootLocation(), "app-launcher-" + UUID.randomUUID()));
114117
this.launcherCache.put(cacheKey, launcher);
115118
return launcher;
116119
}

spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
import java.util.Arrays;
2323
import java.util.Enumeration;
2424
import java.util.List;
25-
import java.util.function.Supplier;
2625
import java.util.jar.JarEntry;
2726
import java.util.jar.JarFile;
2827

29-
import org.springframework.boot.testsupport.BuildOutput;
3028
import org.springframework.util.FileSystemUtils;
3129
import org.springframework.util.StreamUtils;
3230

@@ -38,16 +36,16 @@
3836
*/
3937
class ExplodedApplicationLauncher extends AbstractApplicationLauncher {
4038

41-
private final Supplier<File> exploded;
39+
private final File exploded;
4240

43-
ExplodedApplicationLauncher(Application application, BuildOutput buildOutput) {
44-
super(application, buildOutput);
45-
this.exploded = () -> new File(buildOutput.getRootLocation(), "exploded");
41+
ExplodedApplicationLauncher(Application application, File outputLocation) {
42+
super(application, outputLocation);
43+
this.exploded = new File(outputLocation, "exploded");
4644
}
4745

4846
@Override
4947
protected File getWorkingDirectory() {
50-
return this.exploded.get();
48+
return this.exploded;
5149
}
5250

5351
@Override
@@ -61,21 +59,20 @@ protected List<String> getArguments(File archive, File serverPortFile) {
6159
: "org.springframework.boot.loader.JarLauncher");
6260
try {
6361
explodeArchive(archive);
64-
return Arrays.asList("-cp", this.exploded.get().getAbsolutePath(), mainClass,
65-
serverPortFile.getAbsolutePath());
62+
return Arrays.asList("-cp", this.exploded.getAbsolutePath(), mainClass, serverPortFile.getAbsolutePath());
6663
}
6764
catch (IOException ex) {
6865
throw new RuntimeException(ex);
6966
}
7067
}
7168

7269
private void explodeArchive(File archive) throws IOException {
73-
FileSystemUtils.deleteRecursively(this.exploded.get());
70+
FileSystemUtils.deleteRecursively(this.exploded);
7471
JarFile jarFile = new JarFile(archive);
7572
Enumeration<JarEntry> entries = jarFile.entries();
7673
while (entries.hasMoreElements()) {
7774
JarEntry jarEntry = entries.nextElement();
78-
File extracted = new File(this.exploded.get(), jarEntry.getName());
75+
File extracted = new File(this.exploded, jarEntry.getName());
7976
if (jarEntry.isDirectory()) {
8077
extracted.mkdirs();
8178
}

spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.jar.JarEntry;
2828
import java.util.jar.JarFile;
2929

30-
import org.springframework.boot.testsupport.BuildOutput;
3130
import org.springframework.util.FileCopyUtils;
3231
import org.springframework.util.FileSystemUtils;
3332
import org.springframework.util.StreamUtils;
@@ -43,9 +42,9 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher {
4342

4443
private final File exploded;
4544

46-
IdeApplicationLauncher(Application application, BuildOutput buildOutput) {
47-
super(application, buildOutput);
48-
this.exploded = new File(buildOutput.getRootLocation(), "the+ide application");
45+
IdeApplicationLauncher(Application application, File outputLocation) {
46+
super(application, outputLocation);
47+
this.exploded = new File(outputLocation, "the+ide application");
4948
}
5049

5150
@Override

spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23-
import org.springframework.boot.testsupport.BuildOutput;
24-
2523
/**
2624
* {@link AbstractApplicationLauncher} that launches a packaged Spring Boot application
2725
* using {@code java -jar}.
@@ -30,8 +28,8 @@
3028
*/
3129
class PackagedApplicationLauncher extends AbstractApplicationLauncher {
3230

33-
PackagedApplicationLauncher(Application application, BuildOutput buildOutput) {
34-
super(application, buildOutput);
31+
PackagedApplicationLauncher(Application application, File outputLocation) {
32+
super(application, outputLocation);
3533
}
3634

3735
@Override

0 commit comments

Comments
 (0)