Search in sources :

Example 11 with QueryStatistics

use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldIncludeProfileIfPresent.

@Test
void shouldIncludeProfileIfPresent() throws Throwable {
    // Given
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsUpdates()).thenReturn(false);
    QueryExecution result = mock(QueryExecution.class);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    when(result.fieldNames()).thenReturn(new String[0]);
    when(result.executionType()).thenReturn(explained(READ_ONLY));
    subscriber.onResultCompleted(queryStatistics);
    when(result.getNotifications()).thenReturn(Collections.emptyList());
    when(result.executionPlanDescription()).thenReturn(plan("Join", map("arg1", 1), 2, 4, 3, 1, 2, singletonList("id1"), plan("Scan", map("arg2", 1), 2, 4, 7, 1, 1, singletonList("id2"))));
    var stream = new TestAbstractCypherAdapterStream(result, subscriber, Clock.systemUTC());
    // When
    MapValue meta = metadataOf(stream);
    // Then
    MapValue expectedChild = mapValues("args", mapValues("arg2", intValue(1)), "identifiers", list(stringValue("id2")), "operatorType", stringValue("Scan"), "children", VirtualValues.EMPTY_LIST, "rows", longValue(1L), "dbHits", longValue(2L), "pageCacheHits", longValue(4L), "pageCacheMisses", longValue(7L), "pageCacheHitRatio", doubleValue(4.0 / 11), "time", longValue(1));
    MapValue expectedProfile = mapValues("args", mapValues("arg1", intValue(1)), "identifiers", list(stringValue("id1")), "operatorType", stringValue("Join"), "children", list(expectedChild), "rows", longValue(1L), "dbHits", longValue(2L), "pageCacheHits", longValue(4L), "pageCacheMisses", longValue(3L), "pageCacheHitRatio", doubleValue(4.0 / 7), "time", longValue(2));
    assertMapEqualsWithDelta((MapValue) meta.get("profile"), expectedProfile, 0.0001);
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) MapValue(org.neo4j.values.virtual.MapValue) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 12 with QueryStatistics

use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldDiscardAllReadQuery.

@Test
void shouldDiscardAllReadQuery() throws Throwable {
    // Given
    QueryExecution queryExecution = mock(QueryExecution.class);
    when(queryExecution.fieldNames()).thenReturn(new String[] { "foo" });
    when(queryExecution.executionType()).thenReturn(query(READ_ONLY));
    when(queryExecution.getNotifications()).thenReturn(Collections.emptyList());
    when(queryExecution.await()).thenReturn(false);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsUpdates()).thenReturn(false);
    when(queryStatistics.getNodesCreated()).thenReturn(0);
    when(queryStatistics.getNodesDeleted()).thenReturn(0);
    when(queryStatistics.getRelationshipsCreated()).thenReturn(0);
    when(queryStatistics.getRelationshipsDeleted()).thenReturn(0);
    when(queryStatistics.getPropertiesSet()).thenReturn(0);
    when(queryStatistics.getIndexesAdded()).thenReturn(0);
    when(queryStatistics.getIndexesRemoved()).thenReturn(0);
    when(queryStatistics.getConstraintsAdded()).thenReturn(0);
    when(queryStatistics.getConstraintsRemoved()).thenReturn(0);
    when(queryStatistics.getLabelsAdded()).thenReturn(0);
    when(queryStatistics.getLabelsRemoved()).thenReturn(0);
    subscriber.onResultCompleted(queryStatistics);
    Clock clock = mock(Clock.class);
    var stream = new TestAbstractCypherAdapterStream(queryExecution, subscriber, clock);
    // When
    stream.discardRecords(mock(BoltResult.DiscardingRecordConsumer.class), STREAM_LIMIT_UNLIMITED);
    // Then
    verify(queryExecution, times(1)).cancel();
    verify(queryExecution, times(1)).await();
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) Clock(java.time.Clock) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 13 with QueryStatistics

use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldDiscardAllReadWriteQuery.

@Test
void shouldDiscardAllReadWriteQuery() throws Throwable {
    // Given
    QueryExecution queryExecution = mock(QueryExecution.class);
    when(queryExecution.fieldNames()).thenReturn(new String[] { "foo" });
    when(queryExecution.executionType()).thenReturn(query(READ_WRITE));
    when(queryExecution.getNotifications()).thenReturn(Collections.emptyList());
    when(queryExecution.await()).thenReturn(false);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsUpdates()).thenReturn(false);
    when(queryStatistics.getNodesCreated()).thenReturn(0);
    when(queryStatistics.getNodesDeleted()).thenReturn(0);
    when(queryStatistics.getRelationshipsCreated()).thenReturn(0);
    when(queryStatistics.getRelationshipsDeleted()).thenReturn(0);
    when(queryStatistics.getPropertiesSet()).thenReturn(0);
    when(queryStatistics.getIndexesAdded()).thenReturn(0);
    when(queryStatistics.getIndexesRemoved()).thenReturn(0);
    when(queryStatistics.getConstraintsAdded()).thenReturn(0);
    when(queryStatistics.getConstraintsRemoved()).thenReturn(0);
    when(queryStatistics.getLabelsAdded()).thenReturn(0);
    when(queryStatistics.getLabelsRemoved()).thenReturn(0);
    subscriber.onResultCompleted(queryStatistics);
    Clock clock = mock(Clock.class);
    var stream = new TestAbstractCypherAdapterStream(queryExecution, subscriber, clock);
    // When
    stream.discardRecords(mock(BoltResult.DiscardingRecordConsumer.class), STREAM_LIMIT_UNLIMITED);
    // Then
    verify(queryExecution, times(1)).request(Long.MAX_VALUE);
    verify(queryExecution, times(1)).await();
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) Clock(java.time.Clock) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 14 with QueryStatistics

use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldIncludeSystemUpdates.

@Test
void shouldIncludeSystemUpdates() throws Throwable {
    // Given
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsSystemUpdates()).thenReturn(true);
    when(queryStatistics.getSystemUpdates()).thenReturn(11);
    QueryExecution result = mock(QueryExecution.class);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    when(result.fieldNames()).thenReturn(new String[0]);
    when(result.executionType()).thenReturn(query(READ_WRITE));
    subscriber.onResultCompleted(queryStatistics);
    when(result.getNotifications()).thenReturn(Collections.emptyList());
    Clock clock = mock(Clock.class);
    when(clock.millis()).thenReturn(0L, 1337L);
    var stream = new TestAbstractCypherAdapterStream(result, subscriber, clock);
    // When
    MapValue meta = metadataOf(stream);
    // Then
    assertThat(meta.get("type")).isEqualTo(stringValue("rw"));
    assertThat(meta.get("stats")).isEqualTo(mapValues("system-updates", intValue(11)));
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) MapValue(org.neo4j.values.virtual.MapValue) Clock(java.time.Clock) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Aggregations

QueryStatistics (org.neo4j.graphdb.QueryStatistics)14 Test (org.junit.jupiter.api.Test)8 BoltAdapterSubscriber (org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber)8 QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)8 Clock (java.time.Clock)6 Result (org.neo4j.graphdb.Result)6 MapValue (org.neo4j.values.virtual.MapValue)5 Test (org.junit.Test)4 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)4 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)4 InputPosition (org.neo4j.graphdb.InputPosition)2 ProgressInfo (apoc.result.ProgressInfo)1 Description (org.neo4j.procedure.Description)1 Procedure (org.neo4j.procedure.Procedure)1