forked from grpc-ecosystem/grpc-spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testExamples.sh
220 lines (192 loc) · 4.9 KB
/
testExamples.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
#!/bin/bash
./gradlew clean
./gradlew build
sleep 2s
## Local
localTest() {
echo "Starting Local test"
# Run environment
./gradlew :example:local-grpc-server:bootRun -x jar -x classes &
LOCAL_SERVER=$!
sleep 10s
./gradlew :example:local-grpc-client:bootRun -x jar -x classes &
LOCAL_CLIENT=$!
sleep 30s
# Test
RESPONSE=$(curl -s localhost:8080/)
echo "Response:"
echo "$RESPONSE"
EXPECTED=$(echo -e "Hello ==> Michael")
echo "Expected:"
echo "$EXPECTED"
sleep 2s
# Shutdown
echo "Triggering shutdown"
kill -s TERM $LOCAL_SERVER
kill -s TERM $LOCAL_CLIENT
sleep 5s
# Verify
if [ "$RESPONSE" = "$EXPECTED" ]; then
echo "#----------------------#"
echo "| Local example works! |"
echo "#----------------------#"
else
echo "#-----------------------#"
echo "| Local example failed! |"
echo "#-----------------------#"
exit 1
fi
sleep 30s
}
## Cloud
cloudTest() {
echo "Starting Cloud test"
# Run environment
./gradlew :example:cloud-eureka-server:bootRun -x jar -x classes &
EUREKA=$!
sleep 10s
mkdir -p zipkin
cd zipkin
echo "*" > .gitignore
if [ ! -f zipkin.jar ]; then
curl -sSL https://zipkin.io/quickstart.sh | bash -s
fi
java -jar zipkin.jar &
ZIPKIN=$!
sleep 10s
cd ..
./gradlew :example:cloud-grpc-server:bootRun -x jar -x classes &
CLOUD_SERVER=$!
sleep 30s
./gradlew :example:cloud-grpc-client:bootRun -x jar -x classes &
CLOUD_CLIENT=$!
sleep 30s
# Test
RESPONSE=$(curl -s localhost:8080/)
echo "Response:"
echo "$RESPONSE"
EXPECTED=$(echo -e "Hello ==> Michael")
echo "Expected:"
echo "$EXPECTED"
sleep 2s
# Crash server
kill -s TERM $CLOUD_SERVER
echo "The server crashed (expected)"
sleep 10s
# and restart server
./gradlew :example:cloud-grpc-server:bootRun -x jar -x classes &
CLOUD_SERVER=$!
sleep 60s
# Test again
RESPONSE2=$(curl -s localhost:8080/)
echo "Response:"
echo "$RESPONSE"
EXPECTED=$(echo -e "Hello ==> Michael")
echo "Expected:"
echo "$EXPECTED"
sleep 2s
# Shutdown
echo "Triggering shutdown"
kill -s TERM $EUREKA
kill -s TERM $ZIPKIN
kill -s TERM $CLOUD_SERVER
kill -s TERM $CLOUD_CLIENT
sleep 5s
# Verify part 1
if [ "$RESPONSE" = "$EXPECTED" ]; then
echo "#-----------------------------#"
echo "| Cloud example part 1 works! |"
echo "#-----------------------------#"
else
echo "#------------------------------#"
echo "| Cloud example part 1 failed! |"
echo "#------------------------------#"
exit 1
fi
# Verify part 2
if [ "$RESPONSE2" = "$EXPECTED" ]; then
echo "#-----------------------------#"
echo "| Cloud example part 2 works! |"
echo "#-----------------------------#"
else
echo "#------------------------------#"
echo "| Cloud example part 2 failed! |"
echo "#------------------------------#"
exit 1
fi
}
## Security Basic Auth
securityBasicAuthTest() {
echo "Starting Security Basic Auth test"
# Run environment
./gradlew :example:security-grpc-server:bootRun -x jar -x classes &
LOCAL_SERVER=$!
sleep 10s
./gradlew :example:security-grpc-client:bootRun -x jar -x classes &
LOCAL_CLIENT=$!
sleep 30s
# Test
RESPONSE=$(curl -s localhost:8080/)
echo "Response:"
echo "$RESPONSE"
EXPECTED=$(echo -e "Input:\n- name: Michael (Changeable via URL param ?name=X)\nRequest-Context:\n- auth user: user (Configure via application.yml)\nResponse:\nHello ==> Michael")
echo "Expected:"
echo "$EXPECTED"
sleep 2s
# Shutdown
echo "Triggering shutdown"
kill -s TERM $LOCAL_SERVER
kill -s TERM $LOCAL_CLIENT
sleep 5s
# Verify
if [ "$RESPONSE" = "$EXPECTED" ]; then
echo "#------------------------------------#"
echo "| Security Basic Auth example works! |"
echo "#------------------------------------#"
else
echo "#-------------------------------------#"
echo "| Security Basic Auth example failed! |"
echo "#-------------------------------------#"
exit 1
fi
}
## Security Bearer Auth
securityBearerAuthTest() {
echo "Starting Security Bearer Auth test"
# Run environment
./gradlew :example:security-grpc-bearerAuth-server:bootRun -x jar -x classes &
LOCAL_SERVER=$!
sleep 10s
./gradlew :example:security-grpc-bearerAuth-client:bootRun -x jar -x classes &
LOCAL_CLIENT=$!
sleep 30s
# Test
RESPONSE=$(curl -s localhost:8080/)
echo "Response:"
echo "$RESPONSE"
EXPECTED=$(echo -e "Input:\nMessage: test, Bearer Token is configured in SecurityConfiguration Class\nResponse:\nHello ==> test")
echo "Expected:"
echo "$EXPECTED"
sleep 2s
# Shutdown
echo "Triggering shutdown"
kill -s TERM $LOCAL_SERVER
kill -s TERM $LOCAL_CLIENT
sleep 5s
# Verify
if [ "$RESPONSE" = "$EXPECTED" ]; then
echo "#-------------------------------------#"
echo "| Security Bearer Auth example works! |"
echo "#-------------------------------------#"
else
echo "#--------------------------------------#"
echo "| Security Bearer Auth example failed! |"
echo "#--------------------------------------#"
exit 1
fi
}
## Tests
localTest
cloudTest
securityBasicAuthTest
#securityBearerAuthTest