use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method assertCount.
private void assertCount(int count, RelationshipDirection direction, Consumer<Degrees> asserter) throws Exception {
long start;
int type;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
start = write.nodeCreate();
type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
for (int i = 0; i < count; i++) {
createRelationship(direction, start, type, write);
}
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
createRelationship(direction, start, type, write);
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL)) {
Read read = tx.dataRead();
read.singleNode(start, node);
assertTrue(node.next());
Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
asserter.accept(degrees);
}
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldIncludeAddedRelationshipsByTypeAndDirection.
@Test
void shouldIncludeAddedRelationshipsByTypeAndDirection() throws Exception {
int typeId1;
int typeId2;
long relationship1;
long relationship2;
long sourceNode;
long targetNode;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
typeId1 = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
typeId2 = tx.tokenWrite().relationshipTypeGetOrCreateForName("R2");
sourceNode = write.nodeCreate();
relationship1 = write.relationshipCreate(sourceNode, typeId1, write.nodeCreate());
relationship2 = write.relationshipCreate(sourceNode, typeId2, write.nodeCreate());
targetNode = write.nodeCreate();
tx.commit();
}
SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
try (KernelTransaction tx = beginTransaction(loginContext);
NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
Write write = tx.dataWrite();
// OUTGOING :R
long r1 = write.relationshipCreate(sourceNode, typeId1, targetNode);
// INCOMING :R
long r2 = write.relationshipCreate(targetNode, typeId1, sourceNode);
// LOOP :R
long r3 = write.relationshipCreate(sourceNode, typeId1, sourceNode);
// OUTGOING :R2
long r4 = write.relationshipCreate(sourceNode, typeId2, targetNode);
// INCOMING :R2
long r5 = write.relationshipCreate(targetNode, typeId2, sourceNode);
// LOOP :R2
long r6 = write.relationshipCreate(sourceNode, typeId2, sourceNode);
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
read.singleNode(sourceNode, node);
assertTrue(node.next());
assertRelationships(node, traversal, ALL_RELATIONSHIPS, relationship1, relationship2, r1, r2, r3, r4, r5, r6);
assertRelationships(node, traversal, selection(OUTGOING), relationship1, relationship2, r1, r3, r4, r6);
assertRelationships(node, traversal, selection(typeId1, BOTH), relationship1, r1, r2, r3);
assertRelationships(node, traversal, selection(typeId1, OUTGOING), relationship1, r1, r3);
assertRelationships(node, traversal, selection(typeId1, INCOMING), r2, r3);
assertRelationships(node, traversal, selection(typeId2, BOTH), relationship2, r4, r5, r6);
assertRelationships(node, traversal, selection(typeId2, OUTGOING), relationship2, r4, r6);
assertRelationships(node, traversal, selection(typeId2, INCOMING), r5, r6);
assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, BOTH), relationship1, relationship2, r1, r2, r3, r4, r5, r6);
assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, OUTGOING), relationship1, relationship2, r1, r3, r4, r6);
assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, INCOMING), r2, r3, r5, r6);
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTraversalCursorTestBase method traverse.
private void traverse(RelationshipTestSupport.StartNode start, boolean detached) throws KernelException {
// given
try (NodeCursor node = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor(NULL)) {
// when
read.singleNode(start.id, node);
assertTrue(node.next(), "access node");
if (detached) {
read.relationships(start.id, node.relationshipsReference(), ALL_RELATIONSHIPS, relationship);
} else {
node.relationships(relationship, ALL_RELATIONSHIPS);
}
Map<String, Integer> counts = count(tx, relationship);
// then
assertCounts(start.expectedCounts(), counts);
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTraversalCursorTestBase method shouldHaveBeenAbleToCreateDenseAndSparseNodes.
@Test
void shouldHaveBeenAbleToCreateDenseAndSparseNodes() {
// given
try (NodeCursor node = cursors.allocateNodeCursor(NULL)) {
read.singleNode(dense.id, node);
assertTrue(node.next(), "access dense node");
assertTrue(node.supportsFastDegreeLookup(), "dense node");
read.singleNode(sparse.id, node);
assertTrue(node.next(), "access sparse node");
assertFalse(node.supportsFastDegreeLookup() && supportsSparseNodes(), "sparse node");
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTraversalCursorTestBase method shouldTraverseRelationshipsOfGivenType.
@Test
void shouldTraverseRelationshipsOfGivenType() {
// given
try (NodeCursor node = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor(NULL)) {
int empty = 0;
// when
read.allNodesScan(node);
while (node.next()) {
// then
Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
boolean none = true;
for (int type : degrees.types()) {
none = false;
Sizes degree = new Sizes();
node.relationships(relationship, selection(type, BOTH));
while (relationship.next()) {
assertEquals(type, relationship.type(), "node #" + node.nodeReference() + " relationship has label not part of selection");
if (relationship.sourceNodeReference() == node.nodeReference()) {
degree.outgoing++;
}
if (relationship.targetNodeReference() == node.nodeReference()) {
degree.incoming++;
}
degree.total++;
}
assertNotEquals(0, degree.total, "all");
assertEquals(degrees.outgoingDegree(type), degree.outgoing, "node #" + node.nodeReference() + " outgoing");
assertEquals(degrees.incomingDegree(type), degree.incoming, "node #" + node.nodeReference() + " incoming");
assertEquals(degrees.totalDegree(type), degree.total, "node #" + node.nodeReference() + " all = incoming + outgoing - loop");
}
if (none) {
empty++;
}
}
// then
assertEquals(1, empty, "number of empty nodes");
}
}
Aggregations