This project has retired. For details please refer to its
Attic page.
TestKryoPageRank 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 TestKryoPageRank extends BspCase {
35
36
37
38
39 public TestKryoPageRank() {
40 super(TestPageRank.class.getName());
41 }
42
43 @Test
44 public void testKryoPageRank()
45 throws ClassNotFoundException, IOException, InterruptedException {
46 testPageRankWithKryoWrapper(1);
47 }
48
49 @Test
50 public void testKryoPageRankTenThreadsCompute()
51 throws ClassNotFoundException, IOException, InterruptedException {
52 testPageRankWithKryoWrapper(10);
53 }
54
55
56
57
58
59
60
61
62
63
64
65 private void testPageRankWithKryoWrapper(int numComputeThreads)
66 throws IOException, InterruptedException, ClassNotFoundException {
67 GiraphConfiguration conf = new GiraphConfiguration();
68 conf.setComputationClass(PageRankWithKryoSimpleWritable.class);
69 conf.setVertexInputFormatClass(
70 PageRankWithKryoSimpleWritable.PageRankWithKryoVertexInputFormat.class);
71 conf.setWorkerContextClass(
72 PageRankWithKryoSimpleWritable.PageRankWithKryoWorkerContext.class);
73 conf.setMasterComputeClass(
74 PageRankWithKryoSimpleWritable.PageRankWithKryoMasterCompute.class);
75 conf.setNumComputeThreads(numComputeThreads);
76
77 if (numComputeThreads != 1) {
78 GiraphConstants.USER_PARTITION_COUNT.set(conf, numComputeThreads * 5);
79 }
80 GiraphJob job = prepareJob(getCallingMethodName(), conf);
81 assertTrue(job.run(true));
82 if (!runningInDistributedMode()) {
83 double maxPageRank =
84 PageRankWithKryoSimpleWritable.PageRankWithKryoWorkerContext.getFinalMax();
85 double minPageRank =
86 PageRankWithKryoSimpleWritable.PageRankWithKryoWorkerContext.getFinalMin();
87 long numVertices =
88 PageRankWithKryoSimpleWritable.PageRankWithKryoWorkerContext.getFinalSum();
89 System.out.println(getCallingMethodName() + ": maxPageRank=" +
90 maxPageRank + " minPageRank=" +
91 minPageRank + " numVertices=" + numVertices + ", " +
92 " numComputeThreads=" + numComputeThreads);
93 assertEquals(34.03, maxPageRank, 0.001);
94 assertEquals(0.03, minPageRank, 0.00001);
95 assertEquals(5L, numVertices);
96 }
97 }
98 }