Change DockerComposeProperties shut down default to stop
Closes gh-35239
This commit is contained in:
@@ -103,32 +103,32 @@ class DockerComposeLifecycleManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenEnabledFalseDoesNotStart() {
|
||||
void startWhenEnabledFalseDoesNotStart() {
|
||||
this.properties.setEnabled(false);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
setupRunningServices();
|
||||
this.lifecycleManager.startup();
|
||||
setUpRunningServices();
|
||||
this.lifecycleManager.start();
|
||||
assertThat(listener.getEvent()).isNull();
|
||||
then(this.dockerCompose).should(never()).hasDefinedServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenInTestDoesNotStart() {
|
||||
void startWhenInTestDoesNotStart() {
|
||||
given(this.skipCheck.shouldSkip(any(), any())).willReturn(true);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
setupRunningServices();
|
||||
this.lifecycleManager.startup();
|
||||
setUpRunningServices();
|
||||
this.lifecycleManager.start();
|
||||
assertThat(listener.getEvent()).isNull();
|
||||
then(this.dockerCompose).should(never()).hasDefinedServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenHasNoDefinedServicesDoesNothing() {
|
||||
void startWhenHasNoDefinedServicesDoesNothing() {
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
this.lifecycleManager.startup();
|
||||
this.lifecycleManager.start();
|
||||
assertThat(listener.getEvent()).isNull();
|
||||
then(this.dockerCompose).should().hasDefinedServices();
|
||||
then(this.dockerCompose).should(never()).up(any());
|
||||
@@ -138,27 +138,27 @@ class DockerComposeLifecycleManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenLifecycleStartAndStopAndHasNoRunningServicesDoesStartupAndShutdown() {
|
||||
void startWhenLifecycleStartAndStopAndHasNoRunningServicesDoesUpAndStop() {
|
||||
this.properties.setLifecycleManagement(LifecycleManagement.START_AND_STOP);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||
this.lifecycleManager.startup();
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
assertThat(listener.getEvent()).isNotNull();
|
||||
then(this.dockerCompose).should().up(any());
|
||||
then(this.dockerCompose).should(never()).start(any());
|
||||
then(this.dockerCompose).should().down(any());
|
||||
then(this.dockerCompose).should(never()).stop(any());
|
||||
then(this.dockerCompose).should().stop(any());
|
||||
then(this.dockerCompose).should(never()).down(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenLifecycleStartAndStopAndHasRunningServicesDoesNoStartupOrShutdown() {
|
||||
void startWhenLifecycleStartAndStopAndHasRunningServicesDoesNothing() {
|
||||
this.properties.setLifecycleManagement(LifecycleManagement.START_AND_STOP);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
setupRunningServices();
|
||||
this.lifecycleManager.startup();
|
||||
setUpRunningServices();
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
assertThat(listener.getEvent()).isNotNull();
|
||||
then(this.dockerCompose).should(never()).up(any());
|
||||
@@ -168,12 +168,12 @@ class DockerComposeLifecycleManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenLifecycleNoneDoesNoStartupOrShutdown() {
|
||||
void startWhenLifecycleNoneDoesNothing() {
|
||||
this.properties.setLifecycleManagement(LifecycleManagement.NONE);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
setupRunningServices();
|
||||
this.lifecycleManager.startup();
|
||||
setUpRunningServices();
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
assertThat(listener.getEvent()).isNotNull();
|
||||
then(this.dockerCompose).should(never()).up(any());
|
||||
@@ -183,12 +183,12 @@ class DockerComposeLifecycleManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenLifecycleStartOnlyDoesStartupAndNoShutdown() {
|
||||
void startWhenLifecycleStartOnlyDoesOnlyStart() {
|
||||
this.properties.setLifecycleManagement(LifecycleManagement.START_ONLY);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||
this.lifecycleManager.startup();
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
assertThat(listener.getEvent()).isNotNull();
|
||||
then(this.dockerCompose).should().up(any());
|
||||
@@ -199,97 +199,97 @@ class DockerComposeLifecycleManagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenStartupCommandStartDoesStartupUsingStartAndShutdown() {
|
||||
void startWhenStartCommandStartDoesStartAndStop() {
|
||||
this.properties.setLifecycleManagement(LifecycleManagement.START_AND_STOP);
|
||||
this.properties.getStartup().setCommand(StartupCommand.START);
|
||||
this.properties.getStart().setCommand(StartCommand.START);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||
this.lifecycleManager.startup();
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
assertThat(listener.getEvent()).isNotNull();
|
||||
then(this.dockerCompose).should(never()).up(any());
|
||||
then(this.dockerCompose).should().start(any());
|
||||
then(this.dockerCompose).should().down(any());
|
||||
then(this.dockerCompose).should(never()).stop(any());
|
||||
then(this.dockerCompose).should().stop(any());
|
||||
then(this.dockerCompose).should(never()).down(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenShutdownCommandStopDoesStartupAndShutdownUsingStop() {
|
||||
void startWhenStopCommandDownDoesStartAndDown() {
|
||||
this.properties.setLifecycleManagement(LifecycleManagement.START_AND_STOP);
|
||||
this.properties.getShutdown().setCommand(ShutdownCommand.STOP);
|
||||
this.properties.getStop().setCommand(StopCommand.DOWN);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||
this.lifecycleManager.startup();
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
assertThat(listener.getEvent()).isNotNull();
|
||||
then(this.dockerCompose).should().up(any());
|
||||
then(this.dockerCompose).should(never()).start(any());
|
||||
then(this.dockerCompose).should(never()).down(any());
|
||||
then(this.dockerCompose).should().stop(any());
|
||||
then(this.dockerCompose).should(never()).stop(any());
|
||||
then(this.dockerCompose).should().down(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenHasShutdownTimeoutUsesDuration() {
|
||||
void startWhenHasStopTimeoutUsesDuration() {
|
||||
this.properties.setLifecycleManagement(LifecycleManagement.START_AND_STOP);
|
||||
Duration timeout = Duration.ofDays(1);
|
||||
this.properties.getShutdown().setTimeout(timeout);
|
||||
this.properties.getStop().setTimeout(timeout);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||
this.lifecycleManager.startup();
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
assertThat(listener.getEvent()).isNotNull();
|
||||
then(this.dockerCompose).should().down(timeout);
|
||||
then(this.dockerCompose).should().stop(timeout);
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWhenHasIgnoreLabelIgnoresService() {
|
||||
void startWhenHasIgnoreLabelIgnoresService() {
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
setupRunningServices(Map.of("org.springframework.boot.ignore", "true"));
|
||||
this.lifecycleManager.startup();
|
||||
setUpRunningServices(Map.of("org.springframework.boot.ignore", "true"));
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
assertThat(listener.getEvent()).isNotNull();
|
||||
assertThat(listener.getEvent().getRunningServices()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupWaitsUntilReady() {
|
||||
void startWaitsUntilReady() {
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
setupRunningServices();
|
||||
this.lifecycleManager.startup();
|
||||
setUpRunningServices();
|
||||
this.lifecycleManager.start();
|
||||
this.shutdownHandlers.run();
|
||||
then(this.serviceReadinessChecks).should().waitUntilReady(this.runningServices);
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupGetsDockerComposeWithActiveProfiles() {
|
||||
void startGetsDockerComposeWithActiveProfiles() {
|
||||
this.properties.getProfiles().setActive(Set.of("my-profile"));
|
||||
setupRunningServices();
|
||||
this.lifecycleManager.startup();
|
||||
setUpRunningServices();
|
||||
this.lifecycleManager.start();
|
||||
assertThat(this.activeProfiles).containsExactly("my-profile");
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupPublishesEvent() {
|
||||
void startPublishesEvent() {
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
setupRunningServices();
|
||||
this.lifecycleManager.startup();
|
||||
setUpRunningServices();
|
||||
this.lifecycleManager.start();
|
||||
DockerComposeServicesReadyEvent event = listener.getEvent();
|
||||
assertThat(event).isNotNull();
|
||||
assertThat(event.getSource()).isEqualTo(this.applicationContext);
|
||||
assertThat(event.getRunningServices()).isEqualTo(this.runningServices);
|
||||
}
|
||||
|
||||
private void setupRunningServices() {
|
||||
setupRunningServices(Collections.emptyMap());
|
||||
private void setUpRunningServices() {
|
||||
setUpRunningServices(Collections.emptyMap());
|
||||
}
|
||||
|
||||
private void setupRunningServices(Map<String, String> labels) {
|
||||
private void setUpRunningServices(Map<String, String> labels) {
|
||||
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
|
||||
given(this.dockerCompose.hasRunningServices()).willReturn(true);
|
||||
RunningService runningService = mock(RunningService.class);
|
||||
|
||||
@@ -53,7 +53,7 @@ class DockerComposeListenerTests {
|
||||
ApplicationPreparedEvent event = new ApplicationPreparedEvent(application, new String[0], context);
|
||||
listener.onApplicationEvent(event);
|
||||
assertThat(listener.getManager()).isNotNull();
|
||||
then(listener.getManager()).should().startup();
|
||||
then(listener.getManager()).should().start();
|
||||
}
|
||||
|
||||
static class TestDockerComposeListener extends DockerComposeListener {
|
||||
|
||||
@@ -44,9 +44,9 @@ class DockerComposePropertiesTests {
|
||||
assertThat(properties.getFile()).isNull();
|
||||
assertThat(properties.getLifecycleManagement()).isEqualTo(LifecycleManagement.START_AND_STOP);
|
||||
assertThat(properties.getHost()).isNull();
|
||||
assertThat(properties.getStartup().getCommand()).isEqualTo(StartupCommand.UP);
|
||||
assertThat(properties.getShutdown().getCommand()).isEqualTo(ShutdownCommand.DOWN);
|
||||
assertThat(properties.getShutdown().getTimeout()).isEqualTo(Duration.ofSeconds(10));
|
||||
assertThat(properties.getStart().getCommand()).isEqualTo(StartCommand.UP);
|
||||
assertThat(properties.getStop().getCommand()).isEqualTo(StopCommand.STOP);
|
||||
assertThat(properties.getStop().getTimeout()).isEqualTo(Duration.ofSeconds(10));
|
||||
assertThat(properties.getProfiles().getActive()).isEmpty();
|
||||
}
|
||||
|
||||
@@ -56,18 +56,18 @@ class DockerComposePropertiesTests {
|
||||
source.put("spring.docker.compose.file", "my-compose.yml");
|
||||
source.put("spring.docker.compose.lifecycle-management", "start-only");
|
||||
source.put("spring.docker.compose.host", "myhost");
|
||||
source.put("spring.docker.compose.startup.command", "start");
|
||||
source.put("spring.docker.compose.shutdown.command", "stop");
|
||||
source.put("spring.docker.compose.shutdown.timeout", "5s");
|
||||
source.put("spring.docker.compose.start.command", "start");
|
||||
source.put("spring.docker.compose.stop.command", "down");
|
||||
source.put("spring.docker.compose.stop.timeout", "5s");
|
||||
source.put("spring.docker.compose.profiles.active", "myprofile");
|
||||
Binder binder = new Binder(new MapConfigurationPropertySource(source));
|
||||
DockerComposeProperties properties = DockerComposeProperties.get(binder);
|
||||
assertThat(properties.getFile()).isEqualTo(new File("my-compose.yml"));
|
||||
assertThat(properties.getLifecycleManagement()).isEqualTo(LifecycleManagement.START_ONLY);
|
||||
assertThat(properties.getHost()).isEqualTo("myhost");
|
||||
assertThat(properties.getStartup().getCommand()).isEqualTo(StartupCommand.START);
|
||||
assertThat(properties.getShutdown().getCommand()).isEqualTo(ShutdownCommand.STOP);
|
||||
assertThat(properties.getShutdown().getTimeout()).isEqualTo(Duration.ofSeconds(5));
|
||||
assertThat(properties.getStart().getCommand()).isEqualTo(StartCommand.START);
|
||||
assertThat(properties.getStop().getCommand()).isEqualTo(StopCommand.DOWN);
|
||||
assertThat(properties.getStop().getTimeout()).isEqualTo(Duration.ofSeconds(5));
|
||||
assertThat(properties.getProfiles().getActive()).containsExactly("myprofile");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,32 +31,32 @@ class LifecycleManagementTests {
|
||||
|
||||
@Test
|
||||
void shouldStartupWhenNone() {
|
||||
assertThat(LifecycleManagement.NONE.shouldStartup()).isFalse();
|
||||
assertThat(LifecycleManagement.NONE.shouldStart()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldShutdownWhenNone() {
|
||||
assertThat(LifecycleManagement.NONE.shouldShutdown()).isFalse();
|
||||
assertThat(LifecycleManagement.NONE.shouldStop()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldStartupWhenStartOnly() {
|
||||
assertThat(LifecycleManagement.START_ONLY.shouldStartup()).isTrue();
|
||||
assertThat(LifecycleManagement.START_ONLY.shouldStart()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldShutdownWhenStartOnly() {
|
||||
assertThat(LifecycleManagement.START_ONLY.shouldShutdown()).isFalse();
|
||||
assertThat(LifecycleManagement.START_ONLY.shouldStop()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldStartupWhenStartAndStop() {
|
||||
assertThat(LifecycleManagement.START_AND_STOP.shouldStartup()).isTrue();
|
||||
assertThat(LifecycleManagement.START_AND_STOP.shouldStart()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldShutdownWhenStartAndStop() {
|
||||
assertThat(LifecycleManagement.START_AND_STOP.shouldShutdown()).isTrue();
|
||||
assertThat(LifecycleManagement.START_AND_STOP.shouldStop()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,25 +25,25 @@ import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link StartupCommand}.
|
||||
* Tests for {@link StartCommand}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class StartupCommandTests {
|
||||
class StartCommandTests {
|
||||
|
||||
private DockerCompose dockerCompose = mock(DockerCompose.class);
|
||||
|
||||
@Test
|
||||
void applyToWhenUp() {
|
||||
StartupCommand.UP.applyTo(this.dockerCompose, LogLevel.INFO);
|
||||
StartCommand.UP.applyTo(this.dockerCompose, LogLevel.INFO);
|
||||
then(this.dockerCompose).should().up(LogLevel.INFO);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyToWhenStart() {
|
||||
StartupCommand.START.applyTo(this.dockerCompose, LogLevel.INFO);
|
||||
StartCommand.START.applyTo(this.dockerCompose, LogLevel.INFO);
|
||||
then(this.dockerCompose).should().start(LogLevel.INFO);
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link ShutdownCommand}.
|
||||
* Tests for {@link StopCommand}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class ShutdownCommandTests {
|
||||
class StopCommandTests {
|
||||
|
||||
private DockerCompose dockerCompose = mock(DockerCompose.class);
|
||||
|
||||
@@ -40,13 +40,13 @@ class ShutdownCommandTests {
|
||||
|
||||
@Test
|
||||
void applyToWhenDown() {
|
||||
ShutdownCommand.DOWN.applyTo(this.dockerCompose, this.duration);
|
||||
StopCommand.DOWN.applyTo(this.dockerCompose, this.duration);
|
||||
then(this.dockerCompose).should().down(this.duration);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyToWhenStart() {
|
||||
ShutdownCommand.STOP.applyTo(this.dockerCompose, this.duration);
|
||||
StopCommand.STOP.applyTo(this.dockerCompose, this.duration);
|
||||
then(this.dockerCompose).should().stop(this.duration);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class AbstractDockerComposeIntegrationTests {
|
||||
private final Resource composeResource;
|
||||
|
||||
@AfterAll
|
||||
static void shutdown() {
|
||||
static void shutDown() {
|
||||
SpringApplicationShutdownHandlers shutdownHandlers = SpringApplication.getShutdownHandlers();
|
||||
((Runnable) shutdownHandlers).run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user