This project has retired. For details please refer to its
Attic page.
BrachaTouegDeadlockComputationTest xref
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 static org.apache.giraph.examples.BrachaTouegDeadlockComputation.BRACHA_TOUEG_DL_INITIATOR_ID;
22
23 import java.util.Iterator;
24
25 import org.apache.giraph.conf.GiraphConfiguration;
26 import org.apache.giraph.examples.io.formats.BrachaTouegDeadlockInputFormat;
27 import org.apache.giraph.io.formats.IdWithValueTextOutputFormat;
28 import org.apache.giraph.utils.InternalVertexRunner;
29 import org.junit.Before;
30 import org.junit.Ignore;
31 import org.junit.Test;
32
33
34
35
36 public class BrachaTouegDeadlockComputationTest {
37
38 GiraphConfiguration conf = new GiraphConfiguration();
39
40 @Before
41 public void prepareConf() {
42 this.conf.setComputationClass(BrachaTouegDeadlockComputation.class);
43 this.conf.setVertexInputFormatClass(BrachaTouegDeadlockInputFormat.class);
44 this.conf.setVertexOutputFormatClass(IdWithValueTextOutputFormat.class);
45 }
46
47 @Test
48 public void testEmptyGraph() throws Exception {
49 Iterable<String> results;
50 Iterator<String> result;
51 String[] graph = {};
52
53 results = InternalVertexRunner.run(this.conf, graph);
54 assert results != null;
55
56 result = results.iterator();
57 assert !result.hasNext();
58 }
59
60 @Test
61 public void testOneInitNodeGraph() throws Exception {
62 Iterable<String> results;
63 String[] graph = { "[1,[]]" };
64 String[] expected = { "1\tisFree=true" };
65
66 results = InternalVertexRunner.run(this.conf, graph);
67 checkResults(results, expected);
68 }
69
70 @Test
71 public void testOneNotInitNodeGraph() throws Exception {
72 Iterable<String> results;
73 String[] graph = { "[0,[]]" };
74 String[] expected = { "0\tisFree=false" };
75
76 results = InternalVertexRunner.run(this.conf, graph);
77 checkResults(results, expected);
78 }
79
80 @Test
81 public void testThreeNodesAllNodesFreeGraph() throws Exception {
82 Iterable<String> results;
83 String[] graph = {
84 "[1,[]]",
85 "[2,[[1,0]]]",
86 "[3,[[1,0]]]"
87 };
88 String[] expected = {
89 "1\tisFree=true",
90 "2\tisFree=false",
91 "3\tisFree=false"
92 };
93
94 results = InternalVertexRunner.run(this.conf, graph);
95 checkResults(results, expected);
96 }
97
98 @Test
99 public void testThreeNodesAllNodesBlockedGraph() throws Exception {
100 Iterable<String> results;
101 String[] graph = {
102 "[1,[[2,0]]]",
103 "[2,[[3,0]]]",
104 "[3,[[1,0]]]"
105 };
106 String[] expected = {
107 "1\tisFree=false",
108 "2\tisFree=false",
109 "3\tisFree=false"
110 };
111
112 results = InternalVertexRunner.run(this.conf, graph);
113 checkResults(results, expected);
114 }
115
116 @Test
117 public void testThreeNodesAllNodesFreeMultiEdgesGraph() throws Exception {
118 Iterable<String> results;
119 String[] graph = {
120 "[1,[[2,0],[3,1]]]",
121 "[2,[]]",
122 "[3,[]]"
123 };
124 String[] expected = {
125 "1\tisFree=true",
126 "2\tisFree=true",
127 "3\tisFree=true"
128 };
129
130 results = InternalVertexRunner.run(this.conf, graph);
131 checkResults(results, expected);
132 }
133
134 @Test
135 public void testThreeNodesAllNodesFreeNOutOfMGraph() throws Exception {
136 Iterable<String> results;
137 String[] graph = {
138 "[1,[[2,0],[3,0]]]",
139 "[2,[]]",
140 "[3,[]]"
141 };
142 String[] expected = {
143 "1\tisFree=true",
144 "2\tisFree=true",
145 "3\tisFree=true"
146 };
147
148 results = InternalVertexRunner.run(this.conf, graph);
149 checkResults(results, expected);
150 }
151
152 @Test
153 public void testThreeNodesInitNodeFreeNOutOfMGraph() throws Exception {
154 Iterable<String> results;
155 String[] graph = {
156 "[1,[[2,0],[3,0]]]",
157 "[2,[]]",
158 "[3,[]]"
159 };
160 String[] expected = {
161 "1\tisFree=false",
162 "2\tisFree=true",
163 "3\tisFree=false"
164 };
165
166 BRACHA_TOUEG_DL_INITIATOR_ID.set(this.conf, 2);
167 results = InternalVertexRunner.run(this.conf, graph);
168 checkResults(results, expected);
169 BRACHA_TOUEG_DL_INITIATOR_ID.set(this.conf, 1);
170 }
171
172 @Test
173 public void testThreeNodesAllNodesBlockedNOutOfMGraph() throws Exception {
174 Iterable<String> results;
175 String[] graph = {
176 "[1,[[2,0],[3,0]]]",
177 "[2,[[3,0]]]",
178 "[3,[[2,0]]]"
179 };
180 String[] expected = {
181 "1\tisFree=false",
182 "2\tisFree=false",
183 "3\tisFree=false"
184 };
185
186 results = InternalVertexRunner.run(this.conf, graph);
187 checkResults(results, expected);
188 }
189
190 @Test
191 public void testFiveNodesAllNodesFreeNOutOfMGraph() throws Exception {
192 Iterable<String> results;
193 String[] graph = {
194 "[1,[[2,0], [5,0]]]",
195 "[2,[[4,0]]]",
196 "[3,[[2,0], [5,0]]]",
197 "[4,[[1,0], [5,1], [3,2]]]",
198 "[5,[]]"
199 };
200 String[] expected = {
201 "1\tisFree=true",
202 "2\tisFree=true",
203 "3\tisFree=true",
204 "4\tisFree=true",
205 "5\tisFree=true"
206 };
207
208 results = InternalVertexRunner.run(this.conf, graph);
209 checkResults(results, expected);
210 }
211
212 @Test
213 public void testFiveNodesAllNodesBlockedNOutOfMGraph() throws Exception {
214 Iterable<String> results;
215 String[] graph = {
216 "[1,[[2,0], [5,0]]]",
217 "[2,[[4,0]]]",
218 "[3,[[2,0], [5,0]]]",
219 "[4,[[1,0], [5,1], [3,1]]]",
220 "[5,[]]"
221 };
222 String[] expected = {
223 "1\tisFree=false",
224 "2\tisFree=false",
225 "3\tisFree=false",
226 "4\tisFree=false",
227 "5\tisFree=true"
228 };
229
230 results = InternalVertexRunner.run(this.conf, graph);
231 checkResults(results, expected);
232 }
233
234
235
236
237
238
239 private void checkResults(Iterable<String> results, String[] expected) {
240 Iterator<String> result = results.iterator();
241
242 assert results != null;
243
244 while(result.hasNext()) {
245 String resultStr = result.next();
246 boolean found = false;
247
248 for (int j = 0; j < expected.length; ++j) {
249 if (expected[j].equals(resultStr)) {
250 found = true;
251 }
252 }
253
254 assert found;
255 }
256 }
257 }