Search in sources :

Example 16 with ResultSummary

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

the class BoltStateHandlerTest method stubResultSummaryInAnOpenSession.

private Driver stubResultSummaryInAnOpenSession(Result resultMock, Session sessionMock, String protocolVersion, String databaseName) {
    Driver driverMock = mock(Driver.class);
    ResultSummary resultSummary = mock(ResultSummary.class);
    ServerInfo serverInfo = mock(ServerInfo.class);
    DatabaseInfo databaseInfo = mock(DatabaseInfo.class);
    when(resultSummary.server()).thenReturn(serverInfo);
    when(serverInfo.protocolVersion()).thenReturn(protocolVersion);
    when(resultMock.consume()).thenReturn(resultSummary);
    when(resultSummary.database()).thenReturn(databaseInfo);
    when(databaseInfo.name()).thenReturn(databaseName);
    when(sessionMock.isOpen()).thenReturn(true);
    when(sessionMock.run("CALL db.ping()")).thenReturn(resultMock);
    when(sessionMock.run(anyString(), any(Value.class))).thenReturn(resultMock);
    when(driverMock.session(any())).thenReturn(sessionMock);
    return driverMock;
}
Also used : DatabaseInfo(org.neo4j.driver.summary.DatabaseInfo) ServerInfo(org.neo4j.driver.summary.ServerInfo) ResultSummary(org.neo4j.driver.summary.ResultSummary) Value(org.neo4j.driver.Value) Driver(org.neo4j.driver.Driver) FakeDriver(org.neo4j.shell.test.bolt.FakeDriver)

Example 17 with ResultSummary

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

the class BoltStateHandler method getPing.

private ThrowingAction<CommandException> getPing() {
    return () -> {
        try {
            Result run = session.run("CALL db.ping()");
            ResultSummary summary = run.consume();
            BoltStateHandler.this.protocolVersion = summary.server().protocolVersion();
            updateActualDbName(summary);
        } catch (ClientException e) {
            // In older versions there is no db.ping procedure, use legacy method.
            if (procedureNotFound(e)) {
                Result run = session.run(isSystemDb() ? "CALL db.indexes()" : "RETURN 1");
                ResultSummary summary = run.consume();
                BoltStateHandler.this.protocolVersion = summary.server().protocolVersion();
                updateActualDbName(summary);
            } else {
                throw e;
            }
        }
    };
}
Also used : ResultSummary(org.neo4j.driver.summary.ResultSummary) ClientException(org.neo4j.driver.exceptions.ClientException) Result(org.neo4j.driver.Result)

Example 18 with ResultSummary

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

the class StatisticsCollectorTest method returnStatisticsForDefaultFormatting.

@Test
public void returnStatisticsForDefaultFormatting() throws Exception {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    SummaryCounters summaryCounters = mock(SummaryCounters.class);
    when(resultSummary.counters()).thenReturn(summaryCounters);
    when(summaryCounters.labelsAdded()).thenReturn(1);
    when(summaryCounters.nodesCreated()).thenReturn(10);
    // when
    String actual = new StatisticsCollector(Format.VERBOSE).collect(resultSummary);
    // then
    assertThat(actual, is("Added 10 nodes, Added 1 labels"));
}
Also used : ResultSummary(org.neo4j.driver.summary.ResultSummary) SummaryCounters(org.neo4j.driver.summary.SummaryCounters) Test(org.junit.Test)

Example 19 with ResultSummary

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

the class StatisticsCollectorTest method returnEmptyStringForPlainFormatting.

@Test
public void returnEmptyStringForPlainFormatting() throws Exception {
    // given
    ResultSummary result = mock(ResultSummary.class);
    // when
    String actual = new StatisticsCollector(Format.PLAIN).collect(result);
    // then
    assertThat(actual, is(""));
}
Also used : ResultSummary(org.neo4j.driver.summary.ResultSummary) Test(org.junit.Test)

Example 20 with ResultSummary

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

the class PrettyPrinterTest method prettyPrintProfileInformationIfGlobalMemoryIsMissing.

@Test
public void prettyPrintProfileInformationIfGlobalMemoryIsMissing() {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    ProfiledPlan plan = mock(ProfiledPlan.class);
    when(plan.dbHits()).thenReturn(1000L);
    when(plan.records()).thenReturn(20L);
    when(resultSummary.hasPlan()).thenReturn(true);
    when(resultSummary.hasProfile()).thenReturn(true);
    when(resultSummary.plan()).thenReturn(plan);
    when(resultSummary.profile()).thenReturn(plan);
    when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L);
    when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L);
    when(resultSummary.queryType()).thenReturn(QueryType.READ_ONLY);
    Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v);
    when(plan.arguments()).thenReturn(argumentMap);
    BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
    // when
    String actual = plainPrinter.format(result);
    // then
    String expected = "Plan: \"PROFILE\"\n" + "Statement: \"READ_ONLY\"\n" + "Version: \"3.1\"\n" + "Planner: \"COST\"\n" + "Runtime: \"INTERPRETED\"\n" + "Time: 12\n" + "Rows: 20\n" + "DbHits: 1000\n" + "Memory (Bytes): \"?\"";
    Stream.of(expected.split("\n")).forEach(e -> assertThat(actual, containsString(e)));
}
Also used : ProfiledPlan(org.neo4j.driver.summary.ProfiledPlan) ListBoltResult(org.neo4j.shell.state.ListBoltResult) ResultSummary(org.neo4j.driver.summary.ResultSummary) Value(org.neo4j.driver.Value) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.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