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;
}
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;
}
}
};
}
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"));
}
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(""));
}
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)));
}
Aggregations