1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.examples;
20
21 import org.apache.giraph.edge.EdgeFactory;
22 import org.apache.giraph.graph.DefaultVertex;
23 import org.apache.giraph.graph.Vertex;
24 import org.apache.giraph.utils.MockUtils;
25 import org.apache.hadoop.io.IntWritable;
26 import org.apache.hadoop.io.NullWritable;
27 import org.junit.Test;
28
29 import com.google.common.collect.Lists;
30
31 import static org.apache.giraph.examples.SimpleTriangleClosingComputation.IntArrayListWritable;
32 import static org.junit.Assert.assertEquals;
33
34
35
36
37 public class SimpleTriangleClosingComputationTest {
38
39
40
41
42
43 @Test
44 public void testSuperstepZero() throws Exception {
45
46 Vertex<IntWritable, IntArrayListWritable, NullWritable> vertex =
47 new DefaultVertex<IntWritable, IntArrayListWritable, NullWritable>();
48
49 IntArrayListWritable alw = new IntArrayListWritable();
50
51 SimpleTriangleClosingComputation computation =
52 new SimpleTriangleClosingComputation();
53 MockUtils.MockedEnvironment env = MockUtils.prepareVertexAndComputation(
54 vertex, new IntWritable(1), alw, false, computation, 0L);
55
56 vertex.addEdge(EdgeFactory.create(new IntWritable(5)));
57 vertex.addEdge(EdgeFactory.create(new IntWritable(7)));
58
59 computation.compute(vertex, Lists.<IntWritable>newArrayList(
60 new IntWritable(83), new IntWritable(42)));
61
62 env.verifyMessageSentToAllEdges(vertex, new IntWritable(5));
63 env.verifyMessageSentToAllEdges(vertex, new IntWritable(7));
64 }
65
66
67 @Test
68 public void testSuperstepOne() throws Exception {
69
70
71 Vertex<IntWritable, IntArrayListWritable, NullWritable> vertex =
72 new DefaultVertex<IntWritable, IntArrayListWritable, NullWritable>();
73 SimpleTriangleClosingComputation computation =
74 new SimpleTriangleClosingComputation();
75 MockUtils.MockedEnvironment env = MockUtils.prepareVertexAndComputation(
76 vertex, new IntWritable(1), null, false, computation, 1L);
77
78
79 computation.compute(vertex, Lists.<IntWritable>newArrayList(
80 new IntWritable(7),
81 new IntWritable(3),
82 new IntWritable(4),
83 new IntWritable(7),
84 new IntWritable(4),
85 new IntWritable(2),
86 new IntWritable(4)));
87 final String pairCheck = "[4, 7]";
88 assertEquals(pairCheck, vertex.getValue().toString());
89 }
90 }