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
c9efa5ac
Commit
c9efa5ac
authored
Mar 08, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow non-string return from health query
parent
9d4e940f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
SimpleHealthIndicator.java
...gframework/boot/actuate/health/SimpleHealthIndicator.java
+1
-1
SimpleHealthIndicatorTests.java
...ework/boot/actuate/health/SimpleHealthIndicatorTests.java
+24
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SimpleHealthIndicator.java
View file @
c9efa5ac
...
@@ -78,7 +78,7 @@ public class SimpleHealthIndicator implements HealthIndicator<Map<String, Object
...
@@ -78,7 +78,7 @@ public class SimpleHealthIndicator implements HealthIndicator<Map<String, Object
if
(
StringUtils
.
hasText
(
query
))
{
if
(
StringUtils
.
hasText
(
query
))
{
try
{
try
{
health
.
put
(
"hello"
,
health
.
put
(
"hello"
,
this
.
jdbcTemplate
.
queryForObject
(
query
,
String
.
class
));
this
.
jdbcTemplate
.
queryForObject
(
query
,
Object
.
class
));
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
health
.
put
(
"status"
,
"error"
);
health
.
put
(
"status"
,
"error"
);
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SimpleHealthIndicatorTests.java
View file @
c9efa5ac
...
@@ -24,9 +24,11 @@ import javax.sql.DataSource;
...
@@ -24,9 +24,11 @@ import javax.sql.DataSource;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.datasource.DriverManagerDataSource
;
import
org.springframework.jdbc.datasource.DriverManagerDataSource
;
import
org.springframework.jdbc.datasource.SingleConnectionDataSource
;
import
org.springframework.jdbc.datasource.SingleConnectionDataSource
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
times
;
...
@@ -58,6 +60,28 @@ public class SimpleHealthIndicatorTests {
...
@@ -58,6 +60,28 @@ public class SimpleHealthIndicatorTests {
assertNotNull
(
health
.
get
(
"hello"
));
assertNotNull
(
health
.
get
(
"hello"
));
}
}
@Test
public
void
customQuery
()
{
this
.
indicator
.
setDataSource
(
this
.
dataSource
);
new
JdbcTemplate
(
this
.
dataSource
)
.
execute
(
"CREATE TABLE FOO (id INTEGER IDENTITY PRIMARY KEY)"
);
this
.
indicator
.
setQuery
(
"SELECT COUNT(*) from FOO"
);
Map
<
String
,
Object
>
health
=
this
.
indicator
.
health
();
System
.
err
.
println
(
health
);
assertNotNull
(
health
.
get
(
"database"
));
assertEquals
(
"ok"
,
health
.
get
(
"status"
));
assertNotNull
(
health
.
get
(
"hello"
));
}
@Test
public
void
error
()
{
this
.
indicator
.
setDataSource
(
this
.
dataSource
);
this
.
indicator
.
setQuery
(
"SELECT COUNT(*) from BAR"
);
Map
<
String
,
Object
>
health
=
this
.
indicator
.
health
();
assertNotNull
(
health
.
get
(
"database"
));
assertEquals
(
"error"
,
health
.
get
(
"status"
));
}
@Test
@Test
public
void
connectionClosed
()
throws
Exception
{
public
void
connectionClosed
()
throws
Exception
{
DataSource
dataSource
=
mock
(
DataSource
.
class
);
DataSource
dataSource
=
mock
(
DataSource
.
class
);
...
...
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