mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Improve diagnostics when remote application does not start as expected
See gh-22909
This commit is contained in:
parent
65ccb514d0
commit
2b1bb2f18f
@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
|
import org.awaitility.core.ConditionTimeoutException;
|
||||||
|
|
||||||
import org.springframework.boot.devtools.RemoteSpringApplication;
|
import org.springframework.boot.devtools.RemoteSpringApplication;
|
||||||
import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm;
|
import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm;
|
||||||
@ -77,7 +78,7 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher {
|
|||||||
createRemoteSpringApplicationClassPath(classesDirectory),
|
createRemoteSpringApplicationClassPath(classesDirectory),
|
||||||
RemoteSpringApplication.class.getName(), "--spring.devtools.remote.secret=secret",
|
RemoteSpringApplication.class.getName(), "--spring.devtools.remote.secret=secret",
|
||||||
"http://localhost:" + port);
|
"http://localhost:" + port);
|
||||||
awaitRemoteSpringApplication(remoteSpringApplicationJvm.getStandardOut());
|
awaitRemoteSpringApplication(remoteSpringApplicationJvm);
|
||||||
return remoteSpringApplicationJvm.getProcess();
|
return remoteSpringApplicationJvm.getProcess();
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
@ -105,10 +106,22 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher {
|
|||||||
.getServerPort();
|
.getServerPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void awaitRemoteSpringApplication(File standardOut) throws Exception {
|
private void awaitRemoteSpringApplication(LaunchedJvm launchedJvm) throws Exception {
|
||||||
FileContents contents = new FileContents(standardOut);
|
FileContents contents = new FileContents(launchedJvm.getStandardOut());
|
||||||
Awaitility.waitAtMost(Duration.ofSeconds(30)).until(contents::get,
|
try {
|
||||||
containsString("Started RemoteSpringApplication"));
|
Awaitility.waitAtMost(Duration.ofSeconds(30)).until(contents::get,
|
||||||
|
containsString("Started RemoteSpringApplication"));
|
||||||
|
}
|
||||||
|
catch (ConditionTimeoutException ex) {
|
||||||
|
if (!launchedJvm.getProcess().isAlive()) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Process exited with status " + launchedJvm.getProcess().exitValue()
|
||||||
|
+ " before producing expected standard output.\n\nStandard output:\n\n" + contents.get()
|
||||||
|
+ "\n\nStandard error:\n\n" + new FileContents(launchedJvm.getStandardError()).get(),
|
||||||
|
ex);
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user