use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.
the class FulltextIndexTransactionStateVisitor method indexNode.
private void indexNode(long id) {
if (visitingNodes) {
read.singleNode(id, nodeCursor);
if (nodeCursor.next()) {
TokenSet labels = nodeCursor.labels();
if (schema.isAffected(labels.all())) {
nodeCursor.properties(propertyCursor);
indexProperties(id);
}
}
}
}
use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldSeeNewLabeledNodeInTransaction.
@Test
void shouldSeeNewLabeledNodeInTransaction() throws Exception {
long nodeId;
int labelId;
final String labelName = "Town";
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
labelId = tx.token().labelGetOrCreateForName(labelName);
tx.dataWrite().nodeAddLabel(nodeId, labelId);
try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
tx.dataRead().singleNode(nodeId, node);
assertTrue(node.next(), "should access node");
TokenSet labels = node.labels();
assertEquals(1, labels.numberOfTokens());
assertEquals(labelId, labels.token(0));
assertTrue(node.hasLabel(labelId));
assertFalse(node.hasLabel(labelId + 1));
assertFalse(node.next(), "should only find one node");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
assertThat(tx.getNodeById(nodeId).getLabels()).isEqualTo(Iterables.iterable(label(labelName)));
}
}
use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.
the class NodeCursorTestBase method shouldReadLabels.
@Test
void shouldReadLabels() {
// given
try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
TokenSet labels;
// when
read.singleNode(foo, nodes);
// then
assertTrue(nodes.next(), "should access defined node");
labels = nodes.labels();
assertEquals(1, labels.numberOfTokens(), "number of labels");
int fooLabel = labels.token(0);
assertTrue(nodes.hasLabel(fooLabel));
assertFalse(nodes.next(), "should only access a single node");
// when
read.singleNode(bar, nodes);
// then
assertTrue(nodes.next(), "should access defined node");
labels = nodes.labels();
assertEquals(1, labels.numberOfTokens(), "number of labels");
int barLabel = labels.token(0);
assertFalse(nodes.hasLabel(fooLabel));
assertTrue(nodes.hasLabel(barLabel));
assertFalse(nodes.next(), "should only access a single node");
// when
read.singleNode(baz, nodes);
// then
assertTrue(nodes.next(), "should access defined node");
labels = nodes.labels();
assertEquals(1, labels.numberOfTokens(), "number of labels");
int bazLabel = labels.token(0);
assertFalse(nodes.hasLabel(fooLabel));
assertFalse(nodes.hasLabel(barLabel));
assertTrue(nodes.hasLabel(bazLabel));
assertFalse(nodes.next(), "should only access a single node");
assertNotEquals(fooLabel, barLabel, "distinct labels");
assertNotEquals(fooLabel, bazLabel, "distinct labels");
assertNotEquals(barLabel, bazLabel, "distinct labels");
// when
read.singleNode(barbaz, nodes);
// then
assertTrue(nodes.next(), "should access defined node");
labels = nodes.labels();
assertEquals(2, labels.numberOfTokens(), "number of labels");
if (labels.token(0) == barLabel) {
assertEquals(bazLabel, labels.token(1));
} else {
assertEquals(bazLabel, labels.token(0));
assertEquals(barLabel, labels.token(1));
}
assertFalse(nodes.hasLabel(fooLabel));
assertTrue(nodes.hasLabel(barLabel));
assertTrue(nodes.hasLabel(bazLabel));
assertFalse(nodes.next(), "should only access a single node");
// when
read.singleNode(bare, nodes);
// then
assertTrue(nodes.next(), "should access defined node");
labels = nodes.labels();
assertEquals(0, labels.numberOfTokens(), "number of labels");
assertFalse(nodes.hasLabel(fooLabel));
assertFalse(nodes.hasLabel(barLabel));
assertFalse(nodes.hasLabel(bazLabel));
assertFalse(nodes.next(), "should only access a single node");
}
}
use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.
the class PlainOperationsTest method detachDeleteNodeExclusivelyLockNodes.
@Test
void detachDeleteNodeExclusivelyLockNodes() {
long nodeId = 1L;
returnRelationships(transaction, new TestRelationshipChain(nodeId).outgoing(1, 2L, 42));
when(transaction.ambientNodeCursor()).thenReturn(new StubNodeCursor(false).withNode(nodeId));
TokenSet labels = mock(TokenSet.class);
when(labels.all()).thenReturn(EMPTY_LONG_ARRAY);
when(nodeCursor.labels()).thenReturn(labels);
when(nodeCursor.next()).thenReturn(true);
operations.nodeDetachDelete(nodeId);
order.verify(creationContext).acquireNodeDeletionLock(txState, locks, LockTracer.NONE, nodeId);
order.verify(locks, never()).releaseExclusive(ResourceTypes.NODE, nodeId);
order.verify(locks, never()).releaseExclusive(ResourceTypes.NODE, 2L);
order.verify(txState).nodeDoDelete(nodeId);
}
use of org.neo4j.internal.kernel.api.TokenSet in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquiredSharedLabelLocksWhenRemovingNodeProperty.
@Test
void shouldAcquiredSharedLabelLocksWhenRemovingNodeProperty() throws EntityNotFoundException {
// given
long nodeId = 1L;
long labelId1 = 1;
long labelId2 = 1;
int propertyKeyId = 5;
when(nodeCursor.next()).thenReturn(true);
TokenSet labels = mock(TokenSet.class);
when(labels.all()).thenReturn(new long[] { labelId1, labelId2 });
when(nodeCursor.labels()).thenReturn(labels);
when(propertyCursor.next()).thenReturn(true);
when(propertyCursor.propertyKey()).thenReturn(propertyKeyId);
when(propertyCursor.propertyValue()).thenReturn(Values.of("abc"));
// when
operations.nodeRemoveProperty(nodeId, propertyKeyId);
// then
InOrder order = inOrder(locks);
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.NODE, nodeId);
order.verify(locks).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, labelId1, labelId2);
order.verifyNoMoreInteractions();
}
Aggregations