|
|
|
@ -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.response.SolrPingResponse;
|
|
|
|
|
import org.apache.solr.client.solrj.request.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<>();
|
|
|
|
|
response.add("status", "OK");
|
|
|
|
|
pingResponse.setResponse(response);
|
|
|
|
|
given(solrClient.ping()).willReturn(pingResponse);
|
|
|
|
|
given(solrClient.request(any(CoreAdminRequest.class),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), 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), 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<>();
|
|
|
|
|
NamedList<Object> headers = new NamedList<>();
|
|
|
|
|
headers.add("status", status);
|
|
|
|
|
response.add("responseHeader", headers);
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|