use of org.neo4j.graphdb.traversal.TraversalBranch in project graphdb by neo4j-attic.
the class TraversalPath method ensureEntitiesAreGathered.
private void ensureEntitiesAreGathered() {
if (nodes == null) {
// We don't synchronize on nodes/relationship... and that's fine
// because even if there would be a situation where two (or more)
// threads comes here at the same time everything would still
// work as expected (in here as well as outside).
LinkedList<Node> nodesList = new LinkedList<Node>();
LinkedList<Relationship> relationshipsList = new LinkedList<Relationship>();
TraversalBranch stepper = branch;
while (stepper != null) {
nodesList.addFirst(stepper.node());
Relationship relationship = stepper.relationship();
if (relationship != null) {
relationshipsList.addFirst(relationship);
}
stepper = stepper.parent();
}
nodes = nodesList;
relationships = relationshipsList;
}
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j by neo4j.
the class StandardBranchCollisionDetectorTest method testFilteredPathEvaluation.
@Test
void testFilteredPathEvaluation() {
final Entity endNode = mock(Node.class);
final Entity alternativeEndNode = mock(Node.class);
final Node startNode = mock(Node.class);
Evaluator evaluator = mock(Evaluator.class);
TraversalBranch branch = mock(TraversalBranch.class);
TraversalBranch alternativeBranch = mock(TraversalBranch.class);
when(branch.iterator()).thenAnswer(new IteratorAnswer(endNode));
when(alternativeBranch.iterator()).thenAnswer(new IteratorAnswer(alternativeEndNode));
when(alternativeBranch.startNode()).thenReturn(startNode);
when(evaluator.evaluate(Mockito.any(Path.class))).thenReturn(Evaluation.INCLUDE_AND_CONTINUE);
StandardBranchCollisionDetector collisionDetector = new StandardBranchCollisionDetector(evaluator, path -> alternativeEndNode.equals(path.endNode()) && startNode.equals(path.startNode()));
Collection<Path> incoming = collisionDetector.evaluate(branch, Direction.INCOMING);
Collection<Path> outgoing = collisionDetector.evaluate(branch, Direction.OUTGOING);
Collection<Path> alternativeIncoming = collisionDetector.evaluate(alternativeBranch, Direction.INCOMING);
Collection<Path> alternativeOutgoing = collisionDetector.evaluate(alternativeBranch, Direction.OUTGOING);
assertNull(incoming);
assertNull(outgoing);
assertNull(alternativeIncoming);
assertEquals(1, alternativeOutgoing.size());
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project neo4j by neo4j.
the class TraversalBranchImplTest method shouldExpandOnFirstAccess.
@SuppressWarnings("unchecked")
@Test
void shouldExpandOnFirstAccess() {
// GIVEN
TraversalBranch parent = mock(TraversalBranch.class);
Node source = mock(Node.class);
TraversalBranchImpl branch = new TraversalBranchImpl(parent, source);
@SuppressWarnings("rawtypes") PathExpander expander = mock(PathExpander.class);
when(expander.expand(eq(branch), any(BranchState.class))).thenReturn(Iterables.emptyResourceIterable());
TraversalContext context = mock(TraversalContext.class);
when(context.evaluate(eq(branch), isNull())).thenReturn(INCLUDE_AND_CONTINUE);
// WHEN initializing
branch.initialize(expander, context);
// THEN the branch should not be expanded
verifyNoInteractions(source);
// and WHEN actually traversing from it
branch.next(expander, context);
// THEN we should expand it
verify(expander).expand(any(Path.class), any(BranchState.class));
}
Aggregations