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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
20 # Automated test script for Kafka procon container
22 # NOTE: Need a running instance of kafka
28 export RESP_CONTENT="text/plain"
30 # source function to do curl and check result
31 . ../common/do_curl_function.sh
33 echo "Requires a running kafka"
37 echo "=== hello world ==="
39 RESP_CONTENT="text/plain"
47 do_curl POST /reset 200
49 echo "=== get topics ==="
51 RESP_CONTENT="application/json"
53 do_curl GET /topics 200
55 echo "=== get global counter sent ==="
57 RESP_CONTENT="text/plain"
59 do_curl GET /counters/sent 200
61 echo "=== get global counter received ==="
63 RESP_CONTENT="text/plain"
65 do_curl GET /counters/received 200
67 echo "=== get topic ==="
69 RESP_CONTENT="text/plain"
71 do_curl GET /topics/test-topic 404
73 echo "=== get topic counter sent ==="
75 RESP_CONTENT="text/plain"
77 do_curl GET /topics/test-topic/counters/sent 404
79 echo "=== get topic counter received ==="
81 RESP_CONTENT="text/plain"
83 do_curl GET /topics/test-topic/counters/received 404
85 echo "=== create a topic ==="
89 do_curl PUT /topics/test-topic 405
91 echo "=== start to send on a topic ==="
93 RESP_CONTENT="text/plain"
95 do_curl POST /topics/test-topic/startsend 404
97 echo "=== start to receive from a topic ==="
99 RESP_CONTENT="text/plain"
101 do_curl POST /topics/test-topic/startreceive 404
103 echo "=== send a msg on a topic ==="
104 echo "TEST1" > $payload
105 REQ_CONTENT="text/plain"
106 RESP_CONTENT="text/plain"
108 do_curl POST /topics/test-topic/msg 404 $payload
110 echo "=== receive a msg from a topic ==="
111 echo "TEST1" > $payload
112 REQ_CONTENT="text/plain"
113 RESP_CONTENT="text/plain"
115 do_curl GET /topics/test-topic/msg 404 $payload
117 echo "=== stop to send on a topic ==="
119 RESP_CONTENT="text/plain"
121 do_curl POST /topics/test-topic/stopsend 404
123 echo "=== stop to receive from a topic ==="
125 RESP_CONTENT="text/plain"
127 do_curl POST /topics/test-topic/stopreceive 404
131 echo "=== create topic1 ==="
133 RESP_CONTENT="text/plain"
135 do_curl PUT /topics/topic1?type=text/plain 201
137 echo "=== get topics ==="
139 RESP_CONTENT="application/json"
140 RESULT="json:[\"topic1\"]"
141 do_curl GET /topics 200
143 echo "=== create topic2 ==="
145 RESP_CONTENT="text/plain"
147 do_curl PUT /topics/topic2?type=text/plain 201
149 echo "=== get topics ==="
151 RESP_CONTENT="application/json"
152 RESULT="json:[\"topic1\",\"topic2\"]"
153 do_curl GET /topics 200
155 echo "=== create topic3 ==="
157 RESP_CONTENT="text/plain"
159 do_curl PUT /topics/topic3?type=application/json 201
161 echo "=== get topics ==="
163 RESP_CONTENT="application/json"
164 RESULT="json:[\"topic1\",\"topic2\",\"topic3\"]"
165 do_curl GET /topics 200
167 echo "=== create topic4 ==="
169 RESP_CONTENT="text/plain"
171 do_curl PUT /topics/topic4?type=application/json 201
173 echo "=== get topics ==="
175 RESP_CONTENT="application/json"
176 RESULT="json:[\"topic1\",\"topic2\",\"topic3\",\"topic4\"]"
177 do_curl GET /topics 200
179 echo "=== get topic1 ==="
181 RESP_CONTENT="text/plain"
183 do_curl GET /topics/topic1 200
185 echo "=== get topic2 ==="
187 RESP_CONTENT="text/plain"
189 do_curl GET /topics/topic2 200
191 echo "=== get topic3 ==="
193 RESP_CONTENT="text/plain"
194 RESULT="application/json"
195 do_curl GET /topics/topic3 200
197 echo "=== get topic4 ==="
199 RESP_CONTENT="text/plain"
200 RESULT="application/json"
201 do_curl GET /topics/topic4 200
203 echo "=== send a msg on topic1 ==="
204 echo "TEST11" > $payload
205 REQ_CONTENT="text/plain"
206 RESP_CONTENT="text/plain"
208 do_curl POST /topics/topic1/msg 400 $payload
210 echo "=== receive a msg from topic1 ==="
211 REQ_CONTENT="text/plain"
212 RESP_CONTENT="text/plain"
214 do_curl GET /topics/topic1/msg 400
216 echo "=== send a msg on topic2 ==="
217 echo "TEST22" > $payload
218 REQ_CONTENT="text/plain"
219 RESP_CONTENT="text/plain"
221 do_curl POST /topics/topic2/msg 400 $payload
223 echo "=== receive a msg from topic2 ==="
224 REQ_CONTENT="text/plain"
225 RESP_CONTENT="text/plain"
227 do_curl GET /topics/topic2/msg 400
231 echo "=== send a msg on topic3 ==="
232 echo "{\"test\":\"33\"}" > $payload
233 REQ_CONTENT="application/json"
234 RESP_CONTENT="text/plain"
236 do_curl POST /topics/topic3/msg 400 $payload
238 echo "=== receive a msg from topic3 ==="
240 RESP_CONTENT="text/plain"
242 do_curl GET /topics/topic3/msg 400
244 echo "=== send a msg on topic4 ==="
245 echo "{\"test\":\"44\"}" > $payload
246 REQ_CONTENT="application/json"
247 RESP_CONTENT="text/plain"
249 do_curl POST /topics/topic4/msg 400 $payload
251 echo "=== receive a msg from topic4 ==="
253 RESP_CONTENT="text/plain"
255 do_curl GET /topics/topic2/msg 400
258 echo "=== get global counter sent ==="
260 RESP_CONTENT="text/plain"
262 do_curl GET /counters/sent 200
264 echo "=== get global counter received ==="
266 RESP_CONTENT="text/plain"
268 do_curl GET /counters/received 200
270 echo "=== get topic1 counter sent ==="
272 RESP_CONTENT="text/plain"
274 do_curl GET /topics/topic1/counters/sent 200
276 echo "=== get topic1 counter received ==="
278 RESP_CONTENT="text/plain"
280 do_curl GET /topics/topic1/counters/received 200
282 echo "=== get topic2 counter sent ==="
284 RESP_CONTENT="text/plain"
286 do_curl GET /topics/topic2/counters/sent 200
288 echo "=== get topic2 counter received ==="
290 RESP_CONTENT="text/plain"
292 do_curl GET /topics/topic2/counters/received 200
294 echo "=== get topic3 counter sent ==="
296 RESP_CONTENT="text/plain"
298 do_curl GET /topics/topic3/counters/sent 200
300 echo "=== get topic3 counter received ==="
302 RESP_CONTENT="text/plain"
304 do_curl GET /topics/topic3/counters/received 200
306 echo "=== get topic4 counter sent ==="
308 RESP_CONTENT="text/plain"
310 do_curl GET /topics/topic4/counters/sent 200
312 echo "=== get topic4 counter received ==="
314 RESP_CONTENT="text/plain"
316 do_curl GET /topics/topic4/counters/received 200
318 # Begins send and receive
320 echo "=== set topic1 start sending ==="
322 RESP_CONTENT="text/plain"
324 do_curl POST /topics/topic1/startsend 200
326 echo "=== send a msg on topic1 ==="
327 echo "TEST11" > $payload
328 REQ_CONTENT="application/json"
329 RESP_CONTENT="text/plain"
331 do_curl POST /topics/topic1/msg 400 $payload
333 echo "=== send a msg on topic1 ==="
334 echo "TEST11" > $payload
335 REQ_CONTENT="text/plain"
336 RESP_CONTENT="text/plain"
338 do_curl POST /topics/topic1/msg 200 $payload
340 echo "sleep 2 to allow sending the msg to kafka"
343 echo "=== receive a msg from topic1 ==="
344 REQ_CONTENT="text/plain"
345 RESP_CONTENT="text/plain"
347 do_curl GET /topics/topic1/msg 400
349 echo "=== get topic1 counter sent ==="
351 RESP_CONTENT="text/plain"
353 do_curl GET /topics/topic1/counters/sent 200
355 echo "=== get topic1 counter received ==="
357 RESP_CONTENT="text/plain"
359 do_curl GET /topics/topic1/counters/received 200
361 echo "=== set topic1 start receiving ==="
363 RESP_CONTENT="text/plain"
365 do_curl POST /topics/topic1/startreceive 200
367 echo "sleep 60 to allow kafka to process the msg, unclear why first message takes a long time..."
370 echo "=== get topic1 counter sent ==="
372 RESP_CONTENT="text/plain"
374 do_curl GET /topics/topic1/counters/sent 200
376 echo "=== get topic1 counter received ==="
378 RESP_CONTENT="text/plain"
380 do_curl GET /topics/topic1/counters/received 200
382 echo "=== get global counter sent ==="
384 RESP_CONTENT="text/plain"
386 do_curl GET /counters/sent 200
388 echo "=== get global counter received ==="
390 RESP_CONTENT="text/plain"
392 do_curl GET /counters/received 200
394 echo "=== receive a msg from topic1 ==="
395 REQ_CONTENT="text/plain"
396 RESP_CONTENT="text/plain"
398 do_curl GET /topics/topic1/msg 200
400 echo "=== receive a msg from topic1 ==="
401 REQ_CONTENT="text/plain"
404 do_curl GET /topics/topic1/msg 204
407 echo "=== set topic1 start sending ==="
409 RESP_CONTENT="text/plain"
411 do_curl POST /topics/topic1/startsend 200
413 echo "=== set topic2 start sending ==="
415 RESP_CONTENT="text/plain"
417 do_curl POST /topics/topic2/startsend 200
419 echo "=== set topic3 start sending ==="
421 RESP_CONTENT="text/plain"
423 do_curl POST /topics/topic3/startsend 200
425 echo "=== set topic4 start sending ==="
427 RESP_CONTENT="text/plain"
429 do_curl POST /topics/topic4/startsend 200
431 echo "=== set topic1 start receiving ==="
433 RESP_CONTENT="text/plain"
435 do_curl POST /topics/topic1/startreceive 200
437 echo "=== set topic2 start receiving ==="
439 RESP_CONTENT="text/plain"
441 do_curl POST /topics/topic2/startreceive 200
443 echo "=== set topic3 start receiving ==="
445 RESP_CONTENT="text/plain"
447 do_curl POST /topics/topic3/startreceive 200
449 echo "=== set topic4 start receiving ==="
451 RESP_CONTENT="text/plain"
453 do_curl POST /topics/topic4/startreceive 200
456 # Send and receive on all topics
458 echo "=== send a msg on topic1 ==="
459 echo "TEST101" > $payload
460 REQ_CONTENT="text/plain"
461 RESP_CONTENT="text/plain"
463 do_curl POST /topics/topic1/msg 200 $payload
465 echo "=== send two msg on topic2 ==="
466 echo "TEST201" > $payload
467 REQ_CONTENT="text/plain"
468 RESP_CONTENT="text/plain"
470 do_curl POST /topics/topic2/msg 200 $payload
471 echo "TEST202" > $payload
472 do_curl POST /topics/topic2/msg 200 $payload
474 echo "=== send three msg on topic3 ==="
475 echo "{\"a\":\"msg301\"}" > $payload
476 REQ_CONTENT="application/json"
477 RESP_CONTENT="text/plain"
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
486 echo "=== send four msg on topic4 ==="
487 echo "{\"a\":\"msg401\"}" > $payload
488 REQ_CONTENT="application/json"
489 RESP_CONTENT="text/plain"
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
499 echo "sleep 10 to allow kafka to process msg"
502 echo "=== get global counter sent ==="
504 RESP_CONTENT="text/plain"
506 do_curl GET /counters/sent 200
508 echo "=== get global counter received ==="
510 RESP_CONTENT="text/plain"
512 do_curl GET /counters/received 200
515 echo "=== get topic1 counter sent ==="
517 RESP_CONTENT="text/plain"
519 do_curl GET /topics/topic1/counters/sent 200
521 echo "=== get topic1 counter received ==="
523 RESP_CONTENT="text/plain"
525 do_curl GET /topics/topic1/counters/received 200
528 echo "=== get topic2 counter sent ==="
530 RESP_CONTENT="text/plain"
532 do_curl GET /topics/topic2/counters/sent 200
534 echo "=== get topic2 counter received ==="
536 RESP_CONTENT="text/plain"
538 do_curl GET /topics/topic2/counters/received 200
541 echo "=== get topic3 counter sent ==="
543 RESP_CONTENT="text/plain"
545 do_curl GET /topics/topic3/counters/sent 200
547 echo "=== get topic3 counter received ==="
549 RESP_CONTENT="text/plain"
551 do_curl GET /topics/topic3/counters/received 200
554 echo "=== get topic4 counter sent ==="
556 RESP_CONTENT="text/plain"
558 do_curl GET /topics/topic4/counters/sent 200
560 echo "=== get topic4 counter received ==="
562 RESP_CONTENT="text/plain"
564 do_curl GET /topics/topic4/counters/received 200
567 echo "=== get a msg on topic1 ==="
568 REQ_CONTENT="text/plain"
569 RESP_CONTENT="text/plain"
571 do_curl GET /topics/topic1/msg 200
574 echo "=== attempt to receive a msg from topic1 ==="
575 REQ_CONTENT="text/plain"
578 do_curl GET /topics/topic1/msg 204
580 echo "=== get a two msg on topic2 ==="
581 REQ_CONTENT="text/plain"
582 RESP_CONTENT="text/plain"
584 do_curl GET /topics/topic2/msg 200
586 do_curl GET /topics/topic2/msg 200
589 echo "=== attempt to receive a msg from topic2 ==="
590 REQ_CONTENT="text/plain"
593 do_curl GET /topics/topic2/msg 204
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
605 echo "=== attempt to receive a msg from topic3 ==="
606 REQ_CONTENT="text/plain"
609 do_curl GET /topics/topic3/msg 204
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
623 echo "=== attempt to receive a msg from topic4 ==="
624 REQ_CONTENT="text/plain"
627 do_curl GET /topics/topic4/msg 204
629 echo "********************"
630 echo "*** All tests ok ***"
631 echo "********************"