1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.examples;
2021import org.apache.giraph.combiner.DoubleSumMessageCombiner;
22import org.apache.giraph.conf.GiraphConfiguration;
23import org.apache.giraph.edge.LongNullArrayEdges;
24import org.apache.giraph.utils.InternalVertexRunner;
25import org.junit.Test;
2627import java.util.Map;
2829importstatic org.junit.Assert.assertEquals;
303132/**33 * Tests for {@link PageRankComputation}34 */35publicclassPageRankComputationTest {
3637/**38 * A local integration test on toy data39 */40 @Test
41publicvoid testToyData() throws Exception {
4243// A small graph44 String[] graph = new String[] {
45"1 4 2 3",
46"2 1",
47"4 3 2",
48"5 2 4"49 };
5051 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// Run internally64 Iterable<String> results = InternalVertexRunner.run(conf, graph);
6566 Map<Long, Double> steadyStateProbabilities =
67 RandomWalkTestUtils.parseSteadyStateProbabilities(results);
6869 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 }
8081 }