Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
0e2f7c57
Commit
0e2f7c57
authored
Sep 03, 2017
by
Mark Paluch
Committed by
Stephane Nicoll
Sep 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close reactive Redis connection after health check
Closes gh-10153
parent
11edff75
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
RedisReactiveHealthIndicator.java
...ork/boot/actuate/health/RedisReactiveHealthIndicator.java
+10
-4
RedisReactiveHealthIndicatorTests.java
...oot/actuate/health/RedisReactiveHealthIndicatorTests.java
+13
-6
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RedisReactiveHealthIndicator.java
View file @
0e2f7c57
...
@@ -18,12 +18,14 @@ package org.springframework.boot.actuate.health;
...
@@ -18,12 +18,14 @@ package org.springframework.boot.actuate.health;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
import
org.springframework.data.redis.connection.ReactiveRedisConnection
;
import
org.springframework.data.redis.connection.ReactiveRedisConnectionFactory
;
import
org.springframework.data.redis.connection.ReactiveRedisConnectionFactory
;
/**
/**
* A {@link ReactiveHealthIndicator} for Redis.
* A {@link ReactiveHealthIndicator} for Redis.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Mark Paluch
* @since 2.0.0
* @since 2.0.0
*/
*/
public
class
RedisReactiveHealthIndicator
extends
AbstractReactiveHealthIndicator
{
public
class
RedisReactiveHealthIndicator
extends
AbstractReactiveHealthIndicator
{
...
@@ -37,10 +39,14 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
...
@@ -37,10 +39,14 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
@Override
@Override
protected
Mono
<
Health
>
doHealthCheck
(
Health
.
Builder
builder
)
{
protected
Mono
<
Health
>
doHealthCheck
(
Health
.
Builder
builder
)
{
return
this
.
connectionFactory
.
getReactiveConnection
().
serverCommands
().
info
()
ReactiveRedisConnection
connection
=
this
.
connectionFactory
.
map
(
info
->
builder
.
up
().
withDetail
(
.
getReactiveConnection
();
RedisHealthIndicator
.
VERSION
,
info
.
getProperty
(
return
connection
.
serverCommands
().
info
()
RedisHealthIndicator
.
REDIS_VERSION
)).
build
());
.
map
(
info
->
builder
.
up
()
.
withDetail
(
RedisHealthIndicator
.
VERSION
,
info
.
getProperty
(
RedisHealthIndicator
.
REDIS_VERSION
))
.
build
())
.
doFinally
(
signal
->
connection
.
close
());
}
}
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisReactiveHealthIndicatorTests.java
View file @
0e2f7c57
...
@@ -30,11 +30,13 @@ import org.springframework.data.redis.connection.ReactiveServerCommands;
...
@@ -30,11 +30,13 @@ import org.springframework.data.redis.connection.ReactiveServerCommands;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
/**
* Tests for {@link RedisReactiveHealthIndicator}.
* Tests for {@link RedisReactiveHealthIndicator}.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Mark Paluch
*/
*/
public
class
RedisReactiveHealthIndicatorTests
{
public
class
RedisReactiveHealthIndicatorTests
{
...
@@ -42,15 +44,17 @@ public class RedisReactiveHealthIndicatorTests {
...
@@ -42,15 +44,17 @@ public class RedisReactiveHealthIndicatorTests {
public
void
redisIsUp
()
throws
Exception
{
public
void
redisIsUp
()
throws
Exception
{
Properties
info
=
new
Properties
();
Properties
info
=
new
Properties
();
info
.
put
(
"redis_version"
,
"2.8.9"
);
info
.
put
(
"redis_version"
,
"2.8.9"
);
ReactiveRedisConnection
redisConnection
=
mock
(
ReactiveRedisConnection
.
class
);
ReactiveServerCommands
commands
=
mock
(
ReactiveServerCommands
.
class
);
ReactiveServerCommands
commands
=
mock
(
ReactiveServerCommands
.
class
);
given
(
commands
.
info
()).
willReturn
(
Mono
.
just
(
info
));
given
(
commands
.
info
()).
willReturn
(
Mono
.
just
(
info
));
RedisReactiveHealthIndicator
healthIndicator
=
createHealthIndicator
(
commands
);
RedisReactiveHealthIndicator
healthIndicator
=
createHealthIndicator
(
redisConnection
,
commands
);
Mono
<
Health
>
health
=
healthIndicator
.
health
();
Mono
<
Health
>
health
=
healthIndicator
.
health
();
StepVerifier
.
create
(
health
).
consumeNextWith
(
h
->
{
StepVerifier
.
create
(
health
).
consumeNextWith
(
h
->
{
assertThat
(
h
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
h
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
h
.
getDetails
()).
containsOnlyKeys
(
"version"
);
assertThat
(
h
.
getDetails
()).
containsOnlyKeys
(
"version"
);
assertThat
(
h
.
getDetails
().
get
(
"version"
)).
isEqualTo
(
"2.8.9"
);
assertThat
(
h
.
getDetails
().
get
(
"version"
)).
isEqualTo
(
"2.8.9"
);
}).
verifyComplete
();
}).
verifyComplete
();
verify
(
redisConnection
).
close
();
}
}
@Test
@Test
...
@@ -58,15 +62,18 @@ public class RedisReactiveHealthIndicatorTests {
...
@@ -58,15 +62,18 @@ public class RedisReactiveHealthIndicatorTests {
ReactiveServerCommands
commands
=
mock
(
ReactiveServerCommands
.
class
);
ReactiveServerCommands
commands
=
mock
(
ReactiveServerCommands
.
class
);
given
(
commands
.
info
()).
willReturn
(
Mono
.
error
(
given
(
commands
.
info
()).
willReturn
(
Mono
.
error
(
new
RedisConnectionFailureException
(
"Connection failed"
)));
new
RedisConnectionFailureException
(
"Connection failed"
)));
RedisReactiveHealthIndicator
healthIndicator
=
createHealthIndicator
(
commands
);
ReactiveRedisConnection
redisConnection
=
mock
(
ReactiveRedisConnection
.
class
);
RedisReactiveHealthIndicator
healthIndicator
=
createHealthIndicator
(
redisConnection
,
commands
);
Mono
<
Health
>
health
=
healthIndicator
.
health
();
Mono
<
Health
>
health
=
healthIndicator
.
health
();
StepVerifier
.
create
(
health
)
StepVerifier
.
create
(
health
).
consumeNextWith
(
h
->
{
.
expectError
(
RedisConnectionFailureException
.
class
);
assertThat
(
h
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
}).
verifyComplete
();
verify
(
redisConnection
).
close
();
}
}
private
RedisReactiveHealthIndicator
createHealthIndicator
(
private
RedisReactiveHealthIndicator
createHealthIndicator
(
ReactiveServerCommands
serverCommands
)
{
Reactive
RedisConnection
redisConnection
,
Reactive
ServerCommands
serverCommands
)
{
ReactiveRedisConnection
redisConnection
=
mock
(
ReactiveRedisConnection
.
class
);
ReactiveRedisConnectionFactory
redisConnectionFactory
=
mock
(
ReactiveRedisConnectionFactory
redisConnectionFactory
=
mock
(
ReactiveRedisConnectionFactory
.
class
);
ReactiveRedisConnectionFactory
.
class
);
given
(
redisConnectionFactory
.
getReactiveConnection
()).
willReturn
(
redisConnection
);
given
(
redisConnectionFactory
.
getReactiveConnection
()).
willReturn
(
redisConnection
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment