diff --git a/.gitignore b/.gitignore index af402a820..8297d4d79 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,12 @@ target/ # Folder usually used for CMake **/build + +# war files (usually in tests) +**/*.war + +# test logs +**/*.logs + +# test nohup files +**/nohup.out diff --git a/test/native/Advertise.c b/test/Advertise.c similarity index 100% rename from test/native/Advertise.c rename to test/Advertise.c diff --git a/test/JBCS-1236/testit.sh b/test/JBCS-1236/testit.sh new file mode 100644 index 000000000..abb9144f8 --- /dev/null +++ b/test/JBCS-1236/testit.sh @@ -0,0 +1,323 @@ +#!/usr/bin/sh + +. includes/common.sh + +httpd_all_clean +tomcat_all_remove +MPC_NAME=JBCS-1236 httpd_run + +# Start a bunch ($1, or 6 if no argument is given) of tomcat +# containers, then test them and stop them +runtomcatbatch() { + if [ $1 ]; then + t=$1 + else + t=5 # default value when no argument is given + fi + + for i in $(seq $t 10); + do + tomcat_start $i 0 + done + + tomcat_count=$(expr 3 + 11 - $t) + tomcat_wait_for_n_nodes $tomcat_count || clean_and_exit + for i in $(seq $t 10); + do + tomcat_start_webapp $i || clean_and_exit + done + + # test the tomcats + sleep 20 + tomcat_all_test_app $tomcat_count + if [ $? -ne 0 ]; then + echo "runtomcatbatch tomcat_all_test_app 9 FAILED!" + clean_and_exit + fi + + # "load test" 9 of them + tomcat_all_run_ab $tomcat_count + if [ $? -ne 0 ]; then + echo "runtomcatbatch tomcat_all_run_ab 9 FAILED!" + clean_and_exit + fi + + # retest + tomcat_all_test_app $tomcat_count + if [ $? -ne 0 ]; then + echo "runtomcatbatch tomcat_all_test_app 9 FAILED!" + clean_and_exit + fi + + # stop the tomcats + for i in $(seq $t 10); + do + tomcat_shutdown $i 0 + done + + tomcat_wait_for_n_nodes 3 + if [ $? -ne 0 ]; then + echo "runtomcatbatch tomcat_wait_for_n_nodes 3 FAILED!" + clean_and_exit + fi + + # remove the tomcats + for i in $(seq $t 10); + do + tomcat_remove $i + done + echo "runtomcatbatch Done!" +} + +# single tomcat testing +# we start the tomcat, put the webapp, test it and later stop and clean up +singlecycle() { + echo "singlecycle: Testing tomcat$1" + R=$1 + if [ "X$2" -eq "Xuseran" ]; then + R=$(expr 1 + $RANDOM % 10 + 10) + R=$(expr $R + 2) + # TODO + tomcat_start $1 $R || clean_and_exit + else + R=0 + tomcat_start $1 $R || clean_and_exit + fi + # Wait for it to start + echo "Testing(0) tomcat$1 waiting..." + while true + do + curl -s http://localhost:6666/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null + if [ $? -eq 0 ]; then + break + fi + sleep 1 + done + echo "Testing(0) tomcat$1 started" + tomcat_start_webapp $1 || clean_and_exit + echo "Testing(0) tomcat$1 with webapp" + while true + do + curl -s http://localhost:6666/mod_cluster_manager | grep /tomcat$1 > /dev/null + if [ $? -eq 0 ]; then + break + fi + curl -s http://localhost:6666/mod_cluster_manager | grep /tomcat$1 + sleep 1 + done + echo "Testing(1) tomcat$1" + tomcat_test_app $1 || clean_and_exit + echo "Testing(2) tomcat$1" + tomcat_test_app $1 || clean_and_exit + tomcat_run_ab $1 || clean_and_exit + echo "Testing(3) tomcat$1" + tomcat_shutdown $1 $R || clean_and_exit + while true + do + curl -s http://localhost:6666/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null + if [ $? -ne 0 ]; then + break + fi + sleep 1 + done + tomcat_remove $1 || clean_and_exit + echo "singlecycle Done tomcat$1" +} + +# Run neverending testing loop of a single tomcat +looptomcatforever() { + while true + do + singlecycle $1 || clean_and_exit + done +} + +# Start a bunch of looping tomcats and kill them after $FOREVER_PAUSE (default is 3600 seconds) +forevertomcat() { + (looptomcatforever 12) & + pid12=$! + (looptomcatforever 13) & + pid13=$! + # wait a little to prevent synchronization + sleep 5 + (looptomcatforever 14) & + pid14=$! + (looptomcatforever 15) & + pid15=$! + (looptomcatforever 16) & + pid16=$! + + sleep ${FOREVER_PAUSE:-3600} + + echo "Doing: kill -15 $pid12 $pid13 $pid14 $pid15 $pid16" + kill -15 $pid12 $pid13 $pid14 $pid15 $pid16 + if [ $? -ne 0 ]; then + echo "kill -15 $pid12 $pid13 $pid14 $pid15 $pid16 failed" + clean_and_exit + fi + echo "Tests done, cleaning" + # stop & remove the containers + tomcat_remove_by_name tomcat12 + tomcat_remove_by_name tomcat13 + tomcat_remove_by_name tomcat14 + tomcat_remove_by_name tomcat15 + tomcat_remove_by_name tomcat16 + sleep 10 +} + +# Start and stop successively (one after another) $1 tomcats +cyclestomcats() { + i=1 + while true + do + i=$(expr $i + 1) + if [ $i -gt $1 ]; then + echo "Looks OK, Done!" + break + fi + singlecycle $i useran || clean_and_exit + done +} + +# run test for https://issues.redhat.com/browse/JBCS-1236 +# basically start and stop random tomcats... +runjbcs1236() { + # start 3 tomcats + tomcat_start 2 0 + tomcat_start 3 0 + tomcat_start 4 0 + tomcat_wait_for_n_nodes 3 || clean_and_exit + # check them + tomcat_start_webapp 2 || clean_and_exit + tomcat_start_webapp 3 || clean_and_exit + tomcat_start_webapp 4 || clean_and_exit + sleep 20 + tomcat_test_app 2 || clean_and_exit + tomcat_test_app 3 || clean_and_exit + tomcat_test_app 4 || clean_and_exit + + # start a bunch of tomcats, test, shutdown, remove and try in a loop. + runjbcs1236=0 + while true + do + runjbcs1236=$(expr $runjbcs1236 + 1) + if [ $runjbcs1236 -gt 2 ]; then + echo "Looks OK, runjbcs1236 stopping!" + break + fi + # cycle the tomcats + runtomcatbatch + + if [ $? -ne 0 ]; then + echo "runtomcatbatch: runjbcs1236 Failed!" + clean_and_exit + fi + tomcat_shutdown 2 0 + + tomcat_wait_for_n_nodes 2 + if [ $? -ne 0 ]; then + echo "tomcat_wait_for_n_nodes 2: runjbcs1236 Failed!" + clean_and_exit + fi + tomcat_remove 2 + tomcat_start 5 0 + + tomcat_wait_for_n_nodes 3 + if [ $? -ne 0 ]; then + echo "tomcat_wait_for_n_nodes 3: runjbcs1236 Failed!" + clean_and_exit + fi + tomcat_start_webapp 5 + if [ $? -ne 0 ]; then + echo "tomcat_start_webapp 5: runjbcs1236 Failed!" + clean_and_exit + fi + sleep 20 + tomcat_test_app 5 + if [ $? -ne 0 ]; then + echo "tomcat_test_app 5: runjbcs1236 Failed!" + clean_and_exit + fi + # we have 5 3 4 in shared memory + # read 2 + tomcat_start 2 0 + tomcat_wait_for_n_nodes 4 + if [ $? -ne 0 ]; then + echo "tomcat_wait_for_n_nodes 4: runjbcs1236 Failed!" + clean_and_exit + fi + tomcat_start_webapp 2 + if [ $? -ne 0 ]; then + echo "tomcat_start_webapp 2: runjbcs1236 Failed!" + clean_and_exit + fi + sleep 20 + tomcat_test_app 2 + if [ $? -ne 0 ]; then + echo "tomcat_test_app 2: runjbcs1236 Failed!" + clean_and_exit + fi + + sleep 20 + + # we have 5 3 4 2 in shared memory + # if something was wrong 2 points to 5 + tomcat_shutdown 5 0 + + tomcat_wait_for_n_nodes 3 + if [ $? -ne 0 ]; then + echo "tomcat_wait_for_n_nodes 3: runjbcs1236 Failed!" + clean_and_exit + fi + tomcat_remove 5 + + tomcat_test_app 2 + if [ $? -ne 0 ]; then + echo "tomcat_test_app 2: runjbcs1236 Failed!" + clean_and_exit + fi + + tomcat_test_app 3 + if [ $? -ne 0 ]; then + echo "tomcat_test_app 3: runjbcs1236 Failed!" + clean_and_exit + fi + + tomcat_test_app 4 + if [ $? -ne 0 ]; then + echo "tomcat_test_app 4: runjbcs1236 Failed!" + clean_and_exit + fi + echo "runjbcs1236 loop: $runjbcs1236 DONE" + done + + # cleanup + tomcat_shutdown 4 0 + tomcat_shutdown 3 0 + tomcat_shutdown 2 0 + tomcat_wait_for_n_nodes 0 || clean_and_exit + tomcat_remove 2 + tomcat_remove 3 + tomcat_remove 4 +} + +# JBCS-1236 +echo "Testing JBCS-1236" +cyclestomcats ${TOMCAT_CYCLE_COUNT:-10} +if [ $? -ne 0 ]; then + echo "JBCS-1236 cyclestomcats 100 FAILED!" + clean_and_exit +fi +forevertomcat +if [ $? -ne 0 ]; then + echo "JBCS-1236 forevertomcat FAILED!" + clean_and_exit +fi +runjbcs1236 +if [ $? -ne 0 ]; then + echo "JBCS-1236 runjbcs1236 FAILED!" + clean_and_exit +fi + +httpd_shutdown JBCS-1236 +tomcat_all_remove diff --git a/test/native/MODCLUSTER-640/mod_proxy_cluster.conf b/test/MODCLUSTER-640/mod_proxy_cluster.conf similarity index 100% rename from test/native/MODCLUSTER-640/mod_proxy_cluster.conf rename to test/MODCLUSTER-640/mod_proxy_cluster.conf diff --git a/test/MODCLUSTER-640/testit.sh b/test/MODCLUSTER-640/testit.sh new file mode 100755 index 000000000..bca073b40 --- /dev/null +++ b/test/MODCLUSTER-640/testit.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# Shell to test MODCLUSTER-640 + +pwd | grep MODCLUSTER-640 +if [ $? ]; then + PREFIX=MODCLUSTER-640 +else + PREFIX="." +fi + +. includes/common.sh + +# first stop any previously running tests. +tomcat_all_stop +tomcat_all_remove +httpd_all_clean + +# build httpd + mod_proxy_cluster +rm -f nohup.out +MPC_CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/MODCLUSTER-640/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-640 httpd_run + +# wait until httpd is started +httpd_wait_until_ready || exit 1 + + +# start 2 tomcats +tomcat_start_two + +# wait until the tomcats are in mod_proxy_cluster tables +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 + +sleep 10 + +# test the URL +code=$(/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html) +if [ "${code}" != "200" ]; then + echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html" + clean_and_exit +fi +curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root" +if [ $? -eq 0 ]; then + echo "nocanon test failed, we get \"jsr:root\"!!!" + clean_and_exit +fi + +# Test without UseNocanon On +sed 's:UseNocanon On::' $PREFIX/mod_proxy_cluster.conf > $PREFIX/mod_proxy_cluster_new.conf + +docker cp $PREFIX/mod_proxy_cluster_new.conf MODCLUSTER-640:/usr/local/apache2/conf/mod_proxy_cluster.conf +docker exec -it MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart + +# wait until the tomcats are back in mod_proxy_cluster tables +tomcat_wait_for_n_nodes 2 + +# test the URL +code=$(/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html) +if [ "${code}" != "200" ]; then + echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html" + clean_and_exit +fi +curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root" +if [ $? -ne 0 ]; then + echo "NO nocanon test failed, we don't get \"jsr:root\"!!!" + clean_and_exit +fi + +# Test for just a proxypass / nocanon +sed 's:UseNocanon On::' $PREFIX/mod_proxy_cluster.conf > mod_proxy_cluster_new.conf +echo "ProxyPass / balancer://mycluster/ nocanon" >> $PREFIX/mod_proxy_cluster_new.conf + +docker cp $PREFIX/mod_proxy_cluster_new.conf MODCLUSTER-640:/usr/local/apache2/conf/mod_proxy_cluster.conf +docker exec -it MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart + +# wait until the tomcats are back in mod_proxy_cluster tables +tomcat_wait_for_n_nodes 2 + +# test the URL +code=$(/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html) +if [ "${code}" != "200" ]; then + echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html" + clean_and_exit +fi +curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root" +if [ $? -eq 0 ]; then + echo "nocanon test failed, we get \"jsr:root\"!!!" + tomcat_all_remove + clean_and_exit +fi + +# clean tomcats +tomcat_all_remove +# and httpd +httpd_all_clean diff --git a/test/native/MODCLUSTER-640/webapp1/index.html b/test/MODCLUSTER-640/webapp1/index.html similarity index 100% rename from test/native/MODCLUSTER-640/webapp1/index.html rename to test/MODCLUSTER-640/webapp1/index.html diff --git a/test/native/MODCLUSTER-734/ROOT/status.jsp b/test/MODCLUSTER-734/ROOT/status.jsp similarity index 100% rename from test/native/MODCLUSTER-734/ROOT/status.jsp rename to test/MODCLUSTER-734/ROOT/status.jsp diff --git a/test/native/MODCLUSTER-734/ROOT_OK/status.jsp b/test/MODCLUSTER-734/ROOT_OK/status.jsp similarity index 100% rename from test/native/MODCLUSTER-734/ROOT_OK/status.jsp rename to test/MODCLUSTER-734/ROOT_OK/status.jsp diff --git a/test/MODCLUSTER-734/mod_proxy_cluster.conf b/test/MODCLUSTER-734/mod_proxy_cluster.conf new file mode 100644 index 000000000..db0105749 --- /dev/null +++ b/test/MODCLUSTER-734/mod_proxy_cluster.conf @@ -0,0 +1,29 @@ +LoadModule proxy_module modules/mod_proxy.so +LoadModule proxy_ajp_module modules/mod_proxy_ajp.so +LoadModule manager_module modules/mod_manager.so +LoadModule proxy_cluster_module modules/mod_proxy_cluster.so +LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so +LoadModule watchdog_module modules/mod_watchdog.so + +ProxyHCExpr in_maint {hc('body') !~ /Under maintenance/} +ModProxyClusterHCTemplate hcmethod=GET hcexpr=in_maint hcuri=/status.jsp +#ModProxyClusterHCTemplate hcmethod=CPING hcinterval=5 hcpasses=2 hcfails=3 + +Maxnode 505 +Maxhost 1010 +Maxcontext 1100 +Listen 6666 +ManagerBalancerName mycluster + + + EnableMCPMReceive + + Require ip 127.0.0.1 + Require ip ::1 + + + SetHandler mod_cluster-manager + Require ip 127.0.0.1 + Require ip ::1 + + diff --git a/test/MODCLUSTER-734/testit.sh b/test/MODCLUSTER-734/testit.sh new file mode 100755 index 000000000..944e2d233 --- /dev/null +++ b/test/MODCLUSTER-734/testit.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# if ran from main testsuite, change directory +pwd | grep MODCLUSTER-734 +if [ $? ]; then + PREFIX=MODCLUSTER-734 +else + PREFIX="." +fi + +. includes/common.sh + +clean() { + tomcat_all_remove + # clean httpd + docker stop MODCLUSTER-734 + docker rm MODCLUSTER-734 +} + + +# first stop any previously running tests. +tomcat_all_stop +tomcat_all_remove +httpd_all_clean + +# build httpd + mod_proxy_cluster +rm -f nohup.out +MPC_CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/MODCLUSTER-734/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-734 httpd_run + +# wait until httpd is started +httpd_wait_until_ready || clean_and_exit + +sleep 10 + +# start tomcat8080 and tomcat8081. +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 + +# after a while the health check will get the Under maintenance status.jsp +# and mark the node not OK. +sleep 15 +curl -s http://localhost:6666/mod_cluster_manager | grep "Status: NOTOK" +if [ $? -eq 0 ]; then + echo "MODCLUSTER-734 Done!" +else + echo "MODCLUSTER-734 Failed!" + clean + exit 1 +fi + +clean diff --git a/test/native/MODCLUSTER-755/Dockerfile b/test/MODCLUSTER-755/Dockerfile similarity index 100% rename from test/native/MODCLUSTER-755/Dockerfile rename to test/MODCLUSTER-755/Dockerfile diff --git a/test/native/MODCLUSTER-755/Makefile b/test/MODCLUSTER-755/Makefile similarity index 100% rename from test/native/MODCLUSTER-755/Makefile rename to test/MODCLUSTER-755/Makefile diff --git a/test/native/MODCLUSTER-755/README.md b/test/MODCLUSTER-755/README.md similarity index 100% rename from test/native/MODCLUSTER-755/README.md rename to test/MODCLUSTER-755/README.md diff --git a/test/native/MODCLUSTER-755/addwebapp.sh b/test/MODCLUSTER-755/addwebapp.sh similarity index 100% rename from test/native/MODCLUSTER-755/addwebapp.sh rename to test/MODCLUSTER-755/addwebapp.sh diff --git a/test/native/MODCLUSTER-755/files/index.html b/test/MODCLUSTER-755/files/index.html similarity index 100% rename from test/native/MODCLUSTER-755/files/index.html rename to test/MODCLUSTER-755/files/index.html diff --git a/test/native/MODCLUSTER-755/files/server.xml b/test/MODCLUSTER-755/files/server.xml similarity index 100% rename from test/native/MODCLUSTER-755/files/server.xml rename to test/MODCLUSTER-755/files/server.xml diff --git a/test/native/MODCLUSTER-755/files/start.sh b/test/MODCLUSTER-755/files/start.sh similarity index 90% rename from test/native/MODCLUSTER-755/files/start.sh rename to test/MODCLUSTER-755/files/start.sh index efa798ad7..731e985ee 100644 --- a/test/native/MODCLUSTER-755/files/start.sh +++ b/test/MODCLUSTER-755/files/start.sh @@ -6,7 +6,7 @@ NODE_COUNT=1000 -for ((i=0; i <= $NODE_COUNT; i++)) +for i in $(seq 0 $NODE_COUNT) do PORT=`expr $i + 8999` echo " " >>add.txt diff --git a/test/native/MODCLUSTER-734/mod_proxy_cluster.conf b/test/MODCLUSTER-755/mod_proxy_cluster.conf similarity index 100% rename from test/native/MODCLUSTER-734/mod_proxy_cluster.conf rename to test/MODCLUSTER-755/mod_proxy_cluster.conf diff --git a/test/native/MODCLUSTER-755/mcmps.sh b/test/MODCLUSTER-755/testit.sh similarity index 74% rename from test/native/MODCLUSTER-755/mcmps.sh rename to test/MODCLUSTER-755/testit.sh index db8c6dcc8..6c28f54a2 100755 --- a/test/native/MODCLUSTER-755/mcmps.sh +++ b/test/MODCLUSTER-755/testit.sh @@ -6,6 +6,17 @@ # USE_MULTI_APP - if true different webapps are created for each node. # +. includes/common.sh + +httpd_all_clean +tomcat_all_remove + +MPC_CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/MODCLUSTER-755/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-755 httpd_run + +httpd_wait_until_ready + +tomcat_start + NODE_COUNT="${NODE_COUNT:-500}" APP_COUNT="${APP_COUNT:-2}" HTTPD="${HTTPD:-127.0.0.1:6666/}" @@ -15,16 +26,17 @@ echo "NODE_COUNT: ${NODE_COUNT}" echo "APP_COUNT: ${APP_COUNT}" echo "Apache HTTPD MCMP URL: ${HTTPD}" echo "USE_MULTI_APP: $USE_MULTI_APP" + if [ "x$USE_MULTI_APP" = "xtrue" ]; then echo "The webapp are going to be 1-9000/2-9000 until count (1-9499/2-9499)" fi -for ((i=9000; i < `expr 9000+$NODE_COUNT`; i++)) +for i in $(seq 9000 $(expr 9000 + $NODE_COUNT - 1)) do curl $HTTPD -H "User-Agent: ClusterListener/1.0" -X CONFIG --data "JVMRoute=appserver$i&Host=127.0.0.1&Maxattempts=1&Port=$i&StickySessionForce=No&Timeout=20&Type=ajp&ping=20" curl $HTTPD -H "User-Agent: ClusterListener/1.0" -X STATUS --data "JVMRoute=appserver$i&Load=100" - for ((j=1; j <= $APP_COUNT; j++)) + for j in $(seq 1 $APP_COUNT) do if [ "x$USE_MULTI_APP" = "xtrue" ]; then curl $HTTPD -H "User-Agent: ClusterListener/1.0" -X ENABLE-APP --data "JVMRoute=appserver$i&Alias=default-host%2Clocalhost&Context=%2Fwebapp$j-$i" @@ -34,15 +46,23 @@ do done done +i=0 while [ true ] do - for ((i=9000; i < 9000+$NODE_COUNT; i++)) + for i in $(seq 9000 $(expr 9000 + $NODE_COUNT - 1)) do curl $HTTPD -H "User-Agent: ClusterListener/1.0" -X STATUS --data "JVMRoute=appserver$i&Load=100" if [ $? -ne 0 ]; then echo "htttpd stopped!!!" - break + clean_and_exit fi done sleep 10 + i=$(expr $i + 1) + if [ $i -gt 100 ]; then + break + fi done + +httpd_all_clean +tomcat_all_remove diff --git a/test/native/MODCLUSTER-785/app/status.jsp b/test/MODCLUSTER-785/app/status.jsp similarity index 100% rename from test/native/MODCLUSTER-785/app/status.jsp rename to test/MODCLUSTER-785/app/status.jsp diff --git a/test/native/MODCLUSTER-785/mod_proxy_cluster.conf b/test/MODCLUSTER-785/mod_proxy_cluster.conf similarity index 100% rename from test/native/MODCLUSTER-785/mod_proxy_cluster.conf rename to test/MODCLUSTER-785/mod_proxy_cluster.conf diff --git a/test/native/MODCLUSTER-785/testit.sh b/test/MODCLUSTER-785/testit.sh similarity index 62% rename from test/native/MODCLUSTER-785/testit.sh rename to test/MODCLUSTER-785/testit.sh index 72ce65686..4b32b2030 100755 --- a/test/native/MODCLUSTER-785/testit.sh +++ b/test/MODCLUSTER-785/testit.sh @@ -1,11 +1,15 @@ #!/bin/bash -source ../includes/script.bash -# USe default if IMG not defined. -if [ -z ${IMG+x} ]; then - IMG=quay.io/$USER/tomcat_mod_cluster +# if ran from main testsuite, change directory +pwd | grep MODCLUSTER-785 +if [ $? ]; then + PREFIX=MODCLUSTER-785 +else + PREFIX="." fi +. includes/common.sh + # check for a fork or modcluster repository. if [ -z $SOURCESFORK ]; then SOURCESFORK="modcluster" @@ -21,37 +25,28 @@ else fi # first stop any previously running tests. -stoptomcats -removetomcats +tomcat_all_stop +tomcat_all_remove +httpd_all_clean -# and httpd -docker stop MODCLUSTER-785 -docker rm MODCLUSTER-785 # build httpd + mod_proxy_cluster -# -REPOORIGIN=`git remote -v | grep origin | grep fetch | awk ' { print $2 } ' | awk -F/ ' { print $4 } '` -MPCCONF="https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/native/MODCLUSTER-785/mod_proxy_cluster.conf" -if [ $REPOORIGIN != "modcluster" ]; then - BRANCH=`git branch -v | awk ' { print $2 } '` - MPCCONF="https://raw.githubusercontent.com/$REPOORIGIN/mod_proxy_cluster/${BRANCH}/test/native/MODCLUSTER-785/mod_proxy_cluster.conf" -fi +REPOORIGIN=$(git remote -v | grep "origin.*fetch" | awk ' { print $2 } ' | awk -F/ ' { print $(NF-1) } ' | awk -F"[:|/]" ' { print $(NF-0) } ') +BRANCH=$(git branch --show-current) +MPCCONF="https://raw.githubusercontent.com/${REPOORIGIN}/mod_proxy_cluster/${BRANCH}/test/MODCLUSTER-785/mod_proxy_cluster.conf" + rm -f nohup.out -nohup docker run --network=host -e HTTPD=https://dlcdn.apache.org/httpd/httpd-2.4.57.tar.gz -e SOURCES=${SOURCES} -e BRANCH=${MDBRANCH} -e CONF=$MPCCONF --name MODCLUSTER-785 quay.io/${USER}/mod_cluster_httpd & +MPC_SOURCES=${SOURCES} MPC_BRANCH=${MDBRANCH} MPC_CONF=$MPCCONF MPC_NAME=MODCLUSTER-785 httpd_run -# wait until httpd is started -waitforhttpd || exit 1 -#docker cp mod_proxy_cluster.conf MODCLUSTER-785:/usr/local/apache2/conf/mod_proxy_cluster.conf -#docker exec -it MODCLUSTER-785 /usr/local/apache2/bin/apachectl restart # start tomcat1 on 8080 -starttomcat 1 0 8080 +tomcat_start 1 # wait until tomcat1 is in mod_proxy_cluster tables -waitnodes 1 +tomcat_wait_for_n_nodes 1 # copy the test page in app to tomcat8080 -docker cp app tomcat1:/usr/local/tomcat/webapps/app +docker cp $PREFIX/app tomcat1:/usr/local/tomcat/webapps/app # check that the app is answering sleep 15 @@ -62,8 +57,8 @@ if [ $? -ne 0 ]; then fi # Stop abruptly -docker stop tomcat1 -docker container rm tomcat1 +tomcat_stop 1 +tomcat_remove 1 # it return 503 # make sure we use enough workers @@ -77,13 +72,13 @@ fi sleep 15 # start tomcat1 on 8080 -starttomcat 1 0 8080 +tomcat_start 1 # wait until tomcat1 is in mod_proxy_cluster tables -sleep 5 -waitnodes 1 +tomcat_wait_for_n_nodes 1 + # copy the test page in app to tomcat8080 -docker cp app tomcat1:/usr/local/tomcat/webapps/app +docker cp $PREFIX/app tomcat1:/usr/local/tomcat/webapps/app sleep 15 # check that the app is answering @@ -129,4 +124,9 @@ do echo "*${http_code}*" done +# clean tomcats +tomcat_all_remove +# and httpd +httpd_all_clean + echo "MODCLUSTER-785 Done!" diff --git a/test/README.md b/test/README.md new file mode 100644 index 000000000..6fb3ad3ae --- /dev/null +++ b/test/README.md @@ -0,0 +1,77 @@ +# Running tests + +There are several tests within the repository. Some common tests are within the root directory, more specialized tests +live within their own subdirectories. All tests can be run by a single shell script `testsuite.sh`. The script itself +is a bit parametrized so that you can influence the duration of testing. Upon invocation, the script outputs values of +its parameters. You can change the value by passing the environment variable of the same name with a desired value. + +```sh +# to execute the whole testsuite +sh testsuite.sh +# to execute the testsuite with DEBUG on and only one Tomcat cycle, execute +DEBUG=1 TOMCAT_CYCLE_COUNT=1 sh testsuite.sh +``` + +You can also run the individual testsuites by yourself, just execute the corresponsing script. + +```sh +sh basetests.sh +# alternatively, you can use the run_test function +source includes/common.sh # load definitions +run_test basetests.sh "Basic tests" # run tests +``` + +You might find useful `includes` directory, especially `common.sh` script that contains shared functions for the tests +(mainly for controlling container images, see the section below). + +You should be able to check tests results based on the `$?` as usual so that you can use it in your scripts and automations. + +## Test images + +If you use the main `testsuite.sh` script, you don't have to worry about this too much. Just make sure that you have checked +out and built [mod_cluster](https://github.com/modcluster/mod_cluster) in sub directory at the same level you checked out this +repository. + +Also, if you use `podman` instead of `docker`, make sure you have `podman-docker` package installed (tests are using `docker`). + +If you don't want to use quay.io (the default), just set `IMG` and `HTTPD_IMG` variables to docker, local repository or some +other service. + +There are a few helper functions for both images, however, if you want to control the images manually, use the corresponding +Dockerfiles. See the testsuite, mainly `includes/common.sh`, to see how the images are run. + +### httpd_mod_cluster + +There are two types of images we use in tests. The first one is the httpd image with mod_proxy_cluster. Its Dockerfile can +be found in `httpd` subdirectory and you can create it (as tests do) with the `httpd_create` function. All functions with +the prefix `httpd_` are using this image. + +### tomcat_mod_cluster + +The second image is a Tomcat image with mod_cluster enabled. Its Dockerfile is in the `tomcat` directory and tests use +`tomcat_create` function. As for httpd, all functions orking with tomcat image are prefixed `tomcat_`. + +## Dependencies + +There are several dependecies / other repositories you have to have checked out and built/installed, namely: + +* https://github.com/jfclere/httpd_websocket +* https://github.com/modcluster/mod_cluster + +Alternatively, you can use `setup-dependencies.sh` script that prepares everything for you. + +These tools are required for running tests: + +* git +* docker (or podman with podman-docker package) +* maven +* curl +* jdb (java) +* ss +* ab + +# Testing with miniserver +There is also a python script that can be run to check mod_proxy_cluster. You can find it within `includes` directory +as `miniserver.py`. Execute it simply as `./includes/miniserver.py `. + +You must have `httpd` with `mod_proxy_cluster` running. diff --git a/test/basetests.sh b/test/basetests.sh new file mode 100644 index 000000000..05c0603d6 --- /dev/null +++ b/test/basetests.sh @@ -0,0 +1,49 @@ +#!/usr/bin/sh + +. includes/common.sh + +httpd_all_clean +tomcat_all_remove + +httpd_run + +# Start 2 tomcats, on 8080 and 8081 +tomcat_start_two || clean_and_exit +tomcat_wait_for_n_nodes 2 || clean_and_exit + +# Copy testapp and wait for its start +docker cp testapp tomcat8081:/usr/local/tomcat/webapps +sleep 10 + +# Basic 200 and 404 tests. +echotestlabel "basic 200 and 404 tests" +CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/test.jsp) +if [ ${CODE} != "200" ]; then + echo "Failed can't reach webapp: ${CODE}" + clean_and_exit +fi +CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/toto.jsp) +if [ ${CODE} != "404" ]; then + echo "Failed should get 404" + clean_and_exit +fi + +tomcat_all_remove + +# Loop stopping starting the same tomcat +ITERATION_COUNT=${ITERATION_COUNT:-10} +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} & + sleep 10 + tomcat_wait_for_n_nodes 1 || clean_and_exit + docker exec -it tomcat8080 /usr/local/tomcat/bin/shutdown.sh + tomcat_wait_for_n_nodes 0 || clean_and_exit + docker container rm tomcat8080 + iter=$(expr $iter + 1) +done + +tomcat_all_remove +httpd_all_clean diff --git a/test/native/continue.txt b/test/continue.txt similarity index 100% rename from test/native/continue.txt rename to test/continue.txt diff --git a/test/native/curlloop.sh b/test/curlloop.sh similarity index 92% rename from test/native/curlloop.sh rename to test/curlloop.sh index df7537949..b7bfc6aba 100644 --- a/test/native/curlloop.sh +++ b/test/curlloop.sh @@ -14,7 +14,7 @@ do http_code=`curl -s -m10 -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/test.jsp` for var in "$@" do - if [ "${http_code}" == "${var}" ]; then + if [ "${http_code}" -eq "${var}" ]; then found=1 break fi diff --git a/test/native/examples/test/test.jsp b/test/examples/test/test.jsp similarity index 100% rename from test/native/examples/test/test.jsp rename to test/examples/test/test.jsp diff --git a/test/native/hang.txt b/test/hang.txt similarity index 100% rename from test/native/hang.txt rename to test/hang.txt diff --git a/test/hangingtests.sh b/test/hangingtests.sh new file mode 100644 index 000000000..37c2d37a6 --- /dev/null +++ b/test/hangingtests.sh @@ -0,0 +1,113 @@ +#!/usr/bin/sh + +. includes/common.sh + +httpd_all_clean +tomcat_all_remove + + +# This should suspend the tomcat for ~ 1000 seconds ~ causing it gets removed afterwhile. +jdbsuspend() { + rm -f /tmp/testpipein + mkfifo /tmp/testpipein + rm -f /tmp/testpipeout + mkfifo /tmp/testpipeout + sleep 1000 > /tmp/testpipein & + jdb -attach 6660 < /tmp/testpipein > /tmp/testpipeout & + echo "suspend" > /tmp/testpipein + cat < /tmp/testpipeout & +} + +jdbexit() { + cat > /tmp/testpipeout & + echo "exit" > /tmp/testpipein +} + +#################################### +### S T A R T T E S T S ### +#################################### +httpd_run + +# Create files we need +cat << EOF > continue.txt +cont +exit +EOF +cat << EOF > hang.txt +suspend all +exit +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} & +sleep 10 +tomcat_wait_for_n_nodes 2 || clean_and_exit +# 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} quay.io/${USER}/tomcat_mod_cluster-debug +docker stop tomcat${PORT} +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} quay.io/${USER}/tomcat_mod_cluster-debug & +sleep 10 +docker exec tomcat${PORT} jdb -attach 6660 < continue.txt +tomcat_wait_for_n_nodes 2 || clean_and_exit +echo "2 tomcat started" +# Hang the node, +# jdb and a pipe to hang the tomcat. +jdbsuspend +tomcat_wait_for_n_nodes 1 || clean_and_exit +echo "1 tomcat hanging and gone" +jdbexit +# The tomcat is comming up again +tomcat_wait_for_n_nodes 2 || clean_and_exit +echo "the tomcat is back" + +# Same test with requests, make them in a loop +echo "hanging tomcat removed after a while with requests" +sh curlloop.sh 200 000 & +jdbsuspend +tomcat_wait_for_n_nodes 1 || clean_and_exit +ps -ef | grep curlloop | grep -v grep +if [ $? -ne 0 ]; then + echo "curlloop.sh FAILED!" + clean_and_exit +fi +ps -ef | grep curlloop | grep -v grep | awk ' { print $2 } ' | xargs kill +jdbexit +# The tomcat is comming up again +tomcat_wait_for_n_nodes 2 || clean_and_exit + +# 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_wait_for_n_nodes 1 || clean_and_exit +jdbsuspend +sleep 10 +sh curlloop.sh 000 404 503 & +tomcat_wait_for_n_nodes 0 || clean_and_exit +ps -ef | grep curlloop | grep -v grep +if [ $? -ne 0 ]; then + echo "curlloop.sh FAILED!" + clean_and_exit +fi +ps -ef | grep curlloop | grep -v grep | awk ' { print $2 } ' | xargs kill +jdbexit +# The tomcat is comming up again +tomcat_wait_for_n_nodes 1 || clean_and_exit + +# Cleanup at the end +tomcat_all_stop +tomcat_wait_for_n_nodes 0 || clean_and_exit + +tomcat_all_remove +httpd_all_clean diff --git a/test/native/httpd/Dockerfile b/test/httpd/Dockerfile similarity index 87% rename from test/native/httpd/Dockerfile rename to test/httpd/Dockerfile index c1236e2dd..907479815 100644 --- a/test/native/httpd/Dockerfile +++ b/test/httpd/Dockerfile @@ -5,7 +5,7 @@ RUN yum install gcc wget apr-devel apr-util-devel openssl-devel pcre-devel redha ENV HTTPD=https://dlcdn.apache.org/httpd/httpd-2.4.57.tar.gz ENV SOURCES=https://github.com/modcluster/mod_proxy_cluster ENV BRANCH=main -ENV CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/native/httpd/mod_proxy_cluster.conf +ENV CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/httpd/mod_proxy_cluster.conf ADD install.sh /tmp diff --git a/test/native/httpd/README.md b/test/httpd/README.md similarity index 64% rename from test/native/httpd/README.md rename to test/httpd/README.md index 7b494708f..2c508c238 100644 --- a/test/native/httpd/README.md +++ b/test/httpd/README.md @@ -1,4 +1,4 @@ -# build the image +# Build the image ```bash docker build -t quay.io/${USER}/mod_cluster_httpd . ``` @@ -6,20 +6,17 @@ docker build -t quay.io/${USER}/mod_cluster_httpd . # run it **Note the ENV variables:** -HTTPD: URL to a released httpd tar.gz +* HTTPD: URL to a released httpd tar.gz +* SOURCES: The mod_proxy_sources, url (github) +* BRANCH: A branch, or a tag or a commitid +* CONF: The mod_proxy_cluster configuration file to include in httpd.conf (The *conf files are added to image at build time) -SOURCES: The mod_proxy_sources, url (github) - -BRANCH: A branch, or a tag or a commitid - -CONF: The mod_proxy_cluster configuration file to include in httpd.conf (The *conf files are added to image at build time) - -For example (the default) +For example (the default): ```bash -docker run -d --network=host -e HTTPD=https://dlcdn.apache.org/httpd/httpd-2.4.57.tar.gz -e SOURCES=https://github.com/modcluster/mod_proxy_cluster -e BRANCH=main -e CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/native/httpd/mod_proxy_cluster.conf quay.io/${USER}/mod_cluster_httpd +docker run -d --network=host -e HTTPD=https://dlcdn.apache.org/httpd/httpd-2.4.57.tar.gz -e SOURCES=https://github.com/modcluster/mod_proxy_cluster -e BRANCH=main -e CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/httpd/mod_proxy_cluster.conf quay.io/${USER}/mod_cluster_httpd ``` -# test with different mod_proxy_cluster.conf without rebuilding httpd and mod_proxy_cluster +# Test with different configs without rebuilding httpd or mod_proxy_cluster ```bash docker ps ``` diff --git a/test/native/httpd/install.sh b/test/httpd/install.sh similarity index 78% rename from test/native/httpd/install.sh rename to test/httpd/install.sh index b77f93049..15c349699 100755 --- a/test/native/httpd/install.sh +++ b/test/httpd/install.sh @@ -51,12 +51,6 @@ if [ -f /tmp/$FILECONF ]; then echo "Include conf/$FILECONF" >> /usr/local/apache2/conf/httpd.conf fi -# With the default settings and recent changes c83aff820705cdf4a399c1d748d9cedb66593b9f, -# removed nodes are hanging indefinitely in mod_cluster_manager whose outputs are parsed -# by tests. Setting MaxConnectionPerChild will cause they get removed eventually without -# a need to change tests. -echo -e "\nMaxConnectionsPerChild 16" >> /usr/local/apache2/conf/httpd.conf - # start apache httpd server in foreground /usr/local/apache2/bin/apachectl start diff --git a/test/native/httpd/mod_proxy_cluster.conf b/test/httpd/mod_proxy_cluster.conf similarity index 68% rename from test/native/httpd/mod_proxy_cluster.conf rename to test/httpd/mod_proxy_cluster.conf index e9b23fa65..dea5dc4c4 100644 --- a/test/native/httpd/mod_proxy_cluster.conf +++ b/test/httpd/mod_proxy_cluster.conf @@ -9,17 +9,12 @@ LoadModule slotmem_shm_module modules/mod_slotmem_shm.so LoadModule manager_module modules/mod_manager.so LoadModule proxy_cluster_module modules/mod_proxy_cluster.so -#LoadModule advertise_module modules/mod_advertise.so -#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so -#LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so UseAlias On ProxyPreserveHost On -# CacheShareFor 2 -#ResponseFieldSize 10000 Listen 6666 @@ -34,24 +29,19 @@ ProxyPreserveHost On EnableWsTunnel WSUpgradeHeader websocket - EnableMCPMReceive - #ServerAdvertise on http://jfcpc:6666 - #ServerAdvertise on http://localhost:6666 - #AdvertiseFrequency 5 - #AdvertiseGroup 224.0.1.105:23364 + EnableMCPMReceive - Require ip 10.33.144. - Require ip 127.0.0.1 + Require ip 127.0.0. Require ip ::1 - Require ip 192.168.1. + # This one is used in GH Actions + Require ip 172.17. SetHandler mod_cluster-manager - Require ip 127.0.0.1 - Require ip 10.33.144. - Require ip 192.168.1. + Require ip 127.0.0. Require ip ::1 - Require ip e80::56ee:75ff:fe1d:45fb + # This one is used in GH Actions + Require ip 172.17. diff --git a/test/includes/common.sh b/test/includes/common.sh new file mode 100644 index 000000000..d7ecdce28 --- /dev/null +++ b/test/includes/common.sh @@ -0,0 +1,314 @@ +#!/usr/bin/sh + +IMG=${IMG:=quay.io/$USER/tomcat_mod_cluster} +HTTPD_IMG=${HTTPD_IMG:=quay.io/${USER}/httpd_mod_cluster} + +# Runs a test file ($1) under given name ($2, if given) +run_test() { + local ret=0 + if [ -z ${2+x} ]; then + printf "Running %-42s ..." $2 + else + printf "Running %-42s ..." $1 + fi + if [ $DEBUG ]; then + sh $1 > logs/${2:-$1}.logs 2>&1 + else + sh $1 > /dev/null 2>&1 + fi + if [ $? = 0 ]; then + echo " OK" + else + echo " NOK" + ret=1 + fi + # preserve httpd's logs too if DEBUG + if [ $DEBUG ]; then + docker logs $(docker ps -a | grep $HTTPD_IMG | cut -f 1 -d' ') > logs/${2:-$1}-httpd.logs 2>&1 + fi + # Clean all after run + httpd_shutdown > /dev/null 2>&1 + tomcat_all_remove > /dev/null 2>&1 + return $ret +} + +##################################################### +### H T T P D H E L P E R F U N C T I O N S ### +##################################################### +# create httpd container +httpd_create() { + docker build -t $HTTPD_IMG httpd/ + # docker push $HTTPD_IMG +} + +# Build and run httpd container +httpd_run() { + # if httpd is already running for some reason, end it + httpd_shutdown || true + if [ $DEBUG ]; then + echo "httpd mod_proxy_cluster image config:" + echo " SOURCES: ${MPC_SOURCES:-https://github.com/modcluster/mod_proxy_cluster}" + echo " BRANCH: ${MPC_BRANCH:-main}" + echo " CONF: ${MPC_CONF:-https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/httpd/mod_proxy_cluster.conf}" + echo " NAME: ${MPC_NAME:-httpd-mod_proxy_cluster}" + echo "You can config those with envars MPC_SOURCES, MPC_BRANCH, MPC_CONF, MPC_NAME respectively" + fi + docker run -d --network=host --name ${MPC_NAME:-httpd-mod_proxy_cluster} \ + -e SOURCES=${MPC_SOURCES:-https://github.com/modcluster/mod_proxy_cluster} \ + -e BRANCH=${MPC_BRANCH:-main} \ + -e CONF=${MPC_CONF:-https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/httpd/mod_proxy_cluster.conf} \ + $HTTPD_IMG + httpd_wait_until_ready +} + +httpd_wait_until_ready() { + local i=0 + curl localhost:6666 > /dev/null 2>&1 + while [ $? != 0 ]; + do + i=$(expr $i + 1) + if [ $i -gt 20 ]; then + echo "Failed to run httpd container" + exit 1; + fi + sleep 10; + curl localhost:6666 > /dev/null 2>&1 + done +} + +httpd_shutdown() { + docker ps --format "{{.Names}}" | grep ${MPC_NAME:-httpd-mod_proxy_cluster} + if [ $? = 0 ]; then + docker stop ${MPC_NAME:-httpd-mod_proxy_cluster} + fi + docker ps -a --format "{{.Names}}" | grep ${MPC_NAME:-httpd-mod_proxy_cluster} + if [ $? = 0 ]; then + docker rm ${MPC_NAME:-httpd-mod_proxy_cluster} + fi +} + +httpd_all_clean() { + for i in $(docker ps -a | grep $HTTPD_IMG | cut -f1 -d' '); + do + docker stop $i + docker rm $i + done +} + +clean_and_exit() { + httpd_all_clean + exit ${1:-1} +} + +##################################################### +### T O M C A T H E L P E R F U N C T I O N S ### +##################################################### +tomcat_create() { + docker build -t $IMG tomcat/ + # docker push $IMG +} + +# Start tomcat$1 container on 127.0.0.$2 +# or 127.0.0.$1 if $2 is not given +# arguments: +# $1 tomcat number +# $2 tomcat's last byte of IPv4 address (if 0 or omitted, equals to $1) +# $3 tomcat port (if omitted it's 8080) +tomcat_start() { + ADDR="127.0.0.$1" + if [ ${2:-0} -ne 0 ]; then + ADDR="127.0.0.$2" + fi + + echo "Starting tomcat$1 on $ADDR" + nohup docker run --network=host -e tomcat_ajp_port=8010 \ + -e tomcat_address=$ADDR \ + -e tomcat_port=${3:-8080} \ + -e tomcat_shutdown_port=8005 \ + -e jvm_route=tomcat$1 \ + --name tomcat$1 ${IMG} & + ps -q $! > /dev/null + if [[ $? -ne 0 ]]; then + echo "docker run for tomcat$1 failed" + exit 1 + fi +} + +# +# Stop running given dockered tomcat +tomcat_stop() { + docker ps | grep tomcat$1 + if [ $? -eq 0 ]; then + docker stop tomcat$1 + if [ $? -ne 0 ]; then + echo "Can't stop tomcat$1" + exit 1 + fi + else + echo "$1 is not running" + fi +} + +# +# Stop running all dockered tomcats +tomcat_all_stop() { + for i in $(docker ps -a --format "{{.Names}}" | grep tomcat | sed -e 's/tomcat//g') + do + tomcat_stop $i + done +} + +# +# Wait until there are $1 nodes in OK state (i.e., some will start or go away if the count is different) +tomcat_wait_for_n_nodes() { + nodes=${1:-0} + curl -s http://localhost:6666/mod_cluster_manager -o /dev/null + if [ $? -ne 0 ]; then + echo "httpd isn't running or something is VERY wrong" + exit 1 + fi + NBNODES=-1 + i=0 + while [ ${NBNODES} != ${nodes} ] + do + NBNODES=$(curl -s http://localhost:6666/mod_cluster_manager | grep "Status: OK" | awk ' { print $3} ' | wc -l) + sleep 10 + echo "Waiting for ${nodes} node to be ready: $(date)" + i=$(expr $i + 1) + if [ $i -gt 60 ]; then + echo "Timeout! There are not $nodes nodes but $NBNODES instead" + exit 1 + fi + done + curl -s http://localhost:6666/mod_cluster_manager -o /dev/null + if [ $? -ne 0 ]; then + echo "httpd isn't running or something VERY wrong" + exit 1 + fi + echo "Waiting for the nodes DONE: $(date)" +} + +# +# Stop and remove tomcat docker container of a given name +tomcat_remove_by_name() { + docker ps -a | grep $1 + if [ $? -eq 0 ]; then + echo "Stopping $1" + docker stop $1 + if [ $? -ne 0 ]; then + echo "Can't stop $1" + fi + echo "Removing $1" + docker rm $1 + if [ $? -ne 0 ]; then + echo "Can't remove $1" + fi + fi +} + +# +# Remove all tomcat containers and images +tomcat_all_remove() { + for i in $(docker ps -a --format "{{.Names}}" | grep tomcat) + do + tomcat_remove_by_name $i + done +} + +tomcat_start_two() { + echo "Starting tomcat8080..." + nohup docker run --network=host -e tomcat_port=8080 -e tomcat_shutdown_port=true --name tomcat8080 ${IMG} & + if [ $? -ne 0 ]; then + echo "Can't start tomcat8080" + 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} & + if [ $? -ne 0 ]; then + echo "Can't start tomcat8081" + exit 1 + fi + echo "2 Tomcats started..." +} + +# Start the webapp on the given tomcat +# wait for the tomcat to start. +tomcat_start_webapp() { + while true + do + docker ps --format "{{.Names}}" | grep tomcat$1 + if [ $? -eq 0 ]; then + break + fi + sleep 2 + done + docker cp testapp tomcat$1:/usr/local/tomcat/webapps/tomcat$1 || exit 1 +} + +# Send a shutdown packet to a tomcat$1 container +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 8005 +} + +# Remove the docker image tomcat$1 +# Note: To succesfully remove an image it needs to be stopped +tomcat_remove() { + docker stop tomcat$1 > /dev/null 2>&1 + docker rm tomcat$1 +} + +# +# Run a load test for the given tomcat$1 using ab +tomcat_run_ab() { + ab -c10 -n10 http://localhost:8000/tomcat$1/test.jsp > /dev/null + if [ $? -ne 0 ]; then + echo "abtomcat: Loading tomcat$1 failed" + exit 1 + fi +} + +# +# Run abtomcat for tomcat containers [2..$1] +tomcat_all_run_ab() { + tc=2 + while true + do + tomcat_run_ab $tc || exit 1 + tc=$(expr $tc + 1) + if [ $tc -gt $1 ]; then + echo "abtomcats: Done!" + break + fi + done +} + +# Test whether the webapp is working (responding) +tomcat_test_app() { + CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/tomcat$1/test.jsp) + if [ ${CODE} != "200" ]; then + echo "Failed can't reach tomcat$1: ${CODE}" + exit 1 + fi +} + +# +# Run tomcat_test for tomcat containers [2..$1] +tomcat_all_test_app() { + tc=2 + while true + do + tomcat_test_app $tc || exit 1 + tc=$(expr $tc + 1) + if [ $tc -gt $1 ]; then + echo "tomcat_tests $tc Done!" + break + fi + done +} diff --git a/test/native/includes/miniserver.py b/test/includes/miniserver.py similarity index 100% rename from test/native/includes/miniserver.py rename to test/includes/miniserver.py diff --git a/test/java/.classpath b/test/java/.classpath deleted file mode 100644 index 19c0165c3..000000000 --- a/test/java/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/test/java/.project b/test/java/.project deleted file mode 100644 index eb8c99bde..000000000 --- a/test/java/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - test_mod_cluster - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.jdt.core.javanature - - diff --git a/test/java/Advertize.java b/test/java/Advertize.java deleted file mode 100644 index 939105df8..000000000 --- a/test/java/Advertize.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright(c) 2010 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $ - */ -import java.net.MulticastSocket; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.DatagramPacket; - -public class Advertize -{ - /* - * Client to test Advertize... Run it on node boxes to test for firewall. - */ - public static void main(String[] args) throws Exception - { - if (args.length != 2 && args.length != 3) { - System.out.println("Usage: Advertize multicastaddress port [bindaddress]"); - System.out.println("java Advertize 224.0.1.105 23364"); - System.out.println("or"); - System.out.println("java Advertize 224.0.1.105 23364 10.33.144.3"); - System.out.println("receive from 224.0.1.105:23364"); - System.exit(1); - } - - InetAddress group = InetAddress.getByName(args[0]); - int port = Integer.parseInt(args[1]); - InetAddress socketInterface = null; - if (args.length == 3) - socketInterface = InetAddress.getByName(args[2]); - MulticastSocket s = null; - String value = System.getProperty("os.name"); - if ((value != null) && (value.toLowerCase().startsWith("linux") || value.toLowerCase().startsWith("mac") || value.toLowerCase().startsWith("hp"))) { - System.out.println("Linux like OS"); - s = new MulticastSocket(new InetSocketAddress(group, port)); - } else - s = new MulticastSocket(port); - s.setTimeToLive(0); - if (socketInterface != null) { - s.setInterface(socketInterface); - } - s.joinGroup(group); - boolean ok = true; - System.out.println("ready waiting..."); - while (ok) { - byte[] buf = new byte[1000]; - DatagramPacket recv = new DatagramPacket(buf, buf.length); - s.receive(recv); - String data = new String(buf); - System.out.println("received: " + data); - System.out.println("received from " + recv.getSocketAddress()); - } - s.leaveGroup(group); - } -} diff --git a/test/java/CauseErrorMethod.java b/test/java/CauseErrorMethod.java deleted file mode 100644 index eb18531bd..000000000 --- a/test/java/CauseErrorMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class CauseErrorMethod extends PostMethod { - public String getName() { - return "ERROR"; - } - public CauseErrorMethod(String uri) { - super(uri); - } -} diff --git a/test/java/Clients/JBWEB-117/JBWEB-117.xml b/test/java/Clients/JBWEB-117/JBWEB-117.xml deleted file mode 100644 index 719d99295..000000000 --- a/test/java/Clients/JBWEB-117/JBWEB-117.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - JFC test application - - Welcome to JFC test application - - - - JBWEB_117 - JBWEB_117 - 6 - - - - JBWEB_117 - /JBWEB_117 - - - - - Security Tests - /JBWEB_117 - - - manager - - - - - BASIC - Tomcat Manager Application - - - - - The role that is required to log in to the application. - - manager - - - diff --git a/test/java/Clients/JBWEB-117/build.xml b/test/java/Clients/JBWEB-117/build.xml deleted file mode 100644 index 7b22fbaf7..000000000 --- a/test/java/Clients/JBWEB-117/build.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/java/Clients/JBWEB-117/metainf/context.xml b/test/java/Clients/JBWEB-117/metainf/context.xml deleted file mode 100644 index fcd00fbbb..000000000 --- a/test/java/Clients/JBWEB-117/metainf/context.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/test/java/Clients/JBWEB-117/src/JBWEB_117.java b/test/java/Clients/JBWEB-117/src/JBWEB_117.java deleted file mode 100755 index 4d1474d68..000000000 --- a/test/java/Clients/JBWEB-117/src/JBWEB_117.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright(c) 2008 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $ - */ - -import java.io.*; -import java.text.*; -import java.util.*; -import javax.servlet.*; -import javax.servlet.http.*; - - - -/** - * TestServlet for JBWEB-117 - */ - -public class JBWEB_117 extends HttpServlet { - - public void doGet(HttpServletRequest request, - HttpServletResponse response) - throws IOException, ServletException - { - response.setContentType("text/html"); - - PrintWriter out = response.getWriter(); - out.println(""); - out.println(""); - out.println(""); - - out.println("" + "JBWEB_117" + ""); - out.println(""); - out.println(""); - - - // Read the inputstream. - InputStream in = request.getInputStream(); - if (in!=null) { - byte[] buff = new byte[128]; - int i=0; - try { - int ret=0; - while (ret!=-1) { - ret = in.read(buff); - if (ret>0) { - i = i + ret; - String str = new String(buff,0,ret); - out.println(str); - } - } - } catch (IOException ex) { - ex.printStackTrace(out); - out.println("Merde bug velu!!!"); - out.println("

