Back to home page

Enduro/X

 
 

    


0001 #!/bin/bash
0002 ##
0003 ## @brief @(#) Test021 - XA testing
0004 ##
0005 ## @file run-dom.sh
0006 ##
0007 ## -----------------------------------------------------------------------------
0008 ## Enduro/X Middleware Platform for Distributed Transaction Processing
0009 ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0010 ## Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0011 ## This software is released under one of the following licenses:
0012 ## AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0013 ## See LICENSE file for full text.
0014 ## -----------------------------------------------------------------------------
0015 ## AGPL license:
0016 ##
0017 ## This program is free software; you can redistribute it and/or modify it under
0018 ## the terms of the GNU Affero General Public License, version 3 as published
0019 ## by the Free Software Foundation;
0020 ##
0021 ## This program is distributed in the hope that it will be useful, but WITHOUT ANY
0022 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0023 ## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0024 ## for more details.
0025 ##
0026 ## You should have received a copy of the GNU Affero General Public License along 
0027 ## with this program; if not, write to the Free Software Foundation, Inc.,
0028 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0029 ##
0030 ## -----------------------------------------------------------------------------
0031 ## A commercial use license is available from Mavimax, Ltd
0032 ## contact@mavimax.com
0033 ## -----------------------------------------------------------------------------
0034 ##
0035 
0036 export TESTNO="021"
0037 export TESTNAME_SHORT="xafull"
0038 export TESTNAME="test${TESTNO}_${TESTNAME_SHORT}"
0039 
0040 PWD=`pwd`
0041 if [ `echo $PWD | grep $TESTNAME ` ]; then
0042         # Do nothing 
0043         echo > /dev/null
0044 else
0045         # started from parent folder
0046         pushd .
0047         echo "Doing cd"
0048         cd $TESTNAME
0049 fi;
0050 
0051 . ../testenv.sh
0052 
0053 # Include testing functions
0054 source ./test-func-include.sh
0055 
0056 export TESTDIR="$NDRX_APPHOME/atmitest/$TESTNAME"
0057 export PATH=$PATH:$TESTDIR
0058 # Override timeout!
0059 export NDRX_TOUT=20
0060 export NDRX_ULOG=$TESTDIR
0061 export NDRX_SILENT=Y
0062 
0063 rm -rf $TESTDIR/RM1
0064 rm -rf $TESTDIR/RM2
0065 
0066 if [ ! -d "$TESTDIR/RM1" ]; then
0067     mkdir $TESTDIR/RM1
0068     mkdir $TESTDIR/RM1/active
0069     mkdir $TESTDIR/RM1/prepared
0070     mkdir $TESTDIR/RM1/committed
0071     mkdir $TESTDIR/RM1/aborted
0072 fi
0073 
0074 if [ ! -d "$TESTDIR/RM2" ]; then
0075     mkdir $TESTDIR/RM2
0076     mkdir $TESTDIR/RM2/active
0077     mkdir $TESTDIR/RM2/prepared
0078     mkdir $TESTDIR/RM2/committed
0079     mkdir $TESTDIR/RM2/aborted
0080 fi
0081 
0082 #
0083 # Domain 1 - here client will live
0084 #
0085 function set_dom1 {
0086     echo "Setting domain 1"
0087     . ../dom1.sh
0088     export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1.xml
0089     export NDRX_DMNLOG=$TESTDIR/ndrxd-dom1.log
0090     export NDRX_LOG=$TESTDIR/ndrx-dom1.log
0091     export NDRX_DEBUG_CONF=$TESTDIR/debug-dom1.conf
0092     export NDRX_TEST_RM_DIR=$TESTDIR/RM1
0093 
0094     export NDRX_XA_RES_ID=1
0095     export NDRX_XA_OPEN_STR="+"
0096     export NDRX_XA_CLOSE_STR=$NDRX_XA_OPEN_STR
0097     export NDRX_XA_DRIVERLIB=$TESTDIR/$NDRX_XA_DRIVERLIB_FILENAME
0098     export NDRX_XA_RMLIB=$TESTDIR/libxadrv.so
0099 
0100     if [ "$(uname)" == "Darwin" ]; then
0101         export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:`pwd`
0102         export NDRX_XA_RMLIB=$TESTDIR/libxadrv.dylib
0103     fi
0104 
0105     export NDRX_XA_LAZY_INIT=0
0106 
0107 }
0108 
0109 #
0110 # Domain 2 - here server will live
0111 #
0112 function set_dom2 {
0113     echo "Setting domain 2"
0114     . ../dom2.sh    
0115     export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom2.xml
0116     export NDRX_DMNLOG=$TESTDIR/ndrxd-dom2.log
0117     export NDRX_LOG=$TESTDIR/ndrx-dom2.log
0118     export NDRX_DEBUG_CONF=$TESTDIR/debug-dom2.conf
0119     export NDRX_TEST_RM_DIR=$TESTDIR/RM2
0120 
0121     export NDRX_XA_RES_ID=2
0122     export NDRX_XA_OPEN_STR="+"
0123     export NDRX_XA_CLOSE_STR=$NDRX_XA_OPEN_STR
0124     export NDRX_XA_DRIVERLIB=$TESTDIR/$NDRX_XA_DRIVERLIB_FILENAME
0125     export NDRX_XA_RMLIB=$TESTDIR/libxadrv.so
0126 
0127     if [ "$(uname)" == "Darwin" ]; then
0128         export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:`pwd`
0129         export NDRX_XA_RMLIB=$TESTDIR/libxadrv.dylib
0130     fi
0131 
0132     export NDRX_XA_LAZY_INIT=0
0133 
0134 }
0135 
0136 #
0137 # Generic exit function
0138 #
0139 function go_out {
0140     echo "Test exiting with: $1"
0141     
0142     set_dom1;
0143     xadmin stop -y
0144     xadmin down -y
0145 
0146     set_dom2;
0147     xadmin stop -y
0148     xadmin down -y
0149 
0150     # If some alive stuff left...
0151     xadmin killall atmiclt21
0152 
0153     popd 2>/dev/null
0154     exit $1
0155 }
0156 
0157 #
0158 # Print domain statuses...
0159 #
0160 function print_domains {
0161 
0162     set_dom1;
0163     xadmin ppm
0164     xadmin psvc
0165     xadmin psc
0166 
0167     set_dom2;
0168     xadmin ppm
0169     xadmin psvc
0170     xadmin psc
0171 
0172 }
0173 
0174 
0175 rm *.log
0176 rm ULOG.*
0177 
0178 set_dom1;
0179 xadmin down -y
0180 # Let system to cleanup if any
0181 sleep 2
0182 xadmin start -y || go_out 1
0183 
0184 set_dom2;
0185 xadmin down -y
0186 # Let system to cleanup if any
0187 sleep 2
0188 xadmin start -y || go_out 2
0189 
0190 #exit 0
0191 
0192 # Have some wait for ndrxd goes in service - wait for connection establishment.
0193 sleep 60
0194 
0195 print_domains;
0196 
0197 # Go to domain 1
0198 set_dom1;
0199 xadmin ppm
0200 xadmin psvc
0201 
0202 #
0203 # Test case when tries exceeded, transaction not committed
0204 # after manual commit from xadmin few times, in gets finally committed.
0205 # the config is -m10 attempts each takes -r2x times
0206 #
0207 if [[ $NDRX_XA_DRIVERLIB_FILENAME == *"tryfail"* ]]; then
0208     echo ">>> TRYFAIL testing..."
0209 
0210     (./atmiclt21-try 2>&1) > ./atmiclt-try-dom1.log
0211     RET=$?
0212 
0213     sleep 30
0214 
0215     if [ $RET == 0 ]; then
0216 
0217         # test for transaction to be committed..
0218         # there should be no TRN- files at top level
0219 
0220         if [ ! -f ./RM1/TRN-* ]; then
0221             echo "Transaction must NOT be completed - thus \
0222                     intermediate file must exist!"
0223             RET=-2
0224         fi
0225 
0226         # try to manually commit with xadmin, 11 times, then it will approve
0227         TX=`xadmin pt | grep 'TM ref' | cut -d ':' -f2 | cut -d ')' -f1`
0228 
0229         cmd="xadmin commit $TX -y" 
0230         # 1x2 try for online, 10x2 for background, 2x4 retry, 
0231         for i in 1 2 3 4
0232         do
0233             echo "Running [$cmd"]
0234             eval $cmd
0235         done
0236         
0237         # Commit, should be ok
0238         eval $cmd || exit -10
0239 
0240         if [ -f ./RM1/TRN-* ]; then
0241             echo "Transaction must be completed!"
0242             RET=-3
0243         fi
0244 
0245         if [ ! -f ./RM1/committed/* ]; then
0246             echo "Transaction must be committed!"
0247             RET=-4
0248         fi
0249 
0250     fi
0251     go_out $RET
0252 fi
0253 
0254 #
0255 # Test case when tries not exceeded, we get committed tran
0256 #
0257 echo ">>> LIB: $NDRX_XA_DRIVERLIB_FILENAME"
0258 
0259 if [[ $NDRX_XA_DRIVERLIB_FILENAME == *"tryok"* ]]; then
0260     echo ">>> TRYOK testing..."
0261 
0262     (./atmiclt21-try 2>&1) > ./atmiclt-try-dom1.log
0263     RET=$?
0264 
0265     sleep 20
0266 
0267     if [ $RET == 0 ]; then
0268 
0269         # test for transaction to be committed..
0270         # there should be no TRN- files at top level
0271 
0272         if [ -f ./RM1/TRN-* ]; then
0273                 echo "Transaction must be completed!"
0274                 RET=-2
0275         fi
0276 
0277         if [ ! -f ./RM1/committed/* ]; then
0278                 echo "Transaction must be committed!"
0279                 RET=-3
0280         fi
0281 
0282     fi
0283 
0284     go_out $RET
0285     
0286 fi
0287 
0288 ################################################################################
0289 # Test case when xa_start_entry fails due to connection close (i.e. no 
0290 # work done by tpopen() was closed).
0291 # So it works for both cases when flag enabled end flag disabled
0292 #
0293 ################################################################################
0294 
0295 if [[ $NDRX_XA_DRIVERLIB_FILENAME == *"startfail"* ]]; then
0296 
0297         echo ">>> XA Start fail/retry, flags [$NDRX_XA_FLAGS]"
0298 
0299         (./atmiclt21-startfail $TEST160_FLAG 2>&1) > ./atmiclt-startfail-dom1.log
0300         RET=$?
0301 
0302         echo "Wait 25 sec for abort..."
0303         sleep 25
0304         #
0305         # If all ok, test for transaction files.
0306         #
0307         if [ $RET == 0 ]; then
0308         
0309             # test for transaction to be aborted..
0310             # there should be no TRN- files at top level
0311 
0312             logfiles=(./RM1/TRN-*)
0313             if [[ -f ${logfiles[0]} ]]; then
0314                     echo "Transaction must be completed!"
0315                     RET=-2
0316             fi
0317 
0318             #if [ ! -f ./RM1/aborted/* ]; then
0319             #   echo "Transaction must be aborted!"
0320             #   RET=-3
0321             #fi
0322 
0323         fi
0324 
0325         go_out $RET
0326 fi
0327 
0328 ################################################################################
0329 # Test case for bug when resource manager prepares transaction, but
0330 # tmsrv does not log it as prepared
0331 # After fix it shall abort the transaction after tmsrv restart
0332 ################################################################################
0333 if [[ $NDRX_XA_DRIVERLIB_FILENAME == *"105"* ]]; then
0334 
0335     echo "Testing bug #105 - prepare ok, but process terminates before writting log"
0336 
0337     (./atmiclt21-105 2>&1) > ./atmiclt-105-dom1.log
0338     RET=$?
0339 
0340     # let tmsrv boot back and abort transaction
0341     sleep 10
0342     #
0343     # If all ok, test for transaction files.
0344     #
0345     if [ $RET == 0 ]; then
0346 
0347         # test for transaction to be aborted..
0348         # there should be no TRN- files at top level
0349 
0350         if [ -f ./RM1/TRN-* ]; then
0351                 echo "Transaction must be completed!"
0352                 RET=-2
0353         fi
0354 
0355         if [ ! -f ./RM1/aborted/* ]; then
0356                 echo "Transaction must be aborted!"
0357                 RET=-3
0358         fi
0359 
0360     fi
0361 
0362     go_out $RET
0363 
0364 fi
0365 
0366 ################################################################################
0367 # XA API TESTS
0368 ################################################################################
0369 
0370 echo "TX API Test"
0371 (./atmiclt21tx 2>&1) > ./atmiclt-dom1-tx.log
0372 RET=$?
0373 
0374 if [[ $RET -ne 0 ]]; then
0375     echo "TX API Test fail"
0376     go_out $RET
0377 fi
0378 
0379 CNT=`grep 'TXAPI LOGGED' RM2/committed/* | wc | awk '{print $1}'`
0380 
0381 if [ $CNT -ne 300 ]; then
0382     echo "TXAPI LOGGED 300 not found: $CNT"
0383     go_out -1
0384 fi
0385 
0386 ################################################################################
0387 # Test that pings works...
0388 ################################################################################
0389 PING_DOM1=`grep 'PING OK 0' TM1*.log`
0390 echo "DOM1 PINGs by xa_recover: [$PING_DOM1]"
0391 
0392 if [ "X$PING_DOM1" == "X" ]; then
0393     echo "DOM1 PINGs not working!"
0394     RET=-1
0395     go_out $RET
0396 fi
0397 
0398 echo "DOM1 pings OK"
0399 
0400 PING_DOM2=`grep 'PING OK -4' TM2*.log`
0401 echo "DOM2 PINGs by xa_start TMJOIN: [$PING_DOM2]"
0402 
0403 if [ "X$PING_DOM2" == "X" ]; then
0404     echo "DOM2 PINGs not working!"
0405     RET=-1
0406     go_out $RET
0407 fi
0408 
0409 echo "DOM2 pings OK"
0410 
0411 ################################################################################
0412 echo  "Test tpconvert()"
0413 ################################################################################
0414 xadmin psc
0415 
0416 (./atmiclt21-tpconvert 2>&1) > ./atmiclt21-tpconvert.log
0417 
0418 RET=$?
0419 if [ "X$RET" != "X0" ]; then
0420     echo "atmiclt21-tpconvert failed"
0421     
0422     go_out $RET
0423 fi
0424 
0425 ################################################################################
0426 # Normal tests
0427 ################################################################################
0428 
0429 echo "Housekeep invalid journals (15s)"
0430 
0431 touch ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_1
0432 echo "1449414167259:S:40" > ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_2
0433 echo "1449414167260:R:1:p:0:0" > ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_3
0434 echo "1449414167259:I:1:1:50:5:1,2" > ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_4
0435 echo "1449414167259:I:1:1:50:5:1,2" >> ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_4
0436 
0437 # 15 sec these files shall be alive
0438 # thus after restart files shall be in place..
0439 xadmin restart -s tmsrv
0440 
0441 if [ ! -f ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_1 ]; then
0442     echo "./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_1 does not exist!"
0443     go_out -1
0444 fi
0445 
0446 if [ ! -f ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_2 ]; then
0447     echo "./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_2 does not exist!"
0448     go_out -1
0449 fi
0450 
0451 if [ ! -f ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_3 ]; then
0452     echo "./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_3 does not exist!"
0453     go_out -1
0454 fi
0455 
0456 if [ ! -f ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_4 ]; then
0457     echo "./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_4 does not exist!"
0458     go_out -1
0459 fi
0460 
0461 # let files to become stale
0462 sleep 17
0463 
0464 xadmin restart -s tmsrv
0465 
0466 # let background thread to collect the files
0467 sleep 2
0468 
0469 if [ -f ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_1 ]; then
0470     echo "./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_1 does exist!"
0471     go_out -1
0472 fi
0473 
0474 if [ -f ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_2 ]; then
0475     echo "./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_2 does exist!"
0476     go_out -1
0477 fi
0478 
0479 if [ -f ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_3 ]; then
0480     echo "./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_3 does exist!"
0481     go_out -1
0482 fi
0483 
0484 if [ -f ./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_4 ]; then
0485     echo "./RM1/TRN-1-1-50-THIS_IS_INVALID_TRAN_4 does exist!"
0486     go_out -1
0487 fi
0488 
0489 
0490 echo "Testing journal recovery..."
0491 cp ./test_data/* ./RM1
0492 xadmin restart -s tmsrv
0493 sleep 5
0494 
0495 # All must be completed
0496 ensure_tran 0
0497 
0498 # Run o-api tests
0499 echo "O-api tests:"
0500 #(valgrind --leak-check=full ./atmiclt21-oapi 2>&1) > ./atmiclt-oapi-dom1.log
0501 (./atmiclt21-oapi 2>&1) > ./atmiclt-oapi-dom1.log
0502 RET=$?
0503 
0504 # Run the client test...
0505 echo "Will issue calls to clients:"
0506 (./atmiclt21 2>&1) > ./atmiclt-dom1.log
0507 RET=$?
0508 
0509 echo "Will run conversation tests:"
0510 (./convclt21 2>&1) > ./convclt21-dom1.log
0511 RET2=$?
0512 
0513 echo "Cli tests..."
0514 (./cli-tests.sh 2>&1) > ./cli-tests.sh.log
0515 RET3=$?
0516 
0517 if [[ $RET -eq 0 ]]; then
0518         RET=$RET2;
0519 fi
0520 
0521 if [[ $RET -eq 0 ]]; then
0522         RET=$RET3;
0523 fi
0524 
0525 CNTRM1=`ls -1 ./RM1/TRN-* | wc | awk '{print $1}'`
0526 if [ "X$CNTRM1" != "X0" ]; then
0527     echo "Transaction must be completed (RM1)!"
0528     RET=-2
0529 fi
0530 
0531 CNTRM2=`ls -1 ./RM2/TRN-* | wc | awk '{print $1}'`
0532 if [ "X$CNTRM2" != "X0" ]; then
0533     echo "Transaction must be completed (RM2)!"
0534     RET=-2
0535 fi
0536 
0537 # Catch is there is test error!!!
0538 if [ "X`grep TESTERROR *.log`" != "X" ]; then
0539         echo "Test error detected!"
0540         RET=-2
0541 fi
0542 
0543 go_out $RET
0544 
0545 # vim: set ts=4 sw=4 et smartindent: