Search in sources :

Example 91 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class HazelcastHealthContributorAutoConfigurationIntegrationTests method hazelcastDown.

@Test
void hazelcastDown() {
    this.contextRunner.run((context) -> {
        context.getBean(HazelcastInstance.class).shutdown();
        assertThat(context).hasSingleBean(HazelcastHealthIndicator.class);
        Health health = context.getBean(HazelcastHealthIndicator.class).health();
        assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    });
}
Also used : HazelcastHealthIndicator(org.springframework.boot.actuate.hazelcast.HazelcastHealthIndicator) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test)

Example 92 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class HealthEndpointAutoConfigurationTests method runCreatesReactiveHealthEndpointWebExtension.

@Test
void runCreatesReactiveHealthEndpointWebExtension() {
    this.reactiveContextRunner.run((context) -> {
        ReactiveHealthEndpointWebExtension webExtension = context.getBean(ReactiveHealthEndpointWebExtension.class);
        Mono<WebEndpointResponse<? extends HealthComponent>> response = webExtension.health(ApiVersion.V3, WebServerNamespace.SERVER, SecurityContext.NONE, true, "simple");
        Health health = (Health) (response.block().getBody());
        assertThat(health.getDetails()).containsEntry("counter", 42);
    });
}
Also used : HealthComponent(org.springframework.boot.actuate.health.HealthComponent) Health(org.springframework.boot.actuate.health.Health) WebEndpointResponse(org.springframework.boot.actuate.endpoint.web.WebEndpointResponse) ReactiveHealthEndpointWebExtension(org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension) Test(org.junit.jupiter.api.Test)

Example 93 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class CassandraDriverReactiveHealthIndicatorTests method healthWithNodeVersionShouldAddVersionDetail.

@Test
void healthWithNodeVersionShouldAddVersionDetail() {
    CqlSession session = mock(CqlSession.class);
    Metadata metadata = mock(Metadata.class);
    given(session.getMetadata()).willReturn(metadata);
    Node node = mock(Node.class);
    given(node.getState()).willReturn(NodeState.UP);
    given(node.getCassandraVersion()).willReturn(Version.V4_0_0);
    given(metadata.getNodes()).willReturn(createNodesWithRandomUUID(Collections.singletonList(node)));
    CassandraDriverReactiveHealthIndicator healthIndicator = new CassandraDriverReactiveHealthIndicator(session);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> {
        assertThat(h.getStatus()).isEqualTo(Status.UP);
        assertThat(h.getDetails()).containsOnlyKeys("version");
        assertThat(h.getDetails().get("version")).isEqualTo(Version.V4_0_0);
    }).verifyComplete();
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) Status(org.springframework.boot.actuate.health.Status) NodeState(com.datastax.oss.driver.api.core.metadata.NodeState) StepVerifier(reactor.test.StepVerifier) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Health(org.springframework.boot.actuate.health.Health) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Version(com.datastax.oss.driver.api.core.Version) List(java.util.List) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Health(org.springframework.boot.actuate.health.Health) Node(com.datastax.oss.driver.api.core.metadata.Node) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 94 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class CassandraDriverReactiveHealthIndicatorTests method healthWithoutNodeVersionShouldNotAddVersionDetail.

@Test
void healthWithoutNodeVersionShouldNotAddVersionDetail() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP);
    CassandraDriverReactiveHealthIndicator healthIndicator = new CassandraDriverReactiveHealthIndicator(session);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> {
        assertThat(h.getStatus()).isEqualTo(Status.UP);
        assertThat(h.getDetails().get("version")).isNull();
    }).verifyComplete();
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) Status(org.springframework.boot.actuate.health.Status) NodeState(com.datastax.oss.driver.api.core.metadata.NodeState) StepVerifier(reactor.test.StepVerifier) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Health(org.springframework.boot.actuate.health.Health) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Version(com.datastax.oss.driver.api.core.Version) List(java.util.List) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Health(org.springframework.boot.actuate.health.Health) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 95 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class CassandraDriverReactiveHealthIndicatorTests method healthWithOneHealthyNodeShouldReturnUp.

@Test
void healthWithOneHealthyNodeShouldReturnUp() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP);
    CassandraDriverReactiveHealthIndicator healthIndicator = new CassandraDriverReactiveHealthIndicator(session);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.UP)).verifyComplete();
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) Status(org.springframework.boot.actuate.health.Status) NodeState(com.datastax.oss.driver.api.core.metadata.NodeState) StepVerifier(reactor.test.StepVerifier) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Health(org.springframework.boot.actuate.health.Health) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Version(com.datastax.oss.driver.api.core.Version) List(java.util.List) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Health(org.springframework.boot.actuate.health.Health) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Aggregations

Health (org.springframework.boot.actuate.health.Health)116 Test (org.junit.jupiter.api.Test)89 Status (org.springframework.boot.actuate.health.Status)23 CqlSession (com.datastax.oss.driver.api.core.CqlSession)20 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 BDDMockito.given (org.mockito.BDDMockito.given)18 Mockito.mock (org.mockito.Mockito.mock)18 Mono (reactor.core.publisher.Mono)18 StepVerifier (reactor.test.StepVerifier)18 Test (org.junit.Test)17 List (java.util.List)14 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)11 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)11 Node (com.datastax.oss.driver.api.core.metadata.Node)11 HashMap (java.util.HashMap)11 Version (com.datastax.oss.driver.api.core.Version)10 NodeState (com.datastax.oss.driver.api.core.metadata.NodeState)10 ArrayList (java.util.ArrayList)10 Collections (java.util.Collections)10 Map (java.util.Map)10