Search in sources :

Example 6 with ResultSummary

use of org.neo4j.driver.summary.ResultSummary in project jmeter by apache.

the class BoltSampler method response.

private String response(Result result) {
    StringBuilder response = new StringBuilder();
    List<Record> records;
    if (isRecordQueryResults()) {
        // get records already as consume() will exhaust the stream
        records = result.list();
    } else {
        records = Collections.emptyList();
    }
    response.append("\nSummary:");
    ResultSummary summary = result.consume();
    response.append("\nConstraints Added: ").append(summary.counters().constraintsAdded()).append("\nConstraints Removed: ").append(summary.counters().constraintsRemoved()).append("\nContains Updates: ").append(summary.counters().containsUpdates()).append("\nIndexes Added: ").append(summary.counters().indexesAdded()).append("\nIndexes Removed: ").append(summary.counters().indexesRemoved()).append("\nLabels Added: ").append(summary.counters().labelsAdded()).append("\nLabels Removed: ").append(summary.counters().labelsRemoved()).append("\nNodes Created: ").append(summary.counters().nodesCreated()).append("\nNodes Deleted: ").append(summary.counters().nodesDeleted()).append("\nRelationships Created: ").append(summary.counters().relationshipsCreated()).append("\nRelationships Deleted: ").append(summary.counters().relationshipsDeleted());
    response.append("\n\nRecords: ");
    if (isRecordQueryResults()) {
        for (Record record : records) {
            response.append("\n").append(record);
        }
    } else {
        response.append("Skipped");
        result.consume();
    }
    return response.toString();
}
Also used : ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record)

Example 7 with ResultSummary

use of org.neo4j.driver.summary.ResultSummary in project spring-boot by spring-projects.

the class Neo4jHealthDetailsHandler method addHealthDetails.

/**
 * Add health details for the specified {@link ResultSummary} and {@code edition}.
 * @param builder the {@link Builder} to use
 * @param healthDetails the health details of the server
 */
void addHealthDetails(Builder builder, Neo4jHealthDetails healthDetails) {
    ResultSummary summary = healthDetails.getSummary();
    ServerInfo serverInfo = summary.server();
    builder.up().withDetail("server", healthDetails.getVersion() + "@" + serverInfo.address()).withDetail("edition", healthDetails.getEdition());
    DatabaseInfo databaseInfo = summary.database();
    if (StringUtils.hasText(databaseInfo.name())) {
        builder.withDetail("database", databaseInfo.name());
    }
}
Also used : DatabaseInfo(org.neo4j.driver.summary.DatabaseInfo) ServerInfo(org.neo4j.driver.summary.ServerInfo) ResultSummary(org.neo4j.driver.summary.ResultSummary)

Example 8 with ResultSummary

use of org.neo4j.driver.summary.ResultSummary in project spring-boot by spring-projects.

the class Neo4jReactiveHealthIndicatorTests method neo4jIsUp.

@Test
void neo4jIsUp() {
    ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "test");
    Driver driver = mockDriver(resultSummary, "4711", "ultimate collectors edition");
    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", "ultimate collectors edition");
    }).verifyComplete();
}
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) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 9 with ResultSummary

use of org.neo4j.driver.summary.ResultSummary in project spring-boot by spring-projects.

the class Neo4jHealthIndicatorTests method neo4jIsUpWithoutDatabaseName.

@Test
void neo4jIsUpWithoutDatabaseName() {
    ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", null);
    Driver driver = mockDriver(resultSummary, "4711", "some edition");
    Health health = new Neo4jHealthIndicator(driver).health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
    assertThat(health.getDetails()).doesNotContainKey("database");
    assertThat(health.getDetails()).containsEntry("edition", "some edition");
}
Also used : Health(org.springframework.boot.actuate.health.Health) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) Test(org.junit.jupiter.api.Test)

Example 10 with ResultSummary

use of org.neo4j.driver.summary.ResultSummary in project spring-boot by spring-projects.

the class Neo4jHealthIndicatorTests method neo4jIsUpWithOneSessionExpiredException.

@Test
void neo4jIsUpWithOneSessionExpiredException() {
    ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "");
    Session session = mock(Session.class);
    Result 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.session(any(SessionConfig.class))).willReturn(session);
    Neo4jHealthIndicator healthIndicator = new Neo4jHealthIndicator(driver);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
    then(session).should(times(2)).close();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Health(org.springframework.boot.actuate.health.Health) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) Session(org.neo4j.driver.Session) Result(org.neo4j.driver.Result) Test(org.junit.jupiter.api.Test)

Aggregations

ResultSummary (org.neo4j.driver.summary.ResultSummary)21 Test (org.junit.Test)8 Driver (org.neo4j.driver.Driver)7 Test (org.junit.jupiter.api.Test)6 Value (org.neo4j.driver.Value)6 BoltResult (org.neo4j.shell.state.BoltResult)6 ListBoltResult (org.neo4j.shell.state.ListBoltResult)6 Record (org.neo4j.driver.Record)5 ProfiledPlan (org.neo4j.driver.summary.ProfiledPlan)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Result (org.neo4j.driver.Result)4 Health (org.springframework.boot.actuate.health.Health)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 SessionConfig (org.neo4j.driver.SessionConfig)3 SessionExpiredException (org.neo4j.driver.exceptions.SessionExpiredException)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 BDDMockito.given (org.mockito.BDDMockito.given)2 BDDMockito.then (org.mockito.BDDMockito.then)2