Search in sources :

Example 36 with Health

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

the class RedisHealthIndicatorTests method healthWhenClusterStateIsOkShouldBeUp.

@Test
void healthWhenClusterStateIsOkShouldBeUp() {
    RedisConnectionFactory redisConnectionFactory = createClusterConnectionFactory("ok");
    RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
    assertThat(health.getDetails().get("slots_up")).isEqualTo(4L);
    assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L);
    then(redisConnectionFactory).should(atLeastOnce()).getConnection();
}
Also used : Health(org.springframework.boot.actuate.health.Health) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 37 with Health

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

the class HazelcastHealthIndicatorTests method hazelcastDown.

@Test
void hazelcastDown() {
    HazelcastInstance hazelcast = mock(HazelcastInstance.class);
    given(hazelcast.executeTransaction(any())).willThrow(new HazelcastException());
    Health health = new HazelcastHealthIndicator(hazelcast).health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastException(com.hazelcast.core.HazelcastException) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test)

Example 38 with Health

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

the class JmsHealthIndicatorTests method jmsBrokerIsDown.

@Test
void jmsBrokerIsDown() throws JMSException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    given(connectionFactory.createConnection()).willThrow(new JMSException("test", "123"));
    JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
    Health health = indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("provider")).isNull();
}
Also used : ConnectionFactory(jakarta.jms.ConnectionFactory) Health(org.springframework.boot.actuate.health.Health) JMSException(jakarta.jms.JMSException) Test(org.junit.jupiter.api.Test)

Example 39 with Health

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

the class JmsHealthIndicatorTests method whenConnectionStartIsUnresponsiveStatusIsDown.

@Test
void whenConnectionStartIsUnresponsiveStatusIsDown() throws JMSException {
    ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
    given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
    Connection connection = mock(Connection.class);
    UnresponsiveStartAnswer unresponsiveStartAnswer = new UnresponsiveStartAnswer();
    willAnswer(unresponsiveStartAnswer).given(connection).start();
    willAnswer((invocation) -> {
        unresponsiveStartAnswer.connectionClosed();
        return null;
    }).given(connection).close();
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    given(connectionFactory.createConnection()).willReturn(connection);
    JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
    Health health = indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat((String) health.getDetails().get("error")).contains("Connection closed");
}
Also used : ConnectionFactory(jakarta.jms.ConnectionFactory) Health(org.springframework.boot.actuate.health.Health) ConnectionMetaData(jakarta.jms.ConnectionMetaData) Connection(jakarta.jms.Connection) Test(org.junit.jupiter.api.Test)

Example 40 with Health

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

the class LdapHealthIndicatorTests method ldapIsDown.

@Test
@SuppressWarnings("unchecked")
void ldapIsDown() {
    LdapTemplate ldapTemplate = mock(LdapTemplate.class);
    given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any())).willThrow(new CommunicationException(new javax.naming.CommunicationException("Connection failed")));
    LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat((String) health.getDetails().get("error")).contains("Connection failed");
    then(ldapTemplate).should().executeReadOnly((ContextExecutor<String>) any());
}
Also used : CommunicationException(org.springframework.ldap.CommunicationException) Health(org.springframework.boot.actuate.health.Health) LdapTemplate(org.springframework.ldap.core.LdapTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

Health (org.springframework.boot.actuate.health.Health)118 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 Test (org.junit.Test)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 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