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
a9b5e7c1
Commit
a9b5e7c1
authored
Apr 10, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.4.x' into 1.5.x
parents
db60ed66
9d88e477
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
10 deletions
+41
-10
SolrHealthIndicator.java
...ingframework/boot/actuate/health/SolrHealthIndicator.java
+15
-3
SolrHealthIndicatorTests.java
...amework/boot/actuate/health/SolrHealthIndicatorTests.java
+26
-7
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/SolrHealthIndicator.java
View file @
a9b5e7c1
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -17,11 +17,15 @@
package
org
.
springframework
.
boot
.
actuate
.
health
;
import
org.apache.solr.client.solrj.SolrClient
;
import
org.apache.solr.client.solrj.request.CoreAdminRequest
;
import
org.apache.solr.client.solrj.response.CoreAdminResponse
;
import
org.apache.solr.common.params.CoreAdminParams
;
/**
* {@link HealthIndicator} for Apache Solr.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
* @since 1.1.0
*/
public
class
SolrHealthIndicator
extends
AbstractHealthIndicator
{
...
...
@@ -34,8 +38,16 @@ public class SolrHealthIndicator extends AbstractHealthIndicator {
@Override
protected
void
doHealthCheck
(
Health
.
Builder
builder
)
throws
Exception
{
Object
status
=
this
.
solrClient
.
ping
().
getResponse
().
get
(
"status"
);
builder
.
up
().
withDetail
(
"solrStatus"
,
status
);
CoreAdminRequest
request
=
new
CoreAdminRequest
();
request
.
setAction
(
CoreAdminParams
.
CoreAdminAction
.
STATUS
);
CoreAdminResponse
response
=
request
.
process
(
this
.
solrClient
);
int
status
=
response
.
getStatus
();
if
(
status
==
0
)
{
builder
.
up
().
withDetail
(
"solrStatus"
,
"OK"
);
}
else
{
builder
.
down
().
withDetail
(
"solrStatus"
,
status
);
}
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/SolrHealthIndicatorTests.java
View file @
a9b5e7c1
...
...
@@ -19,7 +19,7 @@ package org.springframework.boot.actuate.health;
import
java.io.IOException
;
import
org.apache.solr.client.solrj.SolrClient
;
import
org.apache.solr.client.solrj.re
sponse.SolrPingResponse
;
import
org.apache.solr.client.solrj.re
quest.CoreAdminRequest
;
import
org.apache.solr.common.util.NamedList
;
import
org.junit.After
;
import
org.junit.Test
;
...
...
@@ -32,6 +32,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
isNull
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
...
...
@@ -65,21 +67,30 @@ public class SolrHealthIndicatorTests {
@Test
public
void
solrIsUp
()
throws
Exception
{
SolrClient
solrClient
=
mock
(
SolrClient
.
class
);
SolrPingResponse
pingResponse
=
new
SolrPingResponse
();
NamedList
<
Object
>
response
=
new
NamedList
<
Object
>();
response
.
add
(
"status"
,
"OK"
);
pingResponse
.
setResponse
(
response
);
given
(
solrClient
.
ping
()).
willReturn
(
pingResponse
);
given
(
solrClient
.
request
(
any
(
CoreAdminRequest
.
class
),
(
String
)
isNull
()))
.
willReturn
(
mockResponse
(
0
));
SolrHealthIndicator
healthIndicator
=
new
SolrHealthIndicator
(
solrClient
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
().
get
(
"solrStatus"
)).
isEqualTo
(
"OK"
);
}
@Test
public
void
solrIsUpAndRequestFailed
()
throws
Exception
{
SolrClient
solrClient
=
mock
(
SolrClient
.
class
);
given
(
solrClient
.
request
(
any
(
CoreAdminRequest
.
class
),
(
String
)
isNull
()))
.
willReturn
(
mockResponse
(
400
));
SolrHealthIndicator
healthIndicator
=
new
SolrHealthIndicator
(
solrClient
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertThat
(
health
.
getDetails
().
get
(
"solrStatus"
)).
isEqualTo
(
400
);
}
@Test
public
void
solrIsDown
()
throws
Exception
{
SolrClient
solrClient
=
mock
(
SolrClient
.
class
);
given
(
solrClient
.
ping
()).
willThrow
(
new
IOException
(
"Connection failed"
));
given
(
solrClient
.
request
(
any
(
CoreAdminRequest
.
class
),
(
String
)
isNull
()))
.
willThrow
(
new
IOException
(
"Connection failed"
));
SolrHealthIndicator
healthIndicator
=
new
SolrHealthIndicator
(
solrClient
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
...
...
@@ -87,4 +98,12 @@ public class SolrHealthIndicatorTests {
.
contains
(
"Connection failed"
));
}
private
NamedList
<
Object
>
mockResponse
(
int
status
)
{
NamedList
<
Object
>
response
=
new
NamedList
<
Object
>();
NamedList
<
Object
>
headers
=
new
NamedList
<
Object
>();
headers
.
add
(
"status"
,
status
);
response
.
add
(
"responseHeader"
,
headers
);
return
response
;
}
}
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