mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish "Handle AbstractReactiveHealthIndicator.doHealthCheck exception"
Closes gh-10822
This commit is contained in:
parent
99c2fa699e
commit
350377c3f2
@ -23,6 +23,7 @@ import reactor.core.publisher.Mono;
|
||||
* {@link Health} instance and error handling.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Nikolay Rybak
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public abstract class AbstractReactiveHealthIndicator implements ReactiveHealthIndicator {
|
||||
@ -33,7 +34,7 @@ public abstract class AbstractReactiveHealthIndicator implements ReactiveHealthI
|
||||
return doHealthCheck(new Health.Builder())
|
||||
.onErrorResume(this::handleFailure);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
catch (Exception ex) {
|
||||
return handleFailure(ex);
|
||||
}
|
||||
}
|
||||
|
@ -40,11 +40,12 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Mark Paluch
|
||||
* @author Nikolay Rybak
|
||||
*/
|
||||
public class RedisReactiveHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void redisIsUp() throws Exception {
|
||||
public void redisIsUp() {
|
||||
Properties info = new Properties();
|
||||
info.put("redis_version", "2.8.9");
|
||||
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
|
||||
@ -62,7 +63,7 @@ public class RedisReactiveHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redisCommandIsDown() throws Exception {
|
||||
public void redisCommandIsDown() {
|
||||
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
|
||||
given(commands.info()).willReturn(
|
||||
Mono.error(new RedisConnectionFailureException("Connection failed")));
|
||||
@ -77,11 +78,13 @@ public class RedisReactiveHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redisConnectionIsDown() throws Exception {
|
||||
ReactiveRedisConnectionFactory redisConnectionFactory = mock(ReactiveRedisConnectionFactory.class);
|
||||
public void redisConnectionIsDown() {
|
||||
ReactiveRedisConnectionFactory redisConnectionFactory = mock(
|
||||
ReactiveRedisConnectionFactory.class);
|
||||
given(redisConnectionFactory.getReactiveConnection()).willThrow(
|
||||
new RedisConnectionException("Unable to connect to localhost:6379"));
|
||||
RedisReactiveHealthIndicator healthIndicator = new RedisReactiveHealthIndicator(redisConnectionFactory);
|
||||
RedisReactiveHealthIndicator healthIndicator = new RedisReactiveHealthIndicator(
|
||||
redisConnectionFactory);
|
||||
Mono<Health> health = healthIndicator.health();
|
||||
StepVerifier.create(health)
|
||||
.consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.DOWN))
|
||||
|
Loading…
Reference in New Issue
Block a user