-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-mr.sh
executable file
·267 lines (202 loc) · 6.65 KB
/
test-mr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env bash
# run the test in a fresh sub-directory.
rm -rf mr-tmp
mkdir mr-tmp || exit 1
cd mr-tmp || exit 1
failed_any=0
printf "\u001bc"
export COORDINATOR_HOST=localhost
export COORDINATOR_PORT=8000
# #########################################################
# echo '***' Starting word count test.
# Word Count
../mrsequential ../apps/wordcount.jar WordCount ../data/pg*txt || exit 1
sort mr-out-0 > mr-correct-wc.txt
rm -f mr-out*
timeout -k 2s 180s ../mrcoordinator ../data/pg*txt &
pid=$!
# give the coordinator time to create the tcp socket
echo '-- wait 1s for the coordinator to start --'
sleep 1
# start multiple workers.
timeout -k 2s 180s ../mrworker ../apps/wordcount.jar WordCount &
timeout -k 2s 180s ../mrworker ../apps/wordcount.jar WordCount &
timeout -k 2s 180s ../mrworker ../apps/wordcount.jar WordCount &
# wait for the coordinator to exit.
wait $pid
# since workers are required to exit when a job is completely finished,
# and not before, that means the job has finished.
sort mr-out* | grep . > mr-wc-all
if cmp mr-wc-all mr-correct-wc.txt
then
echo '---' wc test: PASS
else
echo '---' wc output is not the same as mr-correct-wc.txt
echo '---' wc test: FAIL
failed_any=1
fi
wait # for workers and coordinator to exit
#########################################################
echo '***' Starting indexer.
# Indexer
../mrsequential ../apps/indexer.jar Indexer ../data/pg*txt || exit 1
sort mr-out-0 > mr-correct-indexer.txt
rm -f mr-out*
timeout -k 2s 180s ../mrcoordinator ../data/pg*txt &
pid=$!
echo '-- wait 1s for the coordinator to start --'
sleep 1
# start multiple workers.
timeout -k 2s 180s ../mrworker ../apps/indexer.jar Indexer &
timeout -k 2s 180s ../mrworker ../apps/indexer.jar Indexer &
# wait for the coordinator to exit.
wait $pid
sort mr-out* | grep . > mr-indexer-all
if cmp mr-indexer-all mr-correct-indexer.txt
then
echo '---' indexer test: PASS
else
echo '---' indexer output is not the same as mr-correct-indexer.txt
echo '---' indexer test: FAIL
failed_any=1
fi
wait # for workers and coordinator to exit
#########################################################
echo '***' Starting map parallelism test.
rm -f mr-*
timeout -k 2s 180s ../mrcoordinator ../data/pg*txt &
echo '-- wait 1s for the coordinator to start --'
sleep 1
timeout -k 2s 180s ../mrworker ../apps/map-parallel.jar MapParallel &
timeout -k 2s 180s ../mrworker ../apps/map-parallel.jar MapParallel # << Block
NT=`cat mr-out* | grep '^times-' | wc -l | sed 's/ //g'`
if [ "$NT" != "2" ]
then
echo '---' saw "$NT" workers rather than 2
echo '---' map parallelism test: FAIL
failed_any=1
fi
if cat mr-out* | grep '^parallel.* 2' > /dev/null
then
echo '---' map parallelism test: PASS
else
echo '---' map workers did not run in parallel
echo '---' map parallelism test: FAIL
failed_any=1
fi
wait # for workers to exit
#########################################################
echo '***' Starting reduce parallelism test.
rm -f mr-*
timeout -k 2s 180s ../mrcoordinator ../data/pg*txt &
echo '-- wait 1s for the coordinator to start --'
sleep 1
timeout -k 2s 180s ../mrworker ../apps/reduce-parallel.jar ReduceParallel &
timeout -k 2s 180s ../mrworker ../apps/reduce-parallel.jar ReduceParallel # << Block
NT=`cat mr-out* | grep '^[a-z] 2' | wc -l | sed 's/ //g'`
if [ "$NT" -lt "2" ]
then
echo '---' too few parallel reduces.
echo '---' reduce parallelism test: FAIL
failed_any=1
else
echo '---' reduce parallelism test: PASS
fi
wait
#########################################################
echo '***' Starting job count test.
rm -f mr-*
timeout -k 2s 180s ../mrcoordinator ../data/pg*txt &
echo '-- wait 1s for the coordinator to start --'
sleep 1
timeout -k 2s 180s ../mrworker ../apps/jobcount.jar JobCount &
timeout -k 2s 180s ../mrworker ../apps/jobcount.jar JobCount # << Block
timeout -k 2s 180s ../mrworker ../apps/jobcount.jar JobCount &
timeout -k 2s 180s ../mrworker ../apps/jobcount.jar JobCount # << Block
NT=`cat mr-out* | awk '{print $2}'`
if [ "$NT" -ne "8" ]
then
echo '---' map jobs ran incorrect number of times "($NT != 8)"
echo '---' job count test: FAIL
failed_any=1
else
echo '---' job count test: PASS
fi
wait
#########################################################
# test whether any worker or coordinator exits before the
# task has completed (i.e., all output files have been finalized)
rm -f mr-*
echo '***' Starting early exit test.
timeout -k 2s 180s ../mrcoordinator ../data/pg*txt &
echo '-- wait 1s for the coordinator to start --'
sleep 1
# start multiple workers.
timeout -k 2s 180s ../mrworker ../apps/early-exit.jar EarlyExit0 &
timeout -k 2s 180s ../mrworker ../apps/early-exit.jar EarlyExit0 &
timeout -k 2s 180s ../mrworker ../apps/early-exit.jar EarlyExit0 &
# wait for any of the coord or workers to exit
# `jobs` ensures that any completed old processes from other tests
# are not waited upon
jobs &> /dev/null
wait -n
# a process has exited. this means that the output should be finalized
# otherwise, either a worker or the coordinator exited early
sort mr-out* | grep . > mr-wc-all-initial
# wait for remaining workers and coordinator to exit.
wait
# compare initial and final outputs
sort mr-out* | grep . > mr-wc-all-final
if cmp mr-wc-all-final mr-wc-all-initial
then
echo '---' early exit test: PASS
else
echo '---' output changed after first worker exited
echo '---' early exit test: FAIL
failed_any=1
fi
rm -f mr-*
#########################################################
echo '***' Starting crash test.
# generate the correct output
../mrsequential ../apps/no-crash.jar NoCrash ../data/pg*txt || exit 1
sort mr-out-0 > mr-correct-crash.txt
rm -f mr-out*
rm -f mr-done
(timeout -k 2s 180s ../mrcoordinator ../data/pg*txt ; touch mr-done ) &
echo '-- wait 1s for the coordinator to start --'
sleep 1
# start multiple workers.
timeout -k 2s 180s ../mrworker ../apps/crash.jar Crash &
# respawn workers until the job is done
loop_workers () {
while [ ! -f mr-done ] do
echo "Restarting worker"
timeout -k 2s 180s ../mrworker ../apps/crash.jar Crash
sleep 1
done
}
loop_workers &
loop_workers &
loop_workers &
loop_workers
wait # for workers to finish
sort mr-out* | grep . > mr-crash-all
if cmp mr-crash-all mr-correct-crash.txt
then
echo '---' crash test: PASS
else
echo '---' crash output is not the same as mr-correct-crash.txt
echo '---' crash test: FAIL
failed_any=1
fi
#########################################################
if [ $failed_any -eq 0 ]; then
echo '***' PASSED ALL TESTS
else
echo '***' FAILED SOME TESTS
exit 1
fi
# # # kill possible remaining processes
# kill $(jps | grep worker | awk '{print $1}')
# kill $(jps | grep coordinator | awk '{print $1}')