Move docker compose readiness code and make it package-private
The `ReadinessCheck` interface has been removed making the dedicated package less necessary. By relocating the code we can make more of it pacakge-private. See gh-35544pull/35555/head
parent
060581d078
commit
6b0b6ccf49
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2023 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.docker.compose.readiness;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.bind.Binder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Readiness configuration properties.
|
|
||||||
*
|
|
||||||
* @author Moritz Halbritter
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @since 3.1.0
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(ReadinessProperties.NAME)
|
|
||||||
public class ReadinessProperties {
|
|
||||||
|
|
||||||
static final String NAME = "spring.docker.compose.readiness";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout of the readiness checks.
|
|
||||||
*/
|
|
||||||
private Duration timeout = Duration.ofMinutes(2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TCP properties.
|
|
||||||
*/
|
|
||||||
private final Tcp tcp = new Tcp();
|
|
||||||
|
|
||||||
public Duration getTimeout() {
|
|
||||||
return this.timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeout(Duration timeout) {
|
|
||||||
this.timeout = timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tcp getTcp() {
|
|
||||||
return this.tcp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the properties using the given binder.
|
|
||||||
* @param binder the binder used to get the properties
|
|
||||||
* @return a bound {@link ReadinessProperties} instance
|
|
||||||
*/
|
|
||||||
static ReadinessProperties get(Binder binder) {
|
|
||||||
return binder.bind(ReadinessProperties.NAME, ReadinessProperties.class).orElseGet(ReadinessProperties::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TCP properties.
|
|
||||||
*/
|
|
||||||
public static class Tcp {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout for connections.
|
|
||||||
*/
|
|
||||||
private Duration connectTimeout = Duration.ofMillis(200);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout for reads.
|
|
||||||
*/
|
|
||||||
private Duration readTimeout = Duration.ofMillis(200);
|
|
||||||
|
|
||||||
public Duration getConnectTimeout() {
|
|
||||||
return this.connectTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectTimeout(Duration connectTimeout) {
|
|
||||||
this.connectTimeout = connectTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Duration getReadTimeout() {
|
|
||||||
return this.readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReadTimeout(Duration readTimeout) {
|
|
||||||
this.readTimeout = readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2023 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service readiness checks.
|
|
||||||
*/
|
|
||||||
package org.springframework.boot.docker.compose.readiness;
|
|
4
spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/readiness/TcpConnectServiceReadinessCheckTests.java → spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/TcpConnectServiceReadinessCheckTests.java
4
spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/readiness/TcpConnectServiceReadinessCheckTests.java → spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/TcpConnectServiceReadinessCheckTests.java
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2023 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.docker.compose.readiness;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.bind.Binder;
|
|
||||||
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link ReadinessProperties}.
|
|
||||||
*
|
|
||||||
* @author Moritz Halbritter
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @author Phillip Webb
|
|
||||||
*/
|
|
||||||
class ReadinessPropertiesTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getWhenNoPropertiesReturnsNewInstance() {
|
|
||||||
Binder binder = new Binder(new MapConfigurationPropertySource());
|
|
||||||
ReadinessProperties properties = ReadinessProperties.get(binder);
|
|
||||||
assertThat(properties.getTimeout()).isEqualTo(Duration.ofMinutes(2));
|
|
||||||
assertThat(properties.getTcp().getConnectTimeout()).isEqualTo(Duration.ofMillis(200));
|
|
||||||
assertThat(properties.getTcp().getReadTimeout()).isEqualTo(Duration.ofMillis(200));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getWhenPropertiesReturnsBoundInstance() {
|
|
||||||
Map<String, String> source = new LinkedHashMap<>();
|
|
||||||
source.put("spring.docker.compose.readiness.timeout", "10s");
|
|
||||||
source.put("spring.docker.compose.readiness.tcp.connect-timeout", "400ms");
|
|
||||||
source.put("spring.docker.compose.readiness.tcp.read-timeout", "500ms");
|
|
||||||
Binder binder = new Binder(new MapConfigurationPropertySource(source));
|
|
||||||
ReadinessProperties properties = ReadinessProperties.get(binder);
|
|
||||||
assertThat(properties.getTimeout()).isEqualTo(Duration.ofSeconds(10));
|
|
||||||
assertThat(properties.getTcp().getConnectTimeout()).isEqualTo(Duration.ofMillis(400));
|
|
||||||
assertThat(properties.getTcp().getReadTimeout()).isEqualTo(Duration.ofMillis(500));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue