@Test public void degreeCounting() throws Exception { int numV = 200; int numE = generateRandomGraph(numV); clopen(); final TitanGraphComputer computer = graph.compute(); computer.resultMode(TitanGraphComputer.ResultMode.NONE); computer.workers(4); computer.program(new DegreeCounter()); computer.mapReduce(new DegreeMapper()); ComputerResult result = computer.submit().get(); System.out.println("Execution time (ms) ["+numV+"|"+numE+"]: " + result.memory().getRuntime()); assertTrue(result.memory().exists(DegreeMapper.DEGREE_RESULT)); Map<Long,Integer> degrees = result.memory().get(DegreeMapper.DEGREE_RESULT); assertNotNull(degrees); assertEquals(numV,degrees.size()); int totalCount = 0; for (Map.Entry<Long,Integer> entry : degrees.entrySet()) { int degree = entry.getValue(); TitanVertex v = getV(tx, entry.getKey().longValue()); int count = v.value("uid"); assertEquals(count,degree); totalCount+= degree; } assertEquals(numV*(numV+1)/2,totalCount); assertEquals(1,result.memory().getIteration()); }
@Test public void degreeCounting() throws Exception { int numV = 200; int numE = generateRandomGraph(numV); clopen(); final JanusGraphComputer computer = graph.compute(); computer.resultMode(JanusGraphComputer.ResultMode.NONE); computer.workers(4); computer.program(new DegreeCounter()); computer.mapReduce(new DegreeMapper()); ComputerResult result = computer.submit().get(); System.out.println("Execution time (ms) ["+numV+"|"+numE+"]: " + result.memory().getRuntime()); assertTrue(result.memory().exists(DegreeMapper.DEGREE_RESULT)); Map<Long,Integer> degrees = result.memory().get(DegreeMapper.DEGREE_RESULT); assertNotNull(degrees); assertEquals(numV,degrees.size()); int totalCount = 0; for (Map.Entry<Long,Integer> entry : degrees.entrySet()) { int degree = entry.getValue(); final JanusGraphVertex v = getV(tx, entry.getKey()); int count = v.value("uid"); assertEquals(count,degree); totalCount+= degree; } assertEquals(numV*(numV+1)/2,totalCount); assertEquals(1,result.memory().getIteration()); }
ComputerResult result = computer.submit().get(); Iterator<KeyValue<Long, Double>> ranks = result.memory().get(PageRankMapReduce.DEFAULT_MEMORY_KEY); assertNotNull(ranks); int vertexCounter = 0;
ComputerResult result = computer.submit().get(); Iterator<KeyValue<Long, Double>> ranks = result.memory().get(PageRankMapReduce.DEFAULT_MEMORY_KEY); assertNotNull(ranks); int vertexCounter = 0;
result.memory().get(ShortestDistanceMapReduce.DEFAULT_MEMORY_KEY);
result.memory().get(ShortestDistanceMapReduce.DEFAULT_MEMORY_KEY);
@Test @LoadGraphWith(MODERN) public void shouldSupportBroadcastKeys() throws Exception { final ComputerResult result = graphProvider.getGraphComputer(graph).program(new VertexProgramP()).submit().get(); assertTrue(result.memory().exists("m1")); assertFalse(result.memory().exists("m2")); assertFalse(result.memory().exists("m3")); assertTrue(result.memory().exists("m4")); assertTrue(result.memory().get("m1")); assertEquals(-18, result.memory().<Integer>get("m4").intValue()); assertEquals(2, result.memory().keys().size()); }
@Test @LoadGraphWith(MODERN) public void shouldFindAllShortestPathsWithDefaultParameters() throws Exception { final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()). program(ShortestPathVertexProgram.build().create(graph)).submit().get(); assertTrue(result.memory().exists(ShortestPathVertexProgram.SHORTEST_PATHS)); final List<Path> shortestPaths = result.memory().get(ShortestPathVertexProgram.SHORTEST_PATHS); final List<Path> expected = Arrays.stream(ALL_SHORTEST_PATHS).map(helper::makePath).collect(Collectors.toList()); helper.checkResults(expected, shortestPaths); }
@Test @LoadGraphWith(MODERN) public void shouldFindShortestPathsWithStartVertexFilter() throws Exception { final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()). program(ShortestPathVertexProgram.build().source(__.has("name", "marko")).create(graph)).submit().get(); assertTrue(result.memory().exists(ShortestPathVertexProgram.SHORTEST_PATHS)); final List<Path> shortestPaths = result.memory().get(ShortestPathVertexProgram.SHORTEST_PATHS); final List<Path> expected = Arrays.stream(ALL_SHORTEST_PATHS) .filter(p -> p[0].equals("marko")).map(helper::makePath).collect(Collectors.toList()); helper.checkResults(expected, shortestPaths); }
@Test @LoadGraphWith(MODERN) public void shouldFindShortestPathsWithEndVertexFilter() throws Exception { final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()). program(ShortestPathVertexProgram.build().target(__.has("name", "marko")).create(graph)).submit().get(); assertTrue(result.memory().exists(ShortestPathVertexProgram.SHORTEST_PATHS)); final List<Path> shortestPaths = result.memory().get(ShortestPathVertexProgram.SHORTEST_PATHS); final List<Path> expected = Arrays.stream(ALL_SHORTEST_PATHS) .filter(p -> p[p.length - 1].equals("marko")).map(helper::makePath).collect(Collectors.toList()); helper.checkResults(expected, shortestPaths); }
@Test @LoadGraphWith(MODERN) public void shouldSortMapOutput() throws Exception { final ComputerResult results = graphProvider.getGraphComputer(graph).mapReduce(new MapReduceBB()).submit().get(); final List<Integer> nameLengths = results.memory().get("nameLengths"); assertEquals(6, nameLengths.size()); for (int i = 1; i < nameLengths.size(); i++) { assertTrue(nameLengths.get(i) <= nameLengths.get(i - 1)); } }
@Test @LoadGraphWith(MODERN) public void shouldRespectMaxDistance() throws Exception { final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()). program(ShortestPathVertexProgram.build() .source(__.has("name", "marko")) .maxDistance(1).create(graph)).submit().get(); assertTrue(result.memory().exists(ShortestPathVertexProgram.SHORTEST_PATHS)); final List<Path> shortestPaths = result.memory().get(ShortestPathVertexProgram.SHORTEST_PATHS); final List<Path> expected = Arrays.stream(ALL_SHORTEST_PATHS) .filter(p -> p[0].equals("marko") && p.length <= 2).map(helper::makePath).collect(Collectors.toList()); helper.checkResults(expected, shortestPaths); }
@Test @LoadGraphWith(MODERN) public void shouldSortReduceOutput() throws Exception { final ComputerResult results = graphProvider.getGraphComputer(graph).mapReduce(new MapReduceB()).submit().get(); final List<Integer> nameLengths = results.memory().get("nameLengths"); assertEquals(6, nameLengths.size()); for (int i = 1; i < nameLengths.size(); i++) { assertTrue(nameLengths.get(i) <= nameLengths.get(i - 1)); } }
@Test @LoadGraphWith(MODERN) public void shouldFindAllShortestPathsWithEdgesIncluded() throws Exception { final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()). program(ShortestPathVertexProgram.build().includeEdges(true).create(graph)).submit().get(); assertTrue(result.memory().exists(ShortestPathVertexProgram.SHORTEST_PATHS)); final List<Path> shortestPaths = result.memory().get(ShortestPathVertexProgram.SHORTEST_PATHS); final List<Path> expected = Arrays.stream(ALL_SHORTEST_PATHS).map(p -> helper.makePath(true, p)) .collect(Collectors.toList()); helper.checkResults(expected, shortestPaths); }
@Test @LoadGraphWith(MODERN) public void shouldSupportMultipleMapReduceJobs() throws Exception { final ComputerResult results = graphProvider.getGraphComputer(graph) .program(new VertexProgramH()) .mapReduce(new MapReduceH1()) .mapReduce(new MapReduceH2()).submit().get(); assertEquals(60, results.memory().<Integer>get("a").intValue()); assertEquals(1, results.memory().<Integer>get("b").intValue()); }
@Test @LoadGraphWith(MODERN) public void shouldAllowMapReduceWithNoVertexProgram() throws Exception { final ComputerResult results = graphProvider.getGraphComputer(graph).mapReduce(new MapReduceA()).submit().get(); assertEquals(123, results.memory().<Integer>get("ageSum").intValue()); }