-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_2_ring.sh
executable file
·311 lines (264 loc) · 7.65 KB
/
test_2_ring.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/usr/bin/env bash
go build
cd client
go build
cd ..
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
DEBUG="true"
outputFiles=()
message_c1_1=Weather_is_clear
message_c2_1=Winter_is_coming
message_c1_2=No_clouds_really
message_c2_2=Let\'s_go_skiing
message_c3=Is_anybody_here?
UIPort=12345
gossipPort=5000
name='A'
# General peerster (gossiper) command
#./Peerster -UIPort=12345 -gossipAddr=127.0.0.1:5001 -name=A -peers=127.0.0.1:5002 > A.out &
for i in `seq 1 10`;
do
outFileName="$name.out"
peerPort=$((($gossipPort+1)%10+5000))
peer="127.0.0.1:$peerPort"
gossipAddr="127.0.0.1:$gossipPort"
./Peerster -UIPort=$UIPort -gossipAddr=$gossipAddr -name=$name -peers=$peer > $outFileName &
outputFiles+=("$outFileName")
if [[ "$DEBUG" == "true" ]] ; then
echo "$name running at UIPort $UIPort and gossipPort $gossipPort"
fi
UIPort=$(($UIPort+1))
gossipPort=$(($gossipPort+1))
name=$(echo "$name" | tr "A-Y" "B-Z")
done
./client/client -UIPort=12349 -msg=$message_c1_1
./client/client -UIPort=12346 -msg=$message_c2_1
sleep 2
./client/client -UIPort=12349 -msg=$message_c1_2
sleep 1
./client/client -UIPort=12346 -msg=$message_c2_2
./client/client -UIPort=12351 -msg=$message_c3
sleep 64
pkill -f Peerster
#testing
failed="F"
echo -e "${RED}###CHECK that client messages arrived${NC}"
if !(grep -q "CLIENT MESSAGE $message_c1_1" "E.out") ; then
echo "CLIENT MESSAGE $message_c1_1" "E.out"
failed="T"
fi
if !(grep -q "CLIENT MESSAGE $message_c1_2" "E.out") ; then
echo "CLIENT MESSAGE $message_c1_2" "E.out"
failed="T"
fi
if !(grep -q "CLIENT MESSAGE $message_c2_1" "B.out") ; then
echo "CLIENT MESSAGE $message_c2_1" "B.out"
failed="T"
fi
if !(grep -q "CLIENT MESSAGE $message_c2_2" "B.out") ; then
echo "CLIENT MESSAGE $message_c2_2" "B.out"
failed="T"
fi
if !(grep -q "CLIENT MESSAGE $message_c3" "G.out") ; then
echo "CLIENT MESSAGE $message_c3" "G.out"
failed="T"
fi
if [[ "$failed" == "T" ]] ; then
echo -e "${RED}***FAILED***${NC}"
else
echo -e "${GREEN}***PASSED***${NC}"
fi
failed="F"
echo -e "${RED}###CHECK rumor messages ${NC}"
gossipPort=5000
for i in `seq 0 9`;
do
relayPort=$(($gossipPort-1))
if [[ "$relayPort" == 4999 ]] ; then
relayPort=5009
fi
nextPort=$((($gossipPort+1)%10+5000))
msgLine1="RUMOR origin E from 127.0.0.1:[0-9]{4} ID 1 contents $message_c1_1"
msgLine2="RUMOR origin E from 127.0.0.1:[0-9]{4} ID 2 contents $message_c1_2"
msgLine3="RUMOR origin B from 127.0.0.1:[0-9]{4} ID 1 contents $message_c2_1"
msgLine4="RUMOR origin B from 127.0.0.1:[0-9]{4} ID 2 contents $message_c2_2"
msgLine5="RUMOR origin G from 127.0.0.1:[0-9]{4} ID 1 contents $message_c3"
if [[ "$gossipPort" != 5004 ]] ; then
if !(grep -Eq "$msgLine1" "${outputFiles[$i]}") ; then
echo "$msgLine1" "${outputFiles[$i]}"
failed="T"
fi
if !(grep -Eq "$msgLine2" "${outputFiles[$i]}") ; then
echo "$msgLine2" "${outputFiles[$i]}"
failed="T"
fi
fi
if [[ "$gossipPort" != 5001 ]] ; then
if !(grep -Eq "$msgLine3" "${outputFiles[$i]}") ; then
echo "$msgLine3" "${outputFiles[$i]}"
failed="T"
fi
if !(grep -Eq "$msgLine4" "${outputFiles[$i]}") ; then
echo "$msgLine4" "${outputFiles[$i]}"
failed="T"
fi
fi
if [[ "$gossipPort" != 5006 ]] ; then
if !(grep -Eq "$msgLine5" "${outputFiles[$i]}") ; then
echo "$msgLine5" "${outputFiles[$i]}"
failed="T"
fi
fi
gossipPort=$(($gossipPort+1))
done
if [[ "$failed" == "T" ]] ; then
echo -e "${RED}***FAILED***${NC}"
else
echo -e "${GREEN}***PASSED***${NC}"
fi
failed="F"
echo -e "${RED}###CHECK mongering${NC}"
gossipPort=5000
for i in `seq 0 9`;
do
relayPort=$(($gossipPort-1))
if [[ "$relayPort" == 4999 ]] ; then
relayPort=5009
fi
nextPort=$((($gossipPort+1)%10+5000))
msgLine1="MONGERING with 127.0.0.1:$relayPort"
msgLine2="MONGERING with 127.0.0.1:$nextPort"
if !(grep -q "$msgLine1" "${outputFiles[$i]}") && !(grep -q "$msgLine2" "${outputFiles[$i]}") ; then
echo "$msgLine1" "${outputFiles[$i]}"
echo "$msgLine2" "${outputFiles[$i]}"
failed="T"
fi
gossipPort=$(($gossipPort+1))
done
if [[ "$failed" == "T" ]] ; then
echo -e "${RED}***FAILED***${NC}"
else
echo -e "${GREEN}***PASSED***${NC}"
fi
failed="F"
echo -e "${RED}###CHECK status messages ${NC}"
gossipPort=5000
for i in `seq 0 9`;
do
relayPort=$(($gossipPort-1))
if [[ "$relayPort" == 4999 ]] ; then
relayPort=5009
fi
nextPort=$((($gossipPort+1)%10+5000))
msgLine1="STATUS from 127.0.0.1:$relayPort"
msgLine2="STATUS from 127.0.0.1:$nextPort"
msgLine3="peer E nextID 3"
msgLine4="peer B nextID 3"
msgLine5="peer G nextID 2"
if !(grep -q "$msgLine1" "${outputFiles[$i]}") ; then
echo "$msgLine1" "${outputFiles[$i]}"
failed="T"
fi
if !(grep -q "$msgLine2" "${outputFiles[$i]}") ; then
echo "$msgLine2" "${outputFiles[$i]}"
failed="T"
fi
if !(grep -q "$msgLine3" "${outputFiles[$i]}") ; then
echo "$msgLine3" "${outputFiles[$i]}"
failed="T"
fi
if !(grep -q "$msgLine4" "${outputFiles[$i]}") ; then
echo "$msgLine4" "${outputFiles[$i]}"
failed="T"
fi
if !(grep -q "$msgLine5" "${outputFiles[$i]}") ; then
echo "$msgLine5" "${outputFiles[$i]}"
failed="T"
fi
gossipPort=$(($gossipPort+1))
done
if [[ "$failed" == "T" ]] ; then
echo -e "${RED}***FAILED***${NC}"
else
echo -e "${GREEN}***PASSED***${NC}"
fi
failed="F"
echo -e "${RED}###CHECK flipped coin${NC}"
gossipPort=5000
for i in `seq 0 9`;
do
relayPort=$(($gossipPort-1))
if [[ "$relayPort" == 4999 ]] ; then
relayPort=5009
fi
nextPort=$((($gossipPort+1)%10+5000))
msgLine1="FLIPPED COIN sending rumor to 127.0.0.1:$relayPort"
msgLine2="FLIPPED COIN sending rumor to 127.0.0.1:$nextPort"
if !(grep -q "$msgLine1" "${outputFiles[$i]}") ; then
echo "$msgLine1" "${outputFiles[$i]}"
failed="T"
fi
if !(grep -q "$msgLine2" "${outputFiles[$i]}") ; then
echo "$msgLine2" "${outputFiles[$i]}"
failed="T"
fi
gossipPort=$(($gossipPort+1))
done
if [[ "$failed" == "T" ]] ; then
echo -e "${RED}***FAILED***${NC}"
else
echo -e "${GREEN}***PASSED***${NC}"
fi
failed="F"
echo -e "${RED}###CHECK in sync${NC}"
gossipPort=5000
for i in `seq 0 9`;
do
relayPort=$(($gossipPort-1))
if [[ "$relayPort" == 4999 ]] ; then
relayPort=5009
fi
nextPort=$((($gossipPort+1)%10+5000))
msgLine1="IN SYNC WITH 127.0.0.1:$relayPort"
msgLine2="IN SYNC WITH 127.0.0.1:$nextPort"
if !(grep -q "$msgLine1" "${outputFiles[$i]}") ; then
echo "$msgLine1" "${outputFiles[$i]}"
failed="T"
fi
if !(grep -q "$msgLine2" "${outputFiles[$i]}") ; then
echo "$msgLine2" "${outputFiles[$i]}"
failed="T"
fi
gossipPort=$(($gossipPort+1))
done
if [[ "$failed" == "T" ]] ; then
echo -e "${RED}***FAILED***${NC}"
else
echo -e "${GREEN}***PASSED***${NC}"
fi
failed="F"
echo -e "${RED}###CHECK correct peers${NC}"
gossipPort=5000
for i in `seq 0 9`;
do
relayPort=$(($gossipPort-1))
if [[ "$relayPort" == 4999 ]] ; then
relayPort=5009
fi
nextPort=$((($gossipPort+1)%10+5000))
peersLine1="127.0.0.1:$relayPort,127.0.0.1:$nextPort"
peersLine2="127.0.0.1:$nextPort,127.0.0.1:$relayPort"
if !(grep -q "$peersLine1" "${outputFiles[$i]}") && !(grep -q "$peersLine2" "${outputFiles[$i]}") ; then
echo "$peersLine1" "${outputFiles[$i]}"
echo "$peersLine2" "${outputFiles[$i]}"
failed="T"
fi
gossipPort=$(($gossipPort+1))
done
if [[ "$failed" == "T" ]] ; then
echo -e "${RED}***FAILED***${NC}"
else
echo -e "${GREEN}***PASSED***${NC}"
fi