Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
|spring.cloud.loadbalancer.cache.caffeine.spec | | The spec to use to create caches. See CaffeineSpec for more details on the spec format.
|spring.cloud.loadbalancer.cache.capacity | 256 | Initial cache capacity expressed as int.
|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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static class HealthCheck {
/**
* Initial delay value for the HealthCheck scheduler.
*/
private int initialDelay = 0;
private Duration initialDelay = Duration.ZERO;

/**
* Interval for rerunning the HealthCheck scheduler.
Expand All @@ -58,11 +58,11 @@ public static class HealthCheck {

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,7 +68,7 @@ public HealthCheckServiceInstanceListSupplier(ServiceInstanceListSupplier delega
"/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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void setUp() {
}

@AfterEach
void tearDown() throws Exception {
void tearDown() {
if (listSupplier != null) {
listSupplier.destroy();
listSupplier = null;
Expand Down Expand Up @@ -132,7 +132,7 @@ void shouldReturnFalseIfEndpointNotFound() {

@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);
Expand Down Expand Up @@ -160,16 +160,15 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {
};

return listSupplier.get();
}).expectSubscription()
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
.expectNext(Lists.list(serviceInstance1))
.expectNoEvent(healthCheck.getInterval()).thenCancel()
.verify(VERIFY_TIMEOUT);
}

@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",
Expand All @@ -196,8 +195,7 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {
};

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()
Expand All @@ -206,7 +204,7 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {

@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",
Expand Down Expand Up @@ -234,16 +232,15 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {
};

return listSupplier.get();
}).expectSubscription()
.expectNoEvent(Duration.ofMillis(healthCheck.getInitialDelay()))
}).expectSubscription().expectNoEvent(healthCheck.getInitialDelay())
.expectNext(Lists.list(serviceInstance1))
.expectNoEvent(healthCheck.getInterval()).thenCancel()
.verify(VERIFY_TIMEOUT);
}

@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",
Expand All @@ -269,15 +266,14 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {
};

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);

Expand All @@ -298,16 +294,15 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {
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);
}

@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",
Expand Down Expand Up @@ -336,8 +331,7 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {
};

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())
Expand All @@ -347,7 +341,7 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {

@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);

Expand All @@ -372,8 +366,7 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {
};

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))
Expand All @@ -384,7 +377,7 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {

@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",
Expand All @@ -409,8 +402,7 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {
};

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))
Expand All @@ -423,7 +415,7 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) {

@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);

Expand Down Expand Up @@ -454,8 +446,7 @@ protected Flux<List<ServiceInstance>> healthCheckFlux(
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);
Expand Down