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 */18package org.apache.giraph.examples;
1920import org.apache.giraph.conf.GiraphConfiguration;
21import org.apache.giraph.io.formats.IdWithValueTextOutputFormat;
22import org.apache.giraph.io.formats.IntIntNullTextInputFormat;
23import org.apache.giraph.utils.InternalVertexRunner;
24import org.junit.Test;
2526import com.google.common.collect.Maps;
2728import java.util.Map;
2930importstatic org.junit.Assert.assertEquals;
3132/**33 * Test for max computation34 */35publicclassMaxComputationTest {
36 @Test
37publicvoid testMax() throws Exception {
38 String[] graph = {
39"5 1",
40"1 5 2",
41"2 5",
42 };
4344 GiraphConfiguration conf = new GiraphConfiguration();
45 conf.setComputationClass(MaxComputation.class);
46 conf.setVertexInputFormatClass(IntIntNullTextInputFormat.class);
47 conf.setVertexOutputFormatClass(IdWithValueTextOutputFormat.class);
48 Iterable<String> results = InternalVertexRunner.run(conf, graph);
4950 Map<Integer, Integer> values = parseResults(results);
51 assertEquals(3, values.size());
52 assertEquals(5, (int) values.get(1));
53 assertEquals(5, (int) values.get(2));
54 assertEquals(5, (int) values.get(5));
55 }
5657privatestatic Map<Integer, Integer> parseResults(Iterable<String> results) {
58 Map<Integer, Integer> values = Maps.newHashMap();
59for (String line : results) {
60 String[] tokens = line.split("\\s+");
61int id = Integer.valueOf(tokens[0]);
62int value = Integer.valueOf(tokens[1]);
63 values.put(id, value);
64 }
65return values;
66 }
67 }