This project has retired. For details please refer to its Attic page.
TestMaxSuperstep xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * 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 and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph;
20  
21  import org.apache.giraph.conf.GiraphConfiguration;
22  import org.apache.giraph.counters.GiraphHadoopCounter;
23  import org.apache.giraph.counters.GiraphStats;
24  import org.apache.giraph.examples.SimplePageRankComputation.SimplePageRankVertexInputFormat;
25  import org.apache.giraph.examples.SimplePageRankComputation.SimplePageRankVertexOutputFormat;
26  
27  
28  import org.apache.giraph.graph.BasicComputation;
29  import org.apache.giraph.graph.Vertex;
30  import org.apache.giraph.job.GiraphJob;
31  import org.apache.hadoop.io.DoubleWritable;
32  import org.apache.hadoop.io.FloatWritable;
33  import org.apache.hadoop.io.LongWritable;
34  import org.junit.Test;
35  
36  import java.io.IOException;
37  
38  import static org.junit.Assert.assertEquals;
39  import static org.junit.Assert.assertTrue;
40  
41  /**
42   * Unit test for testing max superstep feature of Giraph
43   */
44  public class TestMaxSuperstep extends BspCase {
45    public TestMaxSuperstep() {
46        super(TestMaxSuperstep.class.getName());
47    }
48  
49    /**
50     * Simple test vertex class that will run forever (voteToHalt is never
51     * called).
52     */
53    public static class InfiniteLoopComputation extends BasicComputation<
54        LongWritable, DoubleWritable, FloatWritable, DoubleWritable> {
55      @Override
56      public void compute(
57          Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
58          Iterable<DoubleWritable> messages) throws IOException {
59      }
60    }
61  
62    /**
63     * Run a job that tests that this job completes in the desired number of
64     * supersteps
65     *
66     * @throws java.io.IOException
67     * @throws ClassNotFoundException
68     * @throws InterruptedException
69     */
70    @Test
71    public void testMaxSuperstep()
72            throws 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));
81      if (!runningInDistributedMode()) {
82        GiraphHadoopCounter superstepCounter =
83            GiraphStats.getInstance().getSuperstepCounter();
84        assertEquals(superstepCounter.getValue(), 3L);
85      }
86    }
87  }