"); - } - out.println("Size of input: " + i); - } else { - out.println("No input"); - } - - // Read session and create it if needed... - HttpSession session = request.getSession(true); - } - - public void doPost(HttpServletRequest request, - HttpServletResponse response) - throws IOException, ServletException - { - doGet(request, response); - } - -} diff --git a/test/java/Clients/testhttpd/build.xml b/test/java/Clients/testhttpd/build.xml deleted file mode 100644 index 003502736..000000000 --- a/test/java/Clients/testhttpd/build.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/java/Clients/testhttpd/src/testhttpd.java b/test/java/Clients/testhttpd/src/testhttpd.java deleted file mode 100755 index 7ef023a80..000000000 --- a/test/java/Clients/testhttpd/src/testhttpd.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright(c) 2010 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $ - */ - -import javax.servlet.*; -import javax.servlet.http.*; -import java.net.URL; -import java.net.Socket; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.InputStream; - -/** - * That servlet can be use to test if the node could reach httpd. - */ - -public class testhttpd extends HttpServlet { - - public void doGet(HttpServletRequest request, - HttpServletResponse response) - throws IOException, ServletException - { - response.setContentType("text/html"); - - PrintWriter out = response.getWriter(); - out.println(""); - out.println(""); - out.println(""); - - out.println("" + "testhttpd" + ""); - out.println(""); - out.println("This test allows to check that httpd is up and configured to accept requests from the node
"); - out.println("The actual version doesn't support SSL so SSL won't be tested fully
"); - out.println("
"); - - String testValue = request.getParameter("url"); - if (testValue != null) { - out.println("Connecting to " + testValue + "
"); - try { - URL u = new URL(testValue); - Socket c = new Socket(u.getHost(), u.getPort()); - out.println("Connected to " + u.getHost() + " : " + u.getPort() + "
"); - PrintWriter o = new PrintWriter(c.getOutputStream()); - InputStream i = c.getInputStream(); - o.println("PING / HTTP/1.1"); - o.println("Host: " + u.getHost()); - o.println(""); - o.flush(); - byte buf[] = new byte [512]; - int ret = i.read(buf); - if (ret >= 0) { - String res = new String(buf, 0, ret); - out.println("Result:
"); - out.println(res); - out.println("
"); - if (res.indexOf("PING-RSP") > 0) - out.println("

