Search in sources :

Example 6 with TokenSet

use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.

the class PlainOperationsTest method shouldAcquiredSharedLabelLocksWhenDetachDeletingNode.

@Test
void shouldAcquiredSharedLabelLocksWhenDetachDeletingNode() {
    // given
    long nodeId = 1L;
    long labelId1 = 1;
    long labelId2 = 2;
    returnRelationships(transaction, new TestRelationshipChain(nodeId));
    when(transaction.ambientNodeCursor()).thenReturn(new StubNodeCursor(false).withNode(nodeId));
    when(nodeCursor.next()).thenReturn(true);
    TokenSet labels = mock(TokenSet.class);
    when(labels.all()).thenReturn(new long[] { labelId1, labelId2 });
    when(nodeCursor.labels()).thenReturn(labels);
    // when
    operations.nodeDetachDelete(nodeId);
    // then
    InOrder order = inOrder(locks, creationContext);
    order.verify(creationContext).acquireNodeDeletionLock(txState, locks, LockTracer.NONE, nodeId);
    order.verify(locks).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, labelId1, labelId2);
    order.verify(locks).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, TOKEN_INDEX_RESOURCE_ID);
    order.verifyNoMoreInteractions();
}
Also used : StubNodeCursor(org.neo4j.internal.kernel.api.helpers.StubNodeCursor) InOrder(org.mockito.InOrder) TokenSet(org.neo4j.internal.kernel.api.TokenSet) TestRelationshipChain(org.neo4j.internal.kernel.api.helpers.TestRelationshipChain) Test(org.junit.jupiter.api.Test)

Example 7 with TokenSet

use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.

the class PlainOperationsTest method shouldAcquiredSharedLabelLocksWhenDeletingNode.

@Test
void shouldAcquiredSharedLabelLocksWhenDeletingNode() {
    // given
    long nodeId = 1L;
    long labelId1 = 1;
    long labelId2 = 2;
    when(nodeCursor.next()).thenReturn(true);
    TokenSet labels = mock(TokenSet.class);
    when(labels.all()).thenReturn(new long[] { labelId1, labelId2 });
    when(nodeCursor.labels()).thenReturn(labels);
    // when
    operations.nodeDelete(nodeId);
    // then
    InOrder order = inOrder(locks, creationContext);
    order.verify(creationContext).acquireNodeDeletionLock(txState, locks, LockTracer.NONE, nodeId);
    order.verify(locks).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, labelId1, labelId2);
    order.verify(locks).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, TOKEN_INDEX_RESOURCE_ID);
    order.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) TokenSet(org.neo4j.internal.kernel.api.TokenSet) Test(org.junit.jupiter.api.Test)

Example 8 with TokenSet

use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.

the class PlainOperationsTest method detachDeleteNodeWithoutRelationshipsExclusivelyLockNode.

@Test
void detachDeleteNodeWithoutRelationshipsExclusivelyLockNode() {
    long nodeId = 1L;
    returnRelationships(transaction, new TestRelationshipChain(nodeId));
    when(transaction.ambientNodeCursor()).thenReturn(new StubNodeCursor(false).withNode(nodeId));
    when(nodeCursor.next()).thenReturn(true);
    TokenSet labels = mock(TokenSet.class);
    when(labels.all()).thenReturn(EMPTY_LONG_ARRAY);
    when(nodeCursor.labels()).thenReturn(labels);
    operations.nodeDetachDelete(nodeId);
    order.verify(creationContext).acquireNodeDeletionLock(txState, locks, LockTracer.NONE, nodeId);
    order.verify(locks, never()).releaseExclusive(ResourceTypes.NODE, nodeId);
    order.verify(txState).nodeDoDelete(nodeId);
}
Also used : StubNodeCursor(org.neo4j.internal.kernel.api.helpers.StubNodeCursor) TokenSet(org.neo4j.internal.kernel.api.TokenSet) TestRelationshipChain(org.neo4j.internal.kernel.api.helpers.TestRelationshipChain) Test(org.junit.jupiter.api.Test)

Example 9 with TokenSet

use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.

the class PlainOperationsTest method shouldAcquireSchemaReadLockBeforeSettingPropertyOnNode.

@Test
void shouldAcquireSchemaReadLockBeforeSettingPropertyOnNode() throws Exception {
    // given
    int relatedLabelId = 50;
    int unrelatedLabelId = 51;
    int propertyKeyId = 8;
    when(nodeCursor.next()).thenReturn(true);
    TokenSet tokenSet = mock(TokenSet.class);
    when(tokenSet.all()).thenReturn(new long[] { relatedLabelId });
    when(nodeCursor.labels()).thenReturn(tokenSet);
    Value value = Values.of(9);
    when(propertyCursor.next()).thenReturn(true);
    when(propertyCursor.propertyKey()).thenReturn(propertyKeyId);
    when(propertyCursor.propertyValue()).thenReturn(NO_VALUE);
    // when
    operations.nodeSetProperty(123, propertyKeyId, value);
    // then
    order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.NODE, 123);
    order.verify(locks).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, relatedLabelId);
    order.verify(locks, never()).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, unrelatedLabelId);
    order.verify(txState).nodeDoAddProperty(123, propertyKeyId, value);
}
Also used : TokenSet(org.neo4j.internal.kernel.api.TokenSet) Value(org.neo4j.values.storable.Value) Test(org.junit.jupiter.api.Test)

Example 10 with TokenSet

use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.

the class LabelsAcceptanceTest method shouldAllowManyLabelsAndPropertyCursor.

@Test
void shouldAllowManyLabelsAndPropertyCursor() {
    int propertyCount = 10;
    int labelCount = 15;
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = tx.createNode();
        for (int i = 0; i < propertyCount; i++) {
            node.setProperty("foo" + i, "bar");
        }
        for (int i = 0; i < labelCount; i++) {
            node.addLabel(label("label" + i));
        }
        tx.commit();
    }
    Set<Integer> seenProperties = new HashSet<>();
    Set<Integer> seenLabels = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        try (NodeCursor nodes = ktx.cursors().allocateNodeCursor(CursorContext.NULL);
            PropertyCursor propertyCursor = ktx.cursors().allocatePropertyCursor(CursorContext.NULL, INSTANCE)) {
            ktx.dataRead().singleNode(node.getId(), nodes);
            while (nodes.next()) {
                nodes.properties(propertyCursor);
                while (propertyCursor.next()) {
                    seenProperties.add(propertyCursor.propertyKey());
                }
                TokenSet labels = nodes.labels();
                for (int i = 0; i < labels.numberOfTokens(); i++) {
                    seenLabels.add(labels.token(i));
                }
            }
        }
        tx.commit();
    }
    assertEquals(propertyCount, seenProperties.size());
    assertEquals(labelCount, seenLabels.size());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenSet(org.neo4j.internal.kernel.api.TokenSet) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

TokenSet (org.neo4j.internal.kernel.api.TokenSet)11 Test (org.junit.jupiter.api.Test)9 InOrder (org.mockito.InOrder)3 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)3 StubNodeCursor (org.neo4j.internal.kernel.api.helpers.StubNodeCursor)3 TestRelationshipChain (org.neo4j.internal.kernel.api.helpers.TestRelationshipChain)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Label (org.neo4j.graphdb.Label)1 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)1 TokenRead (org.neo4j.internal.kernel.api.TokenRead)1 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1 Value (org.neo4j.values.storable.Value)1