mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Merge branch '3.1.x'
Closes gh-38661
This commit is contained in:
commit
de70b4fb4c
@ -118,14 +118,19 @@ class DockerComposeLifecycleManager {
|
||||
Stop stop = this.properties.getStop();
|
||||
Wait wait = this.properties.getReadiness().getWait();
|
||||
List<RunningService> runningServices = dockerCompose.getRunningServices();
|
||||
if (lifecycleManagement.shouldStart() && runningServices.isEmpty()) {
|
||||
start.getCommand().applyTo(dockerCompose, start.getLogLevel());
|
||||
runningServices = dockerCompose.getRunningServices();
|
||||
if (wait == Wait.ONLY_IF_STARTED) {
|
||||
wait = Wait.ALWAYS;
|
||||
if (lifecycleManagement.shouldStart()) {
|
||||
if (runningServices.isEmpty()) {
|
||||
start.getCommand().applyTo(dockerCompose, start.getLogLevel());
|
||||
runningServices = dockerCompose.getRunningServices();
|
||||
if (wait == Wait.ONLY_IF_STARTED) {
|
||||
wait = Wait.ALWAYS;
|
||||
}
|
||||
if (lifecycleManagement.shouldStop()) {
|
||||
this.shutdownHandlers.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout()));
|
||||
}
|
||||
}
|
||||
if (lifecycleManagement.shouldStop()) {
|
||||
this.shutdownHandlers.add(() -> stop.getCommand().applyTo(dockerCompose, stop.getTimeout()));
|
||||
else {
|
||||
logger.info("There are already Docker Compose services running, skipping startup");
|
||||
}
|
||||
}
|
||||
List<RunningService> relevantServices = new ArrayList<>(runningServices);
|
||||
|
@ -29,6 +29,7 @@ import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
@ -38,6 +39,8 @@ import org.springframework.boot.docker.compose.core.DockerCompose;
|
||||
import org.springframework.boot.docker.compose.core.DockerComposeFile;
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Readiness.Wait;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
@ -59,6 +62,7 @@ import static org.mockito.Mockito.never;
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class DockerComposeLifecycleManagerTests {
|
||||
|
||||
@TempDir
|
||||
@ -365,6 +369,21 @@ class DockerComposeLifecycleManagerTests {
|
||||
assertThat(event.getRunningServices()).isEqualTo(this.runningServices);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldLogIfServicesAreAlreadyRunning(CapturedOutput output) {
|
||||
setUpRunningServices();
|
||||
this.lifecycleManager.start();
|
||||
assertThat(output).contains("There are already Docker Compose services running, skipping startup");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotLogIfThereAreNoServicesRunning(CapturedOutput output) {
|
||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||
given(this.dockerCompose.getRunningServices()).willReturn(Collections.emptyList());
|
||||
this.lifecycleManager.start();
|
||||
assertThat(output).doesNotContain("There are already Docker Compose services running, skipping startup");
|
||||
}
|
||||
|
||||
private void setUpRunningServices() {
|
||||
setUpRunningServices(true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user