Skip to content

Commit fbf3ee8

Browse files
committed
Add automatic test for nacos
1 parent 8512802 commit fbf3ee8

File tree

1 file changed

+97
-16
lines changed

1 file changed

+97
-16
lines changed

testExamples.sh

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ localTest() {
4545
fi
4646
}
4747

48-
## Cloud
49-
cloudTest() {
50-
echo "Starting Cloud test"
48+
## Cloud-Eureka
49+
cloudEurekaTest() {
50+
echo "Starting Cloud Eureka test"
5151

5252
# Run environment
5353
./gradlew :example:cloud-eureka-server:bootRun -x jar -x classes --console=plain &
@@ -113,29 +113,109 @@ cloudTest() {
113113

114114
# Verify part 1
115115
if [ "$RESPONSE" = "$EXPECTED" ]; then
116-
echo "#-----------------------------#"
117-
echo "| Cloud example part 1 works! |"
118-
echo "#-----------------------------#"
116+
echo "#------------------------------------#"
117+
echo "| Cloud Eureka example part 1 works! |"
118+
echo "#------------------------------------#"
119119
else
120-
echo "#------------------------------#"
121-
echo "| Cloud example part 1 failed! |"
122-
echo "#------------------------------#"
120+
echo "#-------------------------------------#"
121+
echo "| Cloud Eureka example part 1 failed! |"
122+
echo "#-------------------------------------#"
123123
exit 1
124124
fi
125125

126126
# Verify part 2
127127
if [ "$RESPONSE2" = "$EXPECTED" ]; then
128-
echo "#-----------------------------#"
129-
echo "| Cloud example part 2 works! |"
130-
echo "#-----------------------------#"
128+
echo "#------------------------------------#"
129+
echo "| Cloud Eureka example part 2 works! |"
130+
echo "#------------------------------------#"
131131
else
132-
echo "#------------------------------#"
133-
echo "| Cloud example part 2 failed! |"
134-
echo "#------------------------------#"
132+
echo "#-------------------------------------#"
133+
echo "| Cloud Eureka example part 2 failed! |"
134+
echo "#-------------------------------------#"
135135
exit 1
136136
fi
137137
}
138138

139+
## Cloud-Nacos
140+
cloudNacosTest() {
141+
echo "Starting Cloud Nacos test"
142+
143+
# Run environment
144+
docker pull nacos/nacos-server
145+
NACOS=`docker run --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server`
146+
sleep 10s # Wait for the nacos server to start
147+
148+
./gradlew :example:cloud-grpc-server-nacos:bootRun -x jar -x classes --console=plain &
149+
CLOUD_SERVER=$!
150+
sleep 10s # Wait for the server to start
151+
152+
./gradlew :example:cloud-grpc-client-nacos:bootRun -x jar -x classes --console=plain &
153+
CLOUD_CLIENT=$!
154+
sleep 30s # Wait for the client to start and the server to be ready
155+
sleep 60s # Wait for the discovery service to refresh
156+
157+
# Test
158+
RESPONSE=$(curl -s localhost:8080/)
159+
echo "Response:"
160+
echo "$RESPONSE"
161+
EXPECTED=$(echo -e "Hello ==> Michael")
162+
echo "Expected:"
163+
echo "$EXPECTED"
164+
sleep 1s # Give the user a chance to look at the result
165+
166+
# Crash server
167+
kill -s TERM $CLOUD_SERVER
168+
echo "The server crashed (expected)"
169+
sleep 1s # Wait for the shutdown logs to pass
170+
171+
# and restart server
172+
./gradlew :example:cloud-grpc-server-nacos:bootRun -x jar -x classes --console=plain &
173+
CLOUD_SERVER=$!
174+
sleep 30s # Wait for the server to start
175+
sleep 60s # Wait for the discovery service to refresh
176+
177+
# Test again
178+
RESPONSE2=$(curl -s localhost:8080/)
179+
echo "Response:"
180+
echo "$RESPONSE2"
181+
EXPECTED=$(echo -e "Hello ==> Michael")
182+
echo "Expected:"
183+
echo "$EXPECTED"
184+
sleep 1s # Give the user a chance to look at the result
185+
186+
# Shutdown
187+
echo "Triggering shutdown"
188+
docker stop $NACOS
189+
docker rm -f $NACOS
190+
kill -s TERM $CLOUD_SERVER
191+
kill -s TERM $CLOUD_CLIENT
192+
sleep 1s # Wait for the shutdown logs to pass
193+
194+
# Verify part 1
195+
if [ "$RESPONSE" = "$EXPECTED" ]; then
196+
echo "#-----------------------------------#"
197+
echo "| Cloud Nacos example part 1 works! |"
198+
echo "#-----------------------------------#"
199+
else
200+
echo "#------------------------------------#"
201+
echo "| Cloud Nacos example part 1 failed! |"
202+
echo "#------------------------------------#"
203+
exit 1
204+
fi
205+
206+
# Verify part 2
207+
if [ "$RESPONSE2" = "$EXPECTED" ]; then
208+
echo "#-----------------------------------#"
209+
echo "| Cloud Nacos example part 2 works! |"
210+
echo "#-----------------------------------#"
211+
else
212+
echo "#------------------------------------#"
213+
echo "| Cloud Nacos example part 2 failed! |"
214+
echo "#------------------------------------#"
215+
exit 1
216+
fi
217+
}
218+
139219
## Security Basic Auth
140220
securityBasicAuthTest() {
141221
echo "Starting Security Basic Auth test"
@@ -218,6 +298,7 @@ securityBearerAuthTest() {
218298

219299
## Tests
220300
localTest
221-
cloudTest
301+
cloudEurekaTest
302+
cloudNacosTest
222303
securityBasicAuthTest
223304
#securityBearerAuthTest

0 commit comments

Comments
 (0)