Update version number in container-tag for F Maintenance Release
[sim/a1-interface.git] / near-rt-ric-simulator / test / KAFKA_DISPATCHER_TEST / timeout_test.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2022 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 # Script for error testing of the Kafka message dispatcher
21 # The timeout value should be equal to TIME_OUT param that exist in the start script
22 # Run the script with the args: nonsecure|secure timeout=30
23
24 print_usage() {
25     echo "Usage: ./basic_test.sh nonsecure|secure timeout=30"
26     exit 1
27 }
28
29 if [ $# -ne 2 ]; then
30     print_usage
31 fi
32 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
33     print_usage
34 fi
35
36 timeout=$(echo "$2" | cut -d'=' -f2)
37 regexp_for_number='^[0-9]+$'
38
39 if ! [[ $timeout =~ $regexp_for_number ]] ; then
40    echo "error:"$timeout" Not a number"
41    exit 1
42 else
43     if [ $timeout -le 0 ]; then
44         echo "Timeout value must be greater than zero"
45         exit 1
46     fi
47 fi
48
49 if [ $1 == "nonsecure" ]; then
50     # Default http port for the simulator
51     PORT=7075
52     # Set http protocol
53     HTTPX="http"
54 else
55     #Default https port for the simulator
56     PORT=7175
57     # Set https protocol
58     HTTPX="https"
59 fi
60
61 . ../common/test_common.sh
62
63 echo "=== Kafka message dispatcher hello world ==="
64 RESULT="OK"
65 do_curl GET / 200
66
67 echo "=== Reset force delay ==="
68 RESULT="Force delay has been resetted for all dispatcher responses"
69 do_curl POST /dispatcheradmin/forcedelay 200
70
71 # asynch error test case
72 echo "=== Put policy: shall publish and consume time-out ==="
73 req_id=$(get_random_number)
74 res=$(cat jsonfiles/timeout_response.json)
75 RESULT="json:$res"
76 # asynch callout
77 do_curl PUT  /policytypes/ANR/kafkadispatcher/alpha 408 jsonfiles/alpha_policy.json $req_id &
78 proc_id=$!
79 sleep $timeout
80 # after time out duration, publish the event
81 publish_response_event $req_id kafkatopicres
82 # wait until the main process to be completed
83 wait $proc_id
84
85 # asynch success test case after 10s
86 echo "=== Put policy: shall publish and consume success at least 10 secs later ==="
87 req_id=$(get_random_number)
88 RESULT=""
89 # asynch callout
90 do_curl PUT  /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
91 proc_id=$!
92 sleep 10
93 # after 10s, publish the event
94 publish_response_event $req_id kafkatopicres2
95 # wait until the main process to be completed
96 wait $proc_id
97
98 # asynch error test case
99 echo "=== Get policy status: shall publish and consume time-out ==="
100 req_id=$(get_random_number)
101 res=$(cat jsonfiles/timeout_response.json)
102 RESULT="json:$res"
103 # asynch callout
104 do_curl GET  /policytypes/STD_2/kafkadispatcher/alpha/status 408 jsonfiles/alpha_policy.json $req_id &
105 proc_id=$!
106 sleep $timeout
107 # after time out duration, publish the event
108 publish_response_event $req_id kafkatopicres3
109 # wait until the main process to be completed
110 wait $proc_id
111
112 # asynch success test case after 10s
113 echo "=== Get policy status: shall publish and consume success at least 15 secs later ==="
114 req_id=$(get_random_number)
115 RESULT=""
116 # asynch callout
117 do_curl GET  /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json $req_id &
118 proc_id=$!
119 sleep 15
120 # after 15s, publish the event
121 publish_response_event $req_id kafkatopicres
122 # wait until the main process to be completed
123 wait $proc_id
124
125 # asynch success test case without any delay
126 echo "=== Delete policy: shall publish and consume success ==="
127 req_id=$(get_random_number)
128 RESULT=""
129 # asynch callout
130 do_curl DELETE  /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
131 proc_id=$!
132 publish_response_event $req_id kafkatopicres2
133 # wait until the main process to be completed
134 wait $proc_id
135
136
137 echo "********************"
138 echo "*** All tests ok ***"
139 echo "********************"