Search in sources :

Example 1 with DriverTimeoutException

use of com.datastax.oss.driver.api.core.DriverTimeoutException in project spring-boot by spring-projects.

the class CassandraDriverReactiveHealthIndicatorTests method healthWithCassandraDownShouldReturnDown.

@Test
void healthWithCassandraDownShouldReturnDown() {
    CqlSession session = mock(CqlSession.class);
    given(session.getMetadata()).willThrow(new DriverTimeoutException("Test Exception"));
    CassandraDriverReactiveHealthIndicator cassandraReactiveHealthIndicator = new CassandraDriverReactiveHealthIndicator(session);
    Mono<Health> health = cassandraReactiveHealthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> {
        assertThat(h.getStatus()).isEqualTo(Status.DOWN);
        assertThat(h.getDetails()).containsOnlyKeys("error");
        assertThat(h.getDetails().get("error")).isEqualTo(DriverTimeoutException.class.getName() + ": Test Exception");
    }).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) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 2 with DriverTimeoutException

use of com.datastax.oss.driver.api.core.DriverTimeoutException in project spring-boot by spring-projects.

the class CassandraDriverHealthIndicatorTests method healthWithcassandraDownShouldReturnDown.

@Test
void healthWithcassandraDownShouldReturnDown() {
    CqlSession session = mock(CqlSession.class);
    given(session.getMetadata()).willThrow(new DriverTimeoutException("Test Exception"));
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("error")).isEqualTo(DriverTimeoutException.class.getName() + ": Test Exception");
}
Also used : Health(org.springframework.boot.actuate.health.Health) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Aggregations

CqlSession (com.datastax.oss.driver.api.core.CqlSession)2 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)2 Test (org.junit.jupiter.api.Test)2 Health (org.springframework.boot.actuate.health.Health)2 Version (com.datastax.oss.driver.api.core.Version)1 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 NodeState (com.datastax.oss.driver.api.core.metadata.NodeState)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)1 BDDMockito.given (org.mockito.BDDMockito.given)1 Mockito.mock (org.mockito.Mockito.mock)1 Status (org.springframework.boot.actuate.health.Status)1 Mono (reactor.core.publisher.Mono)1