@Test
    @LoadGraphWith(MODERN)
    public void shouldExecutePageRankWithIterationsBreak() throws Exception {
        if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) {
            final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).
                    program(PageRankVertexProgram.build().epsilon(0.0d).iterations(30).create(graph)).submit().get(); // by using epsilon 0.0, we guarantee iterations 30
            result.graph().traversal().V().forEachRemaining(v -> {
                assertEquals(3, v.keys().size()); // name, age/lang, pageRank
                assertTrue(v.keys().contains("name"));
                assertTrue(v.keys().contains(PageRankVertexProgram.PAGE_RANK));
                assertEquals(1, IteratorUtils.count(v.values("name")));
                assertEquals(1, IteratorUtils.count(v.values(PageRankVertexProgram.PAGE_RANK)));
                final String name = v.value("name");
                final Double pageRank = v.value(PageRankVertexProgram.PAGE_RANK);
                //System.out.println(name + "-----" + pageRank);
                if (name.equals("marko"))
                    assertTrue(pageRank > 0.10 && pageRank < 0.12);
                else if (name.equals("vadas"))
                    assertTrue(pageRank > 0.13 && pageRank < 0.15);
                else if (name.equals("lop"))
                    assertTrue(pageRank > 0.29 && pageRank < 0.31);
                else if (name.equals("josh"))
                    assertTrue(pageRank > 0.13 && pageRank < 0.15);
                else if (name.equals("ripple"))
                    assertTrue(pageRank > 0.16 && pageRank < 0.18);
                else if (name.equals("peter"))
                    assertTrue(pageRank > 0.10 && pageRank < 0.12);
                else
                    throw new IllegalStateException("The following vertex should not exist in the graph: " + name);
            });
            assertEquals(result.memory().getIteration(), 30);
            assertEquals(result.memory().asMap().size(), 0);
        }
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java