Search in sources :

Example 1 with RxResult

use of org.neo4j.driver.reactive.RxResult in project neo4j by neo4j.

the class BoltLocalResultStreamTest method testRxResultStream.

@Test
void testRxResultStream() {
    List<String> result = inRxTx(tx -> {
        RxResult statementResult = tx.run("UNWIND range(0, 4) AS i RETURN 'r' + i as A");
        return Flux.from(statementResult.records()).limitRate(1).collectList().block().stream().map(r -> r.get("A").asString()).collect(Collectors.toList());
    });
    assertThat(result).isEqualTo(List.of("r0", "r1", "r2", "r3", "r4"));
}
Also used : ConnectorPortRegister(org.neo4j.configuration.connectors.ConnectorPortRegister) Driver(org.neo4j.driver.Driver) Flux(org.neo4j.driver.internal.shaded.reactor.core.publisher.Flux) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(org.neo4j.driver.internal.shaded.reactor.core.publisher.Mono) RxTransaction(org.neo4j.driver.reactive.RxTransaction) RxResult(org.neo4j.driver.reactive.RxResult) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Transaction(org.neo4j.driver.Transaction) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) TestInstance(org.junit.jupiter.api.TestInstance) Inject(org.neo4j.test.extension.Inject) BeforeAll(org.junit.jupiter.api.BeforeAll) BoltDbmsExtension(org.neo4j.test.extension.BoltDbmsExtension) RxResult(org.neo4j.driver.reactive.RxResult) Test(org.junit.jupiter.api.Test)

Example 2 with RxResult

use of org.neo4j.driver.reactive.RxResult in project spring-boot by spring-projects.

the class Neo4jReactiveHealthIndicatorTests method mockStatementResult.

private RxResult 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));
    return statementResult;
}
Also used : Record(org.neo4j.driver.Record) RxResult(org.neo4j.driver.reactive.RxResult)

Example 3 with RxResult

use of org.neo4j.driver.reactive.RxResult in project spring-boot by spring-projects.

the class Neo4jReactiveHealthIndicatorTests method neo4jIsUpWithOneSessionExpiredException.

@Test
void neo4jIsUpWithOneSessionExpiredException() {
    ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "");
    RxSession session = mock(RxSession.class);
    RxResult 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 statementResult;
    });
    Driver driver = mock(Driver.class);
    given(driver.rxSession(any(SessionConfig.class))).willReturn(session);
    Neo4jReactiveHealthIndicator healthIndicator = new Neo4jReactiveHealthIndicator(driver);
    healthIndicator.health().as(StepVerifier::create).consumeNextWith((health) -> {
        assertThat(health.getStatus()).isEqualTo(Status.UP);
        assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
        assertThat(health.getDetails()).containsEntry("edition", "some edition");
    }).verifyComplete();
    then(session).should(times(2)).close();
}
Also used : Status(org.springframework.boot.actuate.health.Status) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Driver(org.neo4j.driver.Driver) StepVerifier(reactor.test.StepVerifier) RxSession(org.neo4j.driver.reactive.RxSession) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) BDDMockito.then(org.mockito.BDDMockito.then) Mono(reactor.core.publisher.Mono) Mockito.times(org.mockito.Mockito.times) RxResult(org.neo4j.driver.reactive.RxResult) Test(org.junit.jupiter.api.Test) Values(org.neo4j.driver.Values) SessionConfig(org.neo4j.driver.SessionConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) RxSession(org.neo4j.driver.reactive.RxSession) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) StepVerifier(reactor.test.StepVerifier) RxResult(org.neo4j.driver.reactive.RxResult) Test(org.junit.jupiter.api.Test)

Example 4 with RxResult

use of org.neo4j.driver.reactive.RxResult in project spring-boot by spring-projects.

the class Neo4jReactiveHealthIndicatorTests method mockDriver.

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);
    Driver driver = mock(Driver.class);
    given(driver.rxSession(any(SessionConfig.class))).willReturn(session);
    return driver;
}
Also used : RxSession(org.neo4j.driver.reactive.RxSession) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) RxResult(org.neo4j.driver.reactive.RxResult)

Example 5 with RxResult

use of org.neo4j.driver.reactive.RxResult in project neo4j by neo4j.

the class BoltLocalResultStreamTest method testPartialStream.

@Test
void testPartialStream() {
    List<String> result = inRxTx(tx -> {
        RxResult statementResult = tx.run("UNWIND range(0, 4) AS i RETURN 'r' + i as A");
        return Flux.from(statementResult.records()).limitRequest(2).collectList().block().stream().map(r -> r.get("A").asString()).collect(Collectors.toList());
    });
    assertThat(result).isEqualTo(List.of("r0", "r1"));
}
Also used : ConnectorPortRegister(org.neo4j.configuration.connectors.ConnectorPortRegister) Driver(org.neo4j.driver.Driver) Flux(org.neo4j.driver.internal.shaded.reactor.core.publisher.Flux) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(org.neo4j.driver.internal.shaded.reactor.core.publisher.Mono) RxTransaction(org.neo4j.driver.reactive.RxTransaction) RxResult(org.neo4j.driver.reactive.RxResult) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Transaction(org.neo4j.driver.Transaction) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) TestInstance(org.junit.jupiter.api.TestInstance) Inject(org.neo4j.test.extension.Inject) BeforeAll(org.junit.jupiter.api.BeforeAll) BoltDbmsExtension(org.neo4j.test.extension.BoltDbmsExtension) RxResult(org.neo4j.driver.reactive.RxResult) Test(org.junit.jupiter.api.Test)

Aggregations

RxResult (org.neo4j.driver.reactive.RxResult)5 Driver (org.neo4j.driver.Driver)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Test (org.junit.jupiter.api.Test)3 List (java.util.List)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 AfterAll (org.junit.jupiter.api.AfterAll)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 TestInstance (org.junit.jupiter.api.TestInstance)2 ConnectorPortRegister (org.neo4j.configuration.connectors.ConnectorPortRegister)2 Record (org.neo4j.driver.Record)2 SessionConfig (org.neo4j.driver.SessionConfig)2 Transaction (org.neo4j.driver.Transaction)2 Flux (org.neo4j.driver.internal.shaded.reactor.core.publisher.Flux)2 Mono (org.neo4j.driver.internal.shaded.reactor.core.publisher.Mono)2 RxSession (org.neo4j.driver.reactive.RxSession)2 RxTransaction (org.neo4j.driver.reactive.RxTransaction)2 BoltDbmsExtension (org.neo4j.test.extension.BoltDbmsExtension)2 Inject (org.neo4j.test.extension.Inject)2