New test for delivering notifications through messaging
authorZdeněk Šustr <sustr4@cesnet.cz>
Fri, 1 Apr 2011 13:15:34 +0000 (13:15 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Fri, 1 Apr 2011 13:15:34 +0000 (13:15 +0000)
org.glite.testsuites.ctb/LB/tests/lb-common.sh
org.glite.testsuites.ctb/LB/tests/lb-run-tests.sh
org.glite.testsuites.ctb/LB/tests/lb-test-notif-msg.sh [new file with mode: 0755]

index 064e2fb..a8a862d 100755 (executable)
@@ -64,6 +64,7 @@ LB4AGUACTINFO=glite-lb-ws_lb4agu_GetActivityInfo
 LB4AGUACTSTATUS=glite-lb-ws_lb4agu_GetActivityStatus
 LBREGSANDBOX=glite-lb-register_sandbox
 LBHISTORY=glite-lb-state_history
+LBCMSCLIENT=glite-lb-cmsclient
 
 LB_LOGD=glite-lb-logd 
 LB_INTERLOGD=glite-lb-interlogd
@@ -120,6 +121,7 @@ SYS_SCP=scp
 SYS_TOUCH=touch
 SYS_HOSTNAME=hostname
 SYS_RPM=rpm
+SYS_WC=wc
 
 # not used at the moment
 DEBUG=2
index df77c0b..b9586bb 100755 (executable)
@@ -120,6 +120,8 @@ export LBTSTCOLS
 
 yum install -q -y globus-proxy-utils 
 yum install -q -y postgresql postgresql-server
+yum install -q -y activemq java-1.6.0-openjdk
+
 /etc/init.d/postgresql start
 mv /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.orig
 cat >/var/lib/pgsql/data/pg_hba.conf <<EOF
@@ -130,6 +132,13 @@ EOF
 /etc/init.d/postgresql reload
 createuser -U postgres -S -R -D rtm
 
+if [ -f ~/.activemqrc ]
+       echo ActiveMQ already configured
+else
+       activemq setup ~/.activemqrc
+       activemq start
+fi
+
 
 cd /tmp
 
diff --git a/org.glite.testsuites.ctb/LB/tests/lb-test-notif-msg.sh b/org.glite.testsuites.ctb/LB/tests/lb-test-notif-msg.sh
new file mode 100755 (executable)
index 0000000..3a4da9f
--- /dev/null
@@ -0,0 +1,223 @@
+#!/bin/bash
+#
+# Copyright (c) Members of the EGEE Collaboration. 2004-2010.
+# See http://www.eu-egee.org/partners for details on the copyright holders.
+# 
+# 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,
+# 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.
+#
+
+# show help and usage
+progname=`basename $0`
+showHelp()
+{
+cat << EndHelpHeader
+Script for testing notification delivery
+
+Prerequisities:
+   - LB server
+   - Event logging chain
+   - Notification delivery chain (notification interlogger)
+   - environment variables set:
+
+     GLITE_LOCATION
+     GLITE_WMS_QUERY_SERVER
+     GLITE_WMS_LOG_DESTINATION 
+     GLITE_WMS_NOTIF_SERVER
+
+Tests called:
+
+    job registration
+    notification registration
+    logging events
+    receiving notifications
+
+Returned values:
+    Exit TEST_OK: Test Passed
+    Exit TEST_ERROR: Test Failed
+    Exit 2: Wrong Input
+
+EndHelpHeader
+
+       echo "Usage: $progname [OPTIONS]"
+       echo "Options:"
+       echo " -h | --help            Show this help message."
+       echo " -o | --output 'file'   Redirect all output to the 'file' (stdout by default)."
+       echo " -t | --text            Format output as plain ASCII text."
+       echo " -c | --color           Format output as text with ANSI colours (autodetected by default)."
+       echo " -x | --html            Format output as html."
+}
+
+# read common definitions and functions
+COMMON=lb-common.sh
+if [ ! -r ${COMMON} ]; then
+       printf "Common definitions '${COMMON}' missing!"
+       exit 2
+fi
+source ${COMMON}
+
+logfile=$$.tmp
+flag=0
+while test -n "$1"
+do
+       case "$1" in
+               "-h" | "--help") showHelp && exit 2 ;;
+               "-o" | "--output") shift ; logfile=$1 flag=1 ;;
+               "-t" | "--text")  setOutputASCII ;;
+               "-c" | "--color") setOutputColor ;;
+               "-x" | "--html")  setOutputHTML ;;
+       esac
+       shift
+done
+
+# redirecting all output to $logfile
+touch $logfile
+if [ ! -w $logfile ]; then
+       echo "Cannot write to output file $logfile"
+       exit $TEST_ERROR
+fi
+
+DEBUG=2
+
+##
+#  Starting the test
+#####################
+
+{
+test_start
+
+
+# check_binaries
+printf "Testing if all binaries are available"
+check_binaries $GRIDPROXYINFO $SYS_GREP $SYS_SED $SYS_AWK $LBCMSCLIENT $SYS_EXPR
+if [ $? -gt 0 ]; then
+       test_failed
+else
+       test_done
+fi
+
+printf "Testing credentials"
+
+timeleft=`${GRIDPROXYINFO} | ${SYS_GREP} -E "^timeleft" | ${SYS_SED} "s/timeleft\s*:\s//"`
+
+if [ "$timeleft" = "" ]; then
+        test_failed
+        print_error "No credentials"
+else
+        if [ "$timeleft" = "0:00:00" ]; then
+                test_failed
+                print_error "Credentials expired"
+        else
+                test_done
+
+
+               # Register job:
+               printf "Registering testing job "
+               jobid=`${LBJOBREG} -m ${GLITE_WMS_QUERY_SERVER} -s application 2>&1 | $SYS_GREP "new jobid" | ${SYS_AWK} '{ print $3 }'`
+
+               if [ -z $jobid ]; then
+                       test_failed
+                       print_error "Failed to register job"
+               else
+                       printf "(${jobid}) "
+                       test_done
+               fi
+
+               # Register notification:
+               printf "Registering notification "
+
+               notifid=`${LBNOTIFY} new -j ${jobid} -a x-msg://topic | $SYS_GREP "notification ID" | ${SYS_AWK} '{ print $3 }'`
+
+               if [ -z $notifid ]; then
+                       test_failed
+                       print_error "Failed to register notification"
+               else
+                       printf "(${notifid}) "
+                       test_done
+
+                       BROKERLINE=`grep -E "^broker" /etc/glite-lb/glite-lb-msg.conf`
+
+                       if [ $? = 0 ]; then
+
+                               BROKER=`$SYS_ECHO $BROKERLINE | $SYS_AWK '{print $3}' | $SYS_SED 's/^.*\/\///'`
+
+                               printf "connecting to broker $BROKER... "
+
+                               #Start listening for notifications
+                               ${LBCMSCLIENT} ${BROKER} > $$_notifications.txt &
+                               recpid=$!
+                               test_done
+
+                               printf "Logging events resulting in DONE state... "
+                               $LB_DONE_SH -j ${jobid} > /dev/null 2> /dev/null
+                               test_done
+
+                               printf "Sleep for 10 seconds to give messages time to deliver... "
+
+                               sleep 3
+                               test_done
+
+                               kill $recpid
+
+                               printf "Checking number of messages delivered... "
+
+                               NOofMESSAGES=`$SYS_GREP -E "Message #[0-9]* Received" $$_notifications.txt | $SYS_WC -l`
+                               
+                               printf "$NOofMESSAGES. Checking if >= 10... "
+
+                               cresult=`$SYS_EXPR ${NOofMESSAGES} \>= 10`
+
+                               if [ "$cresult" -eq "1" ]; then
+                                       printf "OK"
+                                       test_done
+                               else
+                                       test_failed
+                                       print_error "Fewer messages than expected"
+                               fi
+
+                               $SYS_RM $$_notifications.txt
+                       else
+                               printf "Cannot determine broker address"
+                               test_skipped
+                       fi
+
+
+
+                       #Drop notification
+                       printf "Dropping the test notification (${notifid})"
+                       dropresult=`${LBNOTIFY} drop ${notifid} 2>&1`
+                       if [ -z $dropresult ]; then
+                               test_done
+                       else
+                               test_failed
+                               print_error "Failed to drop notification ${dropresult}"
+                       fi
+
+                       #Purge test job
+                       joblist=$$_jobs_to_purge.txt
+                       echo $jobid > ${joblist}
+                       try_purge ${joblist}
+
+               fi
+       fi
+fi
+
+test_end
+#} &> $logfile
+}
+
+if [ $flag -ne 1 ]; then
+       cat $logfile
+       $SYS_RM $logfile
+fi
+exit $TEST_OK
+