|
21 | 21 | import java.util.List; |
22 | 22 | import java.util.concurrent.atomic.AtomicBoolean; |
23 | 23 | import java.util.concurrent.atomic.AtomicInteger; |
| 24 | +import java.util.function.BiFunction; |
24 | 25 |
|
25 | 26 | import org.assertj.core.api.Assertions; |
26 | 27 | import org.assertj.core.util.Lists; |
@@ -440,6 +441,34 @@ protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) { |
440 | 441 | .thenCancel().verify(VERIFY_TIMEOUT); |
441 | 442 | } |
442 | 443 |
|
| 444 | + @Test |
| 445 | + void shouldRefetchInstancesWithRepeatingHealthCheck() { |
| 446 | + healthCheck.setInitialDelay(Duration.ofSeconds(1)); |
| 447 | + healthCheck.setRepeatHealthCheck(true); |
| 448 | + healthCheck.setRefetchInstancesInterval(Duration.ofSeconds(1)); |
| 449 | + healthCheck.setRefetchInstances(true); |
| 450 | + ServiceInstance serviceInstance1 = new DefaultServiceInstance("ignored-service-1", SERVICE_ID, "127.0.0.1", |
| 451 | + port, false); |
| 452 | + ServiceInstance serviceInstance2 = new DefaultServiceInstance("ignored-service-2", SERVICE_ID, "127.0.0.2", |
| 453 | + port, false); |
| 454 | + |
| 455 | + StepVerifier.withVirtualTime(() -> { |
| 456 | + ServiceInstanceListSupplier delegate = mock(ServiceInstanceListSupplier.class); |
| 457 | + when(delegate.get()).thenReturn(Flux.just(Collections.singletonList(serviceInstance1))) |
| 458 | + .thenReturn(Flux.just(Collections.singletonList(serviceInstance2))); |
| 459 | + BiFunction<ServiceInstance, String, Mono<Boolean>> healthCheckFunc = healthCheckFunction(webClient); |
| 460 | + listSupplier = new HealthCheckServiceInstanceListSupplier(delegate, healthCheck, healthCheckFunc) { |
| 461 | + @Override |
| 462 | + protected Mono<Boolean> isAlive(ServiceInstance serviceInstance) { |
| 463 | + return Mono.just(true); |
| 464 | + } |
| 465 | + }; |
| 466 | + return listSupplier.get(); |
| 467 | + }).expectSubscription().expectNoEvent(healthCheck.getInitialDelay()).expectNext(Lists.list(serviceInstance1)) |
| 468 | + .thenAwait(healthCheck.getRefetchInstancesInterval()).expectNext(Lists.list(serviceInstance2)) |
| 469 | + .thenCancel().verify(VERIFY_TIMEOUT); |
| 470 | + } |
| 471 | + |
443 | 472 | @Test |
444 | 473 | void shouldCacheResultIfAfterPropertiesSetInvoked() { |
445 | 474 | healthCheck.setInitialDelay(Duration.ofSeconds(1)); |
|
0 commit comments