Commit b152b98f authored by Andy Wilkinson's avatar Andy Wilkinson

Improve diagnostics in DevTools integration tests

See gh-10454
parent 5cf48a29
...@@ -142,9 +142,11 @@ public class DevToolsIntegrationTests { ...@@ -142,9 +142,11 @@ public class DevToolsIntegrationTests {
if (System.currentTimeMillis() > end) { if (System.currentTimeMillis() > end) {
throw new IllegalStateException(String.format( throw new IllegalStateException(String.format(
"server.port file was not written within 30 seconds. " "server.port file was not written within 30 seconds. "
+ "Application output:%n%s", + "Application output:%n%s%s",
FileCopyUtils.copyToString(new FileReader( FileCopyUtils.copyToString(new FileReader(
this.launchedApplication.getStandardOut())))); this.launchedApplication.getStandardOut())),
FileCopyUtils.copyToString(new FileReader(
this.launchedApplication.getStandardError()))));
} }
Thread.sleep(100); Thread.sleep(100);
} }
......
...@@ -49,10 +49,10 @@ class JvmLauncher implements TestRule { ...@@ -49,10 +49,10 @@ class JvmLauncher implements TestRule {
.asList(System.getProperty("java.home") + "/bin/java", "-cp", classpath)); .asList(System.getProperty("java.home") + "/bin/java", "-cp", classpath));
command.addAll(Arrays.asList(args)); command.addAll(Arrays.asList(args));
File standardOut = new File(this.outputDirectory, name + ".out"); File standardOut = new File(this.outputDirectory, name + ".out");
File standardError = new File(this.outputDirectory, name + ".err");
Process process = new ProcessBuilder(command.toArray(new String[command.size()])) Process process = new ProcessBuilder(command.toArray(new String[command.size()]))
.redirectError(new File(this.outputDirectory, name + ".err")) .redirectError(standardError).redirectOutput(standardOut).start();
.redirectOutput(standardOut).start(); return new LaunchedJvm(process, standardOut, standardError);
return new LaunchedJvm(process, standardOut);
} }
static class LaunchedJvm { static class LaunchedJvm {
...@@ -61,9 +61,12 @@ class JvmLauncher implements TestRule { ...@@ -61,9 +61,12 @@ class JvmLauncher implements TestRule {
private final File standardOut; private final File standardOut;
LaunchedJvm(Process process, File standardOut) { private final File standardError;
LaunchedJvm(Process process, File standardOut, File standardError) {
this.process = process; this.process = process;
this.standardOut = standardOut; this.standardOut = standardOut;
this.standardError = standardError;
} }
Process getProcess() { Process getProcess() {
...@@ -74,6 +77,10 @@ class JvmLauncher implements TestRule { ...@@ -74,6 +77,10 @@ class JvmLauncher implements TestRule {
return this.standardOut; return this.standardOut;
} }
File getStandardError() {
return this.standardError;
}
} }
} }
...@@ -29,11 +29,15 @@ class LaunchedApplication { ...@@ -29,11 +29,15 @@ class LaunchedApplication {
private final File standardOut; private final File standardOut;
private final File standardError;
private final Process[] processes; private final Process[] processes;
LaunchedApplication(File classesDirectory, File standardOut, Process... processes) { LaunchedApplication(File classesDirectory, File standardOut, File standardError,
Process... processes) {
this.classesDirectory = classesDirectory; this.classesDirectory = classesDirectory;
this.standardOut = standardOut; this.standardOut = standardOut;
this.standardError = standardError;
this.processes = processes; this.processes = processes;
} }
...@@ -48,6 +52,10 @@ class LaunchedApplication { ...@@ -48,6 +52,10 @@ class LaunchedApplication {
return this.standardOut; return this.standardOut;
} }
File getStandardError() {
return this.standardError;
}
File getClassesDirectory() { File getClassesDirectory() {
return this.classesDirectory; return this.classesDirectory;
} }
......
...@@ -37,7 +37,7 @@ public class LocalApplicationLauncher implements ApplicationLauncher { ...@@ -37,7 +37,7 @@ public class LocalApplicationLauncher implements ApplicationLauncher {
LaunchedJvm jvm = jvmLauncher.launch("local", createApplicationClassPath(), LaunchedJvm jvm = jvmLauncher.launch("local", createApplicationClassPath(),
"com.example.DevToolsTestApplication", "--server.port=0"); "com.example.DevToolsTestApplication", "--server.port=0");
return new LaunchedApplication(new File("target/app"), jvm.getStandardOut(), return new LaunchedApplication(new File("target/app"), jvm.getStandardOut(),
jvm.getProcess()); jvm.getStandardError(), jvm.getProcess());
} }
protected String createApplicationClassPath() throws Exception { protected String createApplicationClassPath() throws Exception {
......
...@@ -48,8 +48,8 @@ abstract class RemoteApplicationLauncher implements ApplicationLauncher { ...@@ -48,8 +48,8 @@ abstract class RemoteApplicationLauncher implements ApplicationLauncher {
"--spring.devtools.remote.secret=secret", "http://localhost:12345"); "--spring.devtools.remote.secret=secret", "http://localhost:12345");
awaitRemoteSpringApplication(remoteSpringApplicationJvm.getStandardOut()); awaitRemoteSpringApplication(remoteSpringApplicationJvm.getStandardOut());
return new LaunchedApplication(new File("target/remote"), return new LaunchedApplication(new File("target/remote"),
applicationJvm.getStandardOut(), applicationJvm.getProcess(), applicationJvm.getStandardOut(), applicationJvm.getStandardError(),
remoteSpringApplicationJvm.getProcess()); applicationJvm.getProcess(), remoteSpringApplicationJvm.getProcess());
} }
protected abstract String createApplicationClassPath() throws Exception; protected abstract String createApplicationClassPath() throws Exception;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment