use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.
the class AbstractCypherAdapterStreamTest method shouldIncludeBasicMetadata.
@Test
void shouldIncludeBasicMetadata() throws Throwable {
// Given
QueryStatistics queryStatistics = mock(QueryStatistics.class);
when(queryStatistics.containsUpdates()).thenReturn(true);
when(queryStatistics.getNodesCreated()).thenReturn(1);
when(queryStatistics.getNodesDeleted()).thenReturn(2);
when(queryStatistics.getRelationshipsCreated()).thenReturn(3);
when(queryStatistics.getRelationshipsDeleted()).thenReturn(4);
when(queryStatistics.getPropertiesSet()).thenReturn(5);
when(queryStatistics.getIndexesAdded()).thenReturn(6);
when(queryStatistics.getIndexesRemoved()).thenReturn(7);
when(queryStatistics.getConstraintsAdded()).thenReturn(8);
when(queryStatistics.getConstraintsRemoved()).thenReturn(9);
when(queryStatistics.getLabelsAdded()).thenReturn(10);
when(queryStatistics.getLabelsRemoved()).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("nodes-created", intValue(1), "nodes-deleted", intValue(2), "relationships-created", intValue(3), "relationships-deleted", intValue(4), "properties-set", intValue(5), "indexes-added", intValue(6), "indexes-removed", intValue(7), "constraints-added", intValue(8), "constraints-removed", intValue(9), "labels-added", intValue(10), "labels-removed", intValue(11)));
}
use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.
the class AbstractCypherAdapterStreamTest method shouldPullAll.
@Test
void shouldPullAll() throws Throwable {
// Given
QueryExecution queryExecution = mock(QueryExecution.class);
when(queryExecution.fieldNames()).thenReturn(new String[0]);
when(queryExecution.executionType()).thenReturn(query(READ_WRITE));
when(queryExecution.getNotifications()).thenReturn(Collections.emptyList());
when(queryExecution.await()).thenReturn(true).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.handleRecords(mock(BoltResult.RecordConsumer.class), STREAM_LIMIT_UNLIMITED);
// Then
verify(queryExecution, times(2)).request(Long.MAX_VALUE);
verify(queryExecution, times(2)).await();
}
use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.
the class CypherAdapterStreamTest method shouldIncludeBasicMetadata.
@Test
public void shouldIncludeBasicMetadata() throws Throwable {
// Given
QueryStatistics queryStatistics = mock(QueryStatistics.class);
when(queryStatistics.containsUpdates()).thenReturn(true);
when(queryStatistics.getNodesCreated()).thenReturn(1);
when(queryStatistics.getNodesDeleted()).thenReturn(2);
when(queryStatistics.getRelationshipsCreated()).thenReturn(3);
when(queryStatistics.getRelationshipsDeleted()).thenReturn(4);
when(queryStatistics.getPropertiesSet()).thenReturn(5);
when(queryStatistics.getIndexesAdded()).thenReturn(6);
when(queryStatistics.getIndexesRemoved()).thenReturn(7);
when(queryStatistics.getConstraintsAdded()).thenReturn(8);
when(queryStatistics.getConstraintsRemoved()).thenReturn(9);
when(queryStatistics.getLabelsAdded()).thenReturn(10);
when(queryStatistics.getLabelsRemoved()).thenReturn(11);
Result result = mock(Result.class);
when(result.getQueryExecutionType()).thenReturn(query(READ_WRITE));
when(result.getQueryStatistics()).thenReturn(queryStatistics);
when(result.getNotifications()).thenReturn(Collections.emptyList());
Clock clock = mock(Clock.class);
when(clock.millis()).thenReturn(0L, 1337L);
TransactionalContext tc = mock(TransactionalContext.class);
CypherAdapterStream stream = new CypherAdapterStream(result, clock);
// When
Map<String, Object> meta = metadataOf(stream);
// Then
assertThat(meta.get("type").toString(), equalTo("rw"));
assertThat(meta.get("stats"), equalTo(map("nodes-created", 1, "nodes-deleted", 2, "relationships-created", 3, "relationships-deleted", 4, "properties-set", 5, "indexes-added", 6, "indexes-removed", 7, "constraints-added", 8, "constraints-removed", 9, "labels-added", 10, "labels-removed", 11)));
assertThat(meta.get("result_consumed_after"), equalTo(1337L));
}
use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.
the class CypherAdapterStreamTest method shouldIncludeProfileIfPresent.
@Test
public void shouldIncludeProfileIfPresent() throws Throwable {
// Given
QueryStatistics queryStatistics = mock(QueryStatistics.class);
when(queryStatistics.containsUpdates()).thenReturn(false);
Result result = mock(Result.class);
when(result.getQueryExecutionType()).thenReturn(explained(READ_ONLY));
when(result.getQueryStatistics()).thenReturn(queryStatistics);
when(result.getNotifications()).thenReturn(Collections.emptyList());
when(result.getExecutionPlanDescription()).thenReturn(plan("Join", map("arg1", 1), 2, 4, 3, 1, singletonList("id1"), plan("Scan", map("arg2", 1), 2, 4, 7, 1, singletonList("id2"))));
TransactionalContext tc = mock(TransactionalContext.class);
CypherAdapterStream stream = new CypherAdapterStream(result, Clock.systemUTC());
// When
Map<String, Object> meta = metadataOf(stream);
// Then
assertThat(meta.get("profile").toString(), equalTo("{args={arg1=1}, pageCacheMisses=3, " + "children=[{args={arg2=1}, pageCacheMisses=7, " + "children=[], dbHits=2, identifiers=[id2], operatorType=Scan, rows=1, pageCacheHits=4}], dbHits=2, " + "identifiers=[id1], operatorType=Join, rows=1, pageCacheHits=4}"));
}
use of org.neo4j.graphdb.QueryStatistics in project neo4j by neo4j.
the class CypherAdapterStreamTest method shouldIncludePlanIfPresent.
@Test
public void shouldIncludePlanIfPresent() throws Throwable {
// Given
QueryStatistics queryStatistics = mock(QueryStatistics.class);
when(queryStatistics.containsUpdates()).thenReturn(false);
Result result = mock(Result.class);
when(result.getQueryExecutionType()).thenReturn(explained(READ_ONLY));
when(result.getQueryStatistics()).thenReturn(queryStatistics);
when(result.getNotifications()).thenReturn(Collections.emptyList());
when(result.getExecutionPlanDescription()).thenReturn(plan("Join", map("arg1", 1), singletonList("id1"), plan("Scan", map("arg2", 1), singletonList("id2"))));
TransactionalContext tc = mock(TransactionalContext.class);
CypherAdapterStream stream = new CypherAdapterStream(result, Clock.systemUTC());
// When
Map<String, Object> meta = metadataOf(stream);
// Then
assertThat(meta.get("plan").toString(), equalTo("{args={arg1=1}, children=[{args={arg2=1}, children=[], identifiers=[id2], operatorType=Scan}], identifiers=[id1], operatorType=Join}"));
}
Aggregations