Switch initialDelay to Duration. (#768)
This commit is contained in:
committed by
GitHub
parent
cfeb38a369
commit
b430529ccc
@@ -31,7 +31,7 @@
|
||||
|spring.cloud.loadbalancer.cache.capacity | 256 | Initial cache capacity expressed as int.
|
||||
|spring.cloud.loadbalancer.cache.enabled | true | Enables Spring Cloud LoadBalancer caching mechanism.
|
||||
|spring.cloud.loadbalancer.cache.ttl | 35s | Time To Live - time counted from writing of the record, after which cache entries are expired, expressed as a {@link Duration}. The property {@link String} has to be in keeping with the appropriate syntax as specified in Spring Boot <code>StringToDurationConverter</code>. @see <a href= "https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToDurationConverter.java">StringToDurationConverter.java</a>
|
||||
|spring.cloud.loadbalancer.health-check.initial-delay | 0 | Initial delay value for the HealthCheck scheduler.
|
||||
|spring.cloud.loadbalancer.health-check.initial-delay | null | Initial delay value for the HealthCheck scheduler.
|
||||
|spring.cloud.loadbalancer.health-check.interval | 25s | Interval for rerunning the HealthCheck scheduler.
|
||||
|spring.cloud.loadbalancer.health-check.path | null | null
|
||||
|spring.cloud.loadbalancer.retry.enabled | true | null
|
||||
|
||||
@@ -49,7 +49,7 @@ public class LoadBalancerProperties {
|
||||
/**
|
||||
* Initial delay value for the HealthCheck scheduler.
|
||||
*/
|
||||
private int initialDelay = 0;
|
||||
private Duration initialDelay = Duration.ZERO;
|
||||
|
||||
/**
|
||||
* Interval for rerunning the HealthCheck scheduler.
|
||||
@@ -58,11 +58,11 @@ public class LoadBalancerProperties {
|
||||
|
||||
private Map<String, String> path = new LinkedCaseInsensitiveMap<>();
|
||||
|
||||
public int getInitialDelay() {
|
||||
public Duration getInitialDelay() {
|
||||
return initialDelay;
|
||||
}
|
||||
|
||||
public void setInitialDelay(int initialDelay) {
|
||||
public void setInitialDelay(Duration initialDelay) {
|
||||
this.initialDelay = initialDelay;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.loadbalancer.core;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -69,7 +68,7 @@ public class HealthCheckServiceInstanceListSupplier
|
||||
"/actuator/health");
|
||||
this.webClient = webClient;
|
||||
aliveInstancesReplay = Flux.defer(delegate)
|
||||
.delaySubscription(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
.delaySubscription(healthCheck.getInitialDelay())
|
||||
.switchMap(serviceInstances -> healthCheckFlux(serviceInstances).map(
|
||||
alive -> Collections.unmodifiableList(new ArrayList<>(alive))))
|
||||
.replay(1).refCount(1);
|
||||
|
||||
@@ -79,7 +79,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
void tearDown() {
|
||||
if (listSupplier != null) {
|
||||
listSupplier.destroy();
|
||||
listSupplier = null;
|
||||
@@ -132,7 +132,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
|
||||
@Test
|
||||
void shouldReturnOnlyAliveService() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
@@ -160,8 +160,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(healthCheck.getInterval()).thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
@@ -169,7 +168,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
|
||||
@Test
|
||||
void shouldEmitOnEachAliveServiceInBatch() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
ServiceInstance serviceInstance2 = new DefaultServiceInstance("ignored-service-2",
|
||||
@@ -196,8 +195,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNext(Lists.list(serviceInstance1, serviceInstance2))
|
||||
.expectNoEvent(healthCheck.getInterval()).thenCancel()
|
||||
@@ -206,7 +204,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
|
||||
@Test
|
||||
void shouldNotFailIfIsAliveReturnsError() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
ServiceInstance serviceInstance2 = new DefaultServiceInstance("ignored-service-2",
|
||||
@@ -234,8 +232,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(healthCheck.getInterval()).thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
@@ -243,7 +240,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
|
||||
@Test
|
||||
void shouldEmitAllInstancesIfAllIsAliveChecksFailed() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
ServiceInstance serviceInstance2 = new DefaultServiceInstance("ignored-service-2",
|
||||
@@ -269,15 +266,14 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNext(Lists.list()).expectNoEvent(healthCheck.getInterval())
|
||||
.thenCancel().verify(VERIFY_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMakeInitialDaleyAfterPropertiesSet() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
|
||||
@@ -298,8 +294,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
listSupplier.afterPropertiesSet();
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(healthCheck.getInterval()).thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
@@ -307,7 +302,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
|
||||
@Test
|
||||
void shouldRepeatIsAliveChecksIndefinitely() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
ServiceInstance serviceInstance2 = new DefaultServiceInstance("ignored-service-2",
|
||||
@@ -336,8 +331,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNext(Lists.list()).expectNoEvent(healthCheck.getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNoEvent(healthCheck.getInterval())
|
||||
@@ -347,7 +341,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
|
||||
@Test
|
||||
void shouldTimeoutIsAliveCheck() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
|
||||
@@ -372,8 +366,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNoEvent(healthCheck.getInterval()).expectNext(Lists.list())
|
||||
.expectNoEvent(healthCheck.getInterval())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
@@ -384,7 +377,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
|
||||
@Test
|
||||
void shouldUpdateInstances() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
ServiceInstance serviceInstance2 = new DefaultServiceInstance("ignored-service-2",
|
||||
@@ -409,8 +402,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
};
|
||||
|
||||
return listSupplier.get();
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.thenAwait(healthCheck.getInterval().dividedBy(2))
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
@@ -423,7 +415,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
|
||||
@Test
|
||||
void shouldCacheResultIfAfterPropertiesSetInvoked() {
|
||||
healthCheck.setInitialDelay(1000);
|
||||
healthCheck.setInitialDelay(Duration.ofSeconds(1));
|
||||
ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1",
|
||||
SERVICE_ID, "127.0.0.1", port, false);
|
||||
|
||||
@@ -454,8 +446,7 @@ class HealthCheckServiceInstanceListSupplierTests {
|
||||
listSupplier.afterPropertiesSet();
|
||||
|
||||
return listSupplier.get().take(1).concatWith(listSupplier.get().take(1));
|
||||
}).expectSubscription()
|
||||
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
|
||||
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
|
||||
.expectNext(Lists.list(serviceInstance1))
|
||||
.expectNext(Lists.list(serviceInstance1)).thenCancel()
|
||||
.verify(VERIFY_TIMEOUT);
|
||||
|
||||
Reference in New Issue
Block a user