use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RandomRelationshipTraversalCursorTestBase method shouldManageRandomTraversals.
@Test
void shouldManageRandomTraversals() {
// given
try (NodeCursor node = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor(NULL)) {
for (int i = 0; i < N_TRAVERSALS; i++) {
// when
long nodeId = NODE_IDS.get(RANDOM.nextInt(N_NODES));
read.singleNode(nodeId, node);
assertTrue(node.next(), "access root node");
int[] types = node.relationshipTypes();
assertFalse(node.next(), "single root");
// then
for (int type : types) {
node.relationships(relationship, selection(type, INCOMING));
while (relationship.next()) {
assertEquals(nodeId, relationship.originNodeReference(), "incoming origin");
relationship.otherNode(node);
}
node.relationships(relationship, selection(type, OUTGOING));
while (relationship.next()) {
assertEquals(nodeId, relationship.originNodeReference(), "outgoing origin");
relationship.otherNode(node);
}
}
}
} catch (Throwable t) {
throw new RuntimeException("Failed with random seed " + SEED, t);
}
}
use of org.neo4j.internal.kernel.api.NodeCursor 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());
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class DeepRelationshipTraversalCursorTestBase method shouldTraverseTreeOfDepthThree.
@Test
void shouldTraverseTreeOfDepthThree() {
try (NodeCursor node = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship1 = cursors.allocateRelationshipTraversalCursor(NULL);
RelationshipTraversalCursor relationship2 = cursors.allocateRelationshipTraversalCursor(NULL)) {
MutableLongSet leafs = new LongHashSet();
long total = 0;
// when
read.singleNode(three_root, node);
assertTrue(node.next(), "access root node");
node.relationships(relationship1, selection(parentRelationshipTypeId, Direction.INCOMING));
while (relationship1.next()) {
relationship1.otherNode(node);
assertTrue(node.next(), "child level 1");
node.relationships(relationship2, selection(parentRelationshipTypeId, Direction.INCOMING));
while (relationship2.next()) {
leafs.add(relationship2.otherNodeReference());
total++;
}
}
// then
assertEquals(expected_total, total, "total number of leaf nodes");
assertEquals(expected_unique, leafs.size(), "number of distinct leaf nodes");
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseNodeCursor.
@Test
void shouldReuseNodeCursor() {
NodeCursor c1 = cursors.allocateNodeCursor(NULL);
read.singleNode(startNode, c1);
c1.close();
NodeCursor c2 = cursors.allocateNodeCursor(NULL);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReusePropertyCursor.
@Test
void shouldReusePropertyCursor() {
NodeCursor node = cursors.allocateNodeCursor(NULL);
PropertyCursor c1 = cursors.allocatePropertyCursor(NULL, INSTANCE);
read.singleNode(propNode, node);
node.next();
node.properties(c1);
node.close();
c1.close();
PropertyCursor c2 = cursors.allocatePropertyCursor(NULL, INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
Aggregations