From 68163a66a5a9e57ab313873a2243cb42578fa539 Mon Sep 17 00:00:00 2001 From: Christian Dupuis Date: Thu, 24 Jul 2014 10:06:26 +0200 Subject: [PATCH] Change query in MongoHealthIndicator This commit changes the query in MongoHealthIndicator from serverStatus to buildInfo to avoid unprivileged access and corresponding errors. fixes #1289 --- .../boot/actuate/health/MongoHealthIndicator.java | 4 ++-- .../boot/actuate/health/MongoHealthIndicatorTests.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java index a13dfdc4be..c28293937a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/MongoHealthIndicator.java @@ -24,7 +24,7 @@ import com.mongodb.CommandResult; /** * Simple implementation of a {@link HealthIndicator} returning status information for * Mongo data stores. - * + * * @author Christian Dupuis * @since 1.1.0 */ @@ -39,7 +39,7 @@ public class MongoHealthIndicator extends AbstractHealthIndicator { @Override protected void doHealthCheck(Health.Builder builder) throws Exception { - CommandResult result = this.mongoTemplate.executeCommand("{ serverStatus: 1 }"); + CommandResult result = this.mongoTemplate.executeCommand("{ buildInfo: 1 }"); builder.up().withDetail("version", result.getString("version")); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java index 16b1d15937..b60b104c5d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MongoHealthIndicatorTests.java @@ -36,7 +36,7 @@ import static org.junit.Assert.assertTrue; /** * Tests for {@link MongoHealthIndicator}. - * + * * @author Christian Dupuis */ public class MongoHealthIndicatorTests { @@ -67,7 +67,7 @@ public class MongoHealthIndicatorTests { CommandResult commandResult = Mockito.mock(CommandResult.class); Mockito.when(commandResult.getString("version")).thenReturn("2.6.4"); MongoTemplate mongoTemplate = Mockito.mock(MongoTemplate.class); - Mockito.when(mongoTemplate.executeCommand("{ serverStatus: 1 }")).thenReturn( + Mockito.when(mongoTemplate.executeCommand("{ buildInfo: 1 }")).thenReturn( commandResult); MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate); @@ -76,13 +76,13 @@ public class MongoHealthIndicatorTests { assertEquals("2.6.4", health.getDetails().get("version")); Mockito.verify(commandResult).getString("version"); - Mockito.verify(mongoTemplate).executeCommand("{ serverStatus: 1 }"); + Mockito.verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); } @Test public void mongoIsDown() throws Exception { MongoTemplate mongoTemplate = Mockito.mock(MongoTemplate.class); - Mockito.when(mongoTemplate.executeCommand("{ serverStatus: 1 }")).thenThrow( + Mockito.when(mongoTemplate.executeCommand("{ buildInfo: 1 }")).thenThrow( new MongoException("Connection failed")); MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate); @@ -91,6 +91,6 @@ public class MongoHealthIndicatorTests { assertTrue(((String) health.getDetails().get("error")) .contains("Connection failed")); - Mockito.verify(mongoTemplate).executeCommand("{ serverStatus: 1 }"); + Mockito.verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); } }