use of org.neo4j.graphdb.traversal.Evaluator in project neo4j by neo4j.
the class CircularGraphTest method testCircularBug.
@Test
public void testCircularBug() {
final long timestamp = 3;
try (Transaction tx = beginTx()) {
getNodeWithName("2").setProperty("timestamp", 1L);
getNodeWithName("3").setProperty("timestamp", 2L);
tx.success();
}
try (Transaction tx2 = beginTx()) {
final RelationshipType type = RelationshipType.withName("TO");
Iterator<Node> nodes = getGraphDb().traversalDescription().depthFirst().relationships(type, Direction.OUTGOING).evaluator(path -> {
Relationship rel = path.lastRelationship();
boolean relIsOfType = rel != null && rel.isType(type);
boolean prune = relIsOfType && (Long) path.endNode().getProperty("timestamp") >= timestamp;
return Evaluation.of(relIsOfType, !prune);
}).traverse(node("1")).nodes().iterator();
assertEquals("2", nodes.next().getProperty("name"));
assertEquals("3", nodes.next().getProperty("name"));
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.graphdb.traversal.Evaluator in project neo4j by neo4j.
the class TestMultiPruneEvaluators method testMaxDepthAndCustomPruneEvaluatorCombined.
@Test
public void testMaxDepthAndCustomPruneEvaluatorCombined() {
Evaluator lessThanThreeRels = new Evaluator() {
public Evaluation evaluate(Path path) {
return count(path.endNode().getRelationships(Direction.OUTGOING).iterator()) < 3 ? Evaluation.INCLUDE_AND_PRUNE : Evaluation.INCLUDE_AND_CONTINUE;
}
};
TraversalDescription description = getGraphDb().traversalDescription().evaluator(Evaluators.all()).evaluator(toDepth(1)).evaluator(lessThanThreeRels);
Set<String> expectedNodes = new HashSet<String>(asList("a", "b", "c", "d", "e"));
try (Transaction tx = beginTx()) {
for (Path position : description.traverse(node("a"))) {
String name = (String) position.endNode().getProperty("name");
assertTrue(name + " shouldn't have been returned", expectedNodes.remove(name));
}
tx.success();
}
assertTrue(expectedNodes.isEmpty());
}
Aggregations