|
|
|
@ -25,9 +25,11 @@ import org.neo4j.driver.SessionConfig;
|
|
|
|
|
import org.neo4j.driver.Values;
|
|
|
|
|
import org.neo4j.driver.exceptions.ServiceUnavailableException;
|
|
|
|
|
import org.neo4j.driver.exceptions.SessionExpiredException;
|
|
|
|
|
import org.neo4j.driver.reactive.RxResult;
|
|
|
|
|
import org.neo4j.driver.reactive.RxSession;
|
|
|
|
|
import org.neo4j.driver.reactive.ReactiveResult;
|
|
|
|
|
import org.neo4j.driver.reactive.ReactiveSession;
|
|
|
|
|
import org.neo4j.driver.summary.ResultSummary;
|
|
|
|
|
import reactor.adapter.JdkFlowAdapter;
|
|
|
|
|
import reactor.core.publisher.Flux;
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
import reactor.test.StepVerifier;
|
|
|
|
|
|
|
|
|
@ -46,6 +48,7 @@ import static org.mockito.Mockito.times;
|
|
|
|
|
*
|
|
|
|
|
* @author Michael J. Simons
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
* @author Brian Clozel
|
|
|
|
|
*/
|
|
|
|
|
class Neo4jReactiveHealthIndicatorTests {
|
|
|
|
|
|
|
|
|
@ -64,17 +67,18 @@ class Neo4jReactiveHealthIndicatorTests {
|
|
|
|
|
@Test
|
|
|
|
|
void neo4jIsUpWithOneSessionExpiredException() {
|
|
|
|
|
ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "");
|
|
|
|
|
RxSession session = mock(RxSession.class);
|
|
|
|
|
RxResult statementResult = mockStatementResult(resultSummary, "4711", "some edition");
|
|
|
|
|
ReactiveSession session = mock(ReactiveSession.class);
|
|
|
|
|
ReactiveResult statementResult = mockStatementResult(resultSummary, "4711", "some edition");
|
|
|
|
|
AtomicInteger count = new AtomicInteger();
|
|
|
|
|
given(session.run(anyString())).will((invocation) -> {
|
|
|
|
|
if (count.compareAndSet(0, 1)) {
|
|
|
|
|
throw new SessionExpiredException("Session expired");
|
|
|
|
|
return JdkFlowAdapter
|
|
|
|
|
.publisherToFlowPublisher(Flux.error(new SessionExpiredException("Session expired")));
|
|
|
|
|
}
|
|
|
|
|
return statementResult;
|
|
|
|
|
return JdkFlowAdapter.publisherToFlowPublisher(Flux.just(statementResult));
|
|
|
|
|
});
|
|
|
|
|
Driver driver = mock(Driver.class);
|
|
|
|
|
given(driver.rxSession(any(SessionConfig.class))).willReturn(session);
|
|
|
|
|
given(driver.reactiveSession(any(SessionConfig.class))).willReturn(session);
|
|
|
|
|
Neo4jReactiveHealthIndicator healthIndicator = new Neo4jReactiveHealthIndicator(driver);
|
|
|
|
|
healthIndicator.health().as(StepVerifier::create).consumeNextWith((health) -> {
|
|
|
|
|
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
|
|
|
@ -87,7 +91,7 @@ class Neo4jReactiveHealthIndicatorTests {
|
|
|
|
|
@Test
|
|
|
|
|
void neo4jIsDown() {
|
|
|
|
|
Driver driver = mock(Driver.class);
|
|
|
|
|
given(driver.rxSession(any(SessionConfig.class))).willThrow(ServiceUnavailableException.class);
|
|
|
|
|
given(driver.reactiveSession(any(SessionConfig.class))).willThrow(ServiceUnavailableException.class);
|
|
|
|
|
Neo4jReactiveHealthIndicator healthIndicator = new Neo4jReactiveHealthIndicator(driver);
|
|
|
|
|
healthIndicator.health().as(StepVerifier::create).consumeNextWith((health) -> {
|
|
|
|
|
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
|
|
|
@ -95,22 +99,22 @@ class Neo4jReactiveHealthIndicatorTests {
|
|
|
|
|
}).verifyComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RxResult mockStatementResult(ResultSummary resultSummary, String version, String edition) {
|
|
|
|
|
private ReactiveResult mockStatementResult(ResultSummary resultSummary, String version, String edition) {
|
|
|
|
|
Record record = mock(Record.class);
|
|
|
|
|
given(record.get("edition")).willReturn(Values.value(edition));
|
|
|
|
|
given(record.get("version")).willReturn(Values.value(version));
|
|
|
|
|
RxResult statementResult = mock(RxResult.class);
|
|
|
|
|
given(statementResult.records()).willReturn(Mono.just(record));
|
|
|
|
|
given(statementResult.consume()).willReturn(Mono.just(resultSummary));
|
|
|
|
|
ReactiveResult statementResult = mock(ReactiveResult.class);
|
|
|
|
|
given(statementResult.records()).willReturn(JdkFlowAdapter.publisherToFlowPublisher(Mono.just(record)));
|
|
|
|
|
given(statementResult.consume()).willReturn(JdkFlowAdapter.publisherToFlowPublisher(Mono.just(resultSummary)));
|
|
|
|
|
return statementResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Driver mockDriver(ResultSummary resultSummary, String version, String edition) {
|
|
|
|
|
RxResult statementResult = mockStatementResult(resultSummary, version, edition);
|
|
|
|
|
RxSession session = mock(RxSession.class);
|
|
|
|
|
given(session.run(anyString())).willReturn(statementResult);
|
|
|
|
|
ReactiveResult statementResult = mockStatementResult(resultSummary, version, edition);
|
|
|
|
|
ReactiveSession session = mock(ReactiveSession.class);
|
|
|
|
|
given(session.run(anyString())).willReturn(JdkFlowAdapter.publisherToFlowPublisher(Mono.just(statementResult)));
|
|
|
|
|
Driver driver = mock(Driver.class);
|
|
|
|
|
given(driver.rxSession(any(SessionConfig.class))).willReturn(session);
|
|
|
|
|
given(driver.reactiveSession(any(SessionConfig.class))).willReturn(session);
|
|
|
|
|
return driver;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|