This project has retired. For details please refer to its
Attic page.
TestPageRank xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.giraph.examples;
19
20 import org.apache.giraph.BspCase;
21 import org.apache.giraph.conf.GiraphConfiguration;
22 import org.apache.giraph.conf.GiraphConstants;
23 import org.apache.giraph.job.GiraphJob;
24 import org.junit.Test;
25
26 import java.io.IOException;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertTrue;
30
31
32
33
34 public class TestPageRank extends BspCase {
35
36
37
38
39 public TestPageRank() {
40 super(TestPageRank.class.getName());
41 }
42
43 @Test
44 public void testBspPageRankSingleCompute()
45 throws ClassNotFoundException, IOException, InterruptedException {
46 testPageRank(1);
47 }
48
49
50 @Test
51 public void testPageRankTenThreadsCompute()
52 throws ClassNotFoundException, IOException, InterruptedException {
53 testPageRank(10);
54 }
55
56
57
58
59
60
61
62
63
64 private void testPageRank(int numComputeThreads)
65 throws IOException, InterruptedException, ClassNotFoundException {
66 GiraphConfiguration conf = new GiraphConfiguration();
67 conf.setComputationClass(SimplePageRankComputation.class);
68 conf.setVertexInputFormatClass(
69 SimplePageRankComputation.SimplePageRankVertexInputFormat.class);
70 conf.setWorkerContextClass(
71 SimplePageRankComputation.SimplePageRankWorkerContext.class);
72 conf.setMasterComputeClass(
73 SimplePageRankComputation.SimplePageRankMasterCompute.class);
74 conf.setNumComputeThreads(numComputeThreads);
75
76 if (numComputeThreads != 1) {
77 GiraphConstants.USER_PARTITION_COUNT.set(conf, numComputeThreads * 5);
78 }
79 GiraphJob job = prepareJob(getCallingMethodName(), conf);
80 assertTrue(job.run(true));
81 if (!runningInDistributedMode()) {
82 double maxPageRank =
83 SimplePageRankComputation.SimplePageRankWorkerContext.getFinalMax();
84 double minPageRank =
85 SimplePageRankComputation.SimplePageRankWorkerContext.getFinalMin();
86 long numVertices =
87 SimplePageRankComputation.SimplePageRankWorkerContext.getFinalSum();
88 System.out.println(getCallingMethodName() + ": maxPageRank=" +
89 maxPageRank + " minPageRank=" +
90 minPageRank + " numVertices=" + numVertices + ", " +
91 " numComputeThreads=" + numComputeThreads);
92 assertEquals(34.03, maxPageRank, 0.001);
93 assertEquals(0.03, minPageRank, 0.00001);
94 assertEquals(5L, numVertices);
95 }
96 }
97 }