1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
43
44 public class TestMaxSuperstep extends BspCase {
45 public TestMaxSuperstep() {
46 super(TestMaxSuperstep.class.getName());
47 }
48
49
50
51
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
64
65
66
67
68
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 }