use of org.neo4j.graphdb.PathExpander in project neo4j by neo4j.
the class TestShortestPath method makeSureAMaxResultCountIsObeyed.
@Test
void makeSureAMaxResultCountIsObeyed() {
//
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c,d,e");
graph.makeEdgeChain(transaction, "a,f,g,h,e");
graph.makeEdgeChain(transaction, "f,i,j,e");
graph.makeEdgeChain(transaction, "i,k,e");
final Node a = graph.getNode(transaction, "a");
final Node e = graph.getNode(transaction, "e");
final PathExpander expander = forTypeAndDirection(R1, OUTGOING);
var context = new BasicEvaluationContext(transaction, graphDb);
testShortestPathFinder(context, finder -> assertEquals(4, count(finder.findAllPaths(a, e))), expander, 10, 10);
for (int i = 4; i >= 1; i--) {
final int count = i;
testShortestPathFinder(context, finder -> assertEquals(count, count(finder.findAllPaths(a, e))), expander, 10, count);
}
transaction.commit();
}
}
use of org.neo4j.graphdb.PathExpander in project neo4j by neo4j.
the class TestShortestPath method filtersTouchesAllIntermediateNodes.
@Test
void filtersTouchesAllIntermediateNodes() {
//
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c,d");
final Node a = graph.getNode(transaction, "a");
final Node d = graph.getNode(transaction, "d");
Collection<Node> touchedByFilter = new HashSet<>();
final Predicate<Node> filter = item -> {
touchedByFilter.add(item);
return true;
};
final PathExpander expander = PathExpanderBuilder.empty().add(R1, OUTGOING).addNodeFilter(filter).build();
// final PathExpander expander = ((StandardExpander) PathExpanders.forTypeAndDirection(R1, OUTGOING)).addNodeFilter( filter );
var context = new BasicEvaluationContext(transaction, graphDb);
Path path = Iterables.single(shortestPath(context, expander, 10).findAllPaths(a, d));
assertEquals(3, path.length());
List<Node> nodes = Iterables.asList(path.nodes());
List<Node> intermediateNodes = nodes.subList(1, nodes.size() - 1);
assertTrue(touchedByFilter.containsAll(intermediateNodes), "touchedByFilter: " + touchedByFilter);
assertFalse(touchedByFilter.contains(a));
assertFalse(touchedByFilter.contains(d));
transaction.commit();
}
}
use of org.neo4j.graphdb.PathExpander 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