Search in sources :

Example 71 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction 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 72 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ReadTracingIT method noPageCacheTracingAvailableOnRelationshipIndexSeek.

@Test
void noPageCacheTracingAvailableOnRelationshipIndexSeek() throws KernelException {
    createRelationshipIndex();
    try (Transaction tx = database.beginTx()) {
        var source = tx.createNode(label);
        var target = tx.createNode(label);
        var relationship = source.createRelationshipTo(target, type);
        relationship.setProperty(property, testPropertyValue);
        tx.commit();
    }
    try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
        var kernelTransaction = transaction.kernelTransaction();
        var dataRead = kernelTransaction.dataRead();
        var indexDescriptor = kernelTransaction.schemaRead().indexGetForName(indexName);
        IndexReadSession indexReadSession = kernelTransaction.dataRead().indexReadSession(indexDescriptor);
        var cursorContext = kernelTransaction.cursorContext();
        assertZeroCursor(cursorContext);
        try (var cursor = kernelTransaction.cursors().allocateRelationshipValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
            dataRead.relationshipIndexSeek(indexReadSession, cursor, unconstrained(), fulltextSearch(testPropertyValue));
            consumeCursor(cursor);
        }
        assertZeroCursor(cursorContext);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 73 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ReadTracingIT method tracePageCacheAccessOnNodeWithoutTxStateCount.

@Test
void tracePageCacheAccessOnNodeWithoutTxStateCount() {
    try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
        var kernelTransaction = transaction.kernelTransaction();
        var cursorContext = kernelTransaction.cursorContext();
        var dataRead = kernelTransaction.dataRead();
        assertZeroCursor(cursorContext);
        dataRead.countsForNodeWithoutTxState(0);
        assertOneCursor(cursorContext);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Example 74 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ReadTracingIT method tracePageCacheAccessOnRelationshipCount.

@Test
void tracePageCacheAccessOnRelationshipCount() {
    try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
        var kernelTransaction = transaction.kernelTransaction();
        var cursorContext = kernelTransaction.cursorContext();
        var dataRead = kernelTransaction.dataRead();
        assertZeroCursor(cursorContext);
        dataRead.countsForRelationship(ANY_LABEL, ANY_RELATIONSHIP_TYPE, ANY_LABEL);
        assertOneCursor(cursorContext);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Example 75 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ReadTracingIT method tracePageCacheAccessOnNodeIndexSeek.

@Test
void tracePageCacheAccessOnNodeIndexSeek() throws KernelException {
    createNodeConstraint();
    createMatchingNode();
    try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
        var kernelTransaction = transaction.kernelTransaction();
        var dataRead = kernelTransaction.dataRead();
        var indexDescriptor = kernelTransaction.schemaRead().indexGetForName(indexName);
        var cursorContext = kernelTransaction.cursorContext();
        int propertyId = kernelTransaction.tokenRead().propertyKey(property);
        assertZeroCursor(cursorContext);
        var indexSession = dataRead.indexReadSession(indexDescriptor);
        try (var cursor = kernelTransaction.cursors().allocateNodeValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
            dataRead.nodeIndexSeek(indexSession, cursor, unconstrained(), stringContains(propertyId, stringValue(testPropertyValue)));
            consumeCursor(cursor);
        }
        assertOneCursor(cursorContext);
        assertThat(cursorContext.getCursorTracer().faults()).isZero();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)126 Transaction (org.neo4j.graphdb.Transaction)58 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)53 Test (org.junit.jupiter.api.Test)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 Node (org.neo4j.graphdb.Node)16 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 Result (org.neo4j.graphdb.Result)12 TokenRead (org.neo4j.internal.kernel.api.TokenRead)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)8 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)7 Relationship (org.neo4j.graphdb.Relationship)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)6 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)5