Search in sources :

Example 86 with InternalTransaction

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

the class Neo4jTransactionalContextTest method shouldNotBeTopLevelWithExplicitTx.

@Test
void shouldNotBeTopLevelWithExplicitTx() {
    InternalTransaction tx = mock(InternalTransaction.class);
    when(tx.transactionType()).thenReturn(KernelTransaction.Type.EXPLICIT);
    Neo4jTransactionalContext context = newContext(tx);
    assertFalse(context.isTopLevelTx());
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Example 87 with InternalTransaction

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

the class Neo4jTransactionalContextTest method shouldThrowWhenGettingTxAfterTermination.

@Test
void shouldThrowWhenGettingTxAfterTermination() {
    MutableObject<Status> terminationReason = new MutableObject<>();
    InternalTransaction tx = mock(InternalTransaction.class);
    doAnswer(invocation -> {
        terminationReason.setValue(Status.Transaction.Terminated);
        return null;
    }).when(tx).terminate();
    when(tx.terminationReason()).then(invocation -> Optional.ofNullable(terminationReason.getValue()));
    Neo4jTransactionalContext context = newContext(tx);
    context.terminate();
    assertThrows(TransactionTerminatedException.class, context::getOrBeginNewIfClosed);
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Test(org.junit.jupiter.api.Test)

Example 88 with InternalTransaction

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

the class CompositeStringLengthValidationIT method shouldHandleCompositeSizesCloseToTheLimit.

@Test
void shouldHandleCompositeSizesCloseToTheLimit() throws KernelException {
    String firstSlot = random.nextAlphaNumericString(firstSlotLength, firstSlotLength);
    String secondSlot = random.nextAlphaNumericString(secondSlotLength, secondSlotLength);
    // given
    IndexDescriptor index = createIndex(KEY, KEY2);
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = tx.createNode(LABEL);
        node.setProperty(KEY, firstSlot);
        node.setProperty(KEY2, secondSlot);
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        int propertyKeyId1 = ktx.tokenRead().propertyKey(KEY);
        int propertyKeyId2 = ktx.tokenRead().propertyKey(KEY2);
        try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            IndexReadSession indexReadSession = ktx.dataRead().indexReadSession(index);
            ktx.dataRead().nodeIndexSeek(indexReadSession, cursor, unconstrained(), PropertyIndexQuery.exact(propertyKeyId1, firstSlot), PropertyIndexQuery.exact(propertyKeyId2, secondSlot));
            assertTrue(cursor.next());
            assertEquals(node.getId(), cursor.nodeReference());
            assertFalse(cursor.next());
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) Node(org.neo4j.graphdb.Node) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 89 with InternalTransaction

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

the class UniqueIndexSeekIT method lockNodeUsingUniqueIndexSeek.

private static void lockNodeUsingUniqueIndexSeek(GraphDatabaseAPI database, String nameProperty) throws KernelException {
    try (Transaction transaction = database.beginTx()) {
        KernelTransaction kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
        TokenRead tokenRead = kernelTransaction.tokenRead();
        Read dataRead = kernelTransaction.dataRead();
        int propertyId = tokenRead.propertyKey(nameProperty);
        IndexDescriptor indexReference = kernelTransaction.schemaRead().indexGetForName(CONSTRAINT_NAME);
        try (NodeValueIndexCursor cursor = kernelTransaction.cursors().allocateNodeValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
            dataRead.lockingNodeUniqueIndexSeek(indexReference, cursor, PropertyIndexQuery.ExactPredicate.exact(propertyId, "value"));
        }
        transaction.commit();
    }
}
Also used : TokenRead(org.neo4j.internal.kernel.api.TokenRead) Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 90 with InternalTransaction

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

the class MultipleOpenCursorsTest method multipleIteratorsNestedInnerNewExists.

@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInnerNewExists(IndexCoordinator indexCoordinator) throws Exception {
    indexCoordinator.init(db);
    try (Transaction tx = db.beginTx()) {
        // when
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExists(ktx)) {
            List<Long> actual1 = new ArrayList<>();
            while (cursor1.next()) {
                actual1.add(cursor1.nodeReference());
                try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExists(ktx)) {
                    List<Long> actual2 = asList(cursor2);
                    indexCoordinator.assertExistsResult(actual2);
                }
            }
            // then
            indexCoordinator.assertExistsResult(actual1);
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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