use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseFullAccessRelationshipTraversalCursor.
@Test
void shouldReuseFullAccessRelationshipTraversalCursor() {
NodeCursor node = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor c1 = cursors.allocateFullAccessRelationshipTraversalCursor(NULL);
read.singleNode(startNode, node);
node.next();
node.relationships(c1, ALL_RELATIONSHIPS);
node.close();
c1.close();
RelationshipTraversalCursor c2 = cursors.allocateFullAccessRelationshipTraversalCursor(NULL);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseRelationshipTraversalCursor.
@Test
void shouldReuseRelationshipTraversalCursor() {
NodeCursor node = cursors.allocateNodeCursor(NULL);
RelationshipTraversalCursor c1 = cursors.allocateRelationshipTraversalCursor(NULL);
read.singleNode(startNode, node);
node.next();
node.relationships(c1, ALL_RELATIONSHIPS);
node.close();
c1.close();
RelationshipTraversalCursor c2 = cursors.allocateRelationshipTraversalCursor(NULL);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeRelationshipInTransaction.
@Test
void shouldSeeRelationshipInTransaction() 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());
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldNewRelationshipBetweenAlreadyConnectedSparseNodes.
@Test
void shouldNewRelationshipBetweenAlreadyConnectedSparseNodes() throws Exception {
long start;
long end;
long existingRelationship;
int type;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
start = write.nodeCreate();
end = write.nodeCreate();
type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
existingRelationship = write.relationshipCreate(start, type, end);
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());
assertFalse(node.supportsFastDegreeLookup());
Degrees degrees = node.degrees(selection(type, BOTH));
assertEquals(2, degrees.outgoingDegree());
assertEquals(0, degrees.incomingDegree());
assertRelationships(OUTGOING, node, type, traversal, newRelationship, existingRelationship);
}
}
}
use of org.neo4j.internal.kernel.api.RelationshipTraversalCursor 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);
}
}
Aggregations