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
42bb8433
Commit
42bb8433
authored
May 25, 2016
by
RichardCSantana
Committed by
Stephane Nicoll
Jul 18, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Bug HealthIndicator for Redis Cluster
See gh-6059
parent
34893eee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
+56
-2
RedisHealthIndicator.java
...ngframework/boot/actuate/health/RedisHealthIndicator.java
+23
-2
RedisHealthIndicatorTests.java
...mework/boot/actuate/health/RedisHealthIndicatorTests.java
+33
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RedisHealthIndicator.java
View file @
42bb8433
...
@@ -18,6 +18,8 @@ package org.springframework.boot.actuate.health;
...
@@ -18,6 +18,8 @@ package org.springframework.boot.actuate.health;
import
java.util.Properties
;
import
java.util.Properties
;
import
org.springframework.data.redis.connection.ClusterInfo
;
import
org.springframework.data.redis.connection.RedisClusterConnection
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisConnectionUtils
;
import
org.springframework.data.redis.core.RedisConnectionUtils
;
...
@@ -28,10 +30,13 @@ import org.springframework.util.Assert;
...
@@ -28,10 +30,13 @@ import org.springframework.util.Assert;
* Redis data stores.
* Redis data stores.
*
*
* @author Christian Dupuis
* @author Christian Dupuis
* @author Richard Santana
* @since 1.1.0
* @since 1.1.0
*/
*/
public
class
RedisHealthIndicator
extends
AbstractHealthIndicator
{
public
class
RedisHealthIndicator
extends
AbstractHealthIndicator
{
private
static
final
String
VERSION
=
"version"
;
private
static
final
String
REDIS_VERSION
=
"redis_version"
;
private
final
RedisConnectionFactory
redisConnectionFactory
;
private
final
RedisConnectionFactory
redisConnectionFactory
;
public
RedisHealthIndicator
(
RedisConnectionFactory
connectionFactory
)
{
public
RedisHealthIndicator
(
RedisConnectionFactory
connectionFactory
)
{
...
@@ -44,8 +49,14 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
...
@@ -44,8 +49,14 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
RedisConnection
connection
=
RedisConnectionUtils
RedisConnection
connection
=
RedisConnectionUtils
.
getConnection
(
this
.
redisConnectionFactory
);
.
getConnection
(
this
.
redisConnectionFactory
);
try
{
try
{
Properties
info
=
connection
.
info
();
if
(
connection
instanceof
RedisClusterConnection
)
{
builder
.
up
().
withDetail
(
"version"
,
info
.
getProperty
(
"redis_version"
));
redisClusterInfo
(
builder
,
((
RedisClusterConnection
)
connection
).
clusterGetClusterInfo
());
}
else
{
Properties
info
=
connection
.
info
();
defaultRedisInfo
(
builder
,
VERSION
,
info
.
getProperty
(
REDIS_VERSION
));
}
}
}
finally
{
finally
{
RedisConnectionUtils
.
releaseConnection
(
connection
,
RedisConnectionUtils
.
releaseConnection
(
connection
,
...
@@ -53,4 +64,14 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
...
@@ -53,4 +64,14 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
}
}
}
}
private
void
redisClusterInfo
(
Health
.
Builder
builder
,
ClusterInfo
clusterInfo
)
{
defaultRedisInfo
(
builder
,
"cluster_size"
,
clusterInfo
.
getClusterSize
());
defaultRedisInfo
(
builder
,
"slots_up"
,
clusterInfo
.
getSlotsOk
());
defaultRedisInfo
(
builder
,
"slots_fail"
,
clusterInfo
.
getSlotsFail
());
}
private
void
defaultRedisInfo
(
Health
.
Builder
builder
,
String
key
,
Object
value
)
{
builder
.
up
().
withDetail
(
key
,
value
);
}
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RedisHealthIndicatorTests.java
View file @
42bb8433
...
@@ -16,10 +16,13 @@
...
@@ -16,10 +16,13 @@
package
org
.
springframework
.
boot
.
actuate
.
health
;
package
org
.
springframework
.
boot
.
actuate
.
health
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Properties
;
import
java.util.Properties
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration
;
...
@@ -27,6 +30,9 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
...
@@ -27,6 +30,9 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
;
import
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.data.redis.RedisConnectionFailureException
;
import
org.springframework.data.redis.RedisConnectionFailureException
;
import
org.springframework.data.redis.connection.ClusterInfo
;
import
org.springframework.data.redis.connection.RedisClusterConnection
;
import
org.springframework.data.redis.connection.RedisClusterNode
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
...
@@ -39,6 +45,7 @@ import static org.mockito.Mockito.verify;
...
@@ -39,6 +45,7 @@ import static org.mockito.Mockito.verify;
* Tests for {@link RedisHealthIndicator}.
* Tests for {@link RedisHealthIndicator}.
*
*
* @author Christian Dupuis
* @author Christian Dupuis
* @author Richard Santana
*/
*/
public
class
RedisHealthIndicatorTests
{
public
class
RedisHealthIndicatorTests
{
...
@@ -99,4 +106,30 @@ public class RedisHealthIndicatorTests {
...
@@ -99,4 +106,30 @@ public class RedisHealthIndicatorTests {
verify
(
redisConnection
).
info
();
verify
(
redisConnection
).
info
();
}
}
@Test
public
void
redisClusterIsUp
()
throws
Exception
{
Properties
clusterProperties
=
new
Properties
();
clusterProperties
.
setProperty
(
"cluster_size"
,
"4"
);
clusterProperties
.
setProperty
(
"cluster_slots_ok"
,
"4"
);
clusterProperties
.
setProperty
(
"cluster_slots_fail"
,
"0"
);
List
<
RedisClusterNode
>
redisMasterNodes
=
Arrays
.
asList
(
new
RedisClusterNode
(
"127.0.0.1"
,
7001
),
new
RedisClusterNode
(
"127.0.0.2"
,
7001
));
RedisClusterConnection
redisConnection
=
mock
(
RedisClusterConnection
.
class
);
given
(
redisConnection
.
clusterGetNodes
()).
willReturn
(
redisMasterNodes
);
given
(
redisConnection
.
clusterGetClusterInfo
())
.
willReturn
(
new
ClusterInfo
(
clusterProperties
));
RedisConnectionFactory
redisConnectionFactory
=
mock
(
RedisConnectionFactory
.
class
);
given
(
redisConnectionFactory
.
getConnection
()).
willReturn
(
redisConnection
);
RedisHealthIndicator
healthIndicator
=
new
RedisHealthIndicator
(
redisConnectionFactory
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
get
(
"cluster_size"
)).
isEqualTo
(
4L
);
assertThat
(
health
.
getDetails
().
get
(
"slots_up"
)).
isEqualTo
(
4L
);
assertThat
(
health
.
getDetails
().
get
(
"slots_fail"
)).
isEqualTo
(
0L
);
verify
(
redisConnectionFactory
,
Mockito
.
atLeastOnce
()).
getConnection
();
}
}
}
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