OK

"); - else - out.println("

FAILED

"); - } - c.close(); - out.println(""); - return; - } catch (Exception ex) { - out.println("Failed: " + ex + "
"); - } - } - - out.println("
"); - out.println("Use: testhttpd/testhttpd?url=http://hostname:port to test
"); - out.println("or testhttpd/testhttpd?url=http://ip:port to test
"); - out.println(""); - - } - - public void doPost(HttpServletRequest request, - HttpServletResponse response) - throws IOException, ServletException - { - doGet(request, response); - } - -} diff --git a/test/java/Clients/testhttpd/testhttpd.xml b/test/java/Clients/testhttpd/testhttpd.xml deleted file mode 100644 index 19f664df1..000000000 --- a/test/java/Clients/testhttpd/testhttpd.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - JFC test application - - Welcome to JFC test application - - - - testhttpd - testhttpd - 6 - - - - testhttpd - /testhttpd - - - diff --git a/test/java/ConfigMethod.java b/test/java/ConfigMethod.java deleted file mode 100644 index b09b29d8d..000000000 --- a/test/java/ConfigMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class ConfigMethod extends PostMethod { - public String getName() { - return "CONFIG"; - } - public ConfigMethod(String uri) { - super(uri); - } -} diff --git a/test/java/DisableMethod.java b/test/java/DisableMethod.java deleted file mode 100644 index fb024dbcd..000000000 --- a/test/java/DisableMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class DisableMethod extends PostMethod { - public String getName() { - return "DISABLE-APP"; - } - public DisableMethod(String uri) { - super(uri); - } -} diff --git a/test/java/DumpMethod.java b/test/java/DumpMethod.java deleted file mode 100644 index 28524654c..000000000 --- a/test/java/DumpMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class DumpMethod extends PostMethod { - public String getName() { - return "DUMP"; - } - public DumpMethod(String uri) { - super(uri); - } -} diff --git a/test/java/EnableMethod.java b/test/java/EnableMethod.java deleted file mode 100644 index 7473e0598..000000000 --- a/test/java/EnableMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class EnableMethod extends PostMethod { - public String getName() { - return "ENABLE-APP"; - } - public EnableMethod(String uri) { - super(uri); - } -} diff --git a/test/java/InfoMethod.java b/test/java/InfoMethod.java deleted file mode 100644 index 6085dba58..000000000 --- a/test/java/InfoMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class InfoMethod extends PostMethod { - public String getName() { - return "INFO"; - } - public InfoMethod(String uri) { - super(uri); - } -} diff --git a/test/java/README.txt b/test/java/README.txt deleted file mode 100644 index 1cbd25e8e..000000000 --- a/test/java/README.txt +++ /dev/null @@ -1,33 +0,0 @@ -The test directory contains to kind of tests: -1 - small test using httpclient that allows to read directly information from httpd (TestHttpClient). -2 - small test suite: - to run it: - mvn test - to run a single test: - mvn -Dtest=mytest test where mytest is for example Test_Chunk_JBWEB_117 -3 - JBW listener: - to test the JBW cluster listener use -Dcluster=false for example: - mvn -Dtest=Test_Chunk_JBWEB_117 -Dcluster=false test -4 - httpd is installed and started via ant - ant httpd - to stop it: - ant stophttpd - -NOTE the httpd should have something like the following in httpd.conf - - Listen jfcpc:6666 - - - Order deny,allow - Deny from all - Allow from 10.33.144 - - - KeepAliveTimeout 300 - MaxKeepAliveRequests 0 - AdvertiseFrequency 5 - EnableMCPMReceive - - -(replace jfpc by your hostname or your IP address) -(replace 10.33.144 by the subnet you want to allow) diff --git a/test/java/RemoveMethod.java b/test/java/RemoveMethod.java deleted file mode 100644 index a5bedf6c0..000000000 --- a/test/java/RemoveMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class RemoveMethod extends PostMethod { - public String getName() { - return "REMOVE-APP"; - } - public RemoveMethod(String uri) { - super(uri); - } -} diff --git a/test/java/SAdvertize.java b/test/java/SAdvertize.java deleted file mode 100644 index 770598307..000000000 --- a/test/java/SAdvertize.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright(c) 2010 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $ - */ -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.DatagramPacket; -import java.net.MulticastSocket; - -public class SAdvertize -{ - /* - * Server to test Advertize... Run it on httpd box to test for firewall. - */ - public static void main(String[] args) throws Exception - { - if (args.length !=3) { - System.out.println("Usage: SAdvertize localaddress multicastaddress port"); - System.out.println("java SAdvertize 10.16.88.178 224.0.1.105 23364"); - System.out.println("send from 10.16.88.178:23364 to 224.0.1.105:23364"); - System.exit(1); - } - InetAddress group = InetAddress.getByName(args[1]); - InetAddress addr = InetAddress.getByName(args[0]); - int port = Integer.parseInt(args[2]); - InetSocketAddress addrs = new InetSocketAddress(addr, port); - - MulticastSocket s = new MulticastSocket(addrs); - s.setTimeToLive(29); - s.joinGroup(group); - boolean ok = true; - while (ok) { - byte[] buf = new byte[1000]; - DatagramPacket recv = new DatagramPacket(buf, buf.length, group, port); - s.send(recv); - Thread.currentThread().sleep(10000); - } - s.leaveGroup(group); - } -} diff --git a/test/java/StatusMethod.java b/test/java/StatusMethod.java deleted file mode 100644 index 35e5cd832..000000000 --- a/test/java/StatusMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class StatusMethod extends PostMethod { - public String getName() { - return "STATUS"; - } - public StatusMethod(String uri) { - super(uri); - } -} diff --git a/test/java/StopMethod.java b/test/java/StopMethod.java deleted file mode 100644 index 0763d25ea..000000000 --- a/test/java/StopMethod.java +++ /dev/null @@ -1,9 +0,0 @@ -import org.apache.commons.httpclient.methods.PostMethod; -public class StopMethod extends PostMethod { - public String getName() { - return "STOP-APP"; - } - public StopMethod(String uri) { - super(uri); - } -} diff --git a/test/java/TestHttpClient.java b/test/java/TestHttpClient.java deleted file mode 100644 index e76ad2b71..000000000 --- a/test/java/TestHttpClient.java +++ /dev/null @@ -1,109 +0,0 @@ -import org.apache.commons.httpclient.*; -import org.apache.commons.httpclient.methods.*; - -public class TestHttpClient -{ - - public static String JVMRoute = System.getProperty("JVMRoute", "node1"); - public static String Host = System.getProperty("Host", "localhost"); - public static String Factor = "50"; - /** - * - * Usage: - * java TestHttpClient http://mywebserver:80/ test - * - * @param args command line arguments - * Argument 0 is a URL to a web server - * Argument 1 is the command to execute. - * - */ - public static void main(String[] args) throws Exception - { - if (args.length == 2) - runit(args[0], args[1]); - else if (args.length == 3) { - Factor = args[2]; - System.out.println("Using factor: " + Factor); - runit(args[0], args[1]); - } else { - System.err.println("missing command line arguments"); - System.exit(1); - } - } - public static int runit(String URL, String command) throws Exception - { - - HttpClient httpClient = new HttpClient(); - PostMethod pm = null; - if (command.compareToIgnoreCase("ENABLE")==0) { - pm = (PostMethod) new EnableMethod(URL); - pm.addParameter("JVMRoute", JVMRoute); - pm.addParameter("context", "/myapp"); - System.out.println("ENABLE"); - } - else if (command.compareToIgnoreCase("DISABLE")==0) { - pm = (PostMethod) new DisableMethod(URL); - pm.addParameter("JVMRoute", JVMRoute); - pm.addParameter("context", "/myapp"); - } - else if (command.compareToIgnoreCase("STOP")==0) { - pm = (PostMethod) new StopMethod(URL); - pm.addParameter("JVMRoute", JVMRoute); - pm.addParameter("context", "/myapp"); - } - else if (command.compareToIgnoreCase("REMOVE")==0) { - pm = (PostMethod) new RemoveMethod(URL); - pm.addParameter("JVMRoute", JVMRoute); - pm.addParameter("context", "/hisapp"); - } - else if (command.compareToIgnoreCase("CONFIG")==0) { - pm = (PostMethod) new ConfigMethod(URL); - pm.addParameter("JVMRoute", JVMRoute); - pm.addParameter("Domain", "domain1"); - pm.addParameter("Host", Host); - pm.addParameter("Port", "8009"); - pm.addParameter("Type", "ajp"); - // pm.addParameter("Reversed", "yes"); - pm.addParameter("Context", "/hisapp,/ourapp"); - } - else if (command.compareToIgnoreCase("DUMP")==0) { - pm = (PostMethod) new DumpMethod(URL); - } - else if (command.compareToIgnoreCase("STATUS")==0) { - System.out.println("STATUS factor: " + Factor); - pm = (PostMethod) new StatusMethod(URL); - pm.addParameter("JVMRoute", JVMRoute); - pm.addParameter("Load", Factor); - } - else if (command.compareToIgnoreCase("ERROR")==0) { - pm = (PostMethod) new CauseErrorMethod(URL); - } - else - pm = (PostMethod) new InfoMethod(URL); - - System.out.println("Connecting to " + URL); - - Integer connectionTimeout = 40000; - pm.getParams().setParameter("http.socket.timeout", connectionTimeout); - pm.getParams().setParameter("http.connection.timeout", connectionTimeout); - httpClient.getParams().setParameter("http.socket.timeout", connectionTimeout); - httpClient.getParams().setParameter("http.connection.timeout", connectionTimeout); - - int httpResponseCode = 0; - try { - httpResponseCode = httpClient.executeMethod(pm); - System.out.println("response: " + httpResponseCode); - System.out.println("response: " + pm.getStatusLine()); - if (httpResponseCode == 500) { - System.out.println(pm.getResponseHeader("Version")); - System.out.println(pm.getResponseHeader("Type")); - System.out.println(pm.getResponseHeader("Mess")); - } - int len = (int) pm.getResponseContentLength(); - System.out.println("response:\n" + pm.getResponseBodyAsString(len)); - } catch(HttpException e) { - e.printStackTrace(); - } - return httpResponseCode; - } -} diff --git a/test/java/TestHttpClient.sh b/test/java/TestHttpClient.sh deleted file mode 100644 index 086e7fabb..000000000 --- a/test/java/TestHttpClient.sh +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright 2008 Red Hat Middleware, LLC. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software distributed -# under the License is distributed on an "AS IS" BASIS,i -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -CLASSES=$HOME/java/commons-httpclient-3.1/commons-httpclient-3.1.jar -javac -classpath $CLASSES *Method.java -javac -classpath $CLASSES:. TestHttpClient.java -CLASSES=$CLASSES:$HOME/java/commons-logging-1.0.4/commons-logging.jar:$HOME/java/commons-codec-1.3/commons-codec-1.3.jar:. - -HTTPD=localhost -JVMROUTE=node1 -HOST=localhost -SCHEME=http -SECURITY="-Djavax.net.ssl.trustStore=$HOME/.keystore -Djavax.net.ssl.keyStore=$HOME/CERTS/demoCA/test.p12 -Djavax.net.ssl.keyStorePassword=changeit -Djavax.net.ssl.keyStoreType=\"PKCS12\"" - - -# Send a CONFIG command. -java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ CONFIG - -java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ DUMP - -# Send a ENABLE for /myapp -java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ ENABLE - -java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ DUMP - -# Send a REMOVE for /hisapp -java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ REMOVE - -java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ DUMP - -java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ STATUS - -#java ${SECURITY} -classpath $CLASSES -DJVMRoute=${JVMROUTE} -DHost=${HOST} TestHttpClient ${SCHEME}://${HTTPD}:6666/test_bla/ INFO diff --git a/test/java/apachectl.bat b/test/java/apachectl.bat deleted file mode 100755 index 710f2bce8..000000000 --- a/test/java/apachectl.bat +++ /dev/null @@ -1,55 +0,0 @@ -@echo off -REM Copyright(c) 2009 Red Hat Middleware, LLC, -REM and individual contributors as indicated by the @authors tag. -REM See the copyright.txt in the distribution for a -REM full listing of individual contributors. -REM -REM This library is free software; you can redistribute it and/or -REM modify it under the terms of the GNU Lesser General Public -REM License as published by the Free Software Foundation; either -REM version 2 of the License, or (at your option) any later version. -REM -REM This library is distributed in the hope that it will be useful, -REM but WITHOUT ANY WARRANTY; without even the implied warranty of -REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -REM Lesser General Public License for more details. -REM -REM You should have received a copy of the GNU Lesser General Public -REM License along with this library in the file COPYING.LIB; -REM if not, write to the Free Software Foundation, Inc., -REM 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -REM -REM @author Jean-Frederic Clere -REM -@echo on - -IF NOT EXIST "@BASELOC@\httpd-2.4" ( - SET HTTPD_VERSION=2.2 -) ELSE ( - SET HTTPD_VERSION=2.4 -) - -@if "%1" == "stop" goto stop -@if "%1" == "start" goto start - -"@BASELOC@\httpd-%HTTPD_VERSION%\bin\httpd.exe" -k install -dir "@BASELOC@\httpd-%HTTPD_VERSION%\logs" -goto end - -:start -REM install will test httpd but using the current user so remove the logs files. -REM wait a little (2 ways) -REM choice /c C /D C /t 30 -REM ping -n 31 localhost > NUL -dir "@BASELOC@\httpd-%HTTPD_VERSION%\logs" -del "@BASELOC@\httpd-%HTTPD_VERSION%\logs\access_log" -del "@BASELOC@\httpd-%HTTPD_VERSION%\logs\error_log" -REM "@BASELOC@\httpd-%HTTPD_VERSION%\bin\httpd.exe" -k start -net start Apache%HTTPD_VERSION% -dir "@BASELOC@\httpd-%HTTPD_VERSION%\logs" -goto end - -:stop -"@BASELOC@\httpd-%HTTPD_VERSION%\bin\httpd.exe" -k stop -"@BASELOC@\httpd-%HTTPD_VERSION%\bin\httpd.exe" -k uninstall -:end diff --git a/test/java/build.properties.default b/test/java/build.properties.default deleted file mode 100644 index a83744fd8..000000000 --- a/test/java/build.properties.default +++ /dev/null @@ -1,52 +0,0 @@ -test.failonerror=true -BUILDTEST=N -build_version=1.2.0.Beta5-SNAPSHOT -root=. - -base-apache.loc=http://archive.apache.org/dist/ -base.path=${user.home}/java -base.apache=${user.home}/java/${os.name}-${os.version}-${os.arch} - -commons-httpclient.loc=${base-apache.loc}/httpcomponents/commons-httpclient/binary/commons-httpclient-3.1.tar.gz -commons-httpclient.jar=${base.path}/commons-httpclient-3.1/commons-httpclient-3.1.jar - -commons-logging.loc=${base-apache.loc}/commons/logging/binaries/commons-logging-1.0.4.tar.gz -commons-logging.jar=${base.path}/commons-logging-1.0.4/commons-logging.jar - -commons-codec.loc=${base-apache.loc}/commons/codec/binaries/commons-codec-1.3.tar.gz -commons-codec.jar=${base.path}/commons-codec-1.3.jar - -# junit stuff -junit.version=4.5 -junit.jar.loc=http://kent.dl.sourceforge.net/sourceforge/junit/junit-${junit.version}.jar -junit.jar=${base.path}/junit-${junit.version}/junit-${junit.version}.jar -base-junit.home=${base.path}/junit-${junit.version} - -# Location of jbossweb jar files. -base-jbossweb.loc=http://repository.jboss.org/nexus/content/groups/public/jboss/web/ -jbossweb.version=2.1.13.TEST1 -base-jbossweb.home=${base.path}/${jbossweb.version}/lib - -jbossweb.jar.loc=${base-jbossweb.loc}/jbossweb/${jbossweb.version}/jbossweb-${jbossweb.version}.jar -jbossweb.jar=${base.path}/${jbossweb.version}/jbossweb-${jbossweb.version}.jar - -servlet-api.jar.loc=${base-jbossweb.loc}/servlet-api/${jbossweb.version}/servlet-api-${jbossweb.version}.jar -servlet-api.jar=${base.path}/${jbossweb.version}/servlet-api-${jbossweb.version}.jar - -base-jboss.loc=http://repository.jboss.com/maven2/jboss - -jboss-logging.version=2.0.3.GA -base-jboss-logging.home=${base.path}/${jboss-logging.version}/lib -jboss-logging.jar.loc=${base-jboss.loc}/jboss-logging-spi/${jboss-logging.version}/jboss-logging-spi-${jboss-logging.version}.jar -jboss-logging.jar=${base.path}/${jboss-logging.version}/jboss-logging-spi-${jboss-logging.version}.jar - -jboss-ejb-api.version=4.2.1.GA -base-jboss-ejb-api.home=${base.path}/${jboss-ejb-api.version}/lib -jboss-ejb-api.jar.loc=${base-jboss.loc}/jboss-ejb-api/${jboss-ejb-api.version}/jboss-ejb-api-${jboss-ejb-api.version}.jar -jboss-ejb-api.jar=${base.path}/${jboss-ejb-api.version}/jboss-ejb-api-spi-${jboss-ejb-api.version}.jar - -mod_cluster.jar=../../core/target/mod_cluster-core-${build_version}.jar -mod_cluster_spi.jar=../../container-spi/target/mod_cluster-container-spi-${build_version}.jar -mod_cluster_catalina.jar=../../container/catalina/target/mod_cluster-container-catalina-${build_version}.jar -mod_cluster_catalina_standalone.jar=../../container/catalina-standalone/target/mod_cluster-container-catalina-standalone-${build_version}.jar -mod_cluster_jbossweb.jar=../../container/jbossweb/target/mod_cluster-container-jbossweb-${build_version}.jar diff --git a/test/java/build.xml b/test/java/build.xml deleted file mode 100644 index 43fb49261..000000000 --- a/test/java/build.xml +++ /dev/null @@ -1,358 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/java/conf/web.xml b/test/java/conf/web.xml deleted file mode 100644 index c1d79d779..000000000 --- a/test/java/conf/web.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - invoker - - org.apache.catalina.servlets.InvokerServlet - - - debug - 0 - - 2 - - - - invoker - /ROOT/* - /myapp/* - /* - - - diff --git a/test/java/installhttpd.sh b/test/java/installhttpd.sh deleted file mode 100644 index ed2e01b5f..000000000 --- a/test/java/installhttpd.sh +++ /dev/null @@ -1,424 +0,0 @@ -#!/bin/sh -# -# Script to install httpd in $BASELOC and configure it for mod_cluster tests. -# $1: IP address to listen (both for normal requests and cluster management ones. -# $2: IP address for the advertise -# $3: sub network to accept cluster management requests. -# $4: Use a binaries from a directory. -# $5: version to build. -# $6: root to find the binaries. -IP=localhost -ADVIP=224.0.1.105 -SUBIP=127.0.0.1 -BUILDTEST=N -build_version=1.0.0.dev -root=. -if [ "x$1" != "x" ] -then - IP=$1 -fi -if [ "x$2" != "x" ] -then - ADVIP=$2 -fi -if [ "x$3" != "x" ] -then - SUBIP=$3 -fi -if [ "x$4" != "x" ] -then - BUILDTEST=$4 -fi -if [ "x$5" != "x" ] -then - build_version=$5 -fi -if [ "x$6" != "x" ] -then - root=$6 -fi - -# -# Set the platform and arch for the download bundles. -if [ "x" = "x$BUILD_CPU" ]; then - BUILD_CPU=`uname -m` -fi -case ${BUILD_CPU} in - sun4u*) - BUILD_CPU=sparcv9 - ;; - i86pc*) - BUILD_CPU=x86 - ;; - i[3-6]86*) - BUILD_CPU=x86 - ;; - x86_64*) - BUILD_CPU=x64 - ;; - ia64*) - BUILD_CPU=i64 - ;; - 9000/800*) - BUILD_CPU=parisc2 - ;; - Power*) - BUILD_CPU=ppc - ;; -esac - -if [ "x" = "x$BUILD_SYS" ]; then - BUILD_SYS=`uname -s` -fi -case ${BUILD_SYS} in - Linux*) - BUILD_SYS="linux2" - ;; - SunOS*) - BUILD_SYS="solaris" - ;; - Darwin*) - BUILD_SYS="macosx" - ;; - HP-UX*) - BUILD_SYS="hpux" - ;; - CYGWIN*) - BUILD_SYS=windows - ;; -esac - -# Display what we are going to do. -echo "on ${BUILD_SYS} ${BUILD_CPU}" -BUILD_TAG=${BUILD_SYS}-${BUILD_CPU} -EXT=tar.gz -BASEHTTPD=opt/jboss/httpd -BASEHTTPDCONF=opt/jboss/httpd/httpd/conf -BASEHTTPDSBIN=opt/jboss/httpd/sbin -BASEHTTPDBIN=opt/jboss/httpd/bin -BASEHTTPDBUILD=opt/jboss/httpd/htdocs/build -BASEHTTPDLIBEXECDIR=opt/jboss/httpd/lib/httpd -case $BUILD_TAG in - *hpux-parisc2*) - BASE=mod_cluster-hp-ux-9000_800 - ;; - *hpux-i64*) - BASE=mod_cluster-hp-ux-ia64 - ;; - *linux2-x86*) - BASE=mod_cluster-linux-i686 - ;; - *linux2-i64*) - BASE=mod_cluster-linux-ia64 - ;; - *linux2-x64*) - BASE=mod_cluster-linux-x86_64 - ;; - *solaris-sparcv9*) - BASE=mod_cluster-solaris-sparc - ;; - *solaris-x86*) - BASE=mod_cluster-solaris-x86 - ;; - *windows*) - echo "Windows later for 2.2.x versus 2.4.x" - BASE=mod_cluster-windows - EXT=zip - BASEHTTPD=httpd-2.2 - BASEHTTPDCONF=${BASEHTTPD}/conf - BASEHTTPDSBIN=${BASEHTTPD}/bin - BASEHTTPDLIBEXECDIR=${BASEHTTPD} - ;; -esac -#PACKVER=rhel-httpd-2.2.8-1.el5s2 -PACKVER=mod_cluster-${build_version} - -# Something like (note don't use ssl for the moment. -# http://hudson.qa.jboss.com/hudson/view/Native/job/mod_cluster-linux-x86_64/lastSuccessfulBuild/artifact/jbossnative/build/unix/output/rhel-httpd-2.2.8-1.el5s2-linux2-x64-ssl.tar.gz -# http://hudson.qa.jboss.com/hudson/view/Native/job/mod_cluster-solaris-x86/lastSuccessfulBuild/artifact/jbossnative/build/unix/output/mod_cluster-1.0.0.dev-solaris-x86.tar.gz -# The result of the build is something like: -# /qa/services/hudson/hudson_workspace/workspace/mod_cluster-linux-i686/jbossnative/build/unix/output/mod_cluster-1.0.0.dev-linux2-x86.tar.gz -# -TARBALL=http://hudson.qa.jboss.com/hudson/view/Native/job/${BASE}/lastSuccessfulBuild/artifact/jbossnative/build/unix/output/${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} - -if [ "x${BUILD_SYS}" = "xwindows" ]; then - BASELOC=`ant base | grep echo | sed 's:\[echo\]::' | sed 's:^ *::'` -else - BASELOC=`ant base | grep echo | sed 's:\[echo\]::' | sed 's:^ *::' | sed 's: :/:g'` -fi - -REMOVE=true -if [ "x${BASELOC}" = "x" ] -then - BASELOC=`pwd` - echo "Using current dir for Base: $BASELOC !!!" - if [ ! -f ${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} ] - then - ant downloadfile -Dsourcefile=${TARBALL} -Ddestfile=${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} -Ddestdir="$BASELOC" - if [ ! -f ${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} ] - then - REMOVE=false - fi - fi -else - if [ "x${BUILDTEST}" = "xN" ] - then - # rm -f ${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} - if [ ! -f ${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} ] - then - ant downloadfile -Dsourcefile=${TARBALL} -Ddestfile=${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} -Ddestdir="$BASELOC" - else - echo "Warning the file ${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} is reused" - fi - else - echo "Using $root (no download)" - EXT=file - fi -fi -TARBALL=`pwd`/${PACKVER}-${BUILD_SYS}-${BUILD_CPU}.${EXT} - -export BASELOC -echo "Base is: $BASELOC !!!" -# Clean previous install -if $REMOVE -then - rm -rf "$BASELOC" - mkdir "$BASELOC" -fi -case ${EXT} in - file) - echo "copying the install from $root to $BASELOC" - cp -rp $root/* "$BASELOC" - case $BUILD_TAG in - *windows*) - EXT=zip - ;; - *) - EXT=tar.gz - ;; - esac - ;; - tar.gz) - (cd $BASELOC - gzip -dc ${TARBALL} | tar xvf - - ) - ;; - *) - (cd "$BASELOC" - unzip ${TARBALL} - ) - ;; -esac - -case $BUILD_TAG in - *windows*) - BASE=mod_cluster-windows - EXT=zip - if [ -d "$BASELOC/httpd-2.2" ]; then - BASEHTTPD=httpd-2.2 - HTTPD_VERSION=2.2 - else - BASEHTTPD=httpd-2.4 - HTTPD_VERSION=2.4 - fi - BASEHTTPDCONF=${BASEHTTPD}/conf - BASEHTTPDSBIN=${BASEHTTPD}/bin - BASEHTTPDLIBEXECDIR=${BASEHTTPD} - ;; -esac - - -if [ -x ${BASEHTTPDSBIN}/apachectl ]; then - HTTPD_VERSION=`${BASEHTTPDSBIN}/apachectl -v | grep "Server version"` - case ${HTTPD_VERSION} in - *2.2*) - HTTPD_VERSION=2.2 - ;; - *2.4*) - HTTPD_VERSION=2.4 - ;; - esac -fi -INSTWIN=false -case ${EXT} in - tar.gz) - # Arrange the installed files - if [ -x ${BASELOC}/${BASEHTTPDSBIN}/installhome.sh ]; then - # Use / test the installhome script - ${BASELOC}/${BASEHTTPDSBIN}/installhome.sh - else - if [ -f ${BASEHTTPDSBIN}/apxs ]; then - files="${BASEHTTPDSBIN}/apachectl ${BASEHTTPDCONF}/httpd.conf ${BASEHTTPDSBIN}/envvars ${BASEHTTPDSBIN}/apxs ${BASEHTTPDBUILD}/config_vars.mk" - echo "httpd-2.2.x" - else - files="${BASEHTTPDSBIN}/apachectl ${BASEHTTPDCONF}/httpd.conf ${BASEHTTPDSBIN}/envvars ${BASEHTTPDBIN}/apxs ${BASEHTTPDBUILD}/config_vars.mk" - echo "httpd-2.4.x" - fi - for FILE in `echo $files` - do - file=${BASELOC}/$FILE - echo "$file" - cp -p $file $file.new - sed "s:${BASEHTTPD}:${BASELOC}/${BASEHTTPD}:" $file > $file.new - mv $file $file.`date +%y%m%d.%H%M%S`.org - mv $file.new $file - done - # Arrange apachectl - file=$BASELOC/${BASEHTTPDSBIN}/apachectl - cp -p $file $file.new - echo "s:\$HTTPD -k \$ARGV:\$HTTPD -k \$ARGV -d ${BASELOC}/${BASEHTTPD}/httpd:" > sed.cmd - sed -f sed.cmd $file > $file.new - mv $file $file.`date +%y%m%d.%H%M%S`.1.org - mv $file.new $file - fi - ;; - *) - # Arrange the installed files - (cd "$BASELOC/httpd-${HTTPD_VERSION}/bin" - ./installconf.bat - ) - INSTWIN=true - ;; -esac - -# -# Arrange httpd.conf -file="$BASELOC/${BASEHTTPDCONF}/httpd.conf" -cp -p "$file" "$file.new" -grep MOD_CLUSTER_ADDS "$file" -if [ $? -ne 0 ] -then - echo "s/Listen 80.*/Listen @IP@:8000/" > sed.cmd - sed -f sed.cmd "$file" > "$file.new" -else - # Uncomment out conf stuff - echo "s/#ServerAdvertise/ServerAdvertise/" > sed.cmd - echo "s/#Advertise/Advertise/" >> sed.cmd - if $INSTWIN - then - # windoze has 8080 and already the MOD_CLUSTER_ADDS. - echo "s/Listen 80.*/Listen @IP@:8000/" >> sed.cmd - else - echo "s/127.0.0.1:6666/@IP@:6666/" >> sed.cmd - echo "s/127.0.0/@SUBIP@/" >> sed.cmd - fi - sed -f sed.cmd "$file" > "$file.new" -fi - -grep MOD_CLUSTER_ADDS "$file" -if [ $? -ne 0 ] -then - if [ "${HTTPD_VERSION}" = "2.2" ]; then - cat >> "$file.new" < - Listen @IP@:6666 - ManagerBalancerName mycluster - - - Order deny,allow - Deny from all - Allow from @SUBIP@ - - - KeepAliveTimeout 300 - MaxKeepAliveRequests 0 - ServerAdvertise on http://@IP@:6666 - AdvertiseFrequency 5 - AdvertiseSecurityKey secret - AdvertiseGroup @ADVIP@:23364 - - - SetHandler mod_cluster-manager - Order deny,allow - Deny from all - Allow from @SUBIP@ - - - - -EOF - else - cat >> "$file.new" < - Listen @IP@:6666 - ManagerBalancerName mycluster - - - Require ip @SUBIP@ - - - KeepAliveTimeout 300 - MaxKeepAliveRequests 0 - ServerAdvertise on http://@IP@:6666 - AdvertiseFrequency 5 - AdvertiseSecurityKey secret - AdvertiseGroup @ADVIP@:23364 - - - SetHandler mod_cluster-manager - Require ip @SUBIP@ - - - - -EOF - fi -fi - -# Add rewrite tests and UseAlias -# Add ProxyPass to test MODCLUSTER-274 (2 should be enough :)). -cat >> "$file.new" <> "$file.new" < sed.cmd -echo "s/@ADVIP@/${ADVIP}/" >> sed.cmd -echo "s/@SUBIP@/${SUBIP}/" >> sed.cmd -sed -f sed.cmd "$file.new" > "$file.new.1" - -# replace httpd.conf by the new file. -mv "$file" "$file.`date +%y%m%d.%H%M%S`.1.org" -mv "$file.new.1" "$file" - -# restore the execute permissions. -chmod a+x "$BASELOC/${BASEHTTPDSBIN}"/* -chmod a+x "$BASELOC/${BASEHTTPD}"/bin/* -case $BUILD_TAG in - *windows*) - # The service is run as Administrators/SYSTEM - chown -R Administrators "$BASELOC/httpd-${HTTPD_VERSION}" - chgrp -R SYSTEM "$BASELOC/httpd-${HTTPD_VERSION}" - ;; -esac diff --git a/test/java/load.sh b/test/java/load.sh deleted file mode 100644 index 6b6fcb1d5..000000000 --- a/test/java/load.sh +++ /dev/null @@ -1 +0,0 @@ -java -classpath $HOME/java/commons-codec-1.3.jar:$HOME/java//commons-logging-1.0.4/commons-logging.jar:$HOME/java//commons-httpclient-3.1/commons-httpclient-3.1.jar:output/classes/ org.jboss.mod_cluster.Client http://localhost:8000/myapp/MyCount $1 diff --git a/test/java/pom.xml b/test/java/pom.xml deleted file mode 100644 index 3708305a4..000000000 --- a/test/java/pom.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - - 4.0.0 - - org.jboss.mod_cluster - mod_cluster-parent - 2.0.0.Alpha1-SNAPSHOT - ../.. - - mod_cluster-tests - mod_cluster: Integration Tests - Test for mod_cluster - http://jboss.org/mod_cluster - - - - org.jboss.mod_cluster - mod_cluster-core - ${project.version} - - - org.jboss.mod_cluster - mod_cluster-container-spi - ${project.version} - - - org.jboss.mod_cluster - mod_cluster-container-catalina - ${project.version} - - - org.jboss.mod_cluster - mod_cluster-container-catalina-standalone - ${project.version} - - - org.jboss.mod_cluster - mod_cluster-container-jbossweb - ${project.version} - - - - org.jboss.web - jbossweb - ${version.jbossweb7} - - - jboss.web - servlet-api - provided - - - - org.jboss.logging - jboss-logging - test - - - commons-httpclient - commons-httpclient - 3.1 - - - junit - junit - - - - - - - dist - - false - - - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - always - - - - - diff --git a/test/java/src/main/java/org/jboss/mod_cluster/Client.java b/test/java/src/main/java/org/jboss/mod_cluster/Client.java deleted file mode 100644 index cab180ad9..000000000 --- a/test/java/src/main/java/org/jboss/mod_cluster/Client.java +++ /dev/null @@ -1,376 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2008 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.Random; - -import org.apache.commons.httpclient.*; -import org.apache.commons.httpclient.methods.*; -import org.apache.commons.httpclient.cookie.CookiePolicy; -import java.util.Date; -import java.text.DateFormat; -import java.text.SimpleDateFormat; - -public class Client extends Thread { - - private String jsessionid = null; - - private String URL = null; - - private String BaseURL = "http://localhost:8000"; - String post = null; - String user = null; - String pass = null; - InputStream fd = null; - private String VirtualHost = null; - - private int nbtest = 10; - private int delay = 1000; - private int wait = 100; - private Random rand = null; - private boolean checkcookie = true; - private boolean checknode = true; - private boolean success = true; - private String node = null; - - public int httpResponseCode = 0; - public String requestedSessionId = null; - - private HttpClient httpClient = null; - - private String response = null; - - private boolean logok = Boolean.valueOf(System.getProperty( - "logok", - "false")).booleanValue(); - - /* - * - * Usage: - * java Client http://mywebserver:80/ test - * - * @param args command line arguments - * Argument 0 is a URL to a web server - * Argument 1 is the max time to wait between requests (in 10 milliseconds units) - * - */ - public static void main(String[] args) throws Exception - { - if (args.length != 2) - { - System.err.println("missing command line arguments"); - System.exit(1); - } - Client client[] = new Client[50]; - for (int i=0; i= 0) - break; - line = bufferedreader.readLine(); - } - String result = ""; - int len = l; - if (!concat) - len = l-2; - while (result.length() < len && (line = bufferedreader.readLine()) != null) { - result = result.concat(line); - if (concat) - result = result.concat("\n"); - } - if (l == 0) - return null; - return result; - } -} diff --git a/test/java/src/main/java/org/jboss/mod_cluster/JBossWeb.java b/test/java/src/main/java/org/jboss/mod_cluster/JBossWeb.java deleted file mode 100644 index 4eec1a099..000000000 --- a/test/java/src/main/java/org/jboss/mod_cluster/JBossWeb.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2008 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.FileInputStream; -import java.io.FileOutputStream; - -import org.apache.tomcat.InstanceManager; - -import java.lang.reflect.InvocationTargetException; -import javax.naming.NamingException; - -import org.apache.catalina.startup.ContextConfig; -import org.apache.catalina.*; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.core.*; -import org.apache.catalina.startup.HostConfig; - -import org.apache.tomcat.util.IntrospectionUtils; - -public class JBossWeb extends StandardService { - - private String route = null; - - private void copyFile(File in, File out) throws IOException { - FileInputStream fis = new FileInputStream(in); - FileOutputStream fos = new FileOutputStream(out); - byte[] buf = new byte[1024]; - int i = 0; - while((i=fis.read(buf))!=-1) { - fos.write(buf, 0, i); - } - fis.close(); - fos.close(); - } - - private static void copyFiles(File src, File dest) throws IOException { - if (src.isDirectory()) { - if (!dest.exists()) - dest.mkdirs(); - - String list[] = src.list(); - for (int i = 0; i < list.length; i++) { - File dest1 = new File(dest, list[i]); - File src1 = new File(src, list[i]); - copyFiles(src1 , dest1); - } - } else { - //This was not a directory, so lets just copy the file - FileInputStream fin = null; - FileOutputStream fout = null; - byte[] buffer = new byte[4096]; //Buffer 4K at a time (you can change this). - int bytesRead; - //open the files for input and output - fin = new FileInputStream(src); - fout = new FileOutputStream (dest); - //while bytesRead indicates a successful read, lets write... - while ((bytesRead = fin.read(buffer)) >= 0) { - fout.write(buffer,0,bytesRead); - } - fout.close(); - fin.close(); - } - } - private void copyNativeDir(String route) throws IOException { - File in = new File("bin/"); - if (!in.exists()) { - return; - } - File ou = new File("node1/bin"); - if (!ou.exists()) { - ou.mkdirs(); - } - copyFiles(in, ou); - } - - /** - * Returns a JBossWeb service to use in our embedded tests. - * - * @param route the JVMRoute of the corresponding node. - * @param host the name of the virtualhost - * @param nat indicated to use native or not. - * @param webapp name of webapp (ROOT maps as / and bla as /bla). - * @param Aliasias an array of String containing the Aliases names. - * @return the created jbossweb service. - */ - - public JBossWeb(String route, String host, boolean nat, String webapp, String[] Aliases) throws IOException { - // Copy native tree... - if (nat) { - copyNativeDir(route); - } - - System.setProperty( "catalina.base", route); - System.setProperty( "catalina.home", route); - this.route = route; - - //Create an Engine - Engine baseEngine = new StandardEngine(); - - baseEngine.setName(host + "Engine" + route); - baseEngine.setDefaultHost(host); - baseEngine.setJvmRoute(route); - baseEngine.setRealm(null); - - // Create node1/webapps/ROOT and index.html - File fd = new File ( route + "/webapps/" + webapp); - fd.mkdirs(); - String docBase = fd.getAbsolutePath(); - String appBase = fd.getParent(); - fd = new File (route + "/webapps/" + webapp, "index.html"); - FileWriter out = new FileWriter(fd); - out.write(route + ":This is a test\n"); - out.close(); - - // Copy a small servlets for testing. - fd = new File ( route + "/webapps/" + webapp + "/WEB-INF/classes"); - fd.mkdirs(); - // Session logic tests... - fd = new File (route + "/webapps/" + webapp + "/WEB-INF/classes" , "MyCount.class"); - File fdin = new File ("MyCount.class"); - if (!fdin.exists()) - fdin = new File ("target/classes/MyCount.class"); - copyFile(fdin, fd); - // Simple tests... - fd = new File (route + "/webapps/" + webapp + "/WEB-INF/classes" , "MyTest.class"); - fdin = new File ("MyTest.class"); - if (!fdin.exists()) - fdin = new File ("target/classes/MyTest.class"); - copyFile(fdin, fd); - - //Create Host - StandardHost baseHost = new StandardHost(); - baseHost.setAppBase(appBase); - baseHost.setName(host); - - // createHost( host, appBase); - // baseHost.setDeployOnStartup(true); - baseHost.setBackgroundProcessorDelay(1); - //StandardHost stdhost = (StandardHost)baseHost; - // stdhost.setDeployXML(true); - baseHost.setConfigClass("org.apache.catalina.startup.ContextConfig"); - // stdhost.setUnpackWARs(true); - if (Aliases != null && Aliases.length>0) { - for (int j = 0; j < Aliases.length; j++) { - baseHost.addAlias(Aliases[j]); - } - } - HostConfig hostConfig = new HostConfig(); - baseHost.addLifecycleListener(hostConfig); - baseEngine.addChild(baseHost); - - //Create default context - Context rootContext = new StandardContext(); - rootContext.setDocBase(docBase); - if (webapp.equals("ROOT")) - rootContext.setPath(""); - else - rootContext.setPath("/" + webapp); - ContextConfig config = new ContextConfig(); - ((Lifecycle) rootContext).addLifecycleListener(config); - - rootContext.setIgnoreAnnotations(true); - rootContext.setPrivileged(true); - rootContext.setInstanceManager(new LocalInstanceManager()); - - Wrapper testwrapper = rootContext.createWrapper(); - testwrapper.setName("MyCount"); - testwrapper.setServletClass("MyCount"); - testwrapper.setLoadOnStartup(0); - rootContext.addChild(testwrapper); - rootContext.addServletMapping("/MyCount", "MyCount"); - - Wrapper wrapper = rootContext.createWrapper(); - wrapper.setName("MyTest"); - wrapper.setServletClass("MyTest"); - wrapper.setLoadOnStartup(0); - rootContext.addChild(wrapper); - rootContext.addServletMapping("/MyTest", "MyTest"); - baseHost.addChild( rootContext ); - // addEngine( baseEngine ); - this.container = baseEngine; - baseEngine.setService(this); - this.setName(host + "Engine" + route); - // setRedirectStreams(false); - } - - - public JBossWeb(String route, String host) throws IOException { - this(route, host, false); - } - public JBossWeb(String route, String host, boolean nat) throws IOException { - this(route, host, nat, "ROOT"); - } - public JBossWeb(String route, String host, String webapp) throws IOException { - this(route, host, false, webapp); - } - public JBossWeb(String route, String host, boolean nat, String webapp) throws IOException { - this(route, host, nat, webapp, null); - } - - /** Add a host - * @param host name of the host - * @param Aliasias an array of String containing the Aliases names. - */ - void AddHost(String host, String[] Aliases) { - - File fd = new File ( host + "/webapps/"); - fd.mkdirs(); - String appBase = fd.getPath(); - - //Create Host - StandardHost baseHost = new StandardHost(); - baseHost.setAppBase(appBase); - baseHost.setName(host); - - baseHost.setBackgroundProcessorDelay(1); - baseHost.setConfigClass("org.apache.catalina.startup.ContextConfig"); - - if (Aliases != null && Aliases.length>0) { - for (int j = 0; j < Aliases.length; j++) { - baseHost.addAlias(Aliases[j]); - } - } - HostConfig hostConfig = new HostConfig(); - baseHost.addLifecycleListener(hostConfig); - Engine engine = (Engine) getContainer(); - engine.addChild(baseHost); - } - - /** - * Add a context to the StandardService (to all the virtual host defined in the Engine). - * @param path for bla is will deploy as /bla. - * @param docBase path to use - * @param servletname name of the server. - * @param wait tell if the wait is 10000 in the parameters of the servlet. - * @param host name of the virtual host where to add the context (null : every virtual hosts). - * @throws IOException - */ - void AddContext(String path, String base, String servletname, boolean wait, String hostname) throws IOException { - File fd = new File ( route + "/webapps/" + base); - fd.mkdirs(); - String docBase = fd.getAbsolutePath(); - fd = new File (route + "/webapps/" + base + "/WEB-INF/classes"); - fd.mkdirs(); - - // Session logic tests... - fd = new File (route + "/webapps/" + base + "/WEB-INF/classes" , "MyCount.class"); - File fdin = new File ("MyCount.class"); - if (!fdin.exists()) - fdin = new File ("target/classes/MyCount.class"); - copyFile(fdin, fd); - // Simple tests... - fd = new File (route + "/webapps/" + base + "/WEB-INF/classes" , "MyTest.class"); - fdin = new File ("MyTest.class"); - if (!fdin.exists()) - fdin = new File ("target/classes/MyTest.class"); - copyFile(fdin, fd); - - - System.out.println("AddContext: " + path + "/" + servletname + " on " + docBase); - - Context context = new StandardContext(); - context.setDocBase(docBase); - context.setPath(path); - context.setInstanceManager(new LocalInstanceManager()); - ContextConfig config = new ContextConfig(); - ((Lifecycle) context).addLifecycleListener(config); - context.setIgnoreAnnotations(true); - context.setPrivileged(true); - - if (servletname != null) { - Wrapper wrapper = context.createWrapper(); - wrapper.setName(servletname); - wrapper.setServletClass(servletname); - if (wait) { - wrapper.addInitParameter("wait", "10000"); - wrapper.setLoadOnStartup(1); - } else { - wrapper.setLoadOnStartup(0); - } - context.addChild(wrapper); - context.addServletMapping("/" + servletname, servletname); - } - - - Engine engine = (Engine) getContainer(); - Container[] containers = engine.findChildren(); - for (int j = 0; j < containers.length; j++) { - if (containers[j] instanceof Host) { - Host host = (Host) containers[j]; - if (hostname != null && !host.getName().equals(hostname)) - continue; - System.out.println("AddContext: " + path + " added on " + host); - host.addChild(context); - } - } - } - void AddContext(String path, String docBase, String servletname, boolean wait) throws IOException { - AddContext(path, docBase, servletname, wait, null); - } - void AddContext(String path, String docBase) throws IOException { - AddContext(path, docBase, "MyCount", false, null); - } - - public void addWAR(String file, String route) throws IOException { - File fd = new File ( route + "/" + route + "/webapps"); - fd.mkdirs(); - - String sep = System.getProperty("file.separator"); - String [] paths = file.split(sep); - - fd = new File (route + "/" + route + "/webapps", paths[paths.length-1]); - File fdin = new File (file); - - copyFile(fdin, fd); - } - - public Connector addConnector(int port) throws Exception { - return addConnector(port, "ajp"); - } - - public Connector addConnector(int port, String scheme) throws Exception { - return addConnector(port, scheme, null); - } - - public Connector addConnector(int port, String protocol, String address) throws Exception { - - - Connector connector = null; - if (protocol.equals("ajp")) { - connector= new Connector("org.apache.coyote.ajp.AjpProtocol"); - } else if (protocol.equals("http")) { - connector= new Connector(protocol); - } - if (address != null) { - IntrospectionUtils.setProperty(connector, "address", - "" + address); - } - - IntrospectionUtils.setProperty(connector, "port", "" + port); - IntrospectionUtils.setProperty(connector, "backlog", "400"); - - // Look in StandardService to see why it works ;-) - addConnector( connector ); - - return connector; - } - - /* - * remove the context from the virtualhost. - */ - public void removeContext(String path, String hostname) { - Engine engine = (Engine) getContainer(); - Container[] containers = engine.findChildren(); - for (int j = 0; j < containers.length; j++) { - if (containers[j] instanceof StandardHost) { - StandardHost host = (StandardHost) containers[j]; - if (hostname != null && !host.getName().equals(hostname)) - continue; - Context context = (Context) host.findChild(path); - if (context != null) - containers[j].removeChild(context); - } - } - } - public void removeContext(String path) { - removeContext(path, null); - } - private static class LocalInstanceManager implements InstanceManager { - @Override - public Object newInstance(String className) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException { - return Class.forName(className).newInstance(); - } - - @Override - public Object newInstance(String fqcn, ClassLoader classLoader) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException { - return Class.forName(fqcn, false, classLoader).newInstance(); - } - - @Override - public Object newInstance(Class c) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException { - return c.newInstance(); - } - - @Override - public void newInstance(Object o) throws IllegalAccessException, InvocationTargetException, NamingException { - throw new IllegalStateException(); - } - - @Override - public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException { - } - } -} diff --git a/test/java/src/main/java/org/jboss/mod_cluster/Maintest.java b/test/java/src/main/java/org/jboss/mod_cluster/Maintest.java deleted file mode 100644 index 64951b0f7..000000000 --- a/test/java/src/main/java/org/jboss/mod_cluster/Maintest.java +++ /dev/null @@ -1,420 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2008 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import junit.framework.Assert; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import junit.textui.TestRunner; - -import java.lang.Exception; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.InetSocketAddress; -import java.util.Map; - -import org.apache.catalina.Service; -import org.apache.catalina.Engine; -import org.apache.catalina.core.StandardServer; -import org.apache.catalina.connector.Connector; - -import org.jboss.modcluster.ModClusterService; -import org.jboss.modcluster.config.impl.ModClusterConfig; -import org.jboss.modcluster.config.impl.SessionDrainingStrategyEnum; -import org.jboss.modcluster.container.catalina.CatalinaEventHandlerAdapter; -import org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider; - -public class Maintest { - - static CatalinaEventHandlerAdapter adapter = null; - - /* Print the service and connectors the server knows */ - static void listServices(StandardServer server) { - Service[] services = server.findServices(); - for (int i = 0; i < services.length; i++) { - System.out.println("service[" + i + "]: " + services[i]); - Engine engine = (Engine) services[i].getContainer(); - System.out.println("engine: " + engine); - System.out.println("connectors: " + services[i].findConnectors()); - Connector [] connectors = services[i].findConnectors(); - for (int j = 0; j < connectors.length; j++) { - System.out.println("connector: " + connectors[j]); - } - } - } - - /* Create the listener - * server: the server to use. - * groupa: multi address to receive from httpd. - * groupp: port to receive from httpd. - * ssl: use ssl. - * domain: domain to send to httpd (to fail over in the domain). - * stickySession: use stickySession. - * stickySessionRemove: remove the sessionid if we are sticky and need to failover. - * stickySessionForce: return an error if we have to failover to another node. - * advertiseSecurityKey: Key for the digest logic. - * balancer: balancer name. - * loadBalancingGroup: mod_cluster domain name. - */ - static ModClusterService createClusterListener(StandardServer server, - String groupa, int groupp, boolean ssl, String domain, - boolean stickySession, boolean stickySessionRemove, - boolean stickySessionForce, String advertiseSecurityKey, - String balancer, String loadBalancingGroup) { - ModClusterConfig config = new ModClusterConfig(); - config.setAdvertiseGroupAddress(groupa); - config.setAdvertisePort(groupp); - config.setSsl(ssl); - config.setLoadBalancingGroup(domain); - config.setStickySession(stickySession); - config.setStickySessionRemove(stickySessionRemove); - config.setStickySessionForce(stickySessionForce); - config.setNodeTimeout(20000); - config.setSessionDrainingStrategy(SessionDrainingStrategyEnum.NEVER); - if (balancer != null) - config.setBalancer(balancer); - if (loadBalancingGroup != null) - config.setLoadBalancingGroup(loadBalancingGroup); - if (advertiseSecurityKey != null) - config.setAdvertiseSecurityKey(advertiseSecurityKey); - SimpleLoadBalanceFactorProvider load = new SimpleLoadBalanceFactorProvider(); - load.setLoadBalanceFactor(1); - ModClusterService service = new ModClusterService(config, load); - adapter = new CatalinaEventHandlerAdapter(service, server); - adapter.start(); - - return service; - } - static ModClusterService createClusterListener(StandardServer server, - String groupa, int groupp, boolean ssl, String domain, - boolean stickySession, boolean stickySessionRemove, - boolean stickySessionForce, String advertiseSecurityKey) - { - return createClusterListener(server, groupa, groupp, ssl, domain, - stickySession, stickySessionRemove, - stickySessionForce, advertiseSecurityKey, null, null); - } - - /* - * Stop the adapter for the ClusterListener - */ - static void StopClusterListener() { - if (adapter != null) { - try { - adapter.stop(); - } catch(Exception ex) { - // Ignore it. - } - } - adapter = null; - } - /* ping httpd */ - static String doProxyPing(ModClusterService pcluster) { - String result = null; - - Map map = pcluster.ping(); - if (map.isEmpty()) - return null; - Object results[] = map.values().toArray(); - result = (String ) results[0]; - - return result; - } - /* ping a node (via JVmRoute). */ - static String doProxyPing(ModClusterService pcluster, String JvmRoute) { - String result = null; - Map map = pcluster.ping(JvmRoute); - if (map.isEmpty()) - return null; - Object results[] = map.values().toArray(); - /* We may have several answers return the first one that has PING-RSP in it */ - for (int i=0; i0) - break; - } - return result; - } - static String doProxyPing(ModClusterService pcluster, String scheme, String host, int port) { - String result = null; - Map map = pcluster.ping(scheme, host, port); - if (map.isEmpty()) - return null; - Object results[] = map.values().toArray(); - /* We may have several answers return the first one that has PING-RSP in it */ - for (int i=0; i0) - break; - } - return result; - } - /* Analyse the PING-RSP message: Type=PING-RSP&State=OK&id=1 */ - static boolean checkProxyPing(String result) { - String [] records = result.split("\n"); - String [] results = null; - if (records.length == 3) - results = records[1].split("&"); - else - results = result.split("&"); - int ret = 0; - for (int j=0; j map = pcluster.getProxyInfo(); - if (map.isEmpty()) - return null; - Object results[] = map.values().toArray(); - result = (String) results[0]; - return result; - } - static String getProxyAddress(ModClusterService pcluster) { - String proxy = null; - - Map map = pcluster.getProxyInfo(); - if (!map.isEmpty()) { - Object results[] = map.keySet().toArray();; - InetSocketAddress result = (InetSocketAddress) results[0]; - proxy = result.getHostName() + ":" + result.getPort(); - } - return proxy; - } - /* Check that the nodes are returned by the INFO command */ - static boolean checkProxyInfo(ModClusterService pcluster, String [] nodes) { - String result = getProxyInfo(pcluster); - return checkProxyInfo(result, nodes); - } - static boolean checkProxyInfo(String result, String [] nodes) { - if (result == null) { - if (nodes == null) - return true; - else - return false; - } - /* create array to check the nodes */ - boolean [] n = null; - if (nodes != null && nodes.length>0) { - n = new boolean[nodes.length]; - for (int i=0; i= 0) { - String res = results[j].substring(6); - if (Integer.parseInt(res) > 0) { - nodeok = true; - break; - } - } - } - /* result[1] should be Name: node_name */ - data = results[1].split(": "); - for (int j=0; j0). */ - static boolean TestForNodes(ModClusterService pcluster, String [] nodes) { - int countinfo = 0; - while ((!Maintest.checkProxyInfo(pcluster, nodes)) && countinfo < 80) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - if (countinfo == 80) { - System.out.println("TestForNodes failed: " + getProxyInfo(pcluster)); - return false; - } else - return true; - } - /* Wait until we are able to connect to httpd and then until the node is in the ok status (load>0). */ - static boolean WaitForNodes(ModClusterService pcluster, String [] nodes) { - if (WaitForHttpd(pcluster, 60) == -1) { - System.out.println("can't find PING-RSP in proxy response"); - return false; - } - return TestForNodes(pcluster, nodes); - } - - // Wait until we are able to PING httpd. - // tries maxtries and wait 5 s between retries... - static int WaitForHttpd(ModClusterService pcluster, int maxtries) { - String result = null; - int tries = 0; - while (result == null && tries 0) { - nonce = nnonce.substring(0, k); - break; - } - } - } else { - System.out.println("response: " + httpResponseCode); - System.out.println("response: " + bm.getStatusLine()); - throw(new Exception("Reponse notok")); - } - // System.out.println("response:\n" + bm.getResponseBodyAsString(len)); - } catch(HttpException e) { - System.out.println("error: " + e); - throw(e); - } - bm.releaseConnection(); - } - /* - * Disable a Node - */ - public void disable(String node) throws Exception { - String DURL = URL + "?nonce=" + nonce + "&Cmd=DISABLE-APP&Range=NODE&JVMRoute=" + node; - DoCmd(DURL); - } - /* Disable a Context */ - public void disable(String node, String host, String context) throws Exception { - String DURL = URL + "?nonce=" + nonce + "&Cmd=DISABLE-APP&Range=CONTEXT&JVMRoute=" + node + - "&Alias=" + host + - "&Context=" + context; - DoCmd(DURL); - } - - private String DoCmd(String DURL) throws Exception { - GetMethod gm = new GetMethod(DURL); - try { - httpResponseCode = httpClient.executeMethod(gm); - - if (httpResponseCode == 200) { - String result = gm.getResponseBodyAsString(); - gm.releaseConnection(); - return result; - } - } catch (HttpException e) { - System.out.println("error: " + e); - throw(e); - } - gm.releaseConnection(); - throw(new Exception("Reponse notok")); - - } - public String getProxyInfo() throws Exception { - String DURL = URL + "?nonce=" + nonce + "&Cmd=INFO&Range=ALL"; - return DoCmd(DURL); - } - public boolean isApacheHttpd() throws Exception { - GetMethod gm = new GetMethod(URL); - try { - httpResponseCode = httpClient.executeMethod(gm); - } catch (HttpException e) { - System.out.println("error: " + e); - throw(e); - } - gm.releaseConnection(); - Header head = gm.getResponseHeader("Server"); - if (head != null) - return head.toString().contains("Apache/2"); - return false; - } -} diff --git a/test/java/src/main/java/org/jboss/mod_cluster/MyCount.java b/test/java/src/main/java/org/jboss/mod_cluster/MyCount.java deleted file mode 100644 index ba73da4dd..000000000 --- a/test/java/src/main/java/org/jboss/mod_cluster/MyCount.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright(c) 2006 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $ - */ - -import java.io.*; -import java.text.*; -import java.util.*; -import javax.servlet.*; -import javax.servlet.http.*; - - - -/** - * Example servlet showing cookies handling (counter). - * - */ - -public class MyCount extends HttpServlet { - - public void init(ServletConfig config) throws ServletException { - String swait = config.getInitParameter("wait"); - int wait = 0; - if (swait != null) { - Integer iwait = new Integer(swait); - wait = iwait.intValue(); - } - - if (wait != 0) { - Thread me = Thread.currentThread(); - try { - me.sleep(wait); - } catch(Exception e) { - throw new ServletException("sleep interrupted"); - } - } - } - - public void doGet(HttpServletRequest request, - HttpServletResponse response) - throws IOException, ServletException - { - response.setContentType("text/html"); - - PrintWriter out = response.getWriter(); - out.println(""); - out.println(""); - out.println(""); - - String title = "sessions.title"; - out.println("" + title + ""); - out.println(""); - out.println(""); - - out.println("

