diff --git a/server/modules/routing/readwritesplit/test/makefile b/server/modules/routing/readwritesplit/test/makefile index 2a5323dfc..daea0059b 100644 --- a/server/modules/routing/readwritesplit/test/makefile +++ b/server/modules/routing/readwritesplit/test/makefile @@ -4,7 +4,8 @@ # testall - clean, build and run local and subdirectories' tests include ../../../../../build_gateway.inc -include ../../../../../makefile.inc +include $(ROOT_PATH)/makefile.inc +include $(ROOT_PATH)/test.inc CC=cc TESTLOG := $(shell pwd)/testrouters.log @@ -29,9 +30,7 @@ runtests: @echo $(shell date) >> $(TESTLOG) @echo "Test MaxScale R/W Split" >> $(TESTLOG) @echo "-------------------------------" >> $(TESTLOG) - ./rwsplit.sh $(TESTLOG) test_transaction_routing1.sql 127.0.0.1 4006 maxuser maxpwd - ./rwsplit.sh $(TESTLOG) test_transaction_routing2.sql 127.0.0.1 4006 maxuser maxpwd - ./rwsplit.sh $(TESTLOG) test_transaction_routing3.sql 127.0.0.1 4006 maxuser maxpwd + ./rwsplit.sh $(TESTLOG) $(THOST) $(TPORT_RW) $(TUSER) $(TPWD) @echo "" >> $(TESTLOG) diff --git a/server/modules/routing/readwritesplit/test/rwsplit.sh b/server/modules/routing/readwritesplit/test/rwsplit.sh index 7e9c77ee5..3481b6497 100755 --- a/server/modules/routing/readwritesplit/test/rwsplit.sh +++ b/server/modules/routing/readwritesplit/test/rwsplit.sh @@ -1,11 +1,10 @@ #!/bin/sh -NARGS=6 +NARGS=5 TLOG=$1 -TINPUT=$2 -THOST=$3 -TPORT=$4 -TUSER=$5 -TPWD=$6 +THOST=$2 +TPORT=$3 +TUSER=$4 +TPWD=$5 if [ $# != $NARGS ] ; then @@ -13,7 +12,7 @@ echo"" echo "Wrong number of arguments, gave "$#" but "$NARGS" is required" echo "" echo "Usage :" -echo " rwsplit.sh " +echo " rwsplit.sh " echo "" exit 1 fi @@ -21,10 +20,29 @@ fi RUNCMD=mysql\ --host=$THOST\ -P$TPORT\ -u$TUSER\ -p$TPWD\ --unbuffered=true\ --disable-reconnect\ --silent +TINPUT=test_transaction_routing1.sql +TRETVAL=2 a=`$RUNCMD < ./$TINPUT` -if [ "$a" != "2" ]; then - echo "$TINPUT FAILED">>$TLOG; +if [ "$a" != "$TRETVAL" ]; then + echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; else echo "$TINPUT PASSED">>$TLOG ; fi +TINPUT=test_transaction_routing2.sql +TRETVAL=foo +a=`$RUNCMD < ./$TINPUT` +if [ "$a" != "$TRETVAL" ]; then + echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; +else + echo "$TINPUT PASSED">>$TLOG ; +fi + +TINPUT=test_transaction_routing3.sql +TRETVAL=bar +a=`$RUNCMD < ./$TINPUT` +if [ "$a" != "$TRETVAL" ]; then + echo "$TINPUT FAILED, return value $a when $TRETVAL was expected">>$TLOG; +else + echo "$TINPUT PASSED">>$TLOG ; +fi diff --git a/server/modules/routing/readwritesplit/test/test_transaction_routing1.sql b/server/modules/routing/readwritesplit/test/test_transaction_routing1.sql index a6ef719c5..af17eb3d5 100644 --- a/server/modules/routing/readwritesplit/test/test_transaction_routing1.sql +++ b/server/modules/routing/readwritesplit/test/test_transaction_routing1.sql @@ -1,7 +1,7 @@ USE test; SET autocommit = 0; SET @a= -1; -SET @b = -2; +SET @b= -2; START TRANSACTION; CREATE TABLE IF NOT EXISTS myCity (a int, b char(20)); INSERT INTO myCity VALUES (1, 'Milan'); @@ -9,7 +9,7 @@ INSERT INTO myCity VALUES (2, 'London'); COMMIT; START TRANSACTION; DELETE FROM myCity; -SET @a = (SELECT COUNT(1) FROM myCity); +SET @a = (SELECT COUNT(*) FROM myCity); ROLLBACK; START TRANSACTION; SET @b = (SELECT COUNT(*) FROM myCity); diff --git a/server/modules/routing/readwritesplit/test/test_transaction_routing2.sql b/server/modules/routing/readwritesplit/test/test_transaction_routing2.sql index 1c69e58f3..2f753e72b 100644 --- a/server/modules/routing/readwritesplit/test/test_transaction_routing2.sql +++ b/server/modules/routing/readwritesplit/test/test_transaction_routing2.sql @@ -1,7 +1,3 @@ -SET autocommit = 1; -SELECT @@server_id INTO @a; -START TRANSACTION; -SELECT @@server_id INTO @b; -COMMIT; -SELECT (@a-@b) INTO @c; -SELECT @a, @b, @c; \ No newline at end of file +SET autocommit = 0; +SELECT @@in_transaction INTO @a; +SELECT @a; \ No newline at end of file diff --git a/test.inc b/test.inc new file mode 100644 index 000000000..ea1ec8019 --- /dev/null +++ b/test.inc @@ -0,0 +1,10 @@ +# +# This file includes parameters needed for running tests and may be included +# in makefiles in test directories if seen useful. +# + +THOST := 127.0.0.1 +TPORT_RCONN := 4008 +TPORT_RW := 4006 +TUSER := maxuser +TPWD := maxpwd