Merge branch '1.5.x'
This commit is contained in:
commit
3c873b08fc
|
|
@ -23,6 +23,6 @@ package org.springframework.boot.devtools.tests;
|
||||||
*/
|
*/
|
||||||
public interface ApplicationLauncher {
|
public interface ApplicationLauncher {
|
||||||
|
|
||||||
LaunchedApplication launchApplication(JavaLauncher javaLauncher) throws Exception;
|
LaunchedApplication launchApplication(JvmLauncher javaLauncher) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public class DevToolsIntegrationTests {
|
||||||
private final ApplicationLauncher applicationLauncher;
|
private final ApplicationLauncher applicationLauncher;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public JavaLauncher javaLauncher = new JavaLauncher();
|
public JvmLauncher javaLauncher = new JvmLauncher();
|
||||||
|
|
||||||
@Parameters(name = "{0}")
|
@Parameters(name = "{0}")
|
||||||
public static Object[] parameters() {
|
public static Object[] parameters() {
|
||||||
|
|
@ -106,7 +106,6 @@ public class DevToolsIntegrationTests {
|
||||||
controller("com.example.ControllerOne").build();
|
controller("com.example.ControllerOne").build();
|
||||||
assertThat(template.getForEntity("http://localhost:" + awaitServerPort() + "/one",
|
assertThat(template.getForEntity("http://localhost:" + awaitServerPort() + "/one",
|
||||||
String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
String.class).getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -138,11 +137,14 @@ public class DevToolsIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int awaitServerPort() throws Exception {
|
private int awaitServerPort() throws Exception {
|
||||||
long end = System.currentTimeMillis() + 20000;
|
long end = System.currentTimeMillis() + 30000;
|
||||||
while (this.serverPortFile.length() == 0) {
|
while (this.serverPortFile.length() == 0) {
|
||||||
if (System.currentTimeMillis() > end) {
|
if (System.currentTimeMillis() > end) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(String.format(
|
||||||
"server.port file was not written within 20 seconds");
|
"server.port file was not written within 30 seconds. "
|
||||||
|
+ "Application output:%n%s",
|
||||||
|
FileCopyUtils.copyToString(new FileReader(
|
||||||
|
this.launchedApplication.getStandardOut()))));
|
||||||
}
|
}
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,12 @@ import org.junit.runner.Description;
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author awilkinson
|
* JUnit {@link TestRule} that launched a JVM and redirects its output to a test
|
||||||
|
* method-specific location.
|
||||||
|
*
|
||||||
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
public class JavaLauncher implements TestRule {
|
class JvmLauncher implements TestRule {
|
||||||
|
|
||||||
private File outputDirectory;
|
private File outputDirectory;
|
||||||
|
|
||||||
|
|
@ -41,13 +44,36 @@ public class JavaLauncher implements TestRule {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process launch(String name, String classpath, String... args) throws IOException {
|
LaunchedJvm launch(String name, String classpath, String... args) throws IOException {
|
||||||
List<String> command = new ArrayList<String>(Arrays
|
List<String> command = new ArrayList<String>(Arrays
|
||||||
.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));
|
||||||
return new ProcessBuilder(command.toArray(new String[command.size()]))
|
File standardOut = new File(this.outputDirectory, name + ".out");
|
||||||
|
Process process = new ProcessBuilder(command.toArray(new String[command.size()]))
|
||||||
.redirectError(new File(this.outputDirectory, name + ".err"))
|
.redirectError(new File(this.outputDirectory, name + ".err"))
|
||||||
.redirectOutput(new File(this.outputDirectory, name + ".out")).start();
|
.redirectOutput(standardOut).start();
|
||||||
|
return new LaunchedJvm(process, standardOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class LaunchedJvm {
|
||||||
|
|
||||||
|
private final Process process;
|
||||||
|
|
||||||
|
private final File standardOut;
|
||||||
|
|
||||||
|
LaunchedJvm(Process process, File standardOut) {
|
||||||
|
this.process = process;
|
||||||
|
this.standardOut = standardOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
Process getProcess() {
|
||||||
|
return this.process;
|
||||||
|
}
|
||||||
|
|
||||||
|
File getStandardOut() {
|
||||||
|
return this.standardOut;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -27,10 +27,13 @@ class LaunchedApplication {
|
||||||
|
|
||||||
private final File classesDirectory;
|
private final File classesDirectory;
|
||||||
|
|
||||||
|
private final File standardOut;
|
||||||
|
|
||||||
private final Process[] processes;
|
private final Process[] processes;
|
||||||
|
|
||||||
LaunchedApplication(File classesDirectory, Process... processes) {
|
LaunchedApplication(File classesDirectory, File standardOut, Process... processes) {
|
||||||
this.classesDirectory = classesDirectory;
|
this.classesDirectory = classesDirectory;
|
||||||
|
this.standardOut = standardOut;
|
||||||
this.processes = processes;
|
this.processes = processes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,6 +43,10 @@ class LaunchedApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File getStandardOut() {
|
||||||
|
return this.standardOut;
|
||||||
|
}
|
||||||
|
|
||||||
File getClassesDirectory() {
|
File getClassesDirectory() {
|
||||||
return this.classesDirectory;
|
return this.classesDirectory;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm;
|
||||||
import org.springframework.util.FileSystemUtils;
|
import org.springframework.util.FileSystemUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
|
@ -31,11 +32,12 @@ import org.springframework.util.StringUtils;
|
||||||
public class LocalApplicationLauncher implements ApplicationLauncher {
|
public class LocalApplicationLauncher implements ApplicationLauncher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LaunchedApplication launchApplication(JavaLauncher javaLauncher)
|
public LaunchedApplication launchApplication(JvmLauncher jvmLauncher)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Process process = javaLauncher.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"), process);
|
return new LaunchedApplication(new File("target/app"), jvm.getStandardOut(),
|
||||||
|
jvm.getProcess());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createApplicationClassPath() throws Exception {
|
protected String createApplicationClassPath() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.boot.devtools.RemoteSpringApplication;
|
import org.springframework.boot.devtools.RemoteSpringApplication;
|
||||||
|
import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm;
|
||||||
import org.springframework.util.FileSystemUtils;
|
import org.springframework.util.FileSystemUtils;
|
||||||
import org.springframework.util.SocketUtils;
|
import org.springframework.util.SocketUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
@ -34,18 +35,19 @@ import org.springframework.util.StringUtils;
|
||||||
abstract class RemoteApplicationLauncher implements ApplicationLauncher {
|
abstract class RemoteApplicationLauncher implements ApplicationLauncher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LaunchedApplication launchApplication(JavaLauncher javaLauncher)
|
public LaunchedApplication launchApplication(JvmLauncher javaLauncher)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
int port = SocketUtils.findAvailableTcpPort();
|
int port = SocketUtils.findAvailableTcpPort();
|
||||||
Process application = javaLauncher.launch("app", createApplicationClassPath(),
|
LaunchedJvm applicationJvm = javaLauncher.launch("app",
|
||||||
"com.example.DevToolsTestApplication", "--server.port=" + port,
|
createApplicationClassPath(), "com.example.DevToolsTestApplication",
|
||||||
"--spring.devtools.remote.secret=secret");
|
"--server.port=" + port, "--spring.devtools.remote.secret=secret");
|
||||||
Process remoteSpringApplication = javaLauncher.launch("remote-spring-application",
|
LaunchedJvm remoteSpringApplicationJvm = javaLauncher.launch(
|
||||||
createRemoteSpringApplicationClassPath(),
|
"remote-spring-application", createRemoteSpringApplicationClassPath(),
|
||||||
RemoteSpringApplication.class.getName(),
|
RemoteSpringApplication.class.getName(),
|
||||||
"--spring.devtools.remote.secret=secret", "http://localhost:" + port);
|
"--spring.devtools.remote.secret=secret", "http://localhost:" + port);
|
||||||
return new LaunchedApplication(new File("target/remote"), application,
|
return new LaunchedApplication(new File("target/remote"),
|
||||||
remoteSpringApplication);
|
applicationJvm.getStandardOut(), applicationJvm.getProcess(),
|
||||||
|
remoteSpringApplicationJvm.getProcess());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String createApplicationClassPath() throws Exception;
|
protected abstract String createApplicationClassPath() throws Exception;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue