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();
}
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();
}
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);
}
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);
}
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());
}
Aggregations