1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.examples;
20
21 import org.apache.giraph.combiner.DoubleSumMessageCombiner;
22 import org.apache.giraph.conf.GiraphConfiguration;
23 import org.apache.giraph.edge.LongNullArrayEdges;
24 import org.apache.giraph.utils.InternalVertexRunner;
25 import org.junit.Test;
26
27 import java.util.Map;
28
29 import static org.junit.Assert.assertEquals;
30
31
32
33
34
35 public class PageRankComputationTest {
36
37
38
39
40 @Test
41 public void testToyData() throws Exception {
42
43
44 String[] graph = new String[] {
45 "1 4 2 3",
46 "2 1",
47 "4 3 2",
48 "5 2 4"
49 };
50
51 GiraphConfiguration conf = new GiraphConfiguration();
52 conf.setInt(RandomWalkWithRestartComputation.MAX_SUPERSTEPS, 50);
53 conf.setFloat(
54 RandomWalkWithRestartComputation.TELEPORTATION_PROBABILITY, 0.15f);
55 conf.setComputationClass(PageRankComputation.class);
56 conf.setMessageCombinerClass(DoubleSumMessageCombiner.class);
57 conf.setOutEdgesClass(LongNullArrayEdges.class);
58 conf.setVertexInputFormatClass(LongDoubleNullTextInputFormat.class);
59 conf.setVertexOutputFormatClass(
60 VertexWithDoubleValueNullEdgeTextOutputFormat.class);
61 conf.setWorkerContextClass(RandomWalkWorkerContext.class);
62 conf.setMasterComputeClass(RandomWalkVertexMasterCompute.class);
63
64 Iterable<String> results = InternalVertexRunner.run(conf, graph);
65
66 Map<Long, Double> steadyStateProbabilities =
67 RandomWalkTestUtils.parseSteadyStateProbabilities(results);
68
69 assertEquals(0.28159076008518047, steadyStateProbabilities.get(1l),
70 RandomWalkTestUtils.EPSILON);
71 assertEquals(0.2514648601529863, steadyStateProbabilities.get(2l),
72 RandomWalkTestUtils.EPSILON);
73 assertEquals(0.22262961972286327, steadyStateProbabilities.get(3l),
74 RandomWalkTestUtils.EPSILON);
75 assertEquals(0.17646783276703806, steadyStateProbabilities.get(4l),
76 RandomWalkTestUtils.EPSILON);
77 assertEquals(0.06784692727193153, steadyStateProbabilities.get(5l),
78 RandomWalkTestUtils.EPSILON);
79 }
80
81 }