Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Use portOffset in Tomcat containers #157

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/JBCS-1236/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/MODCLUSTER-640/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions test/MODCLUSTER-734/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions test/MODCLUSTER-785/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions test/basetests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
24 changes: 10 additions & 14 deletions test/hangingtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
47 changes: 22 additions & 25 deletions test/includes/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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..."
Expand All @@ -268,15 +266,14 @@ 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
ADDR="127.0.0.$2"
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
Expand Down
42 changes: 20 additions & 22 deletions test/maintests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down Expand Up @@ -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" ]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 <Host name=\"example.com\" appBase="examples" />' 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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions test/testsuite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ 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
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..."
Expand Down Expand Up @@ -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!"
Expand Down
5 changes: 1 addition & 4 deletions test/tomcat/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Loading