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;
2021import org.apache.giraph.conf.GiraphConfiguration;
22import org.apache.giraph.counters.GiraphHadoopCounter;
23import org.apache.giraph.counters.GiraphStats;
24import org.apache.giraph.examples.SimplePageRankComputation.SimplePageRankVertexInputFormat;
25import org.apache.giraph.examples.SimplePageRankComputation.SimplePageRankVertexOutputFormat;
262728import org.apache.giraph.graph.BasicComputation;
29import org.apache.giraph.graph.Vertex;
30import org.apache.giraph.job.GiraphJob;
31import org.apache.hadoop.io.DoubleWritable;
32import org.apache.hadoop.io.FloatWritable;
33import org.apache.hadoop.io.LongWritable;
34import org.junit.Test;
3536import java.io.IOException;
3738importstatic org.junit.Assert.assertEquals;
39importstatic org.junit.Assert.assertTrue;
4041/**42 * Unit test for testing max superstep feature of Giraph43 */44publicclassTestMaxSuperstepextendsBspCase {
45publicTestMaxSuperstep() {
46super(TestMaxSuperstep.class.getName());
47 }
4849/**50 * Simple test vertex class that will run forever (voteToHalt is never51 * called).52 */53publicstaticclassInfiniteLoopComputationextends BasicComputation<
54 LongWritable, DoubleWritable, FloatWritable, DoubleWritable> {
55 @Override
56publicvoid compute(
57 Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
58 Iterable<DoubleWritable> messages) throws IOException {
59 }
60 }
6162/**63 * Run a job that tests that this job completes in the desired number of64 * supersteps65 *66 * @throws java.io.IOException67 * @throws ClassNotFoundException68 * @throws InterruptedException69 */70 @Test
71publicvoid testMaxSuperstep()
72throws IOException, InterruptedException, ClassNotFoundException {
73 GiraphConfiguration conf = new GiraphConfiguration();
74 conf.setComputationClass(InfiniteLoopComputation.class);
75 conf.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
76 conf.setVertexOutputFormatClass(SimplePageRankVertexOutputFormat.class);
77 GiraphJob job = prepareJob(getCallingMethodName(), conf,
78 getTempPath(getCallingMethodName()));
79 job.getConfiguration().setMaxNumberOfSupersteps(3);
80 assertTrue(job.run(true));
81if (!runningInDistributedMode()) {
82 GiraphHadoopCounter superstepCounter =
83 GiraphStats.getInstance().getSuperstepCounter();
84 assertEquals(superstepCounter.getValue(), 3L);
85 }
86 }
87 }