use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTraversalCursorTestBase method shouldFollowSpecificRelationship.
@Test
void shouldFollowSpecificRelationship() {
// given
try (NodeCursor node = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor(NULL)) {
// when - traversing from start to end
read.singleNode(start, node);
assertTrue(node.next(), "access start node");
int[] types = node.relationshipTypes();
assertTrue(types.length > 0);
node.relationships(relationship, selection(types[0], OUTGOING));
assertTrue(relationship.next(), "access outgoing relationships");
// then
assertEquals(start, relationship.sourceNodeReference(), "source node");
assertEquals(end, relationship.targetNodeReference(), "target node");
assertEquals(start, relationship.originNodeReference(), "node of origin");
assertEquals(end, relationship.otherNodeReference(), "neighbouring node");
assertEquals(types[0], relationship.type(), "relationship should have correct label");
assertFalse(relationship.next(), "only a single relationship");
node.relationships(relationship, selection(types[0], INCOMING));
assertFalse(relationship.next(), "no incoming relationships");
// when - traversing from end to start
read.singleNode(end, node);
assertTrue(node.next(), "access start node");
types = node.relationshipTypes();
assertTrue(types.length > 0);
node.relationships(relationship, selection(types[0], INCOMING));
assertTrue(relationship.next(), "access incoming relationships");
// then
assertEquals(start, relationship.sourceNodeReference(), "source node");
assertEquals(end, relationship.targetNodeReference(), "target node");
assertEquals(end, relationship.originNodeReference(), "node of origin");
assertEquals(start, relationship.otherNodeReference(), "neighbouring node");
assertEquals(types[0], relationship.type(), "relationship should have correct label");
assertFalse(relationship.next(), "only a single relationship");
node.relationships(relationship, selection(types[0], OUTGOING));
assertFalse(relationship.next(), "no outgoing relationships");
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldAddToCountFromTxState.
@Test
void shouldAddToCountFromTxState() throws Exception {
long start;
long existingRelationship;
int type;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
start = write.nodeCreate();
type = tx.tokenWrite().relationshipTypeGetOrCreateForName("OUT");
existingRelationship = write.relationshipCreate(start, type, write.nodeCreate());
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
long newRelationship = write.relationshipCreate(start, type, write.nodeCreate());
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
read.singleNode(start, node);
assertTrue(node.next());
Degrees degrees = node.degrees(selection(type, BOTH));
assertEquals(2, degrees.outgoingDegree(type));
assertEquals(0, degrees.incomingDegree(type));
assertRelationships(OUTGOING, node, type, traversal, newRelationship, existingRelationship);
}
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method traverse.
private void traverse(RelationshipTestSupport.StartNode start, boolean detached) throws Exception {
try (KernelTransaction tx = beginTransaction()) {
Map<String, Integer> expectedCounts = modifyStartNodeRelationships(start, tx);
// given
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
// when
tx.dataRead().singleNode(start.id, node);
assertTrue(node.next(), "access node");
if (detached) {
tx.dataRead().relationships(start.id, node.relationshipsReference(), ALL_RELATIONSHIPS, relationship);
} else {
node.relationships(relationship, ALL_RELATIONSHIPS);
}
Map<String, Integer> counts = count(tx, relationship);
// then
assertCounts(expectedCounts, counts);
}
tx.rollback();
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeNewTypes.
@Test
void shouldSeeNewTypes() throws Exception {
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
long start = write.nodeCreate();
int outgoing = tx.tokenWrite().relationshipTypeGetOrCreateForName("OUT");
int incoming = tx.tokenWrite().relationshipTypeGetOrCreateForName("IN");
int looping = tx.tokenWrite().relationshipTypeGetOrCreateForName("LOOP");
long out = write.relationshipCreate(start, outgoing, write.nodeCreate());
long in1 = write.relationshipCreate(write.nodeCreate(), incoming, start);
long in2 = write.relationshipCreate(write.nodeCreate(), incoming, start);
long loop = write.relationshipCreate(start, looping, start);
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
read.singleNode(start, node);
assertTrue(node.next());
Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
for (int t : degrees.types()) {
if (t == outgoing) {
assertEquals(1, degrees.outgoingDegree(t));
assertEquals(0, degrees.incomingDegree(t));
assertRelationships(OUTGOING, node, t, traversal, out);
assertNoRelationships(INCOMING, node, t, traversal);
} else if (t == incoming) {
assertEquals(0, degrees.outgoingDegree(t));
assertEquals(2, degrees.incomingDegree(t));
assertRelationships(INCOMING, node, t, traversal, in1, in2);
assertNoRelationships(OUTGOING, node, t, traversal);
} else if (t == looping) {
assertEquals(1, degrees.outgoingDegree(t));
assertEquals(1, degrees.incomingDegree(t));
assertRelationships(BOTH, node, t, traversal, loop);
assertRelationships(OUTGOING, node, t, traversal, loop);
assertRelationships(INCOMING, node, t, traversal, loop);
} else {
fail(t + " is not the type you're looking for ");
}
}
}
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class CachingExpandIntoTest method shouldComputeDegreeOfStartAndEndNode.
@Test
void shouldComputeDegreeOfStartAndEndNode() throws Exception {
// Given
CachingExpandInto expandInto = new CachingExpandInto(mock(Read.class), OUTGOING, memoryTracker);
NodeCursor cursor = mockCursor();
// Then
assertEstimatesCorrectly(expandInto);
// When
findConnections(expandInto, cursor, 42, 43);
// Then
verify(cursor, times(2)).degree(any(RelationshipSelection.class));
assertReleasesHeap(expandInto);
}
Aggregations