@@ -28,8 +28,8 @@ import org.springframework.core.ResolvableType;
|
||||
* Base class for configurations that can combine source beans using a
|
||||
* {@link CompositeHealthIndicator}.
|
||||
*
|
||||
* @param <H> The health indicator type
|
||||
* @param <S> T he bean source type
|
||||
* @param <H> the health indicator type
|
||||
* @param <S> the bean source type
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.4.0
|
||||
*/
|
||||
|
||||
@@ -43,14 +43,14 @@ class ElasticsearchHealthIndicatorConfiguration {
|
||||
@ConditionalOnBean(Client.class)
|
||||
@ConditionalOnEnabledHealthIndicator("elasticsearch")
|
||||
@EnableConfigurationProperties(ElasticsearchHealthIndicatorProperties.class)
|
||||
static class ElasticsearchSpringDataHealthIndicatorConfiguration extends
|
||||
static class ElasticsearchClientHealthIndicatorConfiguration extends
|
||||
CompositeHealthIndicatorConfiguration<ElasticsearchHealthIndicator, Client> {
|
||||
|
||||
private final Map<String, Client> clients;
|
||||
|
||||
private final ElasticsearchHealthIndicatorProperties properties;
|
||||
|
||||
ElasticsearchSpringDataHealthIndicatorConfiguration(Map<String, Client> clients,
|
||||
ElasticsearchClientHealthIndicatorConfiguration(Map<String, Client> clients,
|
||||
ElasticsearchHealthIndicatorProperties properties) {
|
||||
this.clients = clients;
|
||||
this.properties = properties;
|
||||
|
||||
@@ -98,7 +98,7 @@ import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
MongoDataAutoConfiguration.class, RabbitAutoConfiguration.class,
|
||||
RedisAutoConfiguration.class, SolrAutoConfiguration.class })
|
||||
@EnableConfigurationProperties({ HealthIndicatorProperties.class })
|
||||
@Import({ ElasticsearchHealthIndicatorConfiguration.ElasticsearchSpringDataHealthIndicatorConfiguration.class,
|
||||
@Import({ ElasticsearchHealthIndicatorConfiguration.ElasticsearchClientHealthIndicatorConfiguration.class,
|
||||
ElasticsearchHealthIndicatorConfiguration.ElasticsearchJestHealthIndicatorConfiguration.class })
|
||||
public class HealthIndicatorAutoConfiguration {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ElasticsearchHealthIndicatorProperties {
|
||||
private List<String> indices = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* The time, in milliseconds, to wait for a response from the cluster.
|
||||
* Time, in milliseconds, to wait for a response from the cluster.
|
||||
*/
|
||||
private long responseTimeout = 100L;
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ public class ElasticsearchJestHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private final JestClient jestClient;
|
||||
|
||||
private final JsonParser jsonParser = new JsonParser();
|
||||
|
||||
public ElasticsearchJestHealthIndicator(JestClient jestClient) {
|
||||
this.jestClient = jestClient;
|
||||
}
|
||||
@@ -40,8 +42,7 @@ public class ElasticsearchJestHealthIndicator extends AbstractHealthIndicator {
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
JestResult aliases = this.jestClient.execute(new Stats.Builder().build());
|
||||
JsonParser jsonParser = new JsonParser();
|
||||
JsonElement root = jsonParser.parse(aliases.getJsonString());
|
||||
JsonElement root = this.jsonParser.parse(aliases.getJsonString());
|
||||
JsonObject shards = root.getAsJsonObject().get("_shards").getAsJsonObject();
|
||||
int failedShards = shards.get("failed").getAsInt();
|
||||
if (failedShards != 0) {
|
||||
|
||||
@@ -394,7 +394,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void elasticSearchHealthIndicator() {
|
||||
public void elasticsearchHealthIndicator() {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.path.home:target",
|
||||
"management.health.diskspace.enabled:false");
|
||||
@@ -411,7 +411,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void elasticSearchJestHealthIndicator() {
|
||||
public void elasticsearchJestHealthIndicator() {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"management.health.diskspace.enabled:false");
|
||||
this.context.register(JestClientConfiguration.class,
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void elasticSearchIsUp() throws IOException {
|
||||
public void elasticsearchIsUp() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class)))
|
||||
.willReturn(createJestResult(4, 0));
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void elasticSearchIsDown() throws IOException {
|
||||
public void elasticsearchIsDown() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class))).willThrow(
|
||||
new CouldNotConnectException("http://localhost:9200", new IOException()));
|
||||
Health health = this.healthIndicator.health();
|
||||
@@ -65,7 +65,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void elasticSearchIsOutOfService() throws IOException {
|
||||
public void elasticsearchIsOutOfService() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class)))
|
||||
.willReturn(createJestResult(4, 1));
|
||||
Health health = this.healthIndicator.health();
|
||||
|
||||
@@ -18,9 +18,7 @@ package org.springframework.boot.autoconfigure.data.neo4j;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.neo4j.ogm.drivers.http.driver.HttpDriver;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
@@ -48,9 +46,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class Neo4jDataAutoConfigurationTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
|
||||
@@ -86,7 +86,6 @@ public class Neo4jRepositoriesAutoConfigurationTests {
|
||||
"spring.data.neo4j.uri=http://localhost:9797");
|
||||
this.context.register(configurationClasses);
|
||||
this.context.register(Neo4jDataAutoConfiguration.class,
|
||||
Neo4jDataAutoConfiguration.class,
|
||||
Neo4jRepositoriesAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
@@ -78,7 +78,7 @@ class SpringBootTestContextCustomizer implements ContextCustomizer {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link FactoryBean} used to create a configure a {@link TestRestTemplate}.
|
||||
* {@link FactoryBean} used to create and configure a {@link TestRestTemplate}.
|
||||
*/
|
||||
public static class TestRestTemplateFactory
|
||||
implements FactoryBean<TestRestTemplate>, ApplicationContextAware {
|
||||
|
||||
Reference in New Issue
Block a user