use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class CachingExpandIntoTest method shouldNotRecomputeAnythingIfSameNodesAndTypes.
@Test
void shouldNotRecomputeAnythingIfSameNodesAndTypes() throws Exception {
// Given
CachingExpandInto expandInto = new CachingExpandInto(mock(Read.class), OUTGOING, memoryTracker);
findConnections(expandInto, mockCursor(), 42, 43, 100, 101);
NodeCursor cursor = mockCursor();
// When
findConnections(expandInto, cursor, 42, 43, 100, 101);
// Then
verifyNoInteractions(cursor);
assertReleasesHeap(expandInto);
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class CachingExpandIntoTest method shouldComputeDegreeOfStartAndEndNodeEveryTimeIfCacheIsFull.
@Test
void shouldComputeDegreeOfStartAndEndNodeEveryTimeIfCacheIsFull() throws Exception {
// Given
CachingExpandInto expandInto = new CachingExpandInto(mock(Read.class), OUTGOING, memoryTracker, 0, true);
NodeCursor cursor = mockCursor();
// When
findConnections(expandInto, cursor, 42, 43);
findConnections(expandInto, cursor, 42, 43);
findConnections(expandInto, cursor, 42, 43);
findConnections(expandInto, cursor, 42, 43);
findConnections(expandInto, cursor, 42, 43);
// Then, only call 5 times for 42 and 5 times for 43
verify(cursor, times(10)).degree(any(RelationshipSelection.class));
assertReleasesHeap(expandInto);
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class TransactionImpl method allNodesByLabelWithoutIndex.
private ResourceIterator<Node> allNodesByLabelWithoutIndex(KernelTransaction ktx, int labelId) {
NodeCursor cursor = ktx.cursors().allocateNodeCursor(ktx.cursorContext());
ktx.dataRead().allNodesScan(cursor);
var filetredCursor = new FilteringNodeCursorWrapper(cursor, CursorPredicates.hasLabel(labelId));
return new CursorIterator<>(filetredCursor, NodeCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeBothOldAndNewRelationshipsFromSparseNode.
@Test
void shouldSeeBothOldAndNewRelationshipsFromSparseNode() throws Exception {
long start;
long existingRelationship;
int one;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
start = write.nodeCreate();
one = tx.tokenWrite().relationshipTypeGetOrCreateForName("ONE");
existingRelationship = write.relationshipCreate(start, one, write.nodeCreate());
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
int two = tx.tokenWrite().relationshipTypeGetOrCreateForName("TWO");
long newRelationship = write.relationshipCreate(start, two, 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());
assertFalse(node.supportsFastDegreeLookup());
Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
for (int t : degrees.types()) {
if (t == one) {
assertEquals(1, degrees.outgoingDegree(t));
assertEquals(0, degrees.incomingDegree(t));
assertRelationships(OUTGOING, node, t, traversal, existingRelationship);
} else if (t == two) {
assertEquals(1, degrees.outgoingDegree(t));
assertEquals(0, degrees.incomingDegree(t));
assertRelationships(OUTGOING, node, t, traversal, newRelationship);
} 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 RelationshipTransactionStateTestBase method shouldSeeBothOldAndNewRelationshipsFromDenseNode.
@Test
void shouldSeeBothOldAndNewRelationshipsFromDenseNode() throws Exception {
long start;
long existingRelationship;
int one, bulk;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
start = write.nodeCreate();
one = tx.tokenWrite().relationshipTypeGetOrCreateForName("ONE");
existingRelationship = write.relationshipCreate(start, one, write.nodeCreate());
bulk = tx.tokenWrite().relationshipTypeGetOrCreateForName("BULK");
for (int i = 0; i < 100; i++) {
write.relationshipCreate(start, bulk, write.nodeCreate());
}
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
int two = tx.tokenWrite().relationshipTypeGetOrCreateForName("TWO");
long newRelationship = write.relationshipCreate(start, two, 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());
assertTrue(node.supportsFastDegreeLookup());
Degrees degrees = node.degrees(ALL_RELATIONSHIPS);
for (int t : degrees.types()) {
if (t == one) {
assertEquals(1, degrees.outgoingDegree(t));
assertEquals(0, degrees.incomingDegree(t));
assertRelationships(OUTGOING, node, t, traversal, existingRelationship);
} else if (t == two) {
assertEquals(1, degrees.outgoingDegree(t));
assertEquals(0, degrees.incomingDegree(t));
assertRelationships(OUTGOING, node, t, traversal, newRelationship);
} else if (t == bulk) {
assertEquals(100, degrees.outgoingDegree(t));
assertEquals(0, degrees.incomingDegree(t));
} else {
fail(t + " is not the type you're looking for ");
}
}
}
}
}
Aggregations