Add usecases to project pom
[nonrtric.git] / test / kafka-procon / basic_test.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 #  ========================================================================
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License.
17 #  ============LICENSE_END=================================================
18 #
19
20 # Automated test script for Kafka procon container
21
22 # NOTE: Need a running instance of kafka
23
24
25 export PORT=8096
26 export HTTPX="http"
27 export REQ_CONTENT=""
28 export RESP_CONTENT="text/plain"
29
30 # source function to do curl and check result
31 . ../common/do_curl_function.sh
32
33 echo "Requires a running kafka"
34
35 payload=".payload"
36
37 echo "=== hello world ==="
38 REQ_CONTENT=""
39 RESP_CONTENT="text/plain"
40 RESULT="OK"
41 do_curl GET / 200
42
43 echo "=== reset ==="
44 REQ_CONTENT=""
45 RESP_CONTENT=""
46 RESULT="*"
47 do_curl POST /reset 200
48
49 echo "=== get topics ==="
50 REQ_CONTENT=""
51 RESP_CONTENT="application/json"
52 RESULT="json:[]"
53 do_curl GET /topics 200
54
55 echo "=== get global counter sent ==="
56 REQ_CONTENT=""
57 RESP_CONTENT="text/plain"
58 RESULT="0"
59 do_curl GET /counters/sent 200
60
61 echo "=== get global counter received ==="
62 REQ_CONTENT=""
63 RESP_CONTENT="text/plain"
64 RESULT="0"
65 do_curl GET /counters/received 200
66
67 echo "=== get topic ==="
68 REQ_CONTENT=""
69 RESP_CONTENT="text/plain"
70 RESULT="*"
71 do_curl GET /topics/test-topic 404
72
73 echo "=== get topic counter sent ==="
74 REQ_CONTENT=""
75 RESP_CONTENT="text/plain"
76 RESULT="*"
77 do_curl GET /topics/test-topic/counters/sent 404
78
79 echo "=== get topic counter received ==="
80 REQ_CONTENT=""
81 RESP_CONTENT="text/plain"
82 RESULT="*"
83 do_curl GET /topics/test-topic/counters/received 404
84
85 echo "=== create a topic ==="
86 REQ_CONTENT=""
87 RESP_CONTENT=""
88 RESULT="*"
89 do_curl PUT /topics/test-topic 405
90
91 echo "=== start to send on a topic ==="
92 REQ_CONTENT=""
93 RESP_CONTENT="text/plain"
94 RESULT="*"
95 do_curl POST /topics/test-topic/startsend 404
96
97 echo "=== start to receive from a  topic ==="
98 REQ_CONTENT=""
99 RESP_CONTENT="text/plain"
100 RESULT="*"
101 do_curl POST /topics/test-topic/startreceive 404
102
103 echo "=== send a msg on a  topic ==="
104 echo "TEST1" > $payload
105 REQ_CONTENT="text/plain"
106 RESP_CONTENT="text/plain"
107 RESULT="*"
108 do_curl POST /topics/test-topic/msg 404 $payload
109
110 echo "=== receive a msg  from a  topic ==="
111 echo "TEST1" > $payload
112 REQ_CONTENT="text/plain"
113 RESP_CONTENT="text/plain"
114 RESULT="*"
115 do_curl GET /topics/test-topic/msg 404 $payload
116
117 echo "=== stop to send on a  topic ==="
118 REQ_CONTENT=""
119 RESP_CONTENT="text/plain"
120 RESULT="*"
121 do_curl POST /topics/test-topic/stopsend 404
122
123 echo "=== stop to receive from a  topic ==="
124 REQ_CONTENT=""
125 RESP_CONTENT="text/plain"
126 RESULT="*"
127 do_curl POST /topics/test-topic/stopreceive 404
128
129 # Create 4 topics
130
131 echo "=== create topic1 ==="
132 REQ_CONTENT=""
133 RESP_CONTENT="text/plain"
134 RESULT="*"
135 do_curl PUT /topics/topic1?type=text/plain 201
136
137 echo "=== get topics ==="
138 REQ_CONTENT=""
139 RESP_CONTENT="application/json"
140 RESULT="json:[\"topic1\"]"
141 do_curl GET /topics 200
142
143 echo "=== create topic2 ==="
144 REQ_CONTENT=""
145 RESP_CONTENT="text/plain"
146 RESULT="*"
147 do_curl PUT /topics/topic2?type=text/plain 201
148
149 echo "=== get topics ==="
150 REQ_CONTENT=""
151 RESP_CONTENT="application/json"
152 RESULT="json:[\"topic1\",\"topic2\"]"
153 do_curl GET /topics 200
154
155 echo "=== create topic3 ==="
156 REQ_CONTENT=""
157 RESP_CONTENT="text/plain"
158 RESULT="*"
159 do_curl PUT /topics/topic3?type=application/json 201
160
161 echo "=== get topics ==="
162 REQ_CONTENT=""
163 RESP_CONTENT="application/json"
164 RESULT="json:[\"topic1\",\"topic2\",\"topic3\"]"
165 do_curl GET /topics 200
166
167 echo "=== create topic4 ==="
168 REQ_CONTENT=""
169 RESP_CONTENT="text/plain"
170 RESULT="*"
171 do_curl PUT /topics/topic4?type=application/json 201
172
173 echo "=== get topics ==="
174 REQ_CONTENT=""
175 RESP_CONTENT="application/json"
176 RESULT="json:[\"topic1\",\"topic2\",\"topic3\",\"topic4\"]"
177 do_curl GET /topics 200
178
179 echo "=== get topic1 ==="
180 REQ_CONTENT=""
181 RESP_CONTENT="text/plain"
182 RESULT="text/plain"
183 do_curl GET /topics/topic1 200
184
185 echo "=== get topic2 ==="
186 REQ_CONTENT=""
187 RESP_CONTENT="text/plain"
188 RESULT="text/plain"
189 do_curl GET /topics/topic2 200
190
191 echo "=== get topic3 ==="
192 REQ_CONTENT=""
193 RESP_CONTENT="text/plain"
194 RESULT="application/json"
195 do_curl GET /topics/topic3 200
196
197 echo "=== get topic4 ==="
198 REQ_CONTENT=""
199 RESP_CONTENT="text/plain"
200 RESULT="application/json"
201 do_curl GET /topics/topic4 200
202
203 echo "=== send a msg on topic1 ==="
204 echo "TEST11" > $payload
205 REQ_CONTENT="text/plain"
206 RESP_CONTENT="text/plain"
207 RESULT="*"
208 do_curl POST /topics/topic1/msg 400  $payload
209
210 echo "=== receive a msg  from topic1 ==="
211 REQ_CONTENT="text/plain"
212 RESP_CONTENT="text/plain"
213 RESULT="*"
214 do_curl GET /topics/topic1/msg 400
215
216 echo "=== send a msg on topic2 ==="
217 echo "TEST22" > $payload
218 REQ_CONTENT="text/plain"
219 RESP_CONTENT="text/plain"
220 RESULT="*"
221 do_curl POST /topics/topic2/msg 400 $payload
222
223 echo "=== receive a msg  from topic2 ==="
224 REQ_CONTENT="text/plain"
225 RESP_CONTENT="text/plain"
226 RESULT="*"
227 do_curl GET /topics/topic2/msg 400
228
229
230
231 echo "=== send a msg on topic3 ==="
232 echo "{\"test\":\"33\"}" > $payload
233 REQ_CONTENT="application/json"
234 RESP_CONTENT="text/plain"
235 RESULT="*"
236 do_curl POST /topics/topic3/msg 400 $payload
237
238 echo "=== receive a msg  from topic3 ==="
239 REQ_CONTENT=""
240 RESP_CONTENT="text/plain"
241 RESULT="*"
242 do_curl GET /topics/topic3/msg 400
243
244 echo "=== send a msg on topic4 ==="
245 echo "{\"test\":\"44\"}" > $payload
246 REQ_CONTENT="application/json"
247 RESP_CONTENT="text/plain"
248 RESULT="*"
249 do_curl POST /topics/topic4/msg 400 $payload
250
251 echo "=== receive a msg  from topic4 ==="
252 REQ_CONTENT=""
253 RESP_CONTENT="text/plain"
254 RESULT="*"
255 do_curl GET /topics/topic2/msg 400
256
257
258 echo "=== get global counter sent ==="
259 REQ_CONTENT=""
260 RESP_CONTENT="text/plain"
261 RESULT="0"
262 do_curl GET /counters/sent 200
263
264 echo "=== get global counter received ==="
265 REQ_CONTENT=""
266 RESP_CONTENT="text/plain"
267 RESULT="0"
268 do_curl GET /counters/received 200
269
270 echo "=== get topic1 counter sent ==="
271 REQ_CONTENT=""
272 RESP_CONTENT="text/plain"
273 RESULT="0"
274 do_curl GET /topics/topic1/counters/sent 200
275
276 echo "=== get topic1 counter received ==="
277 REQ_CONTENT=""
278 RESP_CONTENT="text/plain"
279 RESULT="0"
280 do_curl GET /topics/topic1/counters/received 200
281
282 echo "=== get topic2 counter sent ==="
283 REQ_CONTENT=""
284 RESP_CONTENT="text/plain"
285 RESULT="0"
286 do_curl GET /topics/topic2/counters/sent 200
287
288 echo "=== get topic2 counter received ==="
289 REQ_CONTENT=""
290 RESP_CONTENT="text/plain"
291 RESULT="0"
292 do_curl GET /topics/topic2/counters/received 200
293
294 echo "=== get topic3 counter sent ==="
295 REQ_CONTENT=""
296 RESP_CONTENT="text/plain"
297 RESULT="0"
298 do_curl GET /topics/topic3/counters/sent 200
299
300 echo "=== get topic3 counter received ==="
301 REQ_CONTENT=""
302 RESP_CONTENT="text/plain"
303 RESULT="0"
304 do_curl GET /topics/topic3/counters/received 200
305
306 echo "=== get topic4 counter sent ==="
307 REQ_CONTENT=""
308 RESP_CONTENT="text/plain"
309 RESULT="0"
310 do_curl GET /topics/topic4/counters/sent 200
311
312 echo "=== get topic4 counter received ==="
313 REQ_CONTENT=""
314 RESP_CONTENT="text/plain"
315 RESULT="0"
316 do_curl GET /topics/topic4/counters/received 200
317
318 # Begins send and receive
319
320 echo "=== set topic1 start sending ==="
321 REQ_CONTENT=""
322 RESP_CONTENT="text/plain"
323 RESULT="*"
324 do_curl POST /topics/topic1/startsend 200
325
326 echo "=== send a msg on topic1 ==="
327 echo "TEST11" > $payload
328 REQ_CONTENT="application/json"
329 RESP_CONTENT="text/plain"
330 RESULT="*"
331 do_curl POST /topics/topic1/msg 400  $payload
332
333 echo "=== send a msg on topic1 ==="
334 echo "TEST11" > $payload
335 REQ_CONTENT="text/plain"
336 RESP_CONTENT="text/plain"
337 RESULT="*"
338 do_curl POST /topics/topic1/msg 200  $payload
339
340 echo "sleep 2  to allow sending the msg to kafka"
341 sleep 2
342
343 echo "=== receive a msg  from topic1 ==="
344 REQ_CONTENT="text/plain"
345 RESP_CONTENT="text/plain"
346 RESULT="*"
347 do_curl GET /topics/topic1/msg 400
348
349 echo "=== get topic1 counter sent ==="
350 REQ_CONTENT=""
351 RESP_CONTENT="text/plain"
352 RESULT="1"
353 do_curl GET /topics/topic1/counters/sent 200
354
355 echo "=== get topic1 counter received ==="
356 REQ_CONTENT=""
357 RESP_CONTENT="text/plain"
358 RESULT="0"
359 do_curl GET /topics/topic1/counters/received 200
360
361 echo "=== set topic1 start receiving ==="
362 REQ_CONTENT=""
363 RESP_CONTENT="text/plain"
364 RESULT="*"
365 do_curl POST /topics/topic1/startreceive 200
366
367 echo "sleep 60 to allow kafka to process the msg, unclear why first message takes a long time..."
368 sleep 60
369
370 echo "=== get topic1 counter sent ==="
371 REQ_CONTENT=""
372 RESP_CONTENT="text/plain"
373 RESULT="1"
374 do_curl GET /topics/topic1/counters/sent 200
375
376 echo "=== get topic1 counter received ==="
377 REQ_CONTENT=""
378 RESP_CONTENT="text/plain"
379 RESULT="1"
380 do_curl GET /topics/topic1/counters/received 200
381
382 echo "=== get global counter sent ==="
383 REQ_CONTENT=""
384 RESP_CONTENT="text/plain"
385 RESULT="1"
386 do_curl GET /counters/sent 200
387
388 echo "=== get global counter received ==="
389 REQ_CONTENT=""
390 RESP_CONTENT="text/plain"
391 RESULT="1"
392 do_curl GET /counters/received 200
393
394 echo "=== receive a msg from topic1 ==="
395 REQ_CONTENT="text/plain"
396 RESP_CONTENT="text/plain"
397 RESULT="TEST11"
398 do_curl GET /topics/topic1/msg 200
399
400 echo "=== receive a msg from topic1 ==="
401 REQ_CONTENT="text/plain"
402 RESP_CONTENT=""
403 RESULT="*"
404 do_curl GET /topics/topic1/msg 204
405
406
407 echo "=== set topic1 start sending ==="
408 REQ_CONTENT=""
409 RESP_CONTENT="text/plain"
410 RESULT="*"
411 do_curl POST /topics/topic1/startsend 200
412
413 echo "=== set topic2 start sending ==="
414 REQ_CONTENT=""
415 RESP_CONTENT="text/plain"
416 RESULT="*"
417 do_curl POST /topics/topic2/startsend 200
418
419 echo "=== set topic3 start sending ==="
420 REQ_CONTENT=""
421 RESP_CONTENT="text/plain"
422 RESULT="*"
423 do_curl POST /topics/topic3/startsend 200
424
425 echo "=== set topic4 start sending ==="
426 REQ_CONTENT=""
427 RESP_CONTENT="text/plain"
428 RESULT="*"
429 do_curl POST /topics/topic4/startsend 200
430
431 echo "=== set topic1 start receiving ==="
432 REQ_CONTENT=""
433 RESP_CONTENT="text/plain"
434 RESULT="*"
435 do_curl POST /topics/topic1/startreceive 200
436
437 echo "=== set topic2 start receiving ==="
438 REQ_CONTENT=""
439 RESP_CONTENT="text/plain"
440 RESULT="*"
441 do_curl POST /topics/topic2/startreceive 200
442
443 echo "=== set topic3 start receiving ==="
444 REQ_CONTENT=""
445 RESP_CONTENT="text/plain"
446 RESULT="*"
447 do_curl POST /topics/topic3/startreceive 200
448
449 echo "=== set topic4 start receiving ==="
450 REQ_CONTENT=""
451 RESP_CONTENT="text/plain"
452 RESULT="*"
453 do_curl POST /topics/topic4/startreceive 200
454
455
456 # Send and receive on all topics
457
458 echo "=== send a msg on topic1 ==="
459 echo "TEST101" > $payload
460 REQ_CONTENT="text/plain"
461 RESP_CONTENT="text/plain"
462 RESULT="*"
463 do_curl POST /topics/topic1/msg 200  $payload
464
465 echo "=== send two msg on topic2 ==="
466 echo "TEST201" > $payload
467 REQ_CONTENT="text/plain"
468 RESP_CONTENT="text/plain"
469 RESULT="*"
470 do_curl POST /topics/topic2/msg 200  $payload
471 echo "TEST202" > $payload
472 do_curl POST /topics/topic2/msg 200  $payload
473
474 echo "=== send three msg on topic3 ==="
475 echo "{\"a\":\"msg301\"}" > $payload
476 REQ_CONTENT="application/json"
477 RESP_CONTENT="text/plain"
478 RESULT="*"
479 do_curl POST /topics/topic3/msg 200  $payload
480 echo "{\"a\":\"msg302\"}" > $payload
481 do_curl POST /topics/topic3/msg 200  $payload
482 echo "{\"a\":\"msg303\"}" > $payload
483 do_curl POST /topics/topic3/msg 200  $payload
484
485
486 echo "=== send four msg on topic4 ==="
487 echo "{\"a\":\"msg401\"}" > $payload
488 REQ_CONTENT="application/json"
489 RESP_CONTENT="text/plain"
490 RESULT="*"
491 do_curl POST /topics/topic4/msg 200  $payload
492 echo "{\"a\":\"msg402\"}" > $payload
493 do_curl POST /topics/topic4/msg 200  $payload
494 echo "{\"a\":\"msg403\"}" > $payload
495 do_curl POST /topics/topic4/msg 200  $payload
496 echo "{\"a\":\"msg404\"}" > $payload
497 do_curl POST /topics/topic4/msg 200  $payload
498
499 echo "sleep 10 to allow kafka to process msg"
500 sleep 10
501
502 echo "=== get global counter sent ==="
503 REQ_CONTENT=""
504 RESP_CONTENT="text/plain"
505 RESULT="11"
506 do_curl GET /counters/sent 200
507
508 echo "=== get global counter received ==="
509 REQ_CONTENT=""
510 RESP_CONTENT="text/plain"
511 RESULT="11"
512 do_curl GET /counters/received 200
513
514
515 echo "=== get topic1 counter sent ==="
516 REQ_CONTENT=""
517 RESP_CONTENT="text/plain"
518 RESULT="2"
519 do_curl GET /topics/topic1/counters/sent 200
520
521 echo "=== get topic1 counter received ==="
522 REQ_CONTENT=""
523 RESP_CONTENT="text/plain"
524 RESULT="2"
525 do_curl GET /topics/topic1/counters/received 200
526
527
528 echo "=== get topic2 counter sent ==="
529 REQ_CONTENT=""
530 RESP_CONTENT="text/plain"
531 RESULT="2"
532 do_curl GET /topics/topic2/counters/sent 200
533
534 echo "=== get topic2 counter received ==="
535 REQ_CONTENT=""
536 RESP_CONTENT="text/plain"
537 RESULT="2"
538 do_curl GET /topics/topic2/counters/received 200
539
540
541 echo "=== get topic3 counter sent ==="
542 REQ_CONTENT=""
543 RESP_CONTENT="text/plain"
544 RESULT="3"
545 do_curl GET /topics/topic3/counters/sent 200
546
547 echo "=== get topic3 counter received ==="
548 REQ_CONTENT=""
549 RESP_CONTENT="text/plain"
550 RESULT="3"
551 do_curl GET /topics/topic3/counters/received 200
552
553
554 echo "=== get topic4 counter sent ==="
555 REQ_CONTENT=""
556 RESP_CONTENT="text/plain"
557 RESULT="4"
558 do_curl GET /topics/topic4/counters/sent 200
559
560 echo "=== get topic4 counter received ==="
561 REQ_CONTENT=""
562 RESP_CONTENT="text/plain"
563 RESULT="4"
564 do_curl GET /topics/topic4/counters/received 200
565
566
567 echo "=== get a msg on topic1 ==="
568 REQ_CONTENT="text/plain"
569 RESP_CONTENT="text/plain"
570 RESULT="TEST101"
571 do_curl GET /topics/topic1/msg 200
572
573
574 echo "=== attempt to receive a msg from topic1 ==="
575 REQ_CONTENT="text/plain"
576 RESP_CONTENT=""
577 RESULT="*"
578 do_curl GET /topics/topic1/msg 204
579
580 echo "=== get a two msg on topic2 ==="
581 REQ_CONTENT="text/plain"
582 RESP_CONTENT="text/plain"
583 RESULT="TEST201"
584 do_curl GET /topics/topic2/msg 200
585 RESULT="TEST202"
586 do_curl GET /topics/topic2/msg 200
587
588
589 echo "=== attempt to receive a msg from topic2 ==="
590 REQ_CONTENT="text/plain"
591 RESP_CONTENT=""
592 RESULT="*"
593 do_curl GET /topics/topic2/msg 204
594
595 echo "=== get three msg on topic3 ==="
596 REQ_CONTENT="text/plain"
597 RESP_CONTENT="application/json"
598 RESULT="json:{\"a\":\"msg301\"}"
599 do_curl GET /topics/topic3/msg 200
600 RESULT="json:{\"a\":\"msg302\"}"
601 do_curl GET /topics/topic3/msg 200
602 RESULT="json:{\"a\":\"msg303\"}"
603 do_curl GET /topics/topic3/msg 200
604
605 echo "=== attempt to receive a msg from topic3 ==="
606 REQ_CONTENT="text/plain"
607 RESP_CONTENT=""
608 RESULT="*"
609 do_curl GET /topics/topic3/msg 204
610
611 echo "=== send four msg on topic4 ==="
612 REQ_CONTENT="text/plain"
613 RESP_CONTENT="application/json"
614 RESULT="json:{\"a\":\"msg401\"}"
615 do_curl GET /topics/topic4/msg 200
616 RESULT="json:{\"a\":\"msg402\"}"
617 do_curl GET /topics/topic4/msg 200
618 RESULT="json:{\"a\":\"msg403\"}"
619 do_curl GET /topics/topic4/msg 200
620 RESULT="json:{\"a\":\"msg404\"}"
621 do_curl GET /topics/topic4/msg 200
622
623 echo "=== attempt to receive a msg from topic4 ==="
624 REQ_CONTENT="text/plain"
625 RESP_CONTENT=""
626 RESULT="*"
627 do_curl GET /topics/topic4/msg 204
628
629 echo "********************"
630 echo "*** All tests ok ***"
631 echo "********************"
632