Search in sources :

Example 31 with InternalTransaction

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

the class CompositeIndexingIT method shouldSeeAllEntitiesAddedBeforeTransaction.

@ParameterizedTest
@MethodSource("params")
void shouldSeeAllEntitiesAddedBeforeTransaction(Params params) throws Exception {
    setup(params.prototypeFactory);
    var entityControl = params.entityControl;
    if (// this test does not make any sense for UNIQUE indexes
    !index.isUnique()) {
        long entity1 = createEntity(entityControl);
        long entity2 = createEntity(entityControl);
        long entity3 = createEntity(entityControl);
        try (Transaction tx = graphDatabaseAPI.beginTx()) {
            KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
            assertThat(entityControl.seek(ktx, index)).contains(entity1, entity2, entity3);
        }
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 32 with InternalTransaction

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

the class CompositeIndexingIT method shouldNotSeeEntitiesLackingOneProperty.

@ParameterizedTest
@MethodSource("params")
void shouldNotSeeEntitiesLackingOneProperty(Params params) throws Exception {
    setup(params.prototypeFactory);
    var entityControl = params.entityControl;
    long entity = createEntity(entityControl);
    try (Transaction tx = graphDatabaseAPI.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        entityControl.createEntity(ktx, index, true);
        assertThat(entityControl.seek(ktx, index)).containsExactly(entity);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 33 with InternalTransaction

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

the class CompositeIndexingIT method createEntity.

private long createEntity(EntityControl entityControl) throws KernelException {
    long id;
    try (Transaction tx = graphDatabaseAPI.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        id = entityControl.createEntity(ktx, index);
        tx.commit();
    }
    return id;
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 34 with InternalTransaction

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

the class CompositeIndexingIT method setup.

void setup(PrototypeFactory prototypeFactory) throws Exception {
    var prototype = prototypeFactory.build(labelId, relTypeId, propIds);
    try (Transaction tx = graphDatabaseAPI.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        if (prototype.isUnique()) {
            ConstraintDescriptor constraint = ktx.schemaWrite().uniquePropertyConstraintCreate(prototype);
            index = ktx.schemaRead().indexGetForName(constraint.getName());
        } else {
            index = ktx.schemaWrite().indexCreate(prototype.schema(), null);
        }
        tx.commit();
    }
    try (Transaction tx = graphDatabaseAPI.beginTx()) {
        tx.schema().awaitIndexesOnline(5, MINUTES);
        tx.commit();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 35 with InternalTransaction

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

the class TransactionTracingIT method tracePageCacheAccessOnAllNodesAccess.

@Test
void tracePageCacheAccessOnAllNodesAccess() {
    try (Transaction transaction = database.beginTx()) {
        for (int i = 0; i < ENTITY_COUNT; i++) {
            transaction.createNode();
        }
        transaction.commit();
    }
    try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
        var cursorContext = transaction.kernelTransaction().cursorContext();
        assertZeroCursor(cursorContext);
        softly.assertThat(Iterables.count(transaction.getAllNodes())).as("Number of expected nodes").isEqualTo(ENTITY_COUNT);
        softly.assertThat(cursorContext.getCursorTracer().pins()).as("Number of cursor pins").isEqualTo(2);
        softly.assertThat(cursorContext.getCursorTracer().unpins()).as("Number of cursor unpins").isEqualTo(1);
        softly.assertThat(cursorContext.getCursorTracer().hits()).as("Number of cursor hits").isEqualTo(2);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) 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