mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish docker compose code
This commit is contained in:
parent
8abebd75fb
commit
75207db6be
@ -130,7 +130,7 @@ class DockerCli {
|
||||
return (line) -> logLevel.log(this.logger, line);
|
||||
}
|
||||
|
||||
private <R> List<String> createCommand(Type type) {
|
||||
private List<String> createCommand(Type type) {
|
||||
return switch (type) {
|
||||
case DOCKER -> new ArrayList<>(this.dockerCommand);
|
||||
case DOCKER_COMPOSE -> {
|
||||
|
@ -94,7 +94,7 @@ class DockerComposeLifecycleManager {
|
||||
logger.trace("Docker compose support not enabled");
|
||||
return;
|
||||
}
|
||||
if (this.skipCheck.shouldSkip(this.classLoader, logger, this.properties.getSkip())) {
|
||||
if (this.skipCheck.shouldSkip(this.classLoader, this.properties.getSkip())) {
|
||||
logger.trace("Docker compose support skipped");
|
||||
return;
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* {@link ApplicationEvent} published when docker compose {@link RunningService} instance
|
||||
* are available. This even is published from the {@link ApplicationPreparedEvent} that
|
||||
* {@link ApplicationEvent} published when docker compose {@link RunningService} instances
|
||||
* are available. This event is published from the {@link ApplicationPreparedEvent} that
|
||||
* performs the docker compose startup.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
|
@ -20,8 +20,6 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.boot.SpringApplicationAotProcessor;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@ -46,7 +44,7 @@ class DockerComposeSkipCheck {
|
||||
SKIPPED_STACK_ELEMENTS = Collections.unmodifiableSet(skipped);
|
||||
}
|
||||
|
||||
boolean shouldSkip(ClassLoader classLoader, Log logger, DockerComposeProperties.Skip properties) {
|
||||
boolean shouldSkip(ClassLoader classLoader, DockerComposeProperties.Skip properties) {
|
||||
if (properties.isInTests() && hasAtLeastOneRequiredClass(classLoader)) {
|
||||
Thread thread = Thread.currentThread();
|
||||
for (StackTraceElement element : thread.getStackTrace()) {
|
||||
|
@ -52,7 +52,7 @@ public enum LifecycleManagement {
|
||||
|
||||
/**
|
||||
* Return whether docker compose should be started.
|
||||
* @return whether docker compose should be started.
|
||||
* @return whether docker compose should be started
|
||||
*/
|
||||
boolean shouldStartup() {
|
||||
return this.startup;
|
||||
|
@ -24,7 +24,8 @@ import org.springframework.boot.docker.compose.core.RunningService;
|
||||
|
||||
/**
|
||||
* Exception thrown if readiness checking has timed out. Related
|
||||
* {@link ServiceNotReadyException} are available from {@link #getSuppressed()}.
|
||||
* {@link ServiceNotReadyException ServiceNotReadyExceptions} are available from
|
||||
* {@link #getSuppressed()}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
|
@ -24,8 +24,8 @@ import java.net.SocketTimeoutException;
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
|
||||
/**
|
||||
* Default {@link ServiceReadinessCheck} that readiness by connecting to the exposed TCP
|
||||
* ports.
|
||||
* Default {@link ServiceReadinessCheck} that checks readiness by connecting to the
|
||||
* exposed TCP ports.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
@ -66,7 +66,7 @@ class TcpConnectServiceReadinessCheck implements ServiceReadinessCheck {
|
||||
|
||||
private void check(RunningService service, int port, Socket socket) throws IOException {
|
||||
try {
|
||||
// -1 is indicates the socket has been closed immediately
|
||||
// -1 indicates the socket has been closed immediately
|
||||
// Other responses or a timeout are considered as success
|
||||
if (socket.getInputStream().read() == -1) {
|
||||
throw new ServiceNotReadyException(service,
|
||||
|
@ -28,7 +28,7 @@ import org.springframework.boot.docker.compose.core.RunningService;
|
||||
*/
|
||||
class ConnectionNamePredicate implements Predicate<DockerComposeConnectionSource> {
|
||||
|
||||
private String required;
|
||||
private final String required;
|
||||
|
||||
ConnectionNamePredicate(String required) {
|
||||
this.required = asCanonicalName(required);
|
||||
|
@ -74,14 +74,13 @@ class DockerComposeServiceConnectionsApplicationListener
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> void register(BeanDefinitionRegistry registry, RunningService runningService,
|
||||
Class<?> connectionDetailsType, ConnectionDetails connectionDetails) {
|
||||
String beanName = getBeanName(runningService, connectionDetailsType, connectionDetails);
|
||||
String beanName = getBeanName(runningService, connectionDetailsType);
|
||||
Class<T> beanType = (Class<T>) connectionDetails.getClass();
|
||||
Supplier<T> beanSupplier = () -> (T) connectionDetails;
|
||||
registry.registerBeanDefinition(beanName, new RootBeanDefinition(beanType, beanSupplier));
|
||||
}
|
||||
|
||||
private String getBeanName(RunningService runningService, Class<?> connectionDetailsType,
|
||||
ConnectionDetails connectionDetails) {
|
||||
private String getBeanName(RunningService runningService, Class<?> connectionDetailsType) {
|
||||
List<String> parts = new ArrayList<>();
|
||||
parts.add(ClassUtils.getShortNameAsProperty(connectionDetailsType));
|
||||
parts.add("for");
|
||||
|
@ -115,7 +115,7 @@ class DockerComposeLifecycleManagerTests {
|
||||
|
||||
@Test
|
||||
void startupWhenInTestDoesNotStart() {
|
||||
given(this.skipCheck.shouldSkip(any(), any(), any())).willReturn(true);
|
||||
given(this.skipCheck.shouldSkip(any(), any())).willReturn(true);
|
||||
EventCapturingListener listener = new EventCapturingListener();
|
||||
this.eventListeners.add(listener);
|
||||
setupRunningServices();
|
||||
|
@ -56,7 +56,7 @@ class DockerComposeListenerTests {
|
||||
then(listener.getManager()).should().startup();
|
||||
}
|
||||
|
||||
class TestDockerComposeListener extends DockerComposeListener {
|
||||
static class TestDockerComposeListener extends DockerComposeListener {
|
||||
|
||||
private final ConfigurableApplicationContext context;
|
||||
|
||||
|
@ -67,7 +67,7 @@ class ServiceReadinessChecksTests {
|
||||
|
||||
private List<RunningService> runningServices;
|
||||
|
||||
private MockServiceReadinessCheck mockTcpCheck = new MockServiceReadinessCheck();
|
||||
private final MockServiceReadinessCheck mockTcpCheck = new MockServiceReadinessCheck();
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
|
Loading…
Reference in New Issue
Block a user