Search in sources :

Example 1 with ProfiledPlan

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

the class PrettyPrinterTest method prettyPrintExplainInformation.

@Test
public void prettyPrintExplainInformation() {
    // 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(false);
    when(resultSummary.plan()).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: \"EXPLAIN\"\n" + "Statement: \"READ_ONLY\"\n" + "Version: \"3.1\"\n" + "Planner: \"COST\"\n" + "Runtime: \"INTERPRETED\"\n" + "Time: 12";
    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)

Example 2 with ProfiledPlan

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

the class TableOutputFormatterTest method prettyPrintPlanInformation.

@Test
public void prettyPrintPlanInformation() throws IOException {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED", "GlobalMemory", 10, "DbHits", 2, "Rows", 3, "EstimatedRows", 10, "Time", 15, "Order", "a", "PageCacheHits", 22, "PageCacheMisses", 2, "Memory", 5).asMap(v -> v);
    ProfiledPlan plan = mock(ProfiledPlan.class);
    when(plan.dbHits()).thenReturn(1000L);
    when(plan.records()).thenReturn(20L);
    when(plan.arguments()).thenReturn(argumentMap);
    when(plan.operatorType()).thenReturn("MyOp");
    when(plan.identifiers()).thenReturn(Arrays.asList("a", "b"));
    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);
    when(plan.arguments()).thenReturn(argumentMap);
    BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
    // when
    String actual = verbosePrinter.format(result);
    // then
    String expected = IOUtils.toString(getClass().getResource("/org/neo4j/shell/prettyprint/expected-pretty-print-plan-information.txt"), UTF_8).replace("\n", NEWLINE);
    assertThat(actual, startsWith(expected));
}
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) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) NodeValue(org.neo4j.driver.internal.value.NodeValue) DurationValue(org.neo4j.driver.internal.value.DurationValue) PathValue(org.neo4j.driver.internal.value.PathValue) PointValue(org.neo4j.driver.internal.value.PointValue) StringContains.containsString(org.hamcrest.core.StringContains.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 3 with ProfiledPlan

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

the class OutputFormatterTest method shouldReportTotalDBHits.

@Test
public void shouldReportTotalDBHits() {
    Value labelScan = buildOperator("NodeByLabelScan", 1002L, 1001L, null);
    Value filter = buildOperator("Filter", 1402, 280, labelScan);
    Value planMap = buildOperator("ProduceResults", 0, 280, filter);
    ProfiledPlan plan = PROFILED_PLAN_FROM_VALUE.apply(planMap);
    ResultSummary summary = new InternalResultSummary(new Query("PROFILE MATCH (n:LABEL) WHERE 20 < n.age < 35 return n"), new InternalServerInfo("agent", new BoltServerAddress("localhost:7687"), ServerVersion.vInDev, BoltProtocolV43.VERSION), new InternalDatabaseInfo("neo4j"), QueryType.READ_ONLY, null, plan, plan, Collections.emptyList(), 39, 55);
    // When
    Map<String, Value> info = OutputFormatter.info(summary);
    // Then
    assertThat(info.get("DbHits").asLong(), equalTo(2404L));
}
Also used : ProfiledPlan(org.neo4j.driver.summary.ProfiledPlan) Query(org.neo4j.driver.Query) InternalDatabaseInfo(org.neo4j.driver.internal.summary.InternalDatabaseInfo) MapValue(org.neo4j.driver.internal.value.MapValue) Value(org.neo4j.driver.Value) ListValue(org.neo4j.driver.internal.value.ListValue) InternalResultSummary(org.neo4j.driver.internal.summary.InternalResultSummary) ResultSummary(org.neo4j.driver.summary.ResultSummary) InternalServerInfo(org.neo4j.driver.internal.summary.InternalServerInfo) InternalResultSummary(org.neo4j.driver.internal.summary.InternalResultSummary) BoltServerAddress(org.neo4j.driver.internal.BoltServerAddress) Test(org.junit.Test)

Example 4 with ProfiledPlan

use of org.neo4j.driver.summary.ProfiledPlan 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)

Example 5 with ProfiledPlan

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

the class PrettyPrinterTest method prettyPrintProfileInformation.

@Test
public void prettyPrintProfileInformation() {
    // 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", "GlobalMemory", 10).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): 10";
    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

Test (org.junit.Test)5 Value (org.neo4j.driver.Value)5 ProfiledPlan (org.neo4j.driver.summary.ProfiledPlan)5 ResultSummary (org.neo4j.driver.summary.ResultSummary)5 BoltResult (org.neo4j.shell.state.BoltResult)4 ListBoltResult (org.neo4j.shell.state.ListBoltResult)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Query (org.neo4j.driver.Query)1 BoltServerAddress (org.neo4j.driver.internal.BoltServerAddress)1 InternalDatabaseInfo (org.neo4j.driver.internal.summary.InternalDatabaseInfo)1 InternalResultSummary (org.neo4j.driver.internal.summary.InternalResultSummary)1 InternalServerInfo (org.neo4j.driver.internal.summary.InternalServerInfo)1 DurationValue (org.neo4j.driver.internal.value.DurationValue)1 ListValue (org.neo4j.driver.internal.value.ListValue)1 MapValue (org.neo4j.driver.internal.value.MapValue)1 NodeValue (org.neo4j.driver.internal.value.NodeValue)1 PathValue (org.neo4j.driver.internal.value.PathValue)1 PointValue (org.neo4j.driver.internal.value.PointValue)1 RelationshipValue (org.neo4j.driver.internal.value.RelationshipValue)1