Skip to content

Commit c8e38a5

Browse files
committed
test: Rework provisioning of containers, add kill option for tomcat
Containers are now using custom docker network with DNS Containers are now using their container names instead of localhost/IPs Parameters/Options now reflect the actual usage
1 parent d3c758b commit c8e38a5

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

test/includes/common.sh

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ httpd_start() {
6767
echo " NAME: ${MPC_NAME:-httpd-mod_proxy_cluster}"
6868
echo "You can config those with envars MPC_SOURCES, MPC_BRANCH, MPC_CONF, MPC_NAME respectively"
6969
fi
70-
docker run -d --network=host --ulimit nofile=65536:65536 --name ${MPC_NAME:-httpd-mod_proxy_cluster} \
70+
docker run -d --network=mod_proxy_cluster_testsuite_net -p 8090:8090 \
71+
--ulimit nofile=65536:65536 --name ${MPC_NAME:-httpd-mod_proxy_cluster} \
72+
-e MPC_NAME=${MPC_NAME:-httpd-mod_proxy_cluster} \
7173
-e CONF=${MPC_CONF:-httpd/mod_proxy_cluster.conf} \
7274
$HTTPD_IMG
7375

@@ -110,28 +112,27 @@ clean_and_exit() {
110112
# By passing arguments you can change
111113
# $1 tomcat version (default is 10.1, see tomcat/Dockerfile)
112114
# $2 tomcat config file (default is server.xml)
113-
# $3 tomcat context file (default is context.xml)
114115
tomcat_create() {
115116
if [ -z "$1" ]; then
116117
docker build -t $IMG -f tomcat/Containerfile tomcat/ \
117-
--build-arg TESTSUITE_TOMCAT_CONFIG=${2:-server.xml} \
118-
--build-arg TESTSUITE_TOMCAT_CONTEXT=${3:-context.xml}
118+
--build-arg TESTSUITE_TOMCAT_CONFIG=server.xml
119119
else
120120
docker build -t $IMG -f tomcat/Containerfile tomcat/ \
121121
--build-arg TESTSUITE_TOMCAT_VERSION=$1 \
122-
--build-arg TESTSUITE_TOMCAT_CONFIG=${2:-server.xml} \
123-
--build-arg TESTSUITE_TOMCAT_CONTEXT=${3:-context.xml}
122+
--build-arg TESTSUITE_TOMCAT_CONFIG=${2:-server.xml}
124123
fi
125124
}
126125

127-
# Start tomcat$1 container on $2 or 127.0.0.$1 if $2 is not given.
128-
# Ports are set by default as follows
129-
# * tomcat port 8080 + $1 - 1
130-
# * tomcat ajp port 8900 + $1 - 1
131-
# * tomcat shutdown port 8005 + $1 - 1
132-
# $1 has to be in range [1, 75].
133-
# Proxy's IP can be specified by $3 (default: 127.0.0.1) and its
134-
# port with $4 (default: 8090).
126+
# Start tomcat$1 container
127+
#
128+
# You can change the defaults by using following variables:
129+
# * PORT (default 8080)
130+
# * SHUTDOWN_PORT (default 8005)
131+
# * AJP_PORT (default 8900)
132+
# * PROXY_PORT (default 8090)
133+
# * OFFSET (applied to all ports, default $1 - 1)
134+
# * PROXY_NAME (default $MPC_NAME)
135+
# By default, only the shutdown port is exposed
135136
tomcat_start() {
136137
if [ -z "$1" ]; then
137138
echo "tomcat_start called without arguments"
@@ -142,19 +143,22 @@ tomcat_start() {
142143
echo "tomcat_start called with invalid \$1 value (got $1, allowed [1, 75])"
143144
exit 2
144145
fi
145-
ADDR="127.0.0.$1"
146-
if [ ! -z "$2" ]; then
147-
ADDR="$2"
148-
fi
149146

150-
local OFFSET=$(expr $1 - 1)
151-
echo "Starting tomcat$1 on $ADDR:$(expr 8080 + $OFFSET)"
152-
nohup docker run --network=host -e tomcat_address=$ADDR \
153-
-e tomcat_port_offset=$OFFSET \
147+
local DEFAULT_OFFSET=$(expr $1 - 1)
148+
local shutport=$(expr ${SHUTDOWN_PORT:-8005} + $DEFAULT_OFFSET)
149+
150+
echo "Starting tomcat$1"
151+
nohup docker run --network=mod_proxy_cluster_testsuite_net \
152+
-p $shutport:$shutport \
153+
-e tomcat_address=tomcat$1 \
154+
-e tomcat_port_offset=${OFFSET:-$DEFAULT_OFFSET} \
154155
-e jvm_route=tomcat$1 \
155-
-e cluster_address=${3:-127.0.0.1} \
156-
-e cluster_port=${4:-8090} \
157-
--name tomcat$1 ${IMG} &
156+
-e proxy_address=${PROXY_NAME:-$MPC_NAME} \
157+
-e tomcat_port=${PORT:-8080} \
158+
-e tomcat_shutdown_port=${SHUTDOWN_PORT:-8005} \
159+
-e tomcat_ajp_port=${AJP_PORT:-8900} \
160+
-e proxy_port=${PROXY_PORT:-8090} \
161+
--name tomcat$1 ${IMG} &
158162
ps -q $! > /dev/null
159163
if [ $? -ne 0 ]; then
160164
echo "docker run for tomcat$1 failed"
@@ -255,22 +259,36 @@ tomcat_start_webapp() {
255259
# $1 tomcat number
256260
# $2 the last segment of IPv4 addr ($1 by default)
257261
tomcat_shutdown() {
258-
ADDR="127.0.0.$1"
259-
if [ ! -z "$2" ]; then
260-
ADDR=$2
262+
if [ -z "$1" ]; then
263+
echo "An argument is required"
264+
exit 1
261265
fi
262266

263-
echo "shutting down tomcat$1 with address: $ADDR"
264-
echo "SHUTDOWN" | nc $ADDR $(expr 8005 + $1 - 1)
267+
echo "shutting down tomcat$1"
268+
echo "SHUTDOWN" | nc localhost $(expr ${SHUTDOWN_PORT:-8005} + $1 - 1)
265269
}
266270

267271
# Remove the docker image tomcat$1
268272
# Note: To succesfully remove an image it needs to be stopped
269273
tomcat_remove() {
274+
if [ -z "$1" ]; then
275+
echo "An argument is required"
276+
exit 1
277+
fi
270278
docker stop tomcat$1 > /dev/null 2>&1
271279
docker rm tomcat$1
272280
}
273281

282+
# Kills the tomcat process in the given tomcat container, but does not
283+
# remove the container itself (it will still exist incl. docker DNS records)
284+
tomcat_kill() {
285+
if [ -z "$1" ]; then
286+
echo "An argument is required"
287+
exit 1
288+
fi
289+
docker exec tomcat$1 pkill -9 java
290+
}
291+
274292
#
275293
# Run a load test for the given tomcat$1 using ab
276294
tomcat_run_ab() {

0 commit comments

Comments
 (0)