" + title + "

"); - HttpSession session = request.getSession(false); - Integer ii = new Integer(0); - if (session == null) { - // Create it. - out.println("create"); - session = request.getSession(true); - session.setAttribute("count", ii); - } - out.println("sessions.id " + session.getId()); - out.println("
"); - out.println("sessions.created "); - out.println(new Date(session.getCreationTime()) + "
"); - out.println("sessions.lastaccessed "); - out.println(new Date(session.getLastAccessedTime())); - out.println("sessions.count "); - out.println(session.getAttribute("count")); - - ii = (Integer) session.getAttribute("count"); - int i = 0; - if (ii != null) - i = ii.intValue(); - i++; - ii = new Integer(i); // JAVA5 : ii.valueOf(i); - session.setAttribute("count", ii); - - out.println("

"); - out.println("sessions.data
"); - Enumeration names = session.getAttributeNames(); - while (names.hasMoreElements()) { - String name = (String) names.nextElement(); - String value = session.getAttribute(name).toString(); - out.println(name + " = " + value + "
"); - // response.addHeader(name, value); - } - - out.println("

"); - out.print("

"); - out.println("sessions.dataname"); - out.println(""); - out.println("
"); - out.println("sessions.datavalue"); - out.println(""); - out.println("
"); - out.println(""); - out.println("
"); - - out.println("

