Search in sources :

Example 11 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution 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 12 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution 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)

Example 13 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution in project neo4j by neo4j.

the class ServerExecutionEngineTest method shouldCloseResourcesInCancel.

@Test
void shouldCloseResourcesInCancel() throws Exception {
    // GIVEN
    TransactionalContextFactory contextFactory = Neo4jTransactionalContextFactory.create(() -> queryService, transactionFactory);
    // We need two node vars to have one non-pooled cursor
    String query = "MATCH (n), (m) WHERE true RETURN n, m, n.name, m.name";
    try (InternalTransaction tx = db.beginTransaction(KernelTransaction.Type.EXPLICIT, AUTH_DISABLED)) {
        tx.createNode();
        tx.createNode();
        TransactionalContext context = contextFactory.newContext(tx, query, MapValue.EMPTY);
        QueryExecution execution = executionEngine.executeQuery(query, MapValue.EMPTY, context, false, DO_NOTHING_SUBSCRIBER);
        execution.request(1);
        // This should close all cursors
        execution.cancel();
        tx.commit();
    }
}
Also used : TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Neo4jTransactionalContextFactory(org.neo4j.kernel.impl.query.Neo4jTransactionalContextFactory) TransactionalContextFactory(org.neo4j.kernel.impl.query.TransactionalContextFactory) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 14 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution in project neo4j by neo4j.

the class BoltQueryExecutorImpl method executeQuery.

@Override
public BoltQueryExecution executeQuery(String query, MapValue parameters, boolean prePopulate, QuerySubscriber subscriber) throws QueryExecutionKernelException {
    TransactionalContext transactionalContext = transactionalContextFactory.newContext(internalTransaction, query, parameters);
    QueryExecution queryExecution = queryExecutionEngine.executeQuery(query, parameters, transactionalContext, prePopulate, subscriber);
    return new BoltQueryExecutionImpl(queryExecution, transactionalContext);
}
Also used : TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) BoltQueryExecution(org.neo4j.bolt.dbapi.BoltQueryExecution) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution)

Example 15 with QueryExecution

use of org.neo4j.kernel.impl.query.QueryExecution in project neo4j by neo4j.

the class StatementResults method connectVia.

public static StatementResult connectVia(SubscribableExecution execution, QuerySubject subject) {
    QueryExecution queryExecution = execution.subscribe(subject);
    subject.setQueryExecution(queryExecution);
    return create(Flux.fromArray(queryExecution.fieldNames()), Flux.from(subject), subject.getSummary(), Mono.just(queryExecution.executionType()));
}
Also used : QueryExecution(org.neo4j.kernel.impl.query.QueryExecution)

Aggregations

QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)15 Test (org.junit.jupiter.api.Test)10 QueryStatistics (org.neo4j.graphdb.QueryStatistics)9 BoltAdapterSubscriber (org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber)8 MapValue (org.neo4j.values.virtual.MapValue)6 Clock (java.time.Clock)5 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)4 VersionContext (org.neo4j.io.pagecache.context.VersionContext)3 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)3 Config (org.neo4j.configuration.Config)2 CompilerFactory (org.neo4j.cypher.internal.CompilerFactory)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 RETURNS_DEEP_STUBS (org.mockito.Mockito.RETURNS_DEEP_STUBS)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1