Remove deprecated HealthIndicator and HealthAggregator 2.2 code
See gh-19699
This commit is contained in:
committed by
Stephane Nicoll
parent
1f1b06dfe2
commit
2e32cb2af1
@@ -1,225 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.elasticsearch;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchTimeoutException;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.support.PlainActionFuture;
|
||||
import org.elasticsearch.client.AdminClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Test for {@link ElasticsearchHealthIndicator}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Deprecated
|
||||
class ElasticsearchHealthIndicatorTests {
|
||||
|
||||
@Mock
|
||||
private Client client;
|
||||
|
||||
@Mock
|
||||
private AdminClient admin;
|
||||
|
||||
@Mock
|
||||
private ClusterAdminClient cluster;
|
||||
|
||||
private ElasticsearchHealthIndicator indicator;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
given(this.client.admin()).willReturn(this.admin);
|
||||
given(this.admin.cluster()).willReturn(this.cluster);
|
||||
this.indicator = new ElasticsearchHealthIndicator(this.client, 100L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultConfigurationQueriesAllIndicesWith100msTimeout() {
|
||||
TestActionFuture responseFuture = new TestActionFuture();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
||||
ArgumentCaptor<ClusterHealthRequest> requestCaptor = ArgumentCaptor.forClass(ClusterHealthRequest.class);
|
||||
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
|
||||
Health health = this.indicator.health();
|
||||
assertThat(responseFuture.getTimeout).isEqualTo(100L);
|
||||
assertThat(requestCaptor.getValue().indices()).contains("_all");
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
}
|
||||
|
||||
@Test
|
||||
void certainIndices() {
|
||||
this.indicator = new ElasticsearchHealthIndicator(this.client, 100L, "test-index-1", "test-index-2");
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
||||
ArgumentCaptor<ClusterHealthRequest> requestCaptor = ArgumentCaptor.forClass(ClusterHealthRequest.class);
|
||||
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
|
||||
Health health = this.indicator.health();
|
||||
assertThat(requestCaptor.getValue().indices()).contains("test-index-1", "test-index-2");
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customTimeout() {
|
||||
this.indicator = new ElasticsearchHealthIndicator(this.client, 1000L);
|
||||
TestActionFuture responseFuture = new TestActionFuture();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
||||
ArgumentCaptor<ClusterHealthRequest> requestCaptor = ArgumentCaptor.forClass(ClusterHealthRequest.class);
|
||||
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
|
||||
this.indicator.health();
|
||||
assertThat(responseFuture.getTimeout).isEqualTo(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthDetails() {
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
||||
Health health = this.indicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
Map<String, Object> details = health.getDetails();
|
||||
assertDetail(details, "clusterName", "test-cluster");
|
||||
assertDetail(details, "activeShards", 1);
|
||||
assertDetail(details, "relocatingShards", 2);
|
||||
assertDetail(details, "activePrimaryShards", 3);
|
||||
assertDetail(details, "initializingShards", 4);
|
||||
assertDetail(details, "unassignedShards", 5);
|
||||
assertDetail(details, "numberOfNodes", 6);
|
||||
assertDetail(details, "numberOfDataNodes", 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void redResponseMapsToDown() {
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.RED));
|
||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
||||
assertThat(this.indicator.health().getStatus()).isEqualTo(Status.DOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void yellowResponseMapsToUp() {
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.YELLOW));
|
||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
||||
assertThat(this.indicator.health().getStatus()).isEqualTo(Status.UP);
|
||||
}
|
||||
|
||||
@Test
|
||||
void responseTimeout() {
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
||||
Health health = this.indicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat((String) health.getDetails().get("error")).contains(ElasticsearchTimeoutException.class.getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> void assertDetail(Map<String, Object> details, String detail, T value) {
|
||||
assertThat((T) details.get(detail)).isEqualTo(value);
|
||||
}
|
||||
|
||||
private static final class StubClusterHealthResponse extends ClusterHealthResponse {
|
||||
|
||||
private final ClusterHealthStatus status;
|
||||
|
||||
private StubClusterHealthResponse() {
|
||||
this(ClusterHealthStatus.GREEN);
|
||||
}
|
||||
|
||||
private StubClusterHealthResponse(ClusterHealthStatus status) {
|
||||
super("test-cluster", new String[0], new ClusterState(null, 0, null, null, RoutingTable.builder().build(),
|
||||
DiscoveryNodes.builder().build(), ClusterBlocks.builder().build(), null, 1, false));
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveShards() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRelocatingShards() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActivePrimaryShards() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInitializingShards() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnassignedShards() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfNodes() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfDataNodes() {
|
||||
return 7;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterHealthStatus getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class TestActionFuture extends PlainActionFuture<ClusterHealthResponse> {
|
||||
|
||||
private long getTimeout = -1L;
|
||||
|
||||
@Override
|
||||
public ClusterHealthResponse actionGet(long timeoutMillis) throws ElasticsearchException {
|
||||
this.getTimeout = timeoutMillis;
|
||||
return super.actionGet(timeoutMillis);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ApplicationHealthIndicator}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@Deprecated
|
||||
class ApplicationHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
void indicatesUp() {
|
||||
ApplicationHealthIndicator healthIndicator = new ApplicationHealthIndicator();
|
||||
assertThat(healthIndicator.health().getStatus()).isEqualTo(Status.UP);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompositeHealthIndicator}
|
||||
*
|
||||
* @author Tyler J. Frederick
|
||||
* @author Phillip Webb
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
@Deprecated
|
||||
class CompositeHealthIndicatorTests {
|
||||
|
||||
private HealthAggregator healthAggregator;
|
||||
|
||||
@Mock
|
||||
private HealthIndicator one;
|
||||
|
||||
@Mock
|
||||
private HealthIndicator two;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
given(this.one.health()).willReturn(new Health.Builder().unknown().withDetail("1", "1").build());
|
||||
given(this.two.health()).willReturn(new Health.Builder().unknown().withDetail("2", "2").build());
|
||||
|
||||
this.healthAggregator = new OrderedHealthAggregator();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithIndicators() {
|
||||
Map<String, HealthIndicator> indicators = new HashMap<>();
|
||||
indicators.put("one", this.one);
|
||||
indicators.put("two", this.two);
|
||||
CompositeHealthIndicator composite = new CompositeHealthIndicator(this.healthAggregator, indicators);
|
||||
Health result = composite.health();
|
||||
assertThat(result.getDetails()).hasSize(2);
|
||||
assertThat(result.getDetails()).containsEntry("one",
|
||||
new Health.Builder().unknown().withDetail("1", "1").build());
|
||||
assertThat(result.getDetails()).containsEntry("two",
|
||||
new Health.Builder().unknown().withDetail("2", "2").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialization() throws Exception {
|
||||
Map<String, HealthIndicator> indicators = new LinkedHashMap<>();
|
||||
indicators.put("db1", this.one);
|
||||
indicators.put("db2", this.two);
|
||||
CompositeHealthIndicator innerComposite = new CompositeHealthIndicator(this.healthAggregator, indicators);
|
||||
CompositeHealthIndicator composite = new CompositeHealthIndicator(this.healthAggregator,
|
||||
Collections.singletonMap("db", innerComposite));
|
||||
Health result = composite.health();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
assertThat(mapper.writeValueAsString(result))
|
||||
.isEqualTo("{\"status\":\"UNKNOWN\",\"details\":{\"db\":{\"status\":\"UNKNOWN\""
|
||||
+ ",\"details\":{\"db1\":{\"status\":\"UNKNOWN\",\"details\""
|
||||
+ ":{\"1\":\"1\"}},\"db2\":{\"status\":\"UNKNOWN\",\"details\":{\"2\":\"2\"}}}}}}");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompositeReactiveHealthIndicator}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
class CompositeReactiveHealthIndicatorTests {
|
||||
|
||||
private static final Health UNKNOWN_HEALTH = Health.unknown().withDetail("detail", "value").build();
|
||||
|
||||
private static final Health HEALTHY = Health.up().build();
|
||||
|
||||
private OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator();
|
||||
|
||||
@Test
|
||||
void singleIndicator() {
|
||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
||||
new DefaultReactiveHealthIndicatorRegistry(Collections.singletonMap("test", () -> Mono.just(HEALTHY))));
|
||||
StepVerifier.create(indicator.health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("test");
|
||||
assertThat(h.getDetails().get("test")).isEqualTo(HEALTHY);
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void longHealth() {
|
||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
indicators.put("test" + i, new TimeoutHealth(10000, Status.UP));
|
||||
}
|
||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
||||
new DefaultReactiveHealthIndicatorRegistry(indicators));
|
||||
StepVerifier.withVirtualTime(indicator::health).expectSubscription().thenAwait(Duration.ofMillis(10000))
|
||||
.consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).hasSize(50);
|
||||
}).verifyComplete();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void timeoutReachedUsesFallback() {
|
||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
||||
indicators.put("slow", new TimeoutHealth(10000, Status.UP));
|
||||
indicators.put("fast", new TimeoutHealth(10, Status.UP));
|
||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
||||
new DefaultReactiveHealthIndicatorRegistry(indicators)).timeoutStrategy(100, UNKNOWN_HEALTH);
|
||||
StepVerifier.create(indicator.health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
|
||||
assertThat(h.getDetails().get("slow")).isEqualTo(UNKNOWN_HEALTH);
|
||||
assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY);
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void timeoutNotReached() {
|
||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
||||
indicators.put("slow", new TimeoutHealth(10000, Status.UP));
|
||||
indicators.put("fast", new TimeoutHealth(10, Status.UP));
|
||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
||||
new DefaultReactiveHealthIndicatorRegistry(indicators)).timeoutStrategy(20000, null);
|
||||
StepVerifier.withVirtualTime(indicator::health).expectSubscription().thenAwait(Duration.ofMillis(10000))
|
||||
.consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
|
||||
assertThat(h.getDetails().get("slow")).isEqualTo(HEALTHY);
|
||||
assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY);
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
static class TimeoutHealth implements ReactiveHealthIndicator {
|
||||
|
||||
private final long timeout;
|
||||
|
||||
private final Status status;
|
||||
|
||||
TimeoutHealth(long timeout, Status status) {
|
||||
this.timeout = timeout;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Health> health() {
|
||||
return Mono.delay(Duration.ofMillis(this.timeout)).map((l) -> Health.status(this.status).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultHealthIndicatorRegistry}.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
class DefaultHealthIndicatorRegistryTests {
|
||||
|
||||
private HealthIndicator one = mock(HealthIndicator.class);
|
||||
|
||||
private HealthIndicator two = mock(HealthIndicator.class);
|
||||
|
||||
private DefaultHealthIndicatorRegistry registry;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
given(this.one.health()).willReturn(new Health.Builder().unknown().withDetail("1", "1").build());
|
||||
given(this.two.health()).willReturn(new Health.Builder().unknown().withDetail("2", "2").build());
|
||||
this.registry = new DefaultHealthIndicatorRegistry();
|
||||
}
|
||||
|
||||
@Test
|
||||
void register() {
|
||||
this.registry.register("one", this.one);
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(2);
|
||||
assertThat(this.registry.get("one")).isSameAs(this.one);
|
||||
assertThat(this.registry.get("two")).isSameAs(this.two);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerAlreadyUsedName() {
|
||||
this.registry.register("one", this.one);
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.registry.register("one", this.two))
|
||||
.withMessageContaining("HealthIndicator with name 'one' already registered");
|
||||
}
|
||||
|
||||
@Test
|
||||
void unregister() {
|
||||
this.registry.register("one", this.one);
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(2);
|
||||
HealthIndicator two = this.registry.unregister("two");
|
||||
assertThat(two).isSameAs(this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unregisterUnknown() {
|
||||
this.registry.register("one", this.one);
|
||||
assertThat(this.registry.getAll()).hasSize(1);
|
||||
HealthIndicator two = this.registry.unregister("two");
|
||||
assertThat(two).isNull();
|
||||
assertThat(this.registry.getAll()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllIsASnapshot() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
||||
assertThat(snapshot).containsOnlyKeys("one");
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(snapshot).containsOnlyKeys("one");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllIsImmutable() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(snapshot::clear);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultReactiveHealthIndicatorRegistry}.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
|
||||
private ReactiveHealthIndicator one = mock(ReactiveHealthIndicator.class);
|
||||
|
||||
private ReactiveHealthIndicator two = mock(ReactiveHealthIndicator.class);
|
||||
|
||||
private DefaultReactiveHealthIndicatorRegistry registry;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
given(this.one.health()).willReturn(Mono.just(new Health.Builder().unknown().withDetail("1", "1").build()));
|
||||
given(this.two.health()).willReturn(Mono.just(new Health.Builder().unknown().withDetail("2", "2").build()));
|
||||
this.registry = new DefaultReactiveHealthIndicatorRegistry();
|
||||
}
|
||||
|
||||
@Test
|
||||
void register() {
|
||||
this.registry.register("one", this.one);
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(2);
|
||||
assertThat(this.registry.get("one")).isSameAs(this.one);
|
||||
assertThat(this.registry.get("two")).isSameAs(this.two);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerAlreadyUsedName() {
|
||||
this.registry.register("one", this.one);
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.registry.register("one", this.two))
|
||||
.withMessageContaining("HealthIndicator with name 'one' already registered");
|
||||
}
|
||||
|
||||
@Test
|
||||
void unregister() {
|
||||
this.registry.register("one", this.one);
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(2);
|
||||
ReactiveHealthIndicator two = this.registry.unregister("two");
|
||||
assertThat(two).isSameAs(this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unregisterUnknown() {
|
||||
this.registry.register("one", this.one);
|
||||
assertThat(this.registry.getAll()).hasSize(1);
|
||||
ReactiveHealthIndicator two = this.registry.unregister("two");
|
||||
assertThat(two).isNull();
|
||||
assertThat(this.registry.getAll()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllIsASnapshot() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
||||
assertThat(snapshot).containsOnlyKeys("one");
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(snapshot).containsOnlyKeys("one");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllIsImmutable() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(snapshot::clear);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.actuate.health.HealthEndpointSupport.HealthResult;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -35,15 +34,6 @@ import static org.mockito.Mockito.mock;
|
||||
class HealthEndpointTests
|
||||
extends HealthEndpointSupportTests<HealthContributorRegistry, HealthContributor, HealthComponent> {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void createWhenUsingDeprecatedConstructorThrowsException() {
|
||||
HealthIndicator healthIndicator = mock(HealthIndicator.class);
|
||||
assertThatIllegalStateException().isThrownBy(() -> new HealthEndpoint(healthIndicator))
|
||||
.withMessage("Unable to create class org.springframework.boot.actuate.health.HealthEndpoint "
|
||||
+ "using deprecated constructor");
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthReturnsSystemHealth() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -27,7 +27,6 @@ import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
||||
import org.springframework.boot.actuate.health.HealthEndpointSupport.HealthResult;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -38,16 +37,6 @@ import static org.mockito.Mockito.mock;
|
||||
class HealthEndpointWebExtensionTests
|
||||
extends HealthEndpointSupportTests<HealthContributorRegistry, HealthContributor, HealthComponent> {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void createWhenUsingDeprecatedConstructorThrowsException() {
|
||||
HealthEndpoint delegate = mock(HealthEndpoint.class);
|
||||
HealthWebEndpointResponseMapper responseMapper = mock(HealthWebEndpointResponseMapper.class);
|
||||
assertThatIllegalStateException().isThrownBy(() -> new HealthEndpointWebExtension(delegate, responseMapper))
|
||||
.withMessage("Unable to create class org.springframework.boot.actuate."
|
||||
+ "health.HealthEndpointWebExtension using deprecated constructor");
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthReturnsSystemHealth() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -29,7 +29,6 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class HealthIndicatorReactiveAdapterTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
/**
|
||||
* Tests for {@link HealthWebEndpointResponseMapper}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
class HealthWebEndpointResponseMapperTests {
|
||||
|
||||
private final HealthStatusHttpMapper statusHttpMapper = new HealthStatusHttpMapper();
|
||||
|
||||
private Set<String> authorizedRoles = Collections.singleton("ACTUATOR");
|
||||
|
||||
@Test
|
||||
void mapDetailsWithDisableDetailsDoesNotInvokeSupplier() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.NEVER);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
SecurityContext securityContext = mock(SecurityContext.class);
|
||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
verifyNoInteractions(supplier);
|
||||
verifyNoInteractions(securityContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapDetailsWithUnauthorizedUserDoesNotInvokeSupplier() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
SecurityContext securityContext = mockSecurityContext("USER");
|
||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
assertThat(response.getBody()).isNull();
|
||||
verifyNoInteractions(supplier);
|
||||
verify(securityContext).isUserInRole("ACTUATOR");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapDetailsWithAuthorizedUserInvokesSupplier() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
given(supplier.get()).willReturn(Health.down().build());
|
||||
SecurityContext securityContext = mockSecurityContext("ACTUATOR");
|
||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
||||
assertThat(response.getBody().getStatus()).isEqualTo(Status.DOWN);
|
||||
verify(supplier).get();
|
||||
verify(securityContext).isUserInRole("ACTUATOR");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapDetailsWithRightAuthoritiesInvokesSupplier() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
given(supplier.get()).willReturn(Health.down().build());
|
||||
SecurityContext securityContext = getSecurityContext("ACTUATOR");
|
||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
||||
assertThat(response.getBody().getStatus()).isEqualTo(Status.DOWN);
|
||||
verify(supplier).get();
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapDetailsWithOtherAuthoritiesShouldNotInvokeSupplier() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
given(supplier.get()).willReturn(Health.down().build());
|
||||
SecurityContext securityContext = getSecurityContext("OTHER");
|
||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
assertThat(response.getBody()).isNull();
|
||||
verifyNoInteractions(supplier);
|
||||
}
|
||||
|
||||
private SecurityContext getSecurityContext(String other) {
|
||||
SecurityContext securityContext = mock(SecurityContext.class);
|
||||
Authentication principal = mock(Authentication.class);
|
||||
given(securityContext.getPrincipal()).willReturn(principal);
|
||||
given(principal.getAuthorities())
|
||||
.willAnswer((invocation) -> Collections.singleton(new SimpleGrantedAuthority(other)));
|
||||
return securityContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapDetailsWithUnavailableHealth() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.ALWAYS);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
SecurityContext securityContext = mock(SecurityContext.class);
|
||||
WebEndpointResponse<Health> response = mapper.mapDetails(supplier, securityContext);
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
assertThat(response.getBody()).isNull();
|
||||
verify(supplier).get();
|
||||
verifyNoInteractions(securityContext);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Supplier<Health> mockSupplier() {
|
||||
return mock(Supplier.class);
|
||||
}
|
||||
|
||||
private SecurityContext mockSecurityContext(String... roles) {
|
||||
List<String> associatedRoles = Arrays.asList(roles);
|
||||
SecurityContext securityContext = mock(SecurityContext.class);
|
||||
given(securityContext.getPrincipal()).willReturn(mock(Principal.class));
|
||||
given(securityContext.isUserInRole(anyString())).will((Answer<Boolean>) (invocation) -> {
|
||||
String expectedRole = invocation.getArgument(0);
|
||||
return associatedRoles.contains(expectedRole);
|
||||
});
|
||||
return securityContext;
|
||||
}
|
||||
|
||||
private HealthWebEndpointResponseMapper createMapper(ShowDetails showDetails) {
|
||||
return new HealthWebEndpointResponseMapper(this.statusHttpMapper, showDetails, this.authorizedRoles);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link OrderedHealthAggregator}.
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
@Deprecated
|
||||
class OrderedHealthAggregatorTests {
|
||||
|
||||
private OrderedHealthAggregator healthAggregator;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.healthAggregator = new OrderedHealthAggregator();
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultOrder() {
|
||||
Map<String, Health> healths = new HashMap<>();
|
||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
||||
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
|
||||
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
|
||||
assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customOrder() {
|
||||
this.healthAggregator.setStatusOrder(Status.UNKNOWN, Status.UP, Status.OUT_OF_SERVICE, Status.DOWN);
|
||||
Map<String, Health> healths = new HashMap<>();
|
||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
||||
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
|
||||
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
|
||||
assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.UNKNOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultOrderWithCustomStatus() {
|
||||
Map<String, Health> healths = new HashMap<>();
|
||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
||||
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
|
||||
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
|
||||
healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build());
|
||||
assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customOrderWithCustomStatus() {
|
||||
this.healthAggregator.setStatusOrder(Arrays.asList("DOWN", "OUT_OF_SERVICE", "UP", "UNKNOWN", "CUSTOM"));
|
||||
Map<String, Health> healths = new HashMap<>();
|
||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
||||
healths.put("h3", new Health.Builder().status(Status.UNKNOWN).build());
|
||||
healths.put("h4", new Health.Builder().status(Status.OUT_OF_SERVICE).build());
|
||||
healths.put("h5", new Health.Builder().status(new Status("CUSTOM")).build());
|
||||
assertThat(this.healthAggregator.aggregate(healths).getStatus()).isEqualTo(Status.DOWN);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -39,7 +39,6 @@ class ReactiveHealthContributorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void adaptWhenHealthIndicatorReturnsHealthIndicatorReactiveAdapter() {
|
||||
HealthIndicator indicator = () -> Health.outOfService().build();
|
||||
ReactiveHealthContributor adapted = ReactiveHealthContributor.adapt(indicator);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -28,7 +28,6 @@ import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
||||
import org.springframework.boot.actuate.health.HealthEndpointSupport.HealthResult;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -39,17 +38,6 @@ import static org.mockito.Mockito.mock;
|
||||
class ReactiveHealthEndpointWebExtensionTests extends
|
||||
HealthEndpointSupportTests<ReactiveHealthContributorRegistry, ReactiveHealthContributor, Mono<? extends HealthComponent>> {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void createWhenUsingDeprecatedConstructorThrowsException() {
|
||||
ReactiveHealthIndicator delegate = mock(ReactiveHealthIndicator.class);
|
||||
HealthWebEndpointResponseMapper responseMapper = mock(HealthWebEndpointResponseMapper.class);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new ReactiveHealthEndpointWebExtension(delegate, responseMapper)).withMessage(
|
||||
"Unable to create class org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension "
|
||||
+ "using deprecated constructor");
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthReturnsSystemHealth() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReactiveHealthIndicatorRegistryFactory}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
class ReactiveHealthIndicatorRegistryFactoryTests {
|
||||
|
||||
private static final Health UP = new Health.Builder().status(Status.UP).build();
|
||||
|
||||
private static final Health DOWN = new Health.Builder().status(Status.DOWN).build();
|
||||
|
||||
private final ReactiveHealthIndicatorRegistryFactory factory = new ReactiveHealthIndicatorRegistryFactory();
|
||||
|
||||
@Test
|
||||
void defaultHealthIndicatorNameFactory() {
|
||||
ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry(
|
||||
Collections.singletonMap("myHealthIndicator", () -> Mono.just(UP)), null);
|
||||
assertThat(registry.getAll()).containsOnlyKeys("my");
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthIndicatorIsAdapted() {
|
||||
ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry(
|
||||
Collections.singletonMap("test", () -> Mono.just(UP)), Collections.singletonMap("regular", () -> DOWN));
|
||||
assertThat(registry.getAll()).containsOnlyKeys("test", "regular");
|
||||
StepVerifier.create(registry.get("regular").health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat(h.getDetails()).isEmpty();
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user