Back to home page

Enduro/X

 
 

    


0001 #!/bin/bash
0002 ##
0003 ## @brief Check the <services> and <routing> syntax - test launcher
0004 ##
0005 ## @file run.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 TESTNAME="test083_ddrsyntax"
0037 
0038 PWD=`pwd`
0039 if [ `echo $PWD | grep $TESTNAME ` ]; then
0040     # Do nothing 
0041     echo > /dev/null
0042 else
0043     # started from parent folder
0044     pushd .
0045     echo "Doing cd"
0046     cd $TESTNAME
0047 fi;
0048 
0049 . ../testenv.sh
0050 
0051 export TESTDIR="$NDRX_APPHOME/atmitest/$TESTNAME"
0052 export PATH=$PATH:$TESTDIR
0053 export NDRX_ULOG=$TESTDIR
0054 export NDRX_TOUT=10
0055 export NDRX_SILENT=Y
0056 
0057 export NDRX_RTSVCMAX=20
0058 export NDRX_RTCRTMAX=800
0059 
0060 #
0061 # Domain 1 - here client will live
0062 #
0063 set_dom1() {
0064     echo "Setting domain 1"
0065     . ../dom1.sh
0066     export NDRX_CONFIG=$TESTDIR/ndrxconfig-dom1.xml
0067     export NDRX_DMNLOG=$TESTDIR/ndrxd-dom1.log
0068     export NDRX_LOG=$TESTDIR/ndrx-dom1.log
0069     export NDRX_DEBUG_CONF=$TESTDIR/debug-dom1.conf
0070 }
0071 
0072 #
0073 # Generic exit function
0074 #
0075 function go_out {
0076     echo "Test exiting with: $1"
0077     
0078     set_dom1;
0079     xadmin stop -y
0080     xadmin down -y
0081 
0082     popd 2>/dev/null
0083     exit $1
0084 }
0085 
0086 #
0087 # validate invalid config
0088 #
0089 validate_invalid() {
0090     config=$1
0091     msg=$2
0092 
0093     echo "---------------------------------------------------------------------"
0094     echo "*** Testing: $msg ($config)"
0095     echo "---------------------------------------------------------------------"
0096     cp $TESTDIR/$1 ndrxconfig-dom1.xml
0097 
0098     OUT=`xadmin reload`
0099     RET=$?
0100 
0101     if [[ "X$RET" == "X0" ]]; then
0102         echo "Config failed [$config] must fail, but didn't"
0103         go_out -1
0104     fi
0105 
0106     # print the output
0107     echo $OUT
0108     
0109 }
0110 
0111 #
0112 # validate syntax with combined xml
0113 #
0114 validate_syntax() {
0115     start=$1
0116     stop=$2
0117     syntax=$3
0118     msg=$4
0119     ftype=$5
0120 
0121     echo "---------------------------------------------------------------------"
0122     echo "*** Testing syntax: $msg [$syntax] type $ftype"
0123     echo "---------------------------------------------------------------------"
0124 
0125     # copy first part + second part of the files and put syntax inside
0126     cat $TESTDIR/$start > ndrxconfig-dom1.xml
0127 
0128     echo "<ranges>" >> ndrxconfig-dom1.xml
0129     echo $3 >> ndrxconfig-dom1.xml
0130     echo "</ranges>" >> ndrxconfig-dom1.xml
0131     echo "<fieldtype>$ftype</fieldtype>" >> ndrxconfig-dom1.xml
0132 
0133     cat $TESTDIR/$stop >> ndrxconfig-dom1.xml
0134 
0135     OUT=`xadmin reload`
0136     RET=$?
0137 
0138     if [[ "$msg" == "OK" ]]; then
0139 
0140         if [[ "X$RET" != "X0" ]]; then
0141             echo "Expected OK [$syntax] got error"
0142             go_out -1
0143         fi
0144 
0145     else
0146         if [[ "X$RET" == "X0" ]]; then
0147             echo "Config failed [$syntax] must fail, but didn't"
0148             go_out -1
0149         fi
0150     fi
0151 
0152     # print the output
0153     echo $OUT
0154 
0155 }
0156 
0157 rm *.log
0158 
0159 #
0160 # Start with OK config
0161 #
0162 cp $TESTDIR/ndrxconfig-ok.xml ndrxconfig-dom1.xml
0163 
0164 set_dom1;
0165 xadmin down -y
0166 xadmin idle || go_out 1
0167 xadmin ldcf
0168 
0169 echo "Testing <services> tag..."
0170 validate_invalid "ndrxconfig-dupsvc.xml" "Duplicate services is not allowed" 
0171 validate_invalid "ndrxconfig-toolong.xml" "Service name too long" 
0172 validate_invalid "ndrxconfig-norout.xml" "Routing not defined" 
0173 validate_invalid "ndrxconfig-emptysvc.xml" "Emtpy service name" 
0174 validate_invalid "ndrxconfig-invalfield.xml" "Invalid field" 
0175 validate_invalid "ndrxconfig-invalautotr.xml" "Invalid autotran setting" 
0176 
0177 echo "Testing <routing> tag..."
0178 
0179 validate_invalid "ndrxconfig-rtnoname.xml" "Missing routing name" 
0180 validate_invalid "ndrxconfig-rtranges.xml" "Two ranges present" 
0181 validate_invalid "ndrxconfig-rtfldmis.xml" "Routing field is missing" 
0182 validate_invalid "ndrxconfig-rtfieldtype.xml" "Invalid field type" 
0183 
0184 validate_invalid "ndrxconfig-rtbuftype.xml" "Inalid buffer type" 
0185 validate_invalid "ndrxconfig-rtbuftype2.xml" "Only UBF supported" 
0186 validate_invalid "ndrxconfig-rtdup.xml" "Duplicate routing entry" 
0187 
0188 
0189 echo "Ranges syntax...(syntax engine)"
0190 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "MIN" "Inval expr" "LONG"
0191 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "MIN-MIN" "Inval expr"  "LONG"
0192 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "MIN-MIN:GRP" "Inval"  "LONG"# this shall not fail
0193 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "MIN-MAX:GRP" "OK"  "LONG"
0194 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "MIN-MAX:GRP,MIN-MIN:G2" "Inval expr"  "LONG"
0195 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "*:*" "OK"  "LONG"
0196 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "5-9:CC," "Fail"  "LONG"
0197 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "5-9:CC,10-11:OK" "OK"  "LONG"
0198 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "5-9:CC,10-11:OK,MAX:*" "Fail"  "LONG"
0199 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "5-9:CC,10-11:OK,MAX-*:*" "Fail"  "LONG"
0200 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "5-9:CC,10-11:OK,*:*" "OK"  "LONG"
0201 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "," "Fail"  "LONG"
0202 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "" "Fail"  "LONG"
0203 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "A-B:C" "Fail"  "LONG" # this is long
0204 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "A-B:C" "OK"  "STRING" # ok for string
0205 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "1-B:C" "Fail"  "LONG" # this is long upper bad
0206 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "1-9:'GRP'" "OK"  "LONG" # numbers
0207 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "1.11-9.99:'GRP'" "Fail"  "LONG" # not a long
0208 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "1.11-9.99:'GRP'" "OK"  "DOUBLE" # ok for double
0209 
0210 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "-1.11-9.99:'GRP'" "OK"  "DOUBLE" # ok for double
0211 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "-1.11--9.99:'GRP'" "fail"  "DOUBLE" # double minus
0212 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "-1.11-+9.99:'GRP'" "OK"  "DOUBLE" # minus + plus ?
0213 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "-1.11-++9.99:'GRP'" "fail"  "DOUBLE" # invalid double..
0214 
0215 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "9-1:'GRP'" "fail"  "DOUBLE"
0216 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "'AA'-'ZZ':'GRP'" "OK"  "STRING"
0217 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "'ZZ' - 'AA':'GRP'" "fail"  "STRING"
0218 
0219 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "MIN - 'AA':'GRP'" "OK"  "STRING"
0220 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "'ZZZ' - MAX:'GRP'" "OK"  "STRING"
0221 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "'ZZZ' - 'MAX':'GRP'" "fail"  "STRING" # max is smaller than aaa
0222 
0223 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "'ZZZ - 'MAX':'GRP'" "fail"  "STRING" # quotes fails
0224 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "''ZZZ - 'MAX':'GRP'" "fail"  "STRING" #
0225 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "'AAA\'' - 'BBB\'':'GRP'" "OK"  "STRING" #
0226 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "AA:*" "OK"  "STRING" # goes to def group
0227 validate_syntax "ndrxconfig-rtsyn_start.xml" "ndrxconfig-rtsyn_end.xml" "-55:G" "OK"  "LONG" # Single value
0228 
0229 
0230 echo "Limits check"
0231 
0232 validate_invalid "ndrxconfig-toomanysvcs.xml" "Too many entries in service shm" 
0233 validate_invalid "ndrxconfig-toomanyroutes.xml" "Too many routing criterions" 
0234 
0235 echo "---------------------------------------------------------------------"
0236 
0237 # TODO: Test for number of service slots -> must fail on given count reached.
0238 # TODO: Also test some 200 bytes criterion -> shall 
0239 
0240 
0241 # Catch is there is test error!!!
0242 if [ "X`grep TESTERROR *.log`" != "X" ]; then
0243     echo "Test error detected!"
0244     RET=-2
0245 fi
0246 
0247 go_out 0
0248 
0249 # vim: set ts=4 sw=4 et smartindent: