From 69cbf1318c2c63fcbf73ede9ba01e7dc37a3ccaf Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 29 Mar 2018 19:54:41 -0700 Subject: [PATCH] Second attempt to fix server test CI failures Switch process redirection off and instead consume streams and copy to System.out/System.err. See gh-12689 --- .../embedded/AbstractApplicationLauncher.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java index c1d006e721e..14f14f04668 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java @@ -18,13 +18,16 @@ package org.springframework.boot.context.embedded; import java.io.File; import java.io.FileReader; -import java.lang.ProcessBuilder.Redirect; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; import java.util.ArrayList; import java.util.List; import org.junit.rules.ExternalResource; import org.springframework.util.FileCopyUtils; +import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; /** @@ -76,12 +79,12 @@ abstract class AbstractApplicationLauncher extends ExternalResource { arguments.addAll(getArguments(archive)); ProcessBuilder processBuilder = new ProcessBuilder( StringUtils.toStringArray(arguments)); - processBuilder.redirectOutput(Redirect.INHERIT); - processBuilder.redirectError(Redirect.INHERIT); if (workingDirectory != null) { processBuilder.directory(workingDirectory); } Process process = processBuilder.start(); + new ConsoleCopy(process.getInputStream(), System.out).start(); + new ConsoleCopy(process.getErrorStream(), System.err).start(); this.httpPort = awaitServerPort(process, serverPortFile); return process; } @@ -102,4 +105,26 @@ abstract class AbstractApplicationLauncher extends ExternalResource { .parseInt(FileCopyUtils.copyToString(new FileReader(serverPortFile))); } + private static class ConsoleCopy extends Thread { + + private final InputStream input; + + private final PrintStream output; + + ConsoleCopy(InputStream input, PrintStream output) { + this.input = input; + this.output = output; + } + + @Override + public void run() { + try { + StreamUtils.copy(this.input, this.output); + } + catch (IOException ex) { + } + } + + } + }