use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeCursorTestBase method shouldAccessNodesByReference.
@Test
void shouldAccessNodesByReference() {
// given
try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
for (long id : NODE_IDS) {
// when
read.singleNode(id, nodes);
// then
assertTrue(nodes.next(), "should access defined node");
assertEquals(id, nodes.nodeReference(), "should access the correct node");
assertFalse(nodes.next(), "should only access a single node");
}
}
}
use of org.neo4j.internal.kernel.api.NodeCursor 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.NodeCursor in project neo4j by neo4j.
the class NodeCursorTestBase method notFindNoIdNode.
@Test
void notFindNoIdNode() throws InvalidTransactionTypeKernelException {
// given a non-commited node created in transaction
long nodeId = tx.dataWrite().nodeCreate();
try (NodeCursor nodes = cursors.allocateNodeCursor(NULL)) {
// when
read.singleNode(-1, nodes);
// then
assertFalse(nodes.next(), "should not access any node");
}
// remove temporarily created node.
tx.dataWrite().nodeDelete(nodeId);
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseFullAccessPropertyCursor.
@Test
void shouldReuseFullAccessPropertyCursor() {
NodeCursor node = cursors.allocateNodeCursor(NULL);
PropertyCursor c1 = cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE);
read.singleNode(propNode, node);
node.next();
node.properties(c1);
node.close();
c1.close();
PropertyCursor c2 = cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseFullAccessRelationshipTraversalCursor.
@Test
void shouldReuseFullAccessRelationshipTraversalCursor() {
NodeCursor node = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor c1 = cursors.allocateFullAccessRelationshipTraversalCursor(NULL);
read.singleNode(startNode, node);
node.next();
node.relationships(c1, ALL_RELATIONSHIPS);
node.close();
c1.close();
RelationshipTraversalCursor c2 = cursors.allocateFullAccessRelationshipTraversalCursor(NULL);
assertThat(c1).isSameAs(c2);
c2.close();
}
Aggregations