Back to home page

Enduro/X

 
 

    


0001 #!/bin/bash
0002 ##
0003 ## @brief tmsrv houskeeping extended tests - test launcher
0004 ##  test will have two parts. 1) check that corrupted logs are collected by
0005 ##  log try-load count processign. 2) check that tries are expired, however
0006 ##  the log is finally collected.
0007 ##
0008 ## @file run.sh
0009 ##
0010 ## -----------------------------------------------------------------------------
0011 ## Enduro/X Middleware Platform for Distributed Transaction Processing
0012 ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0013 ## Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0014 ## This software is released under one of the following licenses:
0015 ## AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0016 ## See LICENSE file for full text.
0017 ## -----------------------------------------------------------------------------
0018 ## AGPL license:
0019 ## 
0020 ## This program is free software; you can redistribute it and/or modify it under
0021 ## the terms of the GNU Affero General Public License, version 3 as published
0022 ## by the Free Software Foundation;
0023 ##
0024 ## This program is distributed in the hope that it will be useful, but WITHOUT ANY
0025 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0026 ## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0027 ## for more details.
0028 ##
0029 ## You should have received a copy of the GNU Affero General Public License along 
0030 ## with this program; if not, write to the Free Software Foundation, Inc., 
0031 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0032 ##
0033 ## -----------------------------------------------------------------------------
0034 ## A commercial use license is available from Mavimax, Ltd
0035 ## contact@mavimax.com
0036 ## -----------------------------------------------------------------------------
0037 ##
0038 
0039 export TESTNAME="test107_tmsrvhkeep"
0040 
0041 PWD=`pwd`
0042 if [ `echo $PWD | grep $TESTNAME ` ]; then
0043     # Do nothing 
0044     echo > /dev/null
0045 else
0046     # started from parent folder
0047     pushd .
0048     echo "Doing cd"
0049     cd $TESTNAME
0050 fi;
0051 
0052 . ../testenv.sh
0053 
0054 export TESTDIR="$NDRX_APPHOME/atmitest/$TESTNAME"
0055 export PATH=$PATH:$TESTDIR
0056 export NDRX_ULOG=$TESTDIR
0057 export NDRX_TOUT=10
0058 export NDRX_SILENT=Y
0059 
0060 if [ "$(uname)" == "Darwin" ]; then
0061     export NDRX_LIBEXT="dylib"
0062 else
0063     export NDRX_LIBEXT="so"
0064 fi
0065 
0066 #
0067 # Common configuration between the domains
0068 #
0069 export NDRX_CCONFIG=$TESTDIR/app-common.ini
0070 
0071 #
0072 # Domain 1 - trasnaction is collected by tries counter (expiry check at attempt)
0073 #
0074 set_dom1_tries() {
0075     echo "Setting domain 1 (tries)"
0076     . ../dom1.sh
0077     export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1-tries.xml
0078     export NDRX_DMNLOG=$TESTDIR/ndrxd-dom1.log
0079     export NDRX_LOG=$TESTDIR/ndrx-dom1.log
0080 }
0081 
0082 #
0083 # Doamin 1 - transaction is collected by log expiry
0084 #
0085 set_dom1_exp() {
0086     echo "Setting domain 1 (tries)"
0087     . ../dom1.sh
0088     export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1-exp.xml
0089     export NDRX_DMNLOG=$TESTDIR/ndrxd-dom1.log
0090     export NDRX_LOG=$TESTDIR/ndrx-dom1.log
0091 }
0092 
0093 #
0094 # Generic exit function
0095 #
0096 function go_out {
0097     echo "Test exiting with: $1"
0098 
0099     xadmin stop -y
0100     xadmin down -y
0101 
0102     # If some alive stuff left...
0103     xadmin killall atmiclt107
0104 
0105     popd 2>/dev/null
0106     exit $1
0107 }
0108 
0109 rm *.log
0110 rm -rf RM2 qdata 2>/dev/null
0111 # where to store the data
0112 mkdir RM2 qdata
0113 
0114 for test in 1 2; do
0115 
0116     echo ">>> Test number [$test]"
0117     rm ULOG* 2>/dev/null
0118 
0119     if [ $test -eq 1 ]; then
0120         set_dom1_tries;
0121     else
0122         set_dom1_exp;
0123     fi
0124     # cleanup old session
0125     xadmin stop -y
0126     xadmin down -y
0127     xadmin start -y
0128 
0129     # load single message, sequence 0
0130     NDRX_CCTAG=RM2TMQ ./atmiclt107 enq 0
0131 
0132     RET=$?
0133     if [[ "X$RET" != "X0" ]]; then
0134         echo "Failed to enqueue message!"
0135         go_out $RET
0136     fi
0137 
0138     # generate transaction entry (incomplete)
0139     NDRX_CCTAG=RM2TMQ ./atmiclt107 deq 1 Y
0140 
0141     RET=$?
0142     if [[ "X$RET" != "X0" ]]; then
0143         echo "Failed to dequeue (broken, locked, dequeue not committed)!"
0144         go_out $RET
0145     fi
0146 
0147     # now corrupt the transaction log
0148     find $TESTDIR/RM2 -type f -exec truncate -s 0 {} \;
0149 
0150     # make any active tmqueue transactions as prepared...
0151     # so that tmrecoversv can collect them...
0152     mv $TESTDIR/qdata/active/* $TESTDIR/qdata/prepared
0153 
0154     # reload tmqueue (to stuck the transaction)
0155     xadmin sreload tmqueue
0156 
0157     # reload tmsrv (to capture broken txn)
0158     xadmin sreload tmsrv
0159 
0160     # let some sanity cycle to run / recover (shall not recover yet...)
0161     sleep 4
0162 
0163     # try dequeue, it shall fail, as  msg is locked...
0164     NDRX_CCTAG=RM2TMQ ./atmiclt107 deq 1 N
0165 
0166     RET=$?
0167     if [[ "X$RET" == "X0" ]]; then
0168         echo "Dequeue must fail!"
0169         go_out $RET
0170     fi
0171 
0172     # wait for tries or expiry to kick in
0173     sleep 20
0174 
0175     NDRX_CCTAG=RM2TMQ ./atmiclt107 deq 1 N
0176 
0177     RET=$?
0178     if [[ "X$RET" != "X0" ]]; then
0179         echo "Dequeue must succeed, but failed (after expiry)!"
0180         go_out $RET
0181     fi
0182 
0183     # verify that tmsrv did not crash...
0184     if [ "X`grep "Server process \[tmsrv\]" ULOG* | grep died `" != "X" ]; then
0185         echo "tmsrv died during the testing!"
0186         go_out -1
0187     fi
0188 
0189     # ensure that log directory is empty..
0190     ls -l $TESTDIR/RM2
0191 
0192     CNT=`ls -1 $TESTDIR/RM2 | wc -l | awk '{print $1}'`
0193     if [ $CNT -ne 0 ]; then
0194         echo "Expected empty log directory, but got $CNT files"
0195         go_out -1
0196     fi
0197 
0198     # verify number of attempts done for loading... (scan the tmsrv log)
0199     ATTEMPTS=`grep "info record - not loading" ULOG*  | wc -l | awk '{print $1}'`
0200 
0201     if [ $test -eq 1 ]; then
0202         if [ $ATTEMPTS -lt 10 ]; then
0203             echo "Expected load attempts atleast 10, but got $ATTEMPTS"
0204             go_out -1
0205         fi
0206     else
0207         if [ $ATTEMPTS -ne 1 ]; then
0208             echo "Expected 1x load attempt, but got $ATTEMPTS"
0209             go_out -1
0210         fi
0211     fi
0212 
0213 done
0214 
0215 # Catch is there is test error!!!
0216 if [ "X`grep TESTERROR *.log`" != "X" ]; then
0217     echo "Test error detected!"
0218     RET=-2
0219 fi
0220 
0221 go_out $RET
0222 # vim: set ts=4 sw=4 et smartindent:
0223