GET based form:
"); - out.print("

"); - out.println("sessions.dataname"); - out.println(""); - out.println("
"); - out.println("sessions.datavalue"); - out.println(""); - out.println("
"); - out.println(""); - out.println("
"); - - out.print("

URL encoded "); - - out.println(""); - out.println(""); - - out.println(""); - out.println(""); - - /* Use headers */ - response.setHeader("RequestedSessionId", request.getRequestedSessionId()); - - } - - public void doPost(HttpServletRequest request, - HttpServletResponse response) - throws IOException, ServletException - { - doGet(request, response); - } - -} diff --git a/test/java/src/main/java/org/jboss/mod_cluster/MyTest.java b/test/java/src/main/java/org/jboss/mod_cluster/MyTest.java deleted file mode 100644 index b2cc80460..000000000 --- a/test/java/src/main/java/org/jboss/mod_cluster/MyTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright(c) 2009 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $ - */ - -import java.io.*; -import java.text.*; -import java.util.*; -import javax.servlet.*; -import javax.servlet.http.*; - - - -/** - * Test servlet for mod_cluster tests. - * - */ - -public class MyTest extends HttpServlet { - - public void doGet(HttpServletRequest request, - HttpServletResponse response) - throws IOException, ServletException - { - response.setContentType("text/html"); - - PrintWriter out = response.getWriter(); - out.println(""); - out.println(""); - out.println(""); - - String title = request.getContextPath() + "/Test servlet"; - out.println("" + title + ""); - out.println(""); - out.println(""); - - out.println("

request.getContextPath(): " + request.getContextPath() + "

"); - out.println("

request.getQueryString(): " + request.getQueryString() + "

