From df029263212cc3b502284b8acfdae0ba4139552d Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Tue, 25 Mar 2014 23:19:24 +0200 Subject: [PATCH] Added structure which can be cloned for multiple test cases. --- .../routing/readwritesplit/test/makefile | 6 +++--- .../routing/readwritesplit/test/rwsplit.sh | 20 ++++++++++-------- .../test/test_transaction_routing1.sql | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 server/modules/routing/readwritesplit/test/test_transaction_routing1.sql diff --git a/server/modules/routing/readwritesplit/test/makefile b/server/modules/routing/readwritesplit/test/makefile index 92374c5cb..5ef294021 100644 --- a/server/modules/routing/readwritesplit/test/makefile +++ b/server/modules/routing/readwritesplit/test/makefile @@ -3,8 +3,8 @@ # runtests - run all local tests # testall - clean, build and run local and subdirectories' tests -include ../../../../build_gateway.inc -include ../../../../makefile.inc +include ../../../../../build_gateway.inc +include ../../../../../makefile.inc CC=cc TESTLOG := $(shell pwd)/testrouters.log @@ -28,7 +28,7 @@ runtests: @echo "Test MaxScale R/W Split" >> $(TESTLOG) @echo "-------------------------------" >> $(TESTLOG) -ifeq ($(shell ./rwsplit.sh; echo $$?), 0) +ifeq ($(shell ./rwsplit.sh $(TESTLOG) 127.0.0.1 4006 maxuser maxpwd ; echo $$?), 0) @echo "MaxScale core PASSED" >> $(TESTLOG) else @echo "MaxScale core FAILED" >> $(TESTLOG) ; exit 1 diff --git a/server/modules/routing/readwritesplit/test/rwsplit.sh b/server/modules/routing/readwritesplit/test/rwsplit.sh index 8a6eba356..dd41f1962 100755 --- a/server/modules/routing/readwritesplit/test/rwsplit.sh +++ b/server/modules/routing/readwritesplit/test/rwsplit.sh @@ -1,12 +1,14 @@ -#! /bin/sh +#!/bin/sh +TLOG=$1 +THOST=$2 +TPORT=$3 +TUSER=$4 +TPWD=$5 +RUNCMD=mysql\ --host=$THOST\ -P$TPORT\ -u$TUSER\ -p$TPWD\ --unbuffered=true\ --disable-reconnect\ --silent +INPUT=test_transaction_routing1.sql -a=`mysql --host=127.0.0.1 -P 4606 -umassi -pmassi --unbuffered=true --disable-reconnect --silent < ./transaction_with_set.sql` -#a=`mysql --host=107.170.19.59 -P 4606 -uvai -pvai --unbuffered=true --disable-reconnect --silent < ./transaction_with_set.sql` - -if [ "$a" -eq 2 ]; then - exit 0 -else - exit 1 -fi +a=`$RUNCMD < ./$INPUT` +if [ "$a" != "2" ]; then echo "$INPUT FAILED">>$TLOG; exit 1 ; +else echo "$INPUT 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 new file mode 100644 index 000000000..252008cc3 --- /dev/null +++ b/server/modules/routing/readwritesplit/test/test_transaction_routing1.sql @@ -0,0 +1,21 @@ +USE test; +SET autocommit = 0; +SET @a= -1; +SET @b = -2; +START TRANSACTION; +CREATE TABLE IF NOT EXISTS myCity (a int, b char(20)); +INSERT INTO myCity VALUES (1, 'Milan'); +INSERT INTO myCity VALUES (2, 'London'); +COMMIT; +-- Now there are two values +START TRANSACTION; +DELETE FROM myCity; +-- Now there are zero values +SET @a = (SELECT COUNT(1) FROM myCity); -- implicit COMMIT for DELETE operation +ROLLBACK; -- nothing to roll back +START TRANSACTION; +SET @b = (SELECT COUNT(*) FROM myCity); -- implicit COMMIT for empty trx +START TRANSACTION; +DROP TABLE myCity; +SELECT (@a+@b) AS res; -- counts 0+0 ans sets the result to 'res' +COMMIT;