diff --git a/test/JBCS-1236/testit.sh b/test/JBCS-1236/testit.sh
index 4f004d107..7e4ca1359 100644
--- a/test/JBCS-1236/testit.sh
+++ b/test/JBCS-1236/testit.sh
@@ -17,7 +17,7 @@ runtomcatbatch() {
for i in $(seq $t 10);
do
- tomcat_start $i 0
+ tomcat_start $i
done
tomcat_count=$(expr 3 + 11 - $t)
@@ -52,7 +52,7 @@ runtomcatbatch() {
# stop the tomcats
for i in $(seq $t 10);
do
- tomcat_shutdown $i 0
+ tomcat_shutdown $i
done
tomcat_wait_for_n_nodes 3
diff --git a/test/MODCLUSTER-640/testit.sh b/test/MODCLUSTER-640/testit.sh
index d2d8e56f5..1cc75be0d 100755
--- a/test/MODCLUSTER-640/testit.sh
+++ b/test/MODCLUSTER-640/testit.sh
@@ -31,8 +31,8 @@ tomcat_start_two
tomcat_wait_for_n_nodes 2
# copy the webapp in the tomcats
-docker cp $PREFIX/webapp1 tomcat8080:/usr/local/tomcat/webapps/webapp1
-docker cp $PREFIX/webapp1 tomcat8081:/usr/local/tomcat/webapps/webapp1
+docker cp $PREFIX/webapp1 tomcat1:/usr/local/tomcat/webapps/webapp1
+docker cp $PREFIX/webapp1 tomcat2:/usr/local/tomcat/webapps/webapp1
sleep 12
diff --git a/test/MODCLUSTER-734/testit.sh b/test/MODCLUSTER-734/testit.sh
index 6b0337025..2bbf37e61 100755
--- a/test/MODCLUSTER-734/testit.sh
+++ b/test/MODCLUSTER-734/testit.sh
@@ -24,15 +24,15 @@ httpd_wait_until_ready || exit 1
sleep 10
-# start tomcat8080 and tomcat8081.
+# start tomcat1 and tomcat2
tomcat_start_two
# wait until they are in mod_proxy_cluster tables
tomcat_wait_for_n_nodes 2
-# copy the test page in ROOT to tomcat8080
-docker cp $PREFIX/ROOT tomcat8080:/usr/local/tomcat/webapps/ROOT
-docker cp $PREFIX/ROOT_OK tomcat8081:/usr/local/tomcat/webapps/ROOT
+# copy the test page in ROOT to tomcat1
+docker cp $PREFIX/ROOT tomcat1:/usr/local/tomcat/webapps/ROOT
+docker cp $PREFIX/ROOT_OK tomcat8082:/usr/local/tomcat/webapps/ROOT
# after a while the health check will get the Under maintenance status.jsp
# and mark the node not OK.
diff --git a/test/MODCLUSTER-785/testit.sh b/test/MODCLUSTER-785/testit.sh
index 377dab638..89dff7ead 100755
--- a/test/MODCLUSTER-785/testit.sh
+++ b/test/MODCLUSTER-785/testit.sh
@@ -26,7 +26,7 @@ tomcat_start 1
# wait until tomcat1 is in mod_proxy_cluster tables
tomcat_wait_for_n_nodes 1
-# copy the test page in app to tomcat8080
+# copy the test page in app to tomcat1
docker cp $PREFIX/app tomcat1:/usr/local/tomcat/webapps/app
# check that the app is answering
@@ -58,7 +58,7 @@ tomcat_start 1
# wait until tomcat1 is in mod_proxy_cluster tables
tomcat_wait_for_n_nodes 1
-# copy the test page in app to tomcat8080
+# copy the test page in app to tomcat1
docker cp $PREFIX/app tomcat1:/usr/local/tomcat/webapps/app
sleep 15
diff --git a/test/basetests.sh b/test/basetests.sh
index afdbf6aef..d1da736c8 100644
--- a/test/basetests.sh
+++ b/test/basetests.sh
@@ -9,10 +9,10 @@ httpd_run || exit 1
# Start 2 tomcats, on 8080 and 8081
tomcat_start_two || exit 1
-tomcat_wait_for_n_nodes 2 || exit 1
+tomcat_wait_for_n_nodes 2 || exit 1
# Copy testapp and wait for its start
-docker cp testapp tomcat8081:/usr/local/tomcat/webapps
+docker cp testapp tomcat2:/usr/local/tomcat/webapps
# The above statement relies on 'autoDeploy' to be enabled in Tomcat; and while the scan interval of auto deploy is 10 seconds,
# this needs to be adequately higher to propagate the MCMP commands to the reverse proxies in time.
@@ -39,12 +39,12 @@ iter=0
while [ $iter -lt $ITERATION_COUNT ]
do
echo "Loop stopping starting the same tomcat iter: $iter"
- nohup docker run --network=host -e tomcat_port=8080 --name tomcat8080 ${IMG} &
+ tomcat_start 1
sleep 12
tomcat_wait_for_n_nodes 1 || exit 1
- docker exec tomcat8080 /usr/local/tomcat/bin/shutdown.sh
+ tomcat_shutdown 1
tomcat_wait_for_n_nodes 0 || exit 1
- docker container rm tomcat8080
+ tomcat_remove 1
iter=$(expr $iter + 1)
done
diff --git a/test/hangingtests.sh b/test/hangingtests.sh
index bbfd98cdc..0b596ca79 100644
--- a/test/hangingtests.sh
+++ b/test/hangingtests.sh
@@ -40,24 +40,22 @@ EOF
# Check that hanging tomcat will be removed
echo "hanging a tomcat checking it is removed after a while no requests"
-PORT=8081
-nohup docker run --network=host -e tomcat_port=${PORT} -e tomcat_shutdown_port=true --name tomcat${PORT} ${IMG} &
-PORT=8080
-nohup docker run --network=host -e tomcat_port=${PORT} -e tomcat_shutdown_port=true --name tomcat${PORT} ${IMG} &
+tomcat_start_two
sleep 10
tomcat_wait_for_n_nodes 2 || exit 1
# curlloop.sh checks for http://localhost:8000/testapp/test.jsp
-docker cp testapp tomcat8080:/usr/local/tomcat/webapps
-docker cp testapp tomcat8081:/usr/local/tomcat/webapps
-docker cp setenv.sh tomcat${PORT}:/usr/local/tomcat/bin
-docker commit tomcat${PORT} ${IMG}-debug
-docker stop tomcat${PORT}
+docker cp testapp tomcat1:/usr/local/tomcat/webapps
+docker cp testapp tomcat2:/usr/local/tomcat/webapps
+
+docker cp setenv.sh tomcat1:/usr/local/tomcat/bin
+docker commit tomcat1 ${IMG}-debug
+tomcat_remove 1
tomcat_wait_for_n_nodes 1
docker container rm tomcat${PORT}
# Start the node.
-nohup docker run --network=host -e tomcat_port=${PORT} -e tomcat_shutdown_port=true --name tomcat${PORT} ${IMG}-debug &
+IMG=${IMG}-debug tomcat_start 1
sleep 10
-docker exec tomcat${PORT} jdb -attach 6660 < continue.txt
+docker exec tomcat1 jdb -attach 6660 < continue.txt
tomcat_wait_for_n_nodes 2 || exit 1
echo "2 tomcat started"
# Hang the node,
@@ -87,9 +85,7 @@ tomcat_wait_for_n_nodes 2 || exit 1
# Same test with requets but stop the other tomcat
echo "single hanging tomcat removed after a while with requests"
-PORT=8081
-docker stop tomcat${PORT}
-docker container rm tomcat${PORT}
+tomcat_remove 2
tomcat_wait_for_n_nodes 1 || exit 1
jdbsuspend
sleep 10
diff --git a/test/includes/common.sh b/test/includes/common.sh
index e7b254f8a..673a746ea 100644
--- a/test/includes/common.sh
+++ b/test/includes/common.sh
@@ -116,33 +116,31 @@ tomcat_create() {
--build-arg TESTSUITE_TOMCAT_CONTEXT=${3:-context.xml}
}
-# Start tomcat$1 container on 127.0.0.$2
-# or 127.0.0.$1 if $2 is not given
-# arguments:
-# $1 tomcat number (required)
-# $2 tomcat's last byte of IPv4 address (if 0 or omitted, equals to $1)
-# $3 tomcat port (if omitted it's 8080 + $1 - 1)
-# $4 tomcat ajp port (if omitted it's 8900 + $1 - 1)
-# $5 tomcat shutdown port (if omitted it's 8005 + $1 - 1)
+# Start tomcat$1 container on 127.0.0.$2 or 127.0.0.$1 if $2 is not given.
+# Ports are set by default as follows
+# * tomcat port 8080 + $1 - 1
+# * tomcat ajp port 8900 + $1 - 1
+# * tomcat shutdown port 8005 + $1 - 1
+# $1 has to be in range [1, 75].
tomcat_start() {
if [ -z "$1" ]; then
echo "tomcat_start called without arguments"
exit 1
fi
+
+ if [ $1 -le 0 ] || [ $1 -gt 75 ]; then
+ echo "tomcat_start called with invalid \$1 value (got $1, allowed [1, 75])"
+ exit 2
+ fi
ADDR="127.0.0.$1"
if [ ${2:-0} -ne 0 ]; then
ADDR="127.0.0.$2"
fi
- local portdef=$(expr 8080 + $1 - 1)
- local ajpdef=$(expr 8900 + $1 - 1)
- local shutdef=$(expr 8005 + $1 - 1)
-
- echo "Starting tomcat$1 on $ADDR"
- nohup docker run --network=host -e tomcat_ajp_port=${4:-$ajpdef} \
- -e tomcat_address=$ADDR \
- -e tomcat_port=${3:-$portdef} \
- -e tomcat_shutdown_port=${5:-$shutdef} \
+ local OFFSET=$(expr $1 - 1)
+ echo "Starting tomcat$1 on $ADDR:$(expr 8080 + $OFFSET)"
+ nohup docker run --network=host -e tomcat_address=$ADDR \
+ -e tomcat_port_offset=$OFFSET \
-e jvm_route=tomcat$1 \
--name tomcat$1 ${IMG} &
ps -q $! > /dev/null
@@ -234,17 +232,17 @@ tomcat_all_remove() {
}
tomcat_start_two() {
- echo "Starting tomcat8080..."
- nohup docker run --network=host -e tomcat_port=8080 -e tomcat_shutdown_port=true --name tomcat8080 ${IMG} &
+ echo "Starting tomcat1..."
+ tomcat_start 1
if [ $? -ne 0 ]; then
- echo "Can't start tomcat8080"
+ echo "Can't start tomcat1"
exit 1
fi
sleep 10
- echo "Starting tomcat8081..."
- nohup docker run --network=host -e tomcat_port=8081 -e tomcat_shutdown_port=true --name tomcat8081 ${IMG} &
+ echo "Starting tomcat2..."
+ tomcat_start 2 1
if [ $? -ne 0 ]; then
- echo "Can't start tomcat8081"
+ echo "Can't start tomcat2"
exit 1
fi
echo "2 Tomcats started..."
@@ -268,7 +266,6 @@ tomcat_start_webapp() {
# arguments:
# $1 tomcat number
# $2 the last segment of IPv4 addr ($1 by default)
-# $3 the shutdown port (8005 + $1 - 1 by default)
tomcat_shutdown() {
ADDR="127.0.0.$1"
if [ $2 -ne 0 ]; then
@@ -276,7 +273,7 @@ tomcat_shutdown() {
fi
echo "shutting down tomcat$1 with address: $ADDR"
- echo "SHUTDOWN" | nc $ADDR ${3:-$(expr 8005 + $1 - 1)}
+ echo "SHUTDOWN" | nc $ADDR $(expr 8005 + $1 - 1)
}
# Remove the docker image tomcat$1
diff --git a/test/maintests.sh b/test/maintests.sh
index 6a90a3a85..40b9d818a 100644
--- a/test/maintests.sh
+++ b/test/maintests.sh
@@ -23,7 +23,7 @@ tomcat_start_two || exit 1
tomcat_wait_for_n_nodes 2 || exit 1
# Copy testapp and wait for its start
-docker cp testapp tomcat8081:/usr/local/tomcat/webapps
+docker cp testapp tomcat2:/usr/local/tomcat/webapps
sleep 12
@@ -42,7 +42,7 @@ if [ "${NEWCO}" != "" ]; then
fi
# Copy testapp and wait for starting
-docker cp testapp tomcat8080:/usr/local/tomcat/webapps
+docker cp testapp tomcat1:/usr/local/tomcat/webapps
sleep 12
# Sticky (yes there are 2 apps now)
@@ -89,7 +89,8 @@ echotestlabel "sticky: stopping one node and doing requests..."
NODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }')
echo $NODE
PORT=$(curl http://localhost:6666/mod_cluster_manager | grep Node | grep $NODE | sed 's:)::' | awk -F : '{ print $3 } ')
-echo "Will stop ${PORT} corresponding to ${NODE} and cookie: ${NEWCO}"
+NAME=$(expr ${PORT} - 8080 + 1)
+echo "Will stop tomcat$NAME corresponding to ${NODE} and cookie: ${NEWCO}"
CODE="200"
i=0
while [ "$CODE" == "200" ]
@@ -101,9 +102,8 @@ do
CODE=$(curl -s -o /dev/null -w "%{http_code}" --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp)
if [ $i -eq 0 ]; then
# stop the tomcat
- echo "tomcat${PORT} being stopped"
- docker stop tomcat${PORT}
- docker container rm tomcat${PORT}
+ echo "tomcat${NAME} being stopped"
+ tomcat_remove $NAME
fi
i=$(expr $i + 1)
done
@@ -114,16 +114,15 @@ if [ ${CODE} != "200" ]; then
fi
# Restart the tomcat
-nohup docker run --network=host -e tomcat_port=${PORT} -e tomcat_shutdown_port=true --name tomcat${PORT} ${IMG} &
-sleep 10
+tomcat_start ${NAME}
# Now try to test the websocket
echotestlabel "testing websocket"
# The websocket-hello app is at: https://github.com/jfclere/httpd_websocket
-docker cp websocket-hello-0.0.1.war tomcat8080:/usr/local/tomcat/webapps
-docker cp websocket-hello-0.0.1.war tomcat8081:/usr/local/tomcat/webapps
+docker cp websocket-hello-0.0.1.war tomcat1:/usr/local/tomcat/webapps
+docker cp websocket-hello-0.0.1.war tomcat2:/usr/local/tomcat/webapps
# Put the testapp in the tomcat we restarted.
-docker cp testapp tomcat${PORT}:/usr/local/tomcat/webapps
+docker cp testapp tomcat${NAME}:/usr/local/tomcat/webapps
sleep 12
mvn -f pom-groovy.xml install
java -jar target/test-1.0.jar WebSocketsTest
@@ -135,8 +134,8 @@ fi
#
# Test a keepalived connection finds the 2 webapps on each tomcat
echotestlabel "Testing keepalived with 2 webapps on each tomcat"
-docker cp testapp tomcat8080:/usr/local/tomcat/webapps/testapp1
-docker cp testapp tomcat8081:/usr/local/tomcat/webapps/testapp2
+docker cp testapp tomcat1:/usr/local/tomcat/webapps/testapp1
+docker cp testapp tomcat2:/usr/local/tomcat/webapps/testapp2
sleep 10
java -jar target/test-1.0.jar HTTPTest
if [ $? -ne 0 ]; then
@@ -147,16 +146,15 @@ fi
#
# Test virtual host
echotestlabel "Testing virtual hosts"
-docker cp tomcat8081:/usr/local/tomcat/conf/server.xml .
+docker cp tomcat2:/usr/local/tomcat/conf/server.xml .
sed '/Host name=.*/i ' server.xml > new.xml
-docker cp new.xml tomcat8081:/usr/local/tomcat/conf/server.xml
-docker cp examples tomcat8081:/usr/local/tomcat
-docker commit tomcat8081 ${IMG}-temporary
-docker stop tomcat8081
-docker container rm tomcat8081
+docker cp new.xml tomcat2:/usr/local/tomcat/conf/server.xml
+docker cp examples tomcat2:/usr/local/tomcat
+docker commit tomcat2 ${IMG}-temporary
+tomcat_remove 2
tomcat_wait_for_n_nodes 1
# Start the node.
-nohup docker run --network=host -e tomcat_port=8081 -e tomcat_shutdown_port=true --name tomcat8081 ${IMG}-temporary &
+IMG=${IMG}-temporary tomcat_start 2 &
tomcat_wait_for_n_nodes 2 || exit 1
# Basically curl --header "Host: example.com" http://127.0.0.1:8000/test/test.jsp gives 200
# in fact the headers are:
@@ -190,8 +188,8 @@ if [ ${CODE} != "404" ]; then
fi
# Shutdown the 2 tomcats
-docker exec tomcat8080 /usr/local/tomcat/bin/shutdown.sh
-docker exec tomcat8081 /usr/local/tomcat/bin/shutdown.sh
+tomcat_remove 1
+tomcat_remove 2
tomcat_wait_for_n_nodes 0
docker container rm tomcat8080
docker container rm tomcat8081
diff --git a/test/testsuite.sh b/test/testsuite.sh
index a70f02da5..7663b7f3a 100644
--- a/test/testsuite.sh
+++ b/test/testsuite.sh
@@ -43,6 +43,7 @@ if [ ! -d tomcat/target ]; then
exit 4
fi
+echo -n "Creating docker containers..."
if [ ! -z ${DEBUG+x} ]; then
httpd_create || exit 2
tomcat_create || exit 3
@@ -50,6 +51,7 @@ else
httpd_create > /dev/null 2>&1 || exit 2
tomcat_create > /dev/null 2>&1 || exit 3
fi
+echo " Done"
# clean everything at first
echo -n "Cleaning possibly running containers..."
@@ -99,8 +101,10 @@ MPC_CONF=httpd/mod_lbmethod_cluster.conf run_test MODCLUSTER-794/testit.sh "MO
res=$(expr $res + $?)
-echo "Clean remaining httpd containers"
-httpd_all_clean
+echo -n "Cleaning containers if any..."
+httpd_all_clean > /dev/null 2>&1
+tomcat_all_remove > /dev/null 2>&1
+echo " Done"
if [ $res -eq 0 ]; then
echo "Tests finished successfully!"
diff --git a/test/tomcat/Dockerfile b/test/tomcat/Dockerfile
index a05af043b..f49dd626a 100644
--- a/test/tomcat/Dockerfile
+++ b/test/tomcat/Dockerfile
@@ -17,13 +17,10 @@ COPY $TESTSUITE_TOMCAT_CONTEXT ./conf/context.xml
COPY start.sh ./
RUN chmod +x start.sh
-
-ENV tomcat_port=
-ENV tomcat_shutdown_port=
-ENV tomcat_ajp_port=
ENV cluster_port=6666
ENV jvm_route=
ENV tomcat_address=
+ENV tomcat_port_offset=0
CMD ["./start.sh"]
diff --git a/test/tomcat/server.xml b/test/tomcat/server.xml
index 3547b1527..80d9ed6cb 100644
--- a/test/tomcat/server.xml
+++ b/test/tomcat/server.xml
@@ -19,9 +19,16 @@
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
-
-
-
+
+
+
-
+ redirectPort="8443"
+ portOffset="port_offset" />