"); - - String test = request.getParameter("test"); - if (test !=null && test.equalsIgnoreCase("timeout")) { - Thread me = Thread.currentThread(); - try { - me.sleep(15000); - } catch(Exception e) { - throw new ServletException("sleep interrupted"); - } - } - - out.println(""); - out.println(""); - - } - - public void doPost(HttpServletRequest request, - HttpServletResponse response) - throws IOException, ServletException - { - doGet(request, response); - } - -} diff --git a/test/java/src/main/java/org/jboss/mod_cluster/NodeInfo.java b/test/java/src/main/java/org/jboss/mod_cluster/NodeInfo.java deleted file mode 100644 index 89588279c..000000000 --- a/test/java/src/main/java/org/jboss/mod_cluster/NodeInfo.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2008 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import java.util.ArrayList; - -public class NodeInfo { - String JVMRoute; - int lbfactor; - int elected; - - /** - * Check that nodes in nodeinfos corresponds to nodes in nodenames - */ - static public boolean check(ArrayList nodes, String [] nodenames) - { - boolean [] in = new boolean[nodenames.length]; - - if (nodes == null || nodenames == null) { - System.out.println("No nodes or no names"); - return false; - } - - NodeInfo [] nodeinfos = new NodeInfo[nodes.size()]; - for (int i=0; i= 0; read = in.read(buffer)) - System.out.write(buffer, 0, read); - out.close(); - in.close(); - socket.close(); - } catch (Exception ex) { - ex.printStackTrace(); - fail("can't send message"); - } - - // Read the result. - String result = Maintest.getProxyInfo(cluster); - System.out.println("INFO: " + result); - if (result.indexOf("ModCluster349")==-1) - fail("can't find ModCluster349 in: " + result); - - // Stop the jboss and remove the services. - try { - wait.stopit(); - wait.join(); - - server.removeService(service); - server.removeService(service2); - } catch (InterruptedException ex) { - ex.printStackTrace(); - fail("can't stop service"); - } - if (clienterror) - fail("Client error"); - - // Wait until httpd as received the stop messages. - countinfo = 0; - nodes = null; - while ((!Maintest.checkProxyInfo(cluster, nodes)) && countinfo < 20) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - Maintest.StopClusterListener(); - System.gc(); - System.out.println("Test349 Done"); - } -} diff --git a/test/java/src/test/java/org/jboss/mod_cluster/TestAddDel.java b/test/java/src/test/java/org/jboss/mod_cluster/TestAddDel.java deleted file mode 100644 index 43ed086fb..000000000 --- a/test/java/src/test/java/org/jboss/mod_cluster/TestAddDel.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2008 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import java.io.IOException; - -import java.util.ArrayList; - -import junit.framework.TestCase; - -import org.apache.catalina.Engine; -import org.apache.catalina.Service; -import org.jboss.modcluster.ModClusterService; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.core.StandardServer; - -public class TestAddDel extends TestCase { - - /* Test */ - public void testAddDel() { - - boolean clienterror = false; - int numbnodes = 10; - String [] nodenames = new String [numbnodes]; - JBossWeb [] service = new JBossWeb[numbnodes]; - ModClusterService lifecycle = null; - - System.out.println("TestAddDel Started"); - System.setProperty("org.apache.catalina.core.StandardService.DELAY_CONNECTOR_STARTUP", "false"); - StandardServer server = new StandardServer(); - for (int i=0; i1) { - // Check that the last alias is also working. - client = new Client(); - client.setVirtualHost(Aliases2[Aliases2.length-1]); - try { - if (client.runit(url, 10, false, true) != 0) - clienterror = true; - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (clienterror) - fail("Client fail (long host: " +Aliases2[Aliases2.length-1] + ")"); - } - - // Start the client and wait for it. - client = new Client(); - clienterror = false; - - // Wait for it. - try { - if (client.runit(url, 10, false, true) != 0) - clienterror = true; - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (clienterror) - fail("Client error"); - - // Test the other nodes - if (virtualhosts != null) - testVirtualHosts(virtualhosts); - - // Stop the connector that has received the request... - url = ""; - if (webapps != null) - url = "/test"; - node = client.getnode(); - if ("node4".equals(node)) { - service2.removeContext(url); - node = "node3"; - } else { - service.removeContext(url); - node = "node4"; - } - - // Run a test on it. (it waits until httpd as received the nodes information). - client.setnode(node); - try { - client.setdelay(30000); - client.start(); - client.join(); - } catch (Exception ex) { - ex.printStackTrace(); - } - if (client.getresultok()) - System.out.println("Test DONE"); - else { - System.out.println("Test FAILED"); - clienterror = true; - } - - // Test the other nodes - if (virtualhosts != null) { - if (virtualhosts.length == 2) - test2VirtualHosts(virtualhosts, service, service2); - else - testVirtualHosts(virtualhosts); - } - - // Stop the server or services. - try { - wait.stopit(); - wait.join(); - server.removeService(service); - server.removeService(service2); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - - // Wait until httpd as received the stop messages. - if (!Maintest.TestForNodes(cluster, null)) - fail("Can't stop nodes"); - Maintest.StopClusterListener(); - - // Test client result. - if (clienterror) - fail("Client test failed"); - - Maintest.testPort(8013); - Maintest.testPort(8014); - System.out.println("TestAliases Done"); - } - private void myAliases(String [] Aliases,String [] Aliases2, VirtualHost [] virtualhosts) { - myAliases(Aliases, Aliases2, virtualhosts, null); - } - - private void testVirtualHosts(VirtualHost[] virtualhosts) { - for (int i=0; i< virtualhosts.length; i++) { - Client client = new Client(); - client.setVirtualHost(virtualhosts[i].host); - // Wait for it. - boolean clienterror = false; - try { - if (client.runit("/" + virtualhosts[i].context + "/" + virtualhosts[i].servletname, 10, false, true) != 0) - clienterror = true; - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (clienterror) - fail("Client failed (" + virtualhosts[i].host + ")"); - System.out.println("Tested " + virtualhosts[i].host + " OK"); - } - - } - - /* - * Tests: - * v1 v1 app1 VirtualHost[0] - * v2 v1 app2 VirtualHost[1] - */ - private void test2VirtualHosts(VirtualHost[] virtualhosts, JBossWeb service, JBossWeb service2 ) { - Client client = new Client(); - client.setVirtualHost(virtualhosts[0].host); - // Wait for it. - boolean clienterror = false; - try { - if (client.runit("/" + virtualhosts[0].context + "/" + virtualhosts[0].servletname, 10, false, true) != 0) - clienterror = true; - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (clienterror) - fail("Client failed (" + virtualhosts[0].host + ")"); - - // Now try the app2 on VirtualHost[0] - client = new Client(); - client.setVirtualHost(virtualhosts[0].host); - // Wait for it. - clienterror = false; - try { - if (client.runit("/" + virtualhosts[0].context + "/" + virtualhosts[1].servletname, 10, false, true) != 0) { - // Make sure the answer comes from JBossWeb - if (client.getResponse().indexOf("JBoss Web") ==-1) - fail("Got 404 from httpd"); - } - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (clienterror) - fail("Client failed (" + virtualhosts[0].host + ")"); - - // Now stop the context on one virtuahost - if (virtualhosts[1].addtofirst) - service.removeContext("/" + virtualhosts[1].context, virtualhosts[1].host); - else - service2.removeContext("/" + virtualhosts[1].context, virtualhosts[1].host); - - // Now try the app2 on VirtualHost[1] - client = new Client(); - client.setVirtualHost(virtualhosts[1].host); - // Wait for it. - clienterror = false; - try { - if (client.runit("/" + virtualhosts[1].context + "/" + virtualhosts[1].servletname, 10, false, true) != 0) { - // Make sure the answer comes from httpd - if (client.getResponse().indexOf("JBoss Web") ==-1) - clienterror = true; - else - fail("Got 404 from JBoss Web"); - } - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (!clienterror) - fail("Client should have failed (" + virtualhosts[1].host + ")"); - - - client = new Client(); - client.setVirtualHost(virtualhosts[0].host); - // Wait for it. - clienterror = false; - try { - if (client.runit("/" + virtualhosts[0].context + "/" + virtualhosts[0].servletname, 10, false, true) != 0) - clienterror = true; - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (clienterror) - fail("Client failed (" + virtualhosts[0].host + ")"); - - - } - - - private void addVirtualHosts(JBossWeb service, JBossWeb service2, VirtualHost[] virtualhosts) throws IOException { - for (int i=0; i< virtualhosts.length; i++) { - if (virtualhosts[i].addtofirst) { - service.AddHost( virtualhosts[i].host, virtualhosts[i].aliases); - String path = "/"+virtualhosts[i].context; - service.AddContext(path, path, virtualhosts[i].servletname, false, virtualhosts[i].host); - } else { - service2.AddHost( virtualhosts[i].host, virtualhosts[i].aliases); - String path = "/"+virtualhosts[i].context; - service2.AddContext(path, path, virtualhosts[i].servletname, false, virtualhosts[i].host); - } - } - - } - public class VirtualHost { - String host; // Name of the Host = 1 first Alias. - String [] aliases; // Alias for the Host. - boolean addtofirst; // node (well service) to add the virtualhost and context. - String servletname; // Servlet to map. (MyCount or MyTest) - String context; // context where the Servlet is deployed. - } - -} diff --git a/test/java/src/test/java/org/jboss/mod_cluster/TestAliasesSize.java b/test/java/src/test/java/org/jboss/mod_cluster/TestAliasesSize.java deleted file mode 100644 index 4ae745866..000000000 --- a/test/java/src/test/java/org/jboss/mod_cluster/TestAliasesSize.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2012 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import java.io.IOException; - -import junit.framework.TestCase; - -import org.apache.catalina.Engine; -import org.apache.catalina.Service; -import org.jboss.modcluster.ModClusterService; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.core.StandardServer; - -public class TestAliasesSize extends TestCase { - - /* Test testAliasesSize (we test the MCMP maxsize here in fact) */ - public void testAliasesSize() { - - boolean clienterror = false; - StandardServer server = new StandardServer(); - JBossWeb service = null; - Connector connector = null; - ModClusterService cluster = null; - System.out.println("TestAliasesSize Started"); - System.setProperty("org.apache.catalina.core.StandardService.DELAY_CONNECTOR_STARTUP", "false"); - try { - String [] Aliases = new String[19]; - /* HOSTALIASZ is 100 that should be enough */ - for (int i=0; i < Aliases.length; i++) { - Aliases[i] = "alias0123456789012345678901234567890123456789012345678901234567890123456789012345out" + i; - } - /* ~ 87 * 19 ~ 1740 :D */ - - service = new JBossWeb("node3", "localhost", false, "ROOT", Aliases); - connector = service.addConnector(8013); - service.AddContext("/test", "/test"); - server.addService(service); - - cluster = Maintest.createClusterListener(server, "224.0.1.105", 23364, false, "dom1", true, false, true, "secret"); - - } catch(Exception ex) { - ex.printStackTrace(); - fail("can't start service"); - } - - // start the server thread. - ServerThread wait = new ServerThread(3000, server); - wait.start(); - - // Wait until we are able to connect to httpd. - int tries = Maintest.WaitForHttpd(cluster, 60); - if (tries == -1) { - fail("can't find PING-RSP in proxy response"); - } - - // Wait until 2 nodes are created in httpd. - String [] nodes = new String[1]; - nodes[0] = "node3"; - Maintest.TestForNodes(cluster, nodes); - - // Test wrong Hostname. - Client client = new Client(); - client.setVirtualHost("mycluster.domain.com"); - - // Wait for it. - try { - if (client.runit("/test/MyCount", 10, false, true) != 0) - clienterror = true; - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (!clienterror) - fail("Client should fail (wrong host)"); - - // Test long Hostname. - client = new Client(); - client.setVirtualHost("alias0123456789012345678901234567890123456789012345678901234567890123456789012345out18"); - clienterror = false; - - // Wait for it. - try { - if (client.runit("/test/MyCount", 10, false, true) != 0) - clienterror = true; - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (clienterror) - fail("Client fail (long host)"); - - // Stop the server or services. - try { - wait.stopit(); - wait.join(); - server.removeService(service); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - - // Wait until httpd as received the stop messages. - Maintest.TestForNodes(cluster, null); - Maintest.StopClusterListener(); - - // Test client result. - if (clienterror) - fail("Client test failed"); - - Maintest.testPort(8013); - System.out.println("TestAliasesSize Done"); - } -} diff --git a/test/java/src/test/java/org/jboss/mod_cluster/TestBalancers.java b/test/java/src/test/java/org/jboss/mod_cluster/TestBalancers.java deleted file mode 100644 index f528ea8d3..000000000 --- a/test/java/src/test/java/org/jboss/mod_cluster/TestBalancers.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2012 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import junit.framework.TestCase; - -import org.jboss.modcluster.ModClusterService; -import org.apache.catalina.core.StandardServer; - -public class TestBalancers extends TestCase { - /* Test that the sessions are really sticky */ - public void testBalancers() { - myBalancers(null, null, null, null); - } - public void testBalancers2() { - myBalancers("balancer", "dom1", "balancer", "dom1"); - } - public void testBalancers3() { - myBalancers("balancer", "dom1", "balancer", "dom2"); - } - - /* We need 2 different applications if we have 2 balancers */ - public void testBalancers4() { - myBalancers("balancer1", "dom1", "/app1", "balancer2", "dom2", "/app2", false); - } - - /* Use Aliases and 2 balancers */ - public void testBalancers5() { - myBalancers("balancer", "dom1", null, "balancer", "dom2", null, true); - } - - private void myBalancers(String balancer, String loadBalancingGroup, String balancer2, String loadBalancingGroup2) { - myBalancers(balancer, loadBalancingGroup, null, balancer2, loadBalancingGroup2, null, false); - } - private void myBalancers(String balancer, String loadBalancingGroup, String app, String balancer2, String loadBalancingGroup2, String app2, boolean testAlias) { - boolean clienterror = false; - System.setProperty("org.apache.catalina.core.StandardService.DELAY_CONNECTOR_STARTUP", "false"); - StandardServer server = new StandardServer(); - StandardServer server2 = new StandardServer(); - JBossWeb service = null; - JBossWeb service2 = null; - ModClusterService cluster = null; - ModClusterService cluster2 = null; - - System.out.println("TestBalancers Started"); - - Maintest.waitForFreePorts(8011, 2); - - try { - - if (testAlias) { - String [] Aliases = new String[1]; - Aliases[0] = "alias1"; - service = new JBossWeb("node1", "localhost", false, "ROOT", Aliases); - } else - service = new JBossWeb("node1", "localhost"); - service.addConnector(8011); - if (app != null) - service.AddContext(app, app, "MyCount", false); - server.addService(service); - - if (testAlias) { - String [] Aliases = new String[1]; - Aliases[0] = "alias2"; - service2 = new JBossWeb("node2", "localhost", false, "ROOT", Aliases); - } else - service2 = new JBossWeb("node2", "localhost"); - service2.addConnector(8012); - if (app2 != null) - service2.AddContext(app2, app2, "MyCount", false); - server2.addService(service2); - - cluster = Maintest.createClusterListener(server, "224.0.1.105", 23364, false, null, true, false, true, "secret", balancer, loadBalancingGroup); - cluster2 = Maintest.createClusterListener(server2, "224.0.1.105", 23364, false, null, true, false, true, "secret", balancer2, loadBalancingGroup2); - - } catch(Exception ex) { - ex.printStackTrace(); - fail("can't start service"); - } - - // start the server thread. - ServerThread wait = new ServerThread(3000, server); - wait.start(); - ServerThread wait2 = new ServerThread(3000, server2); - wait2.start(); - - // Wait until httpd as received the nodes information. - String [] nodes = new String[1]; - nodes[0] = "node1"; - int countinfo = 0; - while ((!Maintest.checkProxyInfo(cluster, nodes)) && countinfo < 20) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - if (countinfo == 20) - fail("Can't start node1"); - nodes[0] = "node2"; - countinfo = 0; - while ((!Maintest.checkProxyInfo(cluster2, nodes)) && countinfo < 20) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - if (countinfo == 20) - fail("Can't start node2"); - - // Start the client and wait for it. - Client client = new Client(); - String node = null; - try { - if (app == null) - client.runit("/MyCount", 20, true); - else - client.runit(app + "/MyCount", 20, true); - node = client.getnode(); - } catch (Exception e) { - e.printStackTrace(); - clienterror = true; - } - countinfo = 0; - while (client.getnode().equals(node) && !clienterror && countinfo < 20) { - Client client2 = new Client(); - String url = "/MyCount"; - // We try to test that the other node on the other balancer is working too. - if (client.getnode().equals("node1")) { - if (app2 != null) - url = app2 + "/MyCount"; - if (testAlias) - client.setVirtualHost("node2"); - } - if (client.getnode().equals("node2")) { - if (app != null) - url = app + "/MyCount"; - if (testAlias) - client.setVirtualHost("node1"); - } - - try { - client2.runit(url, 20, true); - client.start(); - client.join(); - } catch (Exception e) { - e.printStackTrace(); - clienterror = true; - } - client = client2; - countinfo++; - } - if (countinfo == 20) - fail("Can't connect to " + node); - - // Wait for it. - try { - client.start(); - client.join(); - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (client.getresultok()) - System.out.println("Test DONE"); - else { - System.out.println("Test FAILED"); - clienterror = true; - } - - // Stop the jboss and remove the services. - try { - wait.stopit(); - wait.join(); - wait2.stopit(); - wait2.join(); - - server.removeService(service); - server2.removeService(service2); - } catch (InterruptedException ex) { - ex.printStackTrace(); - fail("can't stop service"); - } - if (clienterror) - fail("Client error"); - - // Wait until httpd as received the stop messages. - countinfo = 0; - nodes = null; - while ((!Maintest.checkProxyInfo(cluster, nodes)) && countinfo < 20) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - Maintest.StopClusterListener(); - - System.gc(); - System.out.println("TestBalancers Done"); - } -} diff --git a/test/java/src/test/java/org/jboss/mod_cluster/TestBase.java b/test/java/src/test/java/org/jboss/mod_cluster/TestBase.java deleted file mode 100644 index 0969f7375..000000000 --- a/test/java/src/test/java/org/jboss/mod_cluster/TestBase.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2008 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import java.io.IOException; - -import junit.framework.TestCase; - -import org.apache.catalina.Engine; -import org.apache.catalina.Service; -import org.jboss.modcluster.ModClusterService; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.core.StandardServer; - -public class TestBase extends TestCase { - - /* Test that the sessions are really sticky */ - public void testBase() { - - boolean clienterror = false; - StandardServer server = new StandardServer(); - JBossWeb service = null; - JBossWeb service2 = null; - ModClusterService cluster = null; - - System.out.println("TestBase Started"); - System.setProperty("org.apache.catalina.core.StandardService.DELAY_CONNECTOR_STARTUP", "false"); - try { - - service = new JBossWeb("node1", "localhost"); - service.addConnector(8011); - server.addService(service); - - service2 = new JBossWeb("node2", "localhost"); - service2.addConnector(8010); - server.addService(service2); - - cluster = Maintest.createClusterListener(server, "224.0.1.105", 23364, false, null, true, false, true, "secret"); - - } catch(Exception ex) { - ex.printStackTrace(); - fail("can't start service"); - } - - // start the server thread. - ServerThread wait = new ServerThread(3000, server); - wait.start(); - - // Wait until httpd as received the nodes information. - String [] nodes = new String[2]; - nodes[0] = "node1"; - nodes[1] = "node2"; - int countinfo = 0; - while ((!Maintest.checkProxyInfo(cluster, nodes)) && countinfo < 20) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - - // Start the client and wait for it. - Client client = new Client(); - - // Wait for it. - try { - client.runit("/MyCount", 20, true); - client.start(); - client.join(); - } catch (Exception ex) { - ex.printStackTrace(); - clienterror = true; - } - if (client.getresultok()) - System.out.println("Test DONE"); - else { - System.out.println("Test FAILED"); - clienterror = true; - } - - // Stop the jboss and remove the services. - try { - wait.stopit(); - wait.join(); - - server.removeService(service); - server.removeService(service2); - } catch (InterruptedException ex) { - ex.printStackTrace(); - fail("can't stop service"); - } - if (clienterror) - fail("Client error"); - - // Wait until httpd as received the stop messages. - countinfo = 0; - nodes = null; - while ((!Maintest.checkProxyInfo(cluster, nodes)) && countinfo < 20) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - Maintest.StopClusterListener(); - - System.gc(); - System.out.println("TestBase Done"); - } -} diff --git a/test/java/src/test/java/org/jboss/mod_cluster/TestBaseJgroups.java b/test/java/src/test/java/org/jboss/mod_cluster/TestBaseJgroups.java deleted file mode 100644 index 939adb9f8..000000000 --- a/test/java/src/test/java/org/jboss/mod_cluster/TestBaseJgroups.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2012 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import java.io.IOException; - -import junit.framework.TestCase; - -import org.apache.catalina.Engine; -import org.apache.catalina.Service; -import org.jboss.modcluster.ModClusterService; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.core.StandardServer; - -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; - -public class TestBaseJgroups extends TestCase { - - /* Test that the sessions are really sticky */ - public void testBase() { - System.out.println("TestBaseJgroups doing nothing for the moment..."); - } - public void NotestBase() { - - boolean clienterror = false; - StandardServer server = new StandardServer(); - ModClusterService cluster = null; - JBossWeb service = null; - - System.out.println("TestBaseJgroups Started"); - System.setProperty("org.apache.catalina.core.StandardService.DELAY_CONNECTOR_STARTUP", "false"); - try { - service = new JBossWeb("node1", "localhost"); - service.addConnector(8011); - server.addService(service); - cluster = Maintest.createClusterListener(server, "224.0.1.105", 23364, false, null, true, false, true, "secret"); - } catch(Exception ex) { - ex.printStackTrace(); - fail("can't start service"); - } - - // start the server thread. - ServerThread wait = new ServerThread(3000, server); - wait.start(); - - // Wait until httpd we know about httpd. - String [] nodes = new String[1]; - nodes[0] = "node1"; - int countinfo = 0; - while ((!Maintest.checkProxyInfo(cluster, nodes)) && countinfo < 20) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - - // Create 2 JGroups ID and query the result and remove them. - String proxy = Maintest.getProxyAddress(cluster); - String URL = "http://" + proxy + "/"; - HttpClient httpClient = new HttpClient(); - PostMethod pm = null; - pm = (PostMethod) new AddIdMethod(URL); - pm.addParameter("JGroupUuid", "ID1"); - pm.addParameter("JGroupData", "DATA1"); - String response = processrequest(pm, httpClient); - if (response == null) - fail("ADDID(1) failed on: " + URL); - - pm = (PostMethod) new AddIdMethod(URL); - pm.addParameter("JGroupUuid", "ID2"); - pm.addParameter("JGroupData", "DATA2"); - response = processrequest(pm, httpClient); - if (response == null) - fail("ADDID(2) failed"); - - pm = (PostMethod) new QueryMethod(URL); - pm.addParameter("JGroupUuid", "*"); - response = processrequest(pm, httpClient); - if (response == null) - fail("QUERY failed"); - System.out.println("Response:\n" + response); - String [] records = response.split("\n"); - if (records.length != 2) - fail("QUERY return " + records.length + " JGroupUuid instead 2"); - - pm = (PostMethod) new RemoveIdMethod(URL); - pm.addParameter("JGroupUuid", "ID2"); - response = processrequest(pm, httpClient); - if (response == null) - fail("REMOVE(ID2) failed"); - - pm = (PostMethod) new RemoveIdMethod(URL); - pm.addParameter("JGroupUuid", "ID1"); - response = processrequest(pm, httpClient); - if (response == null) - fail("REMOVE(ID1) failed"); - -/* See MODCLUSTER-282 it doesn't work on all hudson boxes. - pm = (PostMethod) new QueryMethod(URL); - pm.addParameter("JGroupUuid", "*"); - response = processrequest(pm, httpClient); - if (response == null) - fail("QUERY failed"); - System.out.println("Response:\n" + response); - if (response.length() == 0) - System.out.println("AddId + Remove OK"); - else - fail("QUERY returns " + response + " instead nothing"); - */ - - // Stop the jboss and remove the services. - try { - wait.stopit(); - wait.join(); - server.removeService(service); - } catch (InterruptedException ex) { - ex.printStackTrace(); - fail("can't stop service"); - } - if (clienterror) - fail("Client error"); - - // Wait until httpd as received the stop messages. - countinfo = 0; - while ((!Maintest.checkProxyInfo(cluster, null)) && countinfo < 20) { - try { - Thread.sleep(3000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - countinfo++; - } - Maintest.StopClusterListener(); - - System.gc(); - System.out.println("TestBaseJgroups Done"); - } - - public static String processrequest(PostMethod pm, HttpClient httpClient) - { - Integer connectionTimeout = 40000; - pm.getParams().setParameter("http.socket.timeout", connectionTimeout); - pm.getParams().setParameter("http.connection.timeout", connectionTimeout); - httpClient.getParams().setParameter("http.socket.timeout", connectionTimeout); - httpClient.getParams().setParameter("http.connection.timeout", connectionTimeout); - - int httpResponseCode = 0; - try { - httpResponseCode = httpClient.executeMethod(pm); - System.out.println("response: " + httpResponseCode); - System.out.println("response: " + pm.getStatusLine()); - if (httpResponseCode == 500) { - System.out.println(pm.getResponseHeader("Version")); - System.out.println(pm.getResponseHeader("Type")); - System.out.println(pm.getResponseHeader("Mess")); - return null; - } - if (httpResponseCode == 200) { - int len = (int) pm.getResponseContentLength(); - if (len != -1) - return pm.getResponseBodyAsString(len); - else - return pm.getResponseBodyAsString(); - } - } catch(Exception e) { - e.printStackTrace(); - } - return null; - } - - public class AddIdMethod extends PostMethod { - public String getName() { - return "ADDID"; - } - public AddIdMethod(String uri) { - super(uri); - } - } - public class RemoveIdMethod extends PostMethod { - public String getName() { - return "REMOVEID"; - } - public RemoveIdMethod(String uri) { - super(uri); - } - } - public class QueryMethod extends PostMethod { - public String getName() { - return "QUERY"; - } - public QueryMethod(String uri) { - super(uri); - } - } -} diff --git a/test/java/src/test/java/org/jboss/mod_cluster/TestChunkedMCPM.java b/test/java/src/test/java/org/jboss/mod_cluster/TestChunkedMCPM.java deleted file mode 100644 index 830812b73..000000000 --- a/test/java/src/test/java/org/jboss/mod_cluster/TestChunkedMCPM.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * mod_cluster - * - * Copyright(c) 2012 Red Hat Middleware, LLC, - * and individual contributors as indicated by the @authors tag. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * @author Jean-Frederic Clere - * @version $Revision$ - */ - -package org.jboss.mod_cluster; - -import java.io.IOException; - -import java.util.ArrayList; - -import junit.framework.TestCase; - -import org.apache.catalina.Engine; -import org.apache.catalina.Service; -import org.jboss.modcluster.ModClusterService; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.core.StandardServer; - -public class TestChunkedMCPM extends TestCase { - - /* Test */ - public void testChunkedMCPM() { - - boolean clienterror = true; - int numbnodes = 30; - String [] nodenames = new String [numbnodes]; - JBossWeb [] service = new JBossWeb[numbnodes]; - ModClusterService lifecycle = null; - - System.out.println("TestChunkedMCPM Started"); - System.setProperty("org.apache.catalina.core.StandardService.DELAY_CONNECTOR_STARTUP", "false"); - StandardServer server = new StandardServer(); - for (int i=0; i&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') +if [ "${SESSIONCO}" == "" ];then + echo "Failed no sessionid in curl output..." + curl -v http://localhost:8000/testapp/test.jsp +fi +echo ${SESSIONCO} +NEWCO=$(curl -v --cookie "${SESSIONCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') +if [ "${NEWCO}" != "" ]; then + echo "Failed not sticky received : ${NEWCO}???" + clean_and_exit +fi + +# Copy testapp and wait for starting +docker cp testapp tomcat8080:/usr/local/tomcat/webapps +sleep 10 + +# Sticky (yes there are 2 apps now) +echotestlabel "sticky 2 app" +SESSIONCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') +NODE=$(echo ${SESSIONCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }') +echo "first: ${SESSIONCO} node: ${NODE}" +NEWCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') +NEWNODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }') +echo "second: ${NEWCO} node: ${NEWNODE}" +echo "Checking we can reach the 2 nodes" +i=0 +while [ "${NODE}" == "${NEWNODE}" ] +do + NEWCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') + NEWNODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }') + i=$(expr $i + 1) + if [ $i -gt 40 ]; then + echo "Can't find the 2 webapps" + clean_and_exit + fi + if [ "${NEWNODE}" == "" ]; then + echo "Can't find node in request" + clean_and_exit + fi + echo "trying other webapp try: ${i}" + clean_and_exit +done +echo "${i} try gives: ${NEWCO} node: ${NEWNODE}" + +# Still sticky +CO=$(curl -v --cookie "${SESSIONCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') +if [ "${CO}" != "" ]; then + echo "Failed not sticky received : ${CO}???" + clean_and_exit +fi +CO=$(curl -v --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') +if [ "${CO}" != "" ]; then + echo "Failed not sticky received : ${CO}???" + clean_and_exit +fi + +# Stop one of the while running requests. +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}" +CODE="200" +i=0 +while [ "$CODE" == "200" ] +do + if [ $i -gt 100 ]; then + echo "Done remaining tomcat still answering!" + break + fi + 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} + fi + i=$(expr $i + 1) +done +if [ ${CODE} != "200" ]; then + echo "Something was wrong... got: ${CODE}" + curl -v --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp + clean_and_exit +fi + +# Restart the tomcat +nohup docker run --network=host -e tomcat_port=${PORT} -e tomcat_shutdown_port=true --name tomcat${PORT} ${IMG} & + +# Now try to test the websocket +echotestlabel "testing websocket" +# The websocket-hello app is at: https://github.com/jfclere/httpd_websocket +mvn dependency:copy -U -Dartifact=org.apache.tomcat:websocket:hello:0.0.1:war -DoutputDirectory=. +if [ $? -ne 0 ]; then + echo "Something was wrong... can't find org.apache.tomcat:websocket:hello:0.0.1:war" + cp $HOME/.m2/repository/org/apache/tomcat/websocket-hello/0.0.1/websocket-hello-0.0.1.war . + if [ $? -ne 0 ]; then + clean_and_exit + fi +fi +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 +# Put the testapp in the tomcat we restarted. +docker cp testapp tomcat${PORT}:/usr/local/tomcat/webapps +sleep 10 +mvn -f pom-groovy.xml install +java -jar target/test-1.0.jar WebSocketsTest +if [ $? -ne 0 ]; then + echo "Something was wrong... with websocket tests" + clean_and_exit +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 +sleep 10 +java -jar target/test-1.0.jar HTTPTest +if [ $? -ne 0 ]; then + echo "Something was wrong... with HTTP tests" + clean_and_exit +fi + +# +# Test virtual host +echotestlabel "Testing virtual hosts" +docker cp tomcat8081:/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 quay.io/${USER}/tomcat_mod_cluster-examples +docker stop tomcat8081 +docker container rm tomcat8081 +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 quay.io/${USER}/tomcat_mod_cluster-examples & +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: +# X-Forwarded-For: 127.0.0.1 +# X-Forwarded-Host: example.com +# X-Forwarded-Server: fe80::faf4:935b:9dda:2adf +# therefore don't forget ProxyPreserveHost On (otherwise UseAlias On failed...) +# +CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8000/test/test.jsp) +if [ ${CODE} != "200" ]; then + echo "Failed can't rearch webapp at example.com: ${CODE}" + clean_and_exit +fi +# Basically curl --header "Host: localhost" http://127.0.0.1:8000/test/test.jsp gives 400 +CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8000/test/test.jsp) +if [ ${CODE} != "404" ]; then + echo "Failed should NOT rearch webapp at localhost: ${CODE}" + clean_and_exit +fi +# Same using localhost/testapp2 and curl --header "Host: localhost" http://127.0.0.1:8000/testapp2/test.jsp +CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8000/testapp2/test.jsp) +if [ ${CODE} != "200" ]; then + echo "Failed can't rearch webapp at localhost: ${CODE}" + clean_and_exit +fi +# Basically curl --header "Host: example.com" http://127.0.0.1:8000/testapp2/test.jsp gives 400 +CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8000/testapp2/test.jsp) +if [ ${CODE} != "404" ]; then + echo "Failed should NOT rearch webapp at localhost: ${CODE}" + exit 1 +fi + +# Shutdown the 2 tomcats +docker exec -it tomcat8080 /usr/local/tomcat/bin/shutdown.sh +docker exec -it tomcat8081 /usr/local/tomcat/bin/shutdown.sh +tomcat_wait_for_n_nodes 0 +docker container rm tomcat8080 +docker container rm tomcat8081 + +echotestlabel "Done with the tests!!!" diff --git a/test/native/MODCLUSTER-640/testit.sh b/test/native/MODCLUSTER-640/testit.sh deleted file mode 100755 index 623d63335..000000000 --- a/test/native/MODCLUSTER-640/testit.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash -source ../includes/script.bash - -# Shell to test MODCLUSTER-640 - -# check IMG... -if [ -z ${IMG} ]; then - echo "IMG needs to defined, please try" - echo "export IMG=quay.io/${USER}/tomcat_mod_cluster" - exit 1 -fi - -# first stop any previously running tests. -stoptomcats -removetomcats - -# and httpd -docker stop MODCLUSTER-640 -docker rm MODCLUSTER-640 - -# build httpd + mod_proxy_cluster -rm -f nohup.out -nohup docker run --network=host -e HTTPD=https://dlcdn.apache.org/httpd/httpd-2.4.54.tar.gz -e SOURCES=https://github.com/jfclere/mod_proxy_cluster -e BRANCH=main -e CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/native/MODCLUSTER-640/mod_proxy_cluster.conf --name MODCLUSTER-640 quay.io/${USER}/mod_cluster_httpd & - -# wait until httpd is started -waitforhttpd || exit 1 - -# start 2 tomcats -starttomcats - -# wait until the tomcats are in mod_proxy_cluster tables -waitnodes 2 - -# copy the webapp in the tomcats -docker cp webapp1 tomcat8080:/usr/local/tomcat/webapps/webapp1 -docker cp webapp1 tomcat8081:/usr/local/tomcat/webapps/webapp1 - -sleep 10 - -# test the URL -code=`/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html` -if [ "${code}" != "200" ]; then - echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html" - exit 1 -fi -curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root" -if [ $? -eq 0 ]; then - echo "nocanon test failed, we get \"jsr:root\"!!!" - exit 1 -fi - -# Test without UseNocanon On -sed 's:UseNocanon On::' mod_proxy_cluster.conf > mod_proxy_cluster_new.conf - -docker cp mod_proxy_cluster_new.conf MODCLUSTER-640:/usr/local/apache2/conf/mod_proxy_cluster.conf -docker exec -it MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart - -# wait until the tomcats are back in mod_proxy_cluster tables -waitnodes 2 - -# test the URL -code=`/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html` -if [ "${code}" != "200" ]; then - echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html" - exit 1 -fi -curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root" -if [ $? -ne 0 ]; then - echo "NO nocanon test failed, we don't get \"jsr:root\"!!!" - exit 1 -fi - -# Test for just a proxypass / nocanon -sed 's:UseNocanon On::' mod_proxy_cluster.conf > mod_proxy_cluster_new.conf -echo "ProxyPass / balancer://mycluster/ nocanon" >> mod_proxy_cluster_new.conf - -docker cp mod_proxy_cluster_new.conf MODCLUSTER-640:/usr/local/apache2/conf/mod_proxy_cluster.conf -docker exec -it MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart - -# wait until the tomcats are back in mod_proxy_cluster tables -waitnodes 2 - -# test the URL -code=`/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html` -if [ "${code}" != "200" ]; then - echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html" - exit 1 -fi -curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root" -if [ $? -eq 0 ]; then - echo "nocanon test failed, we get \"jsr:root\"!!!" - exit 1 -fi -# stop the previous test -#stopprevioustest diff --git a/test/native/MODCLUSTER-734/testit.sh b/test/native/MODCLUSTER-734/testit.sh deleted file mode 100755 index 10ed331b8..000000000 --- a/test/native/MODCLUSTER-734/testit.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -source ../includes/script.bash - -# check IMG... -if [ -z ${IMG} ]; then - echo "IMG needs to defined, please try" - echo "export IMG=quay.io/${USER}/tomcat_mod_cluster" - exit 1 -fi - -# first stop any previously running tests. -stoptomcats -removetomcats - -# and httpd -docker stop MODCLUSTER-734 -docker rm MODCLUSTER-734 - -# build httpd + mod_proxy_cluster -rm -f nohup.out -nohup docker run --network=host -e HTTPD=https://dlcdn.apache.org/httpd/httpd-2.4.54.tar.gz -e SOURCES=https://github.com/modcluster/mod_proxy_cluster -e BRANCH=main -e CONF=https://raw.githubusercontent.com/modcluster/mod_proxy_cluster/main/test/native/MODCLUSTER-734/mod_proxy_cluster.conf --name MODCLUSTER-734 quay.io/${USER}/mod_cluster_httpd & - -# wait until httpd is started -waitforhttpd || exit 1 -#docker cp mod_proxy_cluster.conf MODCLUSTER-734:/usr/local/apache2/conf/mod_proxy_cluster.conf -#docker exec -it MODCLUSTER-734 /usr/local/apache2/bin/apachectl restart - -# start tomcat8080 and tomcat8081. -starttomcats - -# wait until they are in mod_proxy_cluster tables -waitnodes 2 - -# copy the test page in ROOT to tomcat8080 -docker cp ROOT tomcat8080:/usr/local/tomcat/webapps/ROOT -docker cp ROOT_OK tomcat8081:/usr/local/tomcat/webapps/ROOT - -# after a while the health check will get the Under maintenance status.jsp -# and mark the node not OK. -sleep 15 -curl -s http://localhost:6666/mod_cluster_manager | grep "Status: NOTOK" -if [ $? -eq 0 ]; then - echo "MODCLUSTER-734 Done!" -else - echo "MODCLUSTER-734 Failed!" - exit 1 -fi diff --git a/test/native/Makefile b/test/native/Makefile deleted file mode 100644 index 136ffc04a..000000000 --- a/test/native/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -APACHE_BASE ?= /usr/local/apache -APACHE_INC ?= ${APACHE_BASE}/include -IMG ?= quay.io/${USER}/tomcat_mod_cluster:latest -MOD_CLUSTER_VERSION ?= 2.0.2.Final-SNAPSHOT - -Advertise: Advertise.c - cc -c -I$(APACHE_INC) Advertise.c - cc -o Advertise Advertise.o -L$(APACHE_BASE)/lib -lapr-1 - -jars: - mvn dependency:copy-dependencies - -docker-build: jars - docker build -t ${IMG} . - -docker-push: ## Push docker image with the manager. - docker push ${IMG} - -setup-httpd: - cd httpd - docker build -t quay.io/${USER}/mod_cluster_httpd . - docker run -d --network=host quay.io/${USER}/mod_cluster_httpd - cd .. - -tests: - IMG=${IMG} sh tests.sh diff --git a/test/native/README.md b/test/native/README.md deleted file mode 100644 index 76628ab23..000000000 --- a/test/native/README.md +++ /dev/null @@ -1,111 +0,0 @@ -# tomcat_mod_cluster -Tomcat9 image with mod_cluster enabled. -Start Apache Httpd with mod cluster enabled. - -Make sure you have checkout and build mod_cluster in sub directory at the same level you checkout mod_proxy_cluster. - -There are two variables worth setting: `APACHE_BASE` which is by default set to `/usr/local/apache` and which should -correspond to the path where apache is present, then `IMG` which is set by default to -`quay.io/${USER}/tomcat_mod_cluster`. - -If your setup differs, set those variables to appropriate values simply by running `export APACHE_BASE=/your/path`. - -## Building and pushing the image - -You can build the image by running - -``` -make docker-build -``` -and then push it by - -``` -make docker-push -``` - -Do not forget to log into quay.io before you run those commands. You can log in using `docker login quay.io`. - -If you use `podman` instead of `docker`, you can use `podman-docker` package if it is available for you platform. - -## Running the image -``` -docker run --network=host -e tomcat_port=[port1] -e cluster_port=[port3] [image] -Or -docker run --network=host -e tomcat_ajp_port=[port1] -e cluster_port=[port3] [image] -# You can also add the variable -e tomcat_shutdown_port=true if u want to have a shutdown port -``` - -To load webapps into the container: -``` -docker cp webapp.war :/usr/local/tomcat/webapps/ -``` - -# mod_cluster_tests -Tests can be run by invoking `make tests` or manually by running `sh tests.sh` but in that case -make sure you have exported the IMG variable as described above. - -The docker image should be build and you might push it before, make sure you have exported the IMG variable. -``` -export IMG=quay.io/${USER}/tomcat_mod_cluster -``` -# Testing websocket -Using com.ning.http.client.ws.WebSocketTextListener -To be able to run the test please use https://github.com/jfclere/httpd_websocket just build it: -``` -git clone https://github.com/jfclere/httpd_websocket -cd https://github.com/jfclere/httpd_websocket -mvn install -cd .. -``` -Build the groovy jar -``` -mvn install -``` -run the groovy stuff -``` -java -jar target/test-1.0.jar -``` - -*NOTE: You'll probably need an older JAVA version – version 11 should be ok. You can change it via JAVA env variable.* - -# Running tests -You need an Apache httpd with the mod_cluster.so installed and running. You can run it in docker -- checkout the `httpd/` -subdirectory or simply run `make setup-httpd`. You should have following piece in httpd.conf/mod_proxy_cluster.conf: - -``` -LoadModule manager_module modules/mod_manager.so -LoadModule proxy_cluster_module modules/mod_proxy_cluster.so - -ServerName localhost -Listen 6666 -ManagerBalancerName mycluster -EnableWsTunnel -WSUpgradeHeader "websocket" - - - Require ip 127.0.0.1 - - - KeepAliveTimeout 300 - MaxKeepAliveRequests 0 - - EnableMCPMReceive - - Require ip 127.0.0.1 - - -``` - -Make sure you disable `mod_proxy` module. - -You can run tests running `sh tests.sh`. There are a few variables by which you can influence the duration/number of -repetitions (those are printed out with their respective values right after executions starts). - -If tests fail or you interupt them, make sure that docker tomcat container that were created are removed first -(you need to run `docker container stop ` and `docker container rm `). - -# Testing with miniserver -There is also a python script that can be run to check mod_proxy_cluster. You can find it within `includes` directory -as `miniserver.py`. Execute it simply as `./includes/miniserver.py `. - -You must have `httpd` with `mod_proxy_cluster` running. diff --git a/test/native/includes/script.bash b/test/native/includes/script.bash deleted file mode 100644 index b00d97054..000000000 --- a/test/native/includes/script.bash +++ /dev/null @@ -1,155 +0,0 @@ -#!/bin/bash - -# -# first stop running tomcats -stoptomcat() { -docker ps -a | grep $1 -if [ $? -eq 0 ]; then - echo "Stopping $1" - docker stop $1 - if [ $? -ne 0 ]; then - echo "Can't stop $1" - exit 1 - fi -fi -} -stoptomcats () { -for i in `docker ps -a --format "{{.Names}}" | grep tomcat` -do - stoptomcat $i -done -} - -# -# Wait the nodes to go away or start -waitnodes () { -nodes=$1 -curl -s http://localhost:6666/mod_cluster_manager -o /dev/null -if [ $? -ne 0 ]; then - echo "httpd no started or something VERY wrong" - exit 1 -fi -NBNODES=-1 -i=0 -while [ ${NBNODES} != ${nodes} ] -do - NBNODES=`curl -s http://localhost:6666/mod_cluster_manager | grep Node | awk ' { print $3} ' | wc -l` - sleep 10 - echo "Waiting for ${nodes} node to be ready: `date`" - i=`expr $i + 1` - if [ $i -gt 120 ]; then - echo "Timeout the node(s) number is NOT ${nodes} but ${NBNODES}" - exit 1 - fi - # check if the nodes are OK - if [ ${NBNODES} = ${nodes} ]; then - NBNODESOK=`curl -s http://localhost:6666/mod_cluster_manager | grep "Status: OK" | wc -l` - if [ $NBNODESOK != ${nodes} ]; then - echo "Some nodes are not in OK state..." - exit 1 - fi - fi -done -curl -s http://localhost:6666/mod_cluster_manager -o /dev/null -if [ $? -ne 0 ]; then - echo "httpd no started or something VERY wrong" - exit 1 -fi -echo "Waiting for the node DONE: `date`" -} - -# -# remove them -removetomcatname () { -docker ps -a | grep $1 -if [ $? -eq 0 ]; then - echo "Stopping $1" - docker stop $1 - if [ $? -ne 0 ]; then - echo "Can't stop $1" - fi - echo "Removing $1" - docker rm $1 - if [ $? -ne 0 ]; then - echo "Can't remove $1" - fi -fi -} -removetomcats () { -for i in `docker ps -a --format "{{.Names}}" | grep tomcat` -do - removetomcatname $i -done -} - -# -# Start them again -starttomcats() { -echo "Starting tomcat8080..." -nohup docker run --network=host -e tomcat_port=8080 -e tomcat_shutdown_port=true --name tomcat8080 ${IMG} & -if [ $? -ne 0 ]; then - echo "Can't start tomcat8080" - 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} & -if [ $? -ne 0 ]; then - echo "Can't start tomcat8081" - exit 1 -fi -echo "2 Tomcats started..." -} - -# wait until httpd is started -waitforhttpd () { - while true - do - sleep 10 - grep "cannot open" nohup.out | grep error_log - if [ $? -eq 0 ]; then - echo "httpd start failed" - exit 1 - fi - - grep "resuming normal operations" nohup.out - if [ $? -eq 0 ]; then - break - fi - done - - # httpd started - curl -v http://localhost:8000/ - if [ $? -ne 0 ]; then - echo "Httpd not running???" - exit 1 - fi -} - -# Start tomcat$1 container on 127.0.0.$1 -starttomcat() { - ADDR="127.0.0.$1" - AJPPORT="8010" - HTTPPORT="" - if [ "x$2" != "x" ]; then - if [ $2 -ne 0 ];then - echo "Starting tomcat$1 on 127.0.0.$2" - ADDR="127.0.0.$2" - fi - fi - if [ "x$3" != "x" ]; then - if [ $3 -ne 0 ];then - echo "Starting tomcat$1 on 127.0.0.$2 with http on port $3" - AJPPORT="" - HTTPPORT="$3" - fi - fi - echo "Doing: docker run --network=host -e tomcat_ajp_port=${AJPPORT} -e tomcat_port=${HTTPPORT} -e tomcat_address=$ADDR -e tomcat_shutdown_port=8005 -e jvm_route=tomcat$1 --name tomcat$1 ${IMG}" - nohup docker run --network=host -e tomcat_ajp_port=${AJPPORT} -e tomcat_port=${HTTPPORT} -e tomcat_address=$ADDR -e tomcat_shutdown_port=8005 -e jvm_route=tomcat$1 --name tomcat$1 ${IMG} & - ps -q $! > /dev/null - if [[ $? -ne 0 ]]; then - echo "docker run failed" - exit 1 - fi -} - diff --git a/test/native/tests.sh b/test/native/tests.sh deleted file mode 100644 index b543063a1..000000000 --- a/test/native/tests.sh +++ /dev/null @@ -1,877 +0,0 @@ -#!/bin/bash - -# configuration of variables -# if you want tests to pass much faster, decrease these values -if [ -z ${FOREVER_PAUSE+x} ]; then - FOREVER_PAUSE=3600 # sleep period length during which tomcats are run & stopped -fi -if [ -z ${TOMCAT_CYCLE_COUNT+x} ]; then - TOMCAT_CYCLE_COUNT=100 # the number of repetitions of a test cycle -fi -if [ -z ${ITERATION_COUNT+x} ]; then - ITERATION_COUNT=50 # the number of iteration of starting/stopping a tomcat -fi -if [ -z ${IMG+x} ]; then - IMG=quay.io/$USER/tomcat_mod_cluster -fi - -echo -n "Test values are FOREVER_PAUSE=$FOREVER_PAUSE, TOMCAT_CYCLE_COUNT=$TOMCAT_CYCLE_COUNT," -echo " ITERATION_COUNT=$ITERATION_COUNT, IMG=$IMG" - -# -# Stop running given dockered tomcat -stoptomcat() { - docker ps | grep $1 - if [ $? -eq 0 ]; then - echo "Stopping $1" - docker stop $1 - if [ $? -ne 0 ]; then - echo "Can't stop $1" - exit 1 - fi - else - echo "$1 is not running" - fi -} - -# -# Stop running all dockered tomcats -stoptomcats() { - for i in $(docker ps -a --format "{{.Names}}" | grep tomcat) - do - stoptomcat $i - done -} - -# -# Wait until there are $1 nodes (i.e., some will start or go away if the count is different) -waitnodes() { - nodes=$1 - curl -s http://localhost:6666/mod_cluster_manager -o /dev/null - if [ $? -ne 0 ]; then - echo "httpd no started or something VERY wrong" - exit 1 - fi - NBNODES=-1 - i=0 - while [ ${NBNODES} != ${nodes} ] - do - NBNODES=$(curl -s http://localhost:6666/mod_cluster_manager | grep "Status: OK" | awk ' { print $3} ' | wc -l) - sleep 10 - echo "Waiting for ${nodes} node to be ready: $(date)" - i=$(expr $i + 1) - if [ $i -gt 120 ]; then - echo "Timeout the node(s) number is NOT ${nodes} but ${NBNODES}" - exit 1 - fi - done - curl -s http://localhost:6666/mod_cluster_manager -o /dev/null - if [ $? -ne 0 ]; then - echo "httpd no started or something VERY wrong" - exit 1 - fi - echo "Waiting for the node DONE: $(date)" -} - -# -# Stop and remove tomcat docker container of a given name -removetomcatname() { - docker ps -a | grep $1 - if [ $? -eq 0 ]; then - echo "Stopping $1" - docker stop $1 - if [ $? -ne 0 ]; then - echo "Can't stop $1" - fi - echo "Removing $1" - docker rm $1 - if [ $? -ne 0 ]; then - echo "Can't remove $1" - fi - fi -} - -# -# Remove all tomcat containers and images -removetomcats() { - for i in $(docker ps -a --format "{{.Names}}" | grep tomcat) - do - removetomcatname $i - done -} - -# -# Start them again -starttwotomcats() { - echo "Starting tomcat8080..." - nohup docker run --network=host -e tomcat_port=8080 -e tomcat_shutdown_port=true --name tomcat8080 ${IMG} & - if [ $? -ne 0 ]; then - echo "Can't start tomcat8080" - 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} & - if [ $? -ne 0 ]; then - echo "Can't start tomcat8081" - exit 1 - fi - echo "2 Tomcats started..." -} - -# -# Echo test label message in order to know where we are -echotestlabel() { - MESS=$1 - echo "***************************************************************" - echo "Doing test: $MESS" - echo "***************************************************************" -} - -# This should suspend the tomcat for ~ 1000 seconds ~ causing it gets removed afterwhile. -jdbsuspend() { - rm -f /tmp/testpipein - mkfifo /tmp/testpipein - rm -f /tmp/testpipeout - mkfifo /tmp/testpipeout - sleep 1000 > /tmp/testpipein & - jdb -attach 6660 < /tmp/testpipein > /tmp/testpipeout & - echo "suspend" > /tmp/testpipein - cat < /tmp/testpipeout & -} - -jdbexit() { - cat > /tmp/testpipeout & - echo "exit" > /tmp/testpipein -} - -# Start tomcat$1 container on 127.0.0.$1 -starttomcat() { - ADDR="127.0.0.$1" - if [ $2 -ne 0 ];then - echo "Starting tomcat$1 on 127.0.0.$2" - ADDR="127.0.0.$2" - fi - echo "Doing: docker run --network=host -e tomcat_ajp_port=8010 -e tomcat_address=$ADDR -e tomcat_shutdown_port=8005 -e jvm_route=tomcat$1 --name tomcat$1 ${IMG}" - nohup docker run --network=host -e tomcat_ajp_port=8010 -e tomcat_address=$ADDR -e tomcat_shutdown_port=8005 -e jvm_route=tomcat$1 --name tomcat$1 ${IMG} & - ps -q $! > /dev/null - if [[ $? -ne 0 ]]; then - echo "docker run failed" - exit 1 - fi -} - -# Start the webapp on the given tomcat -# wait for the tomcat to start. -startwebapptomcat() { - while true - do - docker ps --format "{{.Names}}" | grep tomcat$1 - if [ $? -eq 0 ]; then - break - fi - sleep 2 - done - docker cp testapp tomcat$1:/usr/local/tomcat/webapps/tomcat$1 || exit 1 -} - -# Send a shutdown packet to a tomcat$1 container -shutdowntomcat() { - ADDR="127.0.0.$1" - if [ $2 -ne 0 ];then - ADDR="127.0.0.$2" - fi - - echo "shutdowntomcat at $ADDR" - echo "SHUTDOWN" | nc $ADDR 8005 -} - -# Remove the docker image tomcat$1 -# Note: To succesfully remove an image it needs to be stopped -removetomcat() { - docker rm tomcat$1 -} - -# Test whether the webapp is working (responding) -testtomcat() { - CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/tomcat$1/test.jsp) - if [ ${CODE} != "200" ]; then - echo "Failed can't reach $tomcat$1: ${CODE}" - exit 1 - fi -} - -# -# Run testtomcat for tomcat containers [2..$1] -testtomcats() { - tc=2 - while true - do - testtomcat $tc || exit 1 - tc=$(expr $tc + 1) - if [ $tc -gt $1 ]; then - echo "testtomcats $tc Done!" - break - fi - done -} - -# -# Run a load test for the given tomcat$1 using ab -abtomcat() { - ab -c10 -n10 http://localhost:8000/tomcat$1/test.jsp > /dev/null - if [ $? -ne 0 ]; then - echo "abtomcat: Loading tomcat$1 failed" - exit 1 - fi -} - -# -# Run abtomcat for tomcat containers [2..$1] -abtomcats() { - tc=2 - while true - do - abtomcat $tc || exit 1 - tc=$(expr $tc + 1) - if [ $tc -gt $1 ]; then - echo "abtomcats: Done!" - break - fi - done -} - -# -# Start a bunch ($1, or 6 if no argument is given) of tomcat -# containers, then test them and stop them -runtomcatbatch() { - if [ $1 ]; then - t=$1 - else - t=5 # default value when no argument is given - fi - tomcatcount=$t - # TODO: Change those whiles with arbitrary break to for cycles - while true - do - starttomcat $t 0 - t=$(expr $t + 1) - if [ $t -gt 10 ]; then - break - fi - done - waitnodes 9 || exit 1 - t=$tomcatcount - while true - do - startwebapptomcat $t || exit 1 - t=$(expr $t + 1) - if [ $t -gt 10 ]; then - break - fi - done - - # test the tomcats - sleep 20 - testtomcats 9 - if [ $? -ne 0 ];then - echo "runtomcatbatch testtomcats 9 FAILED!" - exit 1 - fi - - # "load test" 9 of them - abtomcats 9 - if [ $? -ne 0 ];then - echo "runtomcatbatch abtomcats 9 FAILED!" - exit 1 - fi - - # retest - testtomcats 9 - if [ $? -ne 0 ];then - echo "runtomcatbatch testtomcats 9 FAILED!" - exit 1 - fi - - # stop the tomcats - t=$tomcatcount - while true - do - shutdowntomcat $t 0 - t=$(expr $t + 1) - if [ $t -gt 10 ]; then - break - fi - done - - waitnodes 3 - if [ $? -ne 0 ];then - echo "runtomcatbatch waitnodes 3 FAILED!" - exit 1 - fi - - # remove the tomcats - t=5 - while true - do - removetomcat $t - t=$(expr $t + 1) - if [ $t -gt 10 ]; then - break - fi - done - echo "runtomcatbatch Done!" -} - -# single tomcat testing -# we start the tomcat, put the webapp, test it and later stop and clean up -singlecycle() { - echo "singlecycle: Testing tomcat$1" - R=$1 - if [ "X$2" = "Xuseran" ]; then - R=$(echo $((1 + $RANDOM % 10))) - R=$(expr $R + 2) - starttomcat $1 $R || exit 1 - else - R=0 - starttomcat $1 $R || exit 1 - fi - # Wait for it to start - echo "Testing(0) tomcat$1 waiting..." - while true - do - curl -s http://localhost:6666/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null - if [ $? -eq 0 ]; then - break - fi - sleep 1 - done - echo "Testing(0) tomcat$1 started" - startwebapptomcat $1 || exit 1 - echo "Testing(0) tomcat$1 with webapp" - while true - do - curl -s http://localhost:6666/mod_cluster_manager | grep /tomcat$1 > /dev/null - if [ $? -eq 0 ]; then - break - fi - curl -s http://localhost:6666/mod_cluster_manager | grep /tomcat$1 - sleep 1 - done - echo "Testing(1) tomcat$1" - testtomcat $1 || exit 1 - echo "Testing(2) tomcat$1" - testtomcat $1 || exit 1 - abtomcat $1 || exit 1 - echo "Testing(3) tomcat$1" - shutdowntomcat $1 $R || exit 1 - while true - do - curl -s http://localhost:6666/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null - if [ $? -ne 0 ]; then - break - fi - sleep 1 - done - removetomcat $1 || exit 1 - echo "singlecycle Done tomcat$1" -} - -# Run neverending testing loop of a single tomcat -looptomcatforever() { - while true - do - singlecycle $1 || exit 1 - done -} - -# Start a bunch of looping tomcats and kill them after $FOREVER_PAUSE (default is 3600 seconds) -forevertomcat() { - (looptomcatforever 12) & - pid12=$! - (looptomcatforever 13) & - pid13=$! - # wait a little to prevent synchronization - sleep 5 - (looptomcatforever 14) & - pid14=$! - (looptomcatforever 15) & - pid15=$! - (looptomcatforever 16) & - pid16=$! - - sleep $FOREVER_PAUSE - - echo "Doing: kill -15 $pid12 $pid13 $pid14 $pid15 $pid16" - kill -15 $pid12 $pid13 $pid14 $pid15 $pid16 - if [ $? -ne 0 ]; then - echo "kill -15 $pid12 $pid13 $pid14 $pid15 $pid16 failed" - exit 1 - fi - echo "Tests done, cleaning" - # stop & remove the containers - removetomcatname tomcat12 - removetomcatname tomcat13 - removetomcatname tomcat14 - removetomcatname tomcat15 - removetomcatname tomcat16 - sleep 10 -} - -# Start and stop successively (one after another) $1 tomcats -cyclestomcats() { - i=1 - while true - do - i=$(expr $i + 1) - if [ $i -gt $1 ]; then - echo "Looks OK, Done!" - break - fi - singlecycle $i useran || exit 1 - done -} - -# run test for https://issues.redhat.com/browse/JBCS-1236 -# basically start and stop random tomcats... -runjbcs1236() { - # start 3 tomcats - starttomcat 2 0 - starttomcat 3 0 - starttomcat 4 0 - waitnodes 3 || exit 1 - # check them - startwebapptomcat 2 || exit 1 - startwebapptomcat 3 || exit 1 - startwebapptomcat 4 || exit 1 - sleep 20 - testtomcat 2 || exit 1 - testtomcat 3 || exit 1 - testtomcat 4 || exit 1 - - # start a bunch of tomcats, test, shutdown, remove and try in a loop. - runjbcs1236=0 - while true - do - runjbcs1236=$(expr $runjbcs1236 + 1) - if [ $runjbcs1236 -gt 2 ]; then - echo "Looks OK, runjbcs1236 stopping!" - break - fi - # cycle the tomcats - runtomcatbatch - if [ $? -ne 0 ]; then - echo "runtomcatbatch: runjbcs1236 Failed!" - exit 1 - fi - shutdowntomcat 2 0 - waitnodes 2 - if [ $? -ne 0 ]; then - echo "waitnodes 2: runjbcs1236 Failed!" - exit 1 - fi - removetomcat 2 - starttomcat 5 0 - waitnodes 3 - if [ $? -ne 0 ]; then - echo "waitnodes 3: runjbcs1236 Failed!" - exit 1 - fi - startwebapptomcat 5 - if [ $? -ne 0 ]; then - echo "startwebapptomcat 5: runjbcs1236 Failed!" - exit 1 - fi - sleep 20 - testtomcat 5 - if [ $? -ne 0 ]; then - echo "testtomcat 5: runjbcs1236 Failed!" - exit 1 - fi - # we have 5 3 4 in shared memory - # readd 2 - starttomcat 2 0 - waitnodes 4 - if [ $? -ne 0 ]; then - echo "waitnodes 4: runjbcs1236 Failed!" - exit 1 - fi - startwebapptomcat 2 - if [ $? -ne 0 ]; then - echo "startwebapptomcat 2: runjbcs1236 Failed!" - exit 1 - fi - sleep 20 - testtomcat 2 - if [ $? -ne 0 ]; then - echo "testtomcat 2: runjbcs1236 Failed!" - exit 1 - fi - # we have 5 3 4 2 in shared memory - # if something was wrong 2 points to 5 - shutdowntomcat 5 0 - waitnodes 3 - if [ $? -ne 0 ]; then - echo "waitnodes 3: runjbcs1236 Failed!" - exit 1 - fi - removetomcat 5 - - testtomcat 2 || exit 1 - if [ $? -ne 0 ]; then - echo "testtomcat 2: runjbcs1236 Failed!" - exit 1 - fi - - testtomcat 3 || exit 1 - if [ $? -ne 0 ]; then - echo "testtomcat 3: runjbcs1236 Failed!" - exit 1 - fi - - testtomcat 4 || exit 1 - if [ $? -ne 0 ]; then - echo "testtomcat 4: runjbcs1236 Failed!" - exit 1 - fi - echotestlabel "runjbcs1236 loop: $runjbcs1236" - done - - # cleanup - shutdowntomcat 4 0 - shutdowntomcat 3 0 - shutdowntomcat 2 0 - waitnodes 0 || exit 1 - removetomcat 2 - removetomcat 3 - removetomcat 4 -} - -# -# Main piece -- tests start here -echotestlabel "Starting tests!!!" -if [ -z ${IMG} ]; then - echo "IMG needs to defined, please try" - echo "export IMG=quay.io/${USER}/tomcat_mod_cluster" - exit 1 -fi - -# Create files we need -cat << EOF > continue.txt -cont -exit -EOF -cat << EOF > hang.txt -suspend all -exit -EOF - -# Clean up possible existing containers before starting... -stoptomcats -waitnodes 0 || exit 1 -removetomcats - -# JBCS-1236 -echotestlabel "JBCS-1236" -cyclestomcats $TOMCAT_CYCLE_COUNT -if [ $? -ne 0 ]; then - echotestlabel "JBCS-1236 cyclestomcats 100 FAILED!" - exit 1 -fi -forevertomcat -if [ $? -ne 0 ]; then - echotestlabel "JBCS-1236 forevertomcat FAILED!" - exit 1 -fi -runjbcs1236 -if [ $? -ne 0 ]; then - echotestlabel "JBCS-1236 runjbcs1236 FAILED!" - exit 1 -fi - -# Start 2 tomcats, on 8080 and 8081 -starttwotomcats || exit 1 -waitnodes 2 || exit 1 - -# Copy testapp and wait for its start -docker cp testapp tomcat8081:/usr/local/tomcat/webapps -sleep 10 - -# Basic 200 and 404 tests. -echotestlabel "basic 200 and 404 tests" -CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/test.jsp) -if [ ${CODE} != "200" ]; then - echo "Failed can't reach webapp: ${CODE}" - exit 1 -fi -CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/toto.jsp) -if [ ${CODE} != "404" ]; then - echo "Failed should get 404" - exit 1 -fi - -# Sticky (yes, there is only one app!!!) -echotestlabel "sticky one app" -SESSIONCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') -if [ "${SESSIONCO}" == "" ];then - echo "Failed no sessionid in curl output..." - curl -v http://localhost:8000/testapp/test.jsp -fi -echo ${SESSIONCO} -NEWCO=$(curl -v --cookie "${SESSIONCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') -if [ "${NEWCO}" != "" ]; then - echo "Failed not sticky received : ${NEWCO}???" - exit 1 -fi - -# Copy testapp and wait for starting -docker cp testapp tomcat8080:/usr/local/tomcat/webapps -sleep 10 - -# Sticky (yes there are 2 apps now) -echotestlabel "sticky 2 app" -SESSIONCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') -NODE=$(echo ${SESSIONCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }') -echo "first: ${SESSIONCO} node: ${NODE}" -NEWCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') -NEWNODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }') -echo "second: ${NEWCO} node: ${NEWNODE}" -echo "Checking we can reach the 2 nodes" -i=0 -while [ "${NODE}" == "${NEWNODE}" ] -do - NEWCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') - NEWNODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }') - i=$(expr $i + 1) - if [ $i -gt 40 ]; then - echo "Can't find the 2 webapps" - exit 1 - fi - if [ "${NEWNODE}" == "" ]; then - echo "Can't find node in request" - exit 1 - fi - echo "trying other webapp try: ${i}" - sleep 1 -done -echo "${i} try gives: ${NEWCO} node: ${NEWNODE}" - -# Still sticky -CO=$(curl -v --cookie "${SESSIONCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') -if [ "${CO}" != "" ]; then - echo "Failed not sticky received : ${CO}???" - exit 1 -fi -CO=$(curl -v --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::') -if [ "${CO}" != "" ]; then - echo "Failed not sticky received : ${CO}???" - exit 1 -fi - -# Stop one of the while running requests. -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}" -CODE="200" -i=0 -while [ "$CODE" == "200" ] -do - if [ $i -gt 100 ]; then - echo "Done remaining tomcat still answering!" - break - fi - 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} - fi - i=$(expr $i + 1) -done -if [ ${CODE} != "200" ]; then - echo "Something was wrong... got: ${CODE}" - curl -v --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp - exit 1 -fi - -# Restart the tomcat -nohup docker run --network=host -e tomcat_port=${PORT} -e tomcat_shutdown_port=true --name tomcat${PORT} ${IMG} & - -# Now try to test the websocket -echotestlabel "testing websocket" -# The websocket-hello app is at: https://github.com/jfclere/httpd_websocket -mvn dependency:copy -U -Dartifact=org.apache.tomcat:websocket:hello:0.0.1:war -DoutputDirectory=. -if [ $? -ne 0 ]; then - echo "Something was wrong... can't find org.apache.tomcat:websocket:hello:0.0.1:war" - cp $HOME/.m2/repository/org/apache/tomcat/websocket-hello/0.0.1/websocket-hello-0.0.1.war . - if [ $? -ne 0 ]; then - exit 1 - fi -fi -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 -# Put the testapp in the tomcat we restarted. -docker cp testapp tomcat${PORT}:/usr/local/tomcat/webapps -sleep 10 -mvn -f pom-groovy.xml install -java -jar target/test-1.0.jar WebSocketsTest -if [ $? -ne 0 ]; then - echo "Something was wrong... with websocket tests" - exit 1 -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 -sleep 10 -java -jar target/test-1.0.jar HTTPTest -if [ $? -ne 0 ]; then - echo "Something was wrong... with HTTP tests" - exit 1 -fi - -# -# Test virtual host -echotestlabel "Testing virtual hosts" -docker cp tomcat8081:/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 quay.io/${USER}/tomcat_mod_cluster-examples -docker stop tomcat8081 -docker container rm tomcat8081 -waitnodes 1 -# Start the node. -nohup docker run --network=host -e tomcat_port=8081 -e tomcat_shutdown_port=true --name tomcat8081 quay.io/${USER}/tomcat_mod_cluster-examples & -waitnodes 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: -# X-Forwarded-For: 127.0.0.1 -# X-Forwarded-Host: example.com -# X-Forwarded-Server: fe80::faf4:935b:9dda:2adf -# therefore don't forget ProxyPreserveHost On (otherwise UseAlias On failed...) -# -CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8000/test/test.jsp) -if [ ${CODE} != "200" ]; then - echo "Failed can't rearch webapp at example.com: ${CODE}" - exit 1 -fi -# Basically curl --header "Host: localhost" http://127.0.0.1:8000/test/test.jsp gives 400 -CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8000/test/test.jsp) -if [ ${CODE} != "404" ]; then - echo "Failed should NOT rearch webapp at localhost: ${CODE}" - exit 1 -fi -# Same using localhost/testapp2 and curl --header "Host: localhost" http://127.0.0.1:8000/testapp2/test.jsp -CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8000/testapp2/test.jsp) -if [ ${CODE} != "200" ]; then - echo "Failed can't rearch webapp at localhost: ${CODE}" - exit 1 -fi -# Basically curl --header "Host: example.com" http://127.0.0.1:8000/testapp2/test.jsp gives 400 -CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8000/testapp2/test.jsp) -if [ ${CODE} != "404" ]; then - echo "Failed should NOT rearch webapp at localhost: ${CODE}" - exit 1 -fi - -# Shutdown the 2 tomcats -docker exec -it tomcat8080 /usr/local/tomcat/bin/shutdown.sh -docker exec -it tomcat8081 /usr/local/tomcat/bin/shutdown.sh -waitnodes 0 -docker container rm tomcat8080 -docker container rm tomcat8081 - -# Loop stopping starting the same tomcat -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} & - sleep 10 - waitnodes 1 || exit 1 - docker exec -it tomcat8080 /usr/local/tomcat/bin/shutdown.sh - waitnodes 0 || exit 1 - docker container rm tomcat8080 - iter=$(expr $iter + 1) -done - -# Check that hanging tomcat will be removed -echotestlabel "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} & -sleep 10 -waitnodes 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} quay.io/${USER}/tomcat_mod_cluster-debug -docker stop tomcat${PORT} -waitnodes 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} quay.io/${USER}/tomcat_mod_cluster-debug & -sleep 10 -docker exec tomcat${PORT} jdb -attach 6660 < continue.txt -waitnodes 2 || exit 1 -echo "2 tomcat started" -# Hang the node, -# jdb and a pipe to hang the tomcat. -jdbsuspend -waitnodes 1 || exit 1 -echo "1 tomcat hanging and gone" -jdbexit -# The tomcat is comming up again -waitnodes 2 || exit 1 -echo "the tomcat is back" - -# Same test with requests, make them in a loop -echotestlabel "hanging tomcat removed after a while with requests" -bash curlloop.sh 200 000 & -jdbsuspend -waitnodes 1 || exit 1 -ps -ef | grep curlloop | grep -v grep -if [ $? -ne 0 ]; then - echo "curlloop.sh FAILED!" - exit 1 -fi -ps -ef | grep curlloop | grep -v grep | awk ' { print $2 } ' | xargs kill -jdbexit -# The tomcat is comming up again -waitnodes 2 || exit 1 - -# Same test with requets but stop the other tomcat -echotestlabel "single hanging tomcat removed after a while with requests" -PORT=8081 -docker stop tomcat${PORT} -docker container rm tomcat${PORT} -waitnodes 1 || exit 1 -jdbsuspend -sleep 10 -bash curlloop.sh 000 404 503 & -waitnodes 0 || exit 1 -ps -ef | grep curlloop | grep -v grep -if [ $? -ne 0 ]; then - echo "curlloop.sh FAILED!" - exit 1 -fi -ps -ef | grep curlloop | grep -v grep | awk ' { print $2 } ' | xargs kill -jdbexit -# The tomcat is comming up again -waitnodes 1 || exit 1 - -# Cleanup at the end -stoptomcats -waitnodes 0 || exit 1 -removetomcats -echotestlabel "Done with the tests!!!" -echo "Done!" - diff --git a/test/native/pom-groovy.xml b/test/pom-groovy.xml similarity index 100% rename from test/native/pom-groovy.xml rename to test/pom-groovy.xml diff --git a/test/native/pom.xml b/test/pom.xml similarity index 96% rename from test/native/pom.xml rename to test/pom.xml index 88ee4b8b4..509829d26 100644 --- a/test/native/pom.xml +++ b/test/pom.xml @@ -9,7 +9,7 @@ 4.0.0 org.jboss.mod_cluster mod_cluster_test - 2.0.2.Final-SNAPSHOT + 2.0.3.Final-SNAPSHOT pom @@ -65,7 +65,7 @@ copy-dependencies - target + tomcat/target false true true diff --git a/test/native/setenv.sh b/test/setenv.sh similarity index 100% rename from test/native/setenv.sh rename to test/setenv.sh diff --git a/test/setup-dependencies.sh b/test/setup-dependencies.sh new file mode 100644 index 000000000..089ca467d --- /dev/null +++ b/test/setup-dependencies.sh @@ -0,0 +1,18 @@ +# Run this from the same directory +TEST_DIR=$(pwd) +cd ../.. +# get websocket demo repository +git clone https://github.com/jfclere/httpd_websocket +cd httpd_websocket +mvn install || exit 1 +cp target/websocket-hello-0.0.1.war $TEST_DIR +cd .. + +# get mod_cluster (Java/Tomcat part) +git clone https://github.com/modcluster/mod_cluster +cd mod_cluster +mvn install || exit 2 +cd $TEST_DIR + +# prepare jars +mvn dependency:copy-dependencies diff --git a/test/native/src/main/gvy/org/jboss/modcluster/Main.gvy b/test/src/main/gvy/org/jboss/modcluster/Main.gvy similarity index 100% rename from test/native/src/main/gvy/org/jboss/modcluster/Main.gvy rename to test/src/main/gvy/org/jboss/modcluster/Main.gvy diff --git a/test/native/src/main/gvy/org/jboss/modcluster/WebHTTPTest.gvy b/test/src/main/gvy/org/jboss/modcluster/WebHTTPTest.gvy similarity index 100% rename from test/native/src/main/gvy/org/jboss/modcluster/WebHTTPTest.gvy rename to test/src/main/gvy/org/jboss/modcluster/WebHTTPTest.gvy diff --git a/test/native/src/main/gvy/org/jboss/modcluster/WebSocketsTest.gvy b/test/src/main/gvy/org/jboss/modcluster/WebSocketsTest.gvy similarity index 100% rename from test/native/src/main/gvy/org/jboss/modcluster/WebSocketsTest.gvy rename to test/src/main/gvy/org/jboss/modcluster/WebSocketsTest.gvy diff --git a/test/native/testapp/test-750.jsp b/test/testapp/test-750.jsp similarity index 100% rename from test/native/testapp/test-750.jsp rename to test/testapp/test-750.jsp diff --git a/test/native/testapp/test.jsp b/test/testapp/test.jsp similarity index 100% rename from test/native/testapp/test.jsp rename to test/testapp/test.jsp diff --git a/test/testsuite.sh b/test/testsuite.sh new file mode 100644 index 000000000..b4b8c3d3a --- /dev/null +++ b/test/testsuite.sh @@ -0,0 +1,69 @@ +#!/usr/bin/sh + +# configuration of variables +# if you want tests to pass much faster, decrease these values +if [ -z ${FOREVER_PAUSE+x} ]; then + export FOREVER_PAUSE=3600 # sleep period length during which tomcats are run & stopped +fi +if [ -z ${TOMCAT_CYCLE_COUNT+x} ]; then + export TOMCAT_CYCLE_COUNT=100 # the number of repetitions of a test cycle +fi +if [ -z ${ITERATION_COUNT+x} ]; then + export ITERATION_COUNT=50 # the number of iteration of starting/stopping a tomcat +fi +if [ -z ${IMG+x} ]; then + export IMG=quay.io/$USER/tomcat_mod_cluster +fi +if [ -z ${HTTPD_IMG+x} ]; then + export HTTPD_IMG=quay.io/${USER}/httpd_mod_cluster +fi + +echo "Test parameters are:" +echo " FOREVER_PAUSE=$FOREVER_PAUSE" +echo " TOMCAT_CYCLE_COUNT=$TOMCAT_CYCLE_COUNT" +echo " ITERATION_COUNT=$ITERATION_COUNT" +echo " IMG=$IMG" +echo " HTTPD_IMG=$HTTPD_IMG" + +if [ ! -d logs ]; then + mkdir logs +fi + +. includes/common.sh + +httpd_create > /dev/null 2>&1 || exit 2 +tomcat_create > /dev/null 2>&1 || exit 3 + +# clean everything at first +httpd_all_clean +tomcat_all_remove + +res=0 + +run_test basetests.sh "Basic tests" +res=$(expr $res + $?) +run_test hangingtests.sh "Hanging tests" +res=$(expr $res + $?) +run_test maintests.sh "Main tests" +res=$(expr $res + $?) +run_test JBCS-1236/testit.sh "JBCS-1236" +res=$(expr $res + $?) +run_test MODCLUSTER-640/testit.sh "MODCLUSTER-640" +res=$(expr $res + $?) +run_test MODCLUSTER-734/testit.sh "MODCLUSTER-734" +res=$(expr $res + $?) +run_test MODCLUSTER-755/testit.sh "MODCLUSTER-755" +res=$(expr $res + $?) +run_test MODCLUSTER-785/testit.sh "MODCLUSTER-785" +res=$(expr $res + $?) + +echo "Clean remaining httpd containers" +httpd_all_clean + +if [ $res -eq 0 ]; then + echo "Tests finished successfully!" +else + echo "Tests finished, but some failed." +fi + +exit $res diff --git a/test/native/Dockerfile b/test/tomcat/Dockerfile similarity index 72% rename from test/native/Dockerfile rename to test/tomcat/Dockerfile index 40b72bd31..1fe94bd85 100644 --- a/test/native/Dockerfile +++ b/test/tomcat/Dockerfile @@ -3,9 +3,9 @@ FROM tomcat:8.5 WORKDIR /usr/local/tomcat COPY target/*.jar ./lib/ -COPY ./files/server.xml ./conf/ -COPY ./files/context.xml ./conf/ -COPY ./files/start.sh ./ +COPY server.xml ./conf/ +COPY context.xml ./conf/ +COPY start.sh ./ RUN chmod +x start.sh diff --git a/test/tomcat/README.md b/test/tomcat/README.md new file mode 100644 index 000000000..7a13f86f0 --- /dev/null +++ b/test/tomcat/README.md @@ -0,0 +1,25 @@ +# Build the image +```bash +docker build -t quay.io/${USER}/mod_cluster_tomcat . +``` + +# Run image +**Note the ENV variables:** + +* tomcat_port: port on which tomcat will listen (default: 8080) +* tomcat_shutdown_port: port on which tomcat will listen to SHUTDOWN command (default 8005) +* tomcat_ajp_port: port on which AJP will be listener (default: 8009) +* cluster_port: port on which the httpd counterpart listens (default: 6666) +* jvm_route: route name of the tomcat +* tomcat_address: ip address of the tomcat + +For example: +```bash +docker run --network=host -e tomcat_ajp_port=8010 -e tomcat_address=127.0.0.15 -e jvm_route=tomcat15 --name tomcat15 quay.io/${USER}/mod_cluster_tomcat +``` + +then you can uload a webapp into your running instance by executing + +```bash +docker cp webapp.war tomcat1:/usr/local/tomcat/webapps/ +``` diff --git a/test/native/files/context.xml b/test/tomcat/context.xml similarity index 100% rename from test/native/files/context.xml rename to test/tomcat/context.xml diff --git a/test/native/files/server.xml b/test/tomcat/server.xml similarity index 100% rename from test/native/files/server.xml rename to test/tomcat/server.xml diff --git a/test/native/files/start.sh b/test/tomcat/start.sh similarity index 89% rename from test/native/files/start.sh rename to test/tomcat/start.sh index 80cbe8e11..10b5c9c96 100644 --- a/test/native/files/start.sh +++ b/test/tomcat/start.sh @@ -41,19 +41,19 @@ else fi -if [ ${cluster_port}==0 ]; then +if [ "${cluster_port}" -eq "0" ]; then cluster_port=6666 fi sed -i "s/proxyport/${cluster_port}/" ./conf/server.xml sed -i "s/proxyaddress/127.0.0.1/" ./conf/server.xml -echo "jvm_route: ${jvm_route} and tomcat_port: ${tomcat_port}" +echo "jvm_route: ${jvm_route} and tomcat_port: ${tomcat_port} and tomcat_address: ${tomcat_address}" if [ ! -z ${jvm_route} ]; then sed -i "/" ./conf/server.xml fi # copy webapp war file. -mv *.war webapps/ || true +mv *.war webapps/ || true catalina.sh run