@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
@Test @LoadGraphWith(GRATEFUL) public void shouldSupportWorkerCount() throws Exception { int maxWorkers = graphProvider.getGraphComputer(graph).features().getMaxWorkers(); if (maxWorkers != Integer.MAX_VALUE) { for (int i = maxWorkers + 1; i < maxWorkers + 10; i++) { try { graphProvider.getGraphComputer(graph).program(new VertexProgramL()).workers(i).submit().get(); fail("Should throw a GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported() exception"); } catch (final IllegalArgumentException e) { assertTrue(e.getMessage().contains("computer requires more workers")); } } } if (maxWorkers > 25) maxWorkers = 25; for (int i = 1; i <= maxWorkers; i++) { ComputerResult result = graphProvider.getGraphComputer(graph).program(new VertexProgramL()).workers(i).submit().get(); assertEquals(Integer.valueOf(i).longValue(), (long) result.memory().get("workerCount")); } }
this.resultGraphMode = GraphComputerHelper.getResultGraphState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.resultGraphMode)); if (!this.features().supportsResultGraphPersistCombination(this.resultGraphMode, this.persistMode)) throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraphMode, this.persistMode);
if (!this.features().supportsResultGraphPersistCombination(this.resultGraph, this.persist)) throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraph, this.persist); if (this.workers > this.features().getMaxWorkers()) throw GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported(this.workers, this.features().getMaxWorkers());
if (!this.features().supportsResultGraphPersistCombination(this.resultGraph, this.persist)) throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraph, this.persist); if (this.workers > this.features().getMaxWorkers()) throw GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported(this.workers, this.features().getMaxWorkers());
@Test @LoadGraphWith(MODERN) public void shouldDumpWholeGraph() throws Exception { if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.EDGES)) { final ComputerResult result = graphProvider.getGraphComputer(graph).program(CloneVertexProgram.build().create(graph)).submit().get(); result.graph().traversal().V().forEachRemaining(v -> {
@Test @LoadGraphWith(MODERN) public void shouldDumpWholeGraph() throws Exception { if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.EDGES)) { final ComputerResult result = graphProvider.getGraphComputer(graph).program(BulkDumperVertexProgram.build().create(graph)).submit().get(); result.graph().traversal().V().forEachRemaining(v -> {
public void shouldSupportGraphFilter() throws Exception { if (!graphProvider.getGraphComputer(graph).features().supportsGraphFilter()) { try { graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software"));
@Test @LoadGraphWith(MODERN) public void shouldExecutePageRankWithEpsilonBreak() 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.00001d).iterations(30).create(graph)).submit().get(); // by using epsilon 0.00001, we should get iterations 11
@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
@Test @LoadGraphWith(MODERN) public void shouldNotAllowBadGraphComputers() { try { graph.compute(BadGraphComputer.class); fail("Providing a bad graph computer class should fail"); } catch (Exception ex) { validateException(Graph.Exceptions.graphDoesNotSupportProvidedGraphComputer(BadGraphComputer.class), ex); } if (!new BadGraphComputer().features().supportsGraphFilter()) { try { new BadGraphComputer().vertices(__.hasLabel("software")); fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage()); } try { new BadGraphComputer().edges(__.bothE()); fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage()); } } else { fail("Should not support graph filter: " + BadGraphComputer.class); } }
@Test @LoadGraphWith(GRATEFUL) public void shouldSupportWorkerCount() throws Exception { int maxWorkers = graphProvider.getGraphComputer(graph).features().getMaxWorkers(); if (maxWorkers != Integer.MAX_VALUE) { for (int i = maxWorkers + 1; i < maxWorkers + 10; i++) { try { graphProvider.getGraphComputer(graph).program(new VertexProgramL()).workers(i).submit().get(); fail("Should throw a GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported() exception"); } catch (final IllegalArgumentException e) { assertTrue(e.getMessage().contains("computer requires more workers")); } } } if (maxWorkers > 25) maxWorkers = 25; for (int i = 1; i <= maxWorkers; i++) { ComputerResult result = graphProvider.getGraphComputer(graph).program(new VertexProgramL()).workers(i).submit().get(); assertEquals(Integer.valueOf(i).longValue(), (long) result.memory().get("workerCount")); } }
@Test @LoadGraphWith(MODERN) public void shouldProcessResultGraphOriginalWithPersistVertexProperties() throws Exception { final GraphComputer computer = graphProvider.getGraphComputer(graph); if (computer.features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.ORIGINAL, GraphComputer.Persist.VERTEX_PROPERTIES)) { final ComputerResult result = computer.program(new VertexProgramK()).result(GraphComputer.ResultGraph.ORIGINAL).persist(GraphComputer.Persist.VERTEX_PROPERTIES).submit().get(); assertEquals(Long.valueOf(6l), result.graph().traversal().V().count().next()); assertEquals(Long.valueOf(6l), result.graph().traversal().E().count().next()); assertEquals(Long.valueOf(18l), result.graph().traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), result.graph().traversal().E().values().count().next()); assertEquals(28l, result.graph().traversal().V().values("money").sum().next()); /// assertEquals(Long.valueOf(6l), graph.traversal().V().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().count().next()); assertEquals(Long.valueOf(18l), graph.traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().values().count().next()); assertEquals(28l, graph.traversal().V().values("money").sum().next()); } }
@Test @LoadGraphWith(MODERN) public void shouldProcessResultGraphNewWithPersistVertexProperties() throws Exception { final GraphComputer computer = graphProvider.getGraphComputer(graph); if (computer.features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) { final ComputerResult result = computer.program(new VertexProgramK()).result(GraphComputer.ResultGraph.NEW).persist(GraphComputer.Persist.VERTEX_PROPERTIES).submit().get(); assertEquals(Long.valueOf(6l), result.graph().traversal().V().count().next()); assertEquals(Long.valueOf(0l), result.graph().traversal().E().count().next()); assertEquals(Long.valueOf(18l), result.graph().traversal().V().values().count().next()); assertEquals(Long.valueOf(0l), result.graph().traversal().E().values().count().next()); assertEquals(28l, result.graph().traversal().V().values("money").sum().next()); /// assertEquals(Long.valueOf(6l), graph.traversal().V().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().count().next()); assertEquals(Long.valueOf(12l), graph.traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().values().count().next()); assertFalse(graph.traversal().V().values("money").sum().hasNext()); } }
@Test @LoadGraphWith(MODERN) public void shouldProcessResultGraphNewWithPersistNothing() throws Exception { final GraphComputer computer = graphProvider.getGraphComputer(graph); if (computer.features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.NOTHING)) { final ComputerResult result = computer.program(new VertexProgramK()).result(GraphComputer.ResultGraph.NEW).persist(GraphComputer.Persist.NOTHING).submit().get(); assertEquals(Long.valueOf(0l), result.graph().traversal().V().count().next()); assertEquals(Long.valueOf(0l), result.graph().traversal().E().count().next()); assertEquals(Long.valueOf(0l), result.graph().traversal().V().values().count().next()); assertEquals(Long.valueOf(0l), result.graph().traversal().E().values().count().next()); assertFalse(result.graph().traversal().V().values("money").sum().hasNext()); /// assertEquals(Long.valueOf(6l), graph.traversal().V().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().count().next()); assertEquals(Long.valueOf(12l), graph.traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().values().count().next()); assertFalse(graph.traversal().V().values("money").sum().hasNext()); } }
@Test @LoadGraphWith(MODERN) public void shouldProcessResultGraphOriginalWithPersistEdges() throws Exception { final GraphComputer computer = graphProvider.getGraphComputer(graph); if (computer.features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.ORIGINAL, GraphComputer.Persist.EDGES)) { final ComputerResult result = computer.program(new VertexProgramK()).result(GraphComputer.ResultGraph.ORIGINAL).persist(GraphComputer.Persist.EDGES).submit().get(); assertEquals(Long.valueOf(6l), result.graph().traversal().V().count().next()); assertEquals(Long.valueOf(6l), result.graph().traversal().E().count().next()); assertEquals(Long.valueOf(18l), result.graph().traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), result.graph().traversal().E().values().count().next()); assertEquals(28l, result.graph().traversal().V().values("money").sum().next()); /// assertEquals(Long.valueOf(6l), graph.traversal().V().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().count().next()); assertEquals(Long.valueOf(18l), graph.traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().values().count().next()); assertEquals(28l, graph.traversal().V().values("money").sum().next()); } }
@Test @LoadGraphWith(MODERN) public void shouldProcessResultGraphOriginalWithPersistNothing() throws Exception { final GraphComputer computer = graphProvider.getGraphComputer(graph); if (computer.features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.ORIGINAL, GraphComputer.Persist.NOTHING)) { final ComputerResult result = computer.program(new VertexProgramK()).result(GraphComputer.ResultGraph.ORIGINAL).persist(GraphComputer.Persist.NOTHING).submit().get(); assertEquals(Long.valueOf(6l), result.graph().traversal().V().count().next()); assertEquals(Long.valueOf(6l), result.graph().traversal().E().count().next()); assertEquals(Long.valueOf(12l), result.graph().traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), result.graph().traversal().E().values().count().next()); assertFalse(result.graph().traversal().V().values("money").sum().hasNext()); /// assertEquals(Long.valueOf(6l), graph.traversal().V().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().count().next()); assertEquals(Long.valueOf(12l), graph.traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().values().count().next()); assertFalse(graph.traversal().V().values("money").sum().hasNext()); } }
@Test @LoadGraphWith(MODERN) public void shouldProcessResultGraphNewWithPersistEdges() throws Exception { final GraphComputer computer = graphProvider.getGraphComputer(graph); if (computer.features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.EDGES)) { final ComputerResult result = computer.program(new VertexProgramK()).result(GraphComputer.ResultGraph.NEW).persist(GraphComputer.Persist.EDGES).submit().get(); assertEquals(Long.valueOf(6l), result.graph().traversal().V().count().next()); assertEquals(Long.valueOf(6l), result.graph().traversal().E().count().next()); assertEquals(Long.valueOf(18l), result.graph().traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), result.graph().traversal().E().values().count().next()); assertEquals(28l, result.graph().traversal().V().values("money").sum().next()); /// assertEquals(Long.valueOf(6l), graph.traversal().V().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().count().next()); assertEquals(Long.valueOf(12l), graph.traversal().V().values().count().next()); assertEquals(Long.valueOf(6l), graph.traversal().E().values().count().next()); assertFalse(graph.traversal().V().values("money").sum().hasNext()); } }
@Test @LoadGraphWith public void shouldSupportPersistResultGraphPairsStatedInFeatures() throws Exception { for (final GraphComputer.ResultGraph resultGraph : GraphComputer.ResultGraph.values()) { for (final GraphComputer.Persist persist : GraphComputer.Persist.values()) { final GraphComputer computer = graphProvider.getGraphComputer(graph); if (computer.features().supportsResultGraphPersistCombination(resultGraph, persist)) { computer.program(new VertexProgramK()).result(resultGraph).persist(persist).submit().get(); } else { try { computer.program(new VertexProgramK()).result(resultGraph).persist(persist).submit().get(); fail("The GraphComputer " + computer + " states that it does support the following resultGraph/persist pair: " + resultGraph + ":" + persist); } catch (final IllegalArgumentException e) { assertEquals(GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(resultGraph, persist).getMessage(), e.getMessage()); } } } } }
if (!this.features().supportsResultGraphPersistCombination(this.resultGraph, this.persist)) throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraph, this.persist); if (this.workers > this.features().getMaxWorkers()) throw GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported(this.workers, this.features().getMaxWorkers());