use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor 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.RelationshipTraversalCursor in project neo4j by neo4j.
the class CachingExpandIntoTest method findConnections.
private void findConnections(CachingExpandInto expandInto, NodeCursor cursor, long from, long to, int... types) {
RelationshipTraversalCursor relationships = expandInto.connectingRelationships(cursor, mock(RelationshipTraversalCursor.class), from, types, to);
// While we traverse the relationships, we estimate with the cursor, which references the CachingExpandInto
assertEstimatesCorrectly(relationships);
while (relationships.next()) {
assertEstimatesCorrectly(relationships);
}
// Once the cursor is exhausted, it will close itself. Now we need to measure using expandInto directly again
assertEstimatesCorrectly(expandInto);
// Make sure that next is idempotent, even if cursor is already closed
relationships.next();
assertEstimatesCorrectly(expandInto);
}
use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor 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.RelationshipTraversalCursor 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 ");
}
}
}
}
}
use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeRelationshipInTransactionBeforeCursorInitialization.
@Test
void shouldSeeRelationshipInTransactionBeforeCursorInitialization() throws Exception {
long n1, n2;
try (KernelTransaction tx = beginTransaction()) {
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
long r = tx.dataWrite().relationshipCreate(n1, label, n2);
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
tx.dataRead().singleNode(n1, node);
assertTrue(node.next(), "should access node");
node.relationships(relationship, ALL_RELATIONSHIPS);
assertTrue(relationship.next(), "should find relationship");
assertEquals(r, relationship.relationshipReference());
// should not be seen
tx.dataWrite().relationshipCreate(n1, label, n2);
assertFalse(relationship.next(), "should not find relationship added after cursor init");
}
tx.commit();
}
}
Aggregations