Various tests for developers
authorGreg Sabino Mullane <greg@endpoint.com>
Sat, 30 Nov 2013 16:42:15 +0000 (11:42 -0500)
committerGreg Sabino Mullane <greg@endpoint.com>
Sat, 30 Nov 2013 16:42:15 +0000 (11:42 -0500)
dev/conflict.test [new file with mode: 0755]
dev/makedelta.test [moved from makedelta.test with 100% similarity]
dev/multidb.test [new file with mode: 0755]

diff --git a/dev/conflict.test b/dev/conflict.test
new file mode 100755 (executable)
index 0000000..045a92c
--- /dev/null
@@ -0,0 +1,181 @@
+##!/bin/bash
+
+## A quick self-containted test of the conflict system
+## Not a replacement for the real tests so much as a development aid
+
+## Uses:
+## Four databases, A, B, C, and D (aka ctest1 ctest2 ctest3 ctest4)
+## Three table: alpha, beta, charlie
+## Two syncs: AB A <=> B and BC (B <=> C) -> D
+## For safety, this runs on port 5492.
+## Do not change it to 5432, as this drops the bucardo database! :)
+## This must be run from the root Bucardo source code directory
+
+export PGPORT=5492
+
+## Ensure we use the Bucardo.pm in the current directory
+export PERL5LIB=.
+
+## Quick check that our scripts compile cleanly
+perl -c bucardo || exit
+perl -c Bucardo.pm || exit
+
+## Just in case, stop any running Bucardos
+./bucardo stop --quiet 2>/dev/null
+
+## Bail if the cluster is not reachable
+psql -q -c 'select 1' >/dev/null 2>/dev/null
+
+if [[ $? -ne 0 ]];then
+  echo Could not connect to Postgres on port $PGPORT
+  exit
+fi
+
+## Terminate any old connections, and drop databases
+echo Dropping existing test databases
+psql -AX -qt -c "select pg_terminate_backend(pid) FROM pg_stat_activity where datname IN ('ctest1','ctest2','ctest3','ctest4','bucardo')" >/dev/null
+psql -qc 'drop database ctest1' 2>/dev/null
+psql -qc 'drop database ctest2' 2>/dev/null
+psql -qc 'drop database ctest3' 2>/dev/null
+psql -qc 'drop database ctest4' 2>/dev/null
+psql -qc 'drop database bucardo' 2>/dev/null
+
+echo Creating test databases
+psql -qc 'create database ctest1'
+psql ctest1 -qc 'create sequence mseq increment by 3 start with 1'
+psql ctest1 -qc "create table alpha(id int not null default nextval('mseq'), email text)"
+psql ctest1 -qc "create unique index alpha_unique on alpha(id)"
+psql ctest1 -qc 'create table beta(id serial primary key, fk1 int references alpha(id))'
+psql ctest1 -qc 'create table charlie(id serial primary key, fk1 int references alpha(id))'
+
+psql -qc 'create database ctest2 template ctest1'
+psql ctest2 -qc 'alter sequence mseq restart with 2'
+
+psql -qc 'create database ctest3 template ctest1'
+psql ctest3 -qc 'alter sequence mseq restart with 3'
+
+psql -qc 'create database ctest4 template ctest1'
+
+echo Installing Bucardo
+./bucardo install --batch --quiet
+./bucardo set log_level=debug --quiet
+
+echo Adding databases A B C D
+./bucardo add db A dbname=ctest1 --quiet
+./bucardo add db B dbname=ctest2 --quiet
+./bucardo add db C dbname=ctest3 --quiet
+./bucardo add db D dbname=ctest4 --quiet
+echo Adding table, relgroup, and syncs
+./bucardo add table alpha beta relgroup=mgroup --quiet
+./bucardo add sync AB relgroup=mgroup dbs=A:source,B:source autokick=false --quiet isolation_level=repeatable_read
+./bucardo add sync BC relgroup=mgroup dbs=B:source,C:source,D:target --quiet
+
+echo Starting Bucardo
+rm -f log.bucardo
+./bucardo start --logdest=. --quiet
+sleep 2
+
+echo Creating a conflict that will violate FKs if left to itself
+psql -AX -qt ctest1 -c "insert into alpha(id,email) values (1,'alice'),(2,'bob')"
+psql -AX -qt ctest1 -c "insert into beta(fk1) values (1)"
+echo Table beta references alpha.id 1
+
+echo Kicking sync AB
+./bucardo kick AB 0
+
+./bucardo stop
+exit
+
+
+echo On A, switching beta to reference alpha.id 2
+psql -AX -qt ctest1 -c "update beta set fk1 = 2"
+echo On B, deleting alpha.id 2
+psql -AX -qt ctest2 -c "delete from alpha where id = 2"
+
+echo Kicking sync AB
+./bucardo kick AB 0
+
+psql -A -t ctest1 -c "select 'A.alpha.id:', id from alpha"
+psql -A -t ctest1 -c "select 'A.beta.id|fk1:', id,fk1 from beta"
+psql -A -t ctest2 -c "select 'B.alpha.id:', id from alpha"
+psql -A -t ctest2 -c "select 'B.beta.id|fk1:', id,fk1 from beta"
+
+
+exit
+
+echo Makedelta is off, so row \"alice\" added to A will not make it to C
+sleep 2
+
+psql -A -t ctest2 -c "select 'B:', * from alpha"
+psql -A -t ctest3 -c "select 'C:', * from alpha"
+psql -A -t ctest4 -c "select 'D:', * from alpha"
+
+./bucardo update table alpha makedelta=B
+
+./bucardo stop --quiet
+sleep 2
+
+psql ctest1 -U bucardo -c "select * from delta_public_alpha"
+psql ctest1 -U bucardo -c "select * from stage_public_alpha"
+psql ctest1 -U bucardo -c "select * from track_public_alpha"
+psql ctest1 -U bucardo -c "select * from bucardo_delta_targets"
+
+
+exit
+
+
+./bucardo start --logdest=. --quiet
+
+echo Makedelta is on for B, so row \"bob\" added to A will make it to C
+psql -AX -qt ctest1 -c "insert into alpha(email) values ('bob')"
+sleep 3
+
+psql -At ctest1 -c "select 'A:', * from alpha"
+psql -At ctest2 -c "select 'B:', * from alpha"
+psql -At ctest3 -c "select 'C:', * from alpha"
+psql -At ctest4 -c "select 'D:', * from alpha"
+
+./bucardo update table alpha set makedelta=A
+./bucardo message Changed makedelta
+./bucardo reload sync AB
+
+echo Makedelta is on for A only, so row \"bob\" deleted from A will not make it to C
+psql -AX -qt ctest1 -c "delete from alpha where email = 'bob'"
+sleep 3
+
+psql -At ctest1 -c "select 'A:', * from alpha"
+psql -At ctest2 -c "select 'B:', * from alpha"
+psql -At ctest3 -c "select 'C:', * from alpha"
+psql -At ctest4 -c "select 'D:', * from alpha"
+
+./bucardo update table alpha set makedelta=on
+./bucardo message Changed makedelta
+./bucardo reload sync AB
+
+echo Makedelta is on for everyone, so row \"mallory\" to A will not make it to B,C,D
+psql -AX -qt ctest1 -c "insert into alpha(email) values ('mallory')"
+sleep 3
+
+psql -At ctest1 -c "select 'A:', * from alpha"
+psql -At ctest2 -c "select 'B:', * from alpha"
+psql -At ctest3 -c "select 'C:', * from alpha"
+psql -At ctest4 -c "select 'D:', * from alpha"
+
+./bucardo update table alpha set makedelta=off
+./bucardo message Changed makedelta
+./bucardo reload sync AB
+
+echo Makedelta is off for everyone, so row \"mallory\" removed from A will stay on C
+psql -AX -qt ctest1 -c "delete from alpha where email = 'mallory'"
+sleep 3
+
+psql -At ctest1 -c "select 'A:', * from alpha"
+psql -At ctest2 -c "select 'B:', * from alpha"
+psql -At ctest3 -c "select 'C:', * from alpha"
+psql -At ctest4 -c "select 'D:', * from alpha"
+
+
+echo Stopping Bucardo
+./bucardo stop
+
+
similarity index 100%
rename from makedelta.test
rename to dev/makedelta.test
diff --git a/dev/multidb.test b/dev/multidb.test
new file mode 100755 (executable)
index 0000000..5d98d02
--- /dev/null
@@ -0,0 +1,196 @@
+##!/bin/bash
+
+## A quick self-contained test of the makedelta system
+## With multiple databases!
+## Not a replacement for the real tests so much as a development aid
+
+## Uses:
+## Four databases, A, B, C, and D (aka mtest1 mtest2 mtest3 mtest4)
+## One table: foobar
+## Two syncs: AB A <=> B and BC (B <=> C) -> D
+## For safety, this runs on port 5492.
+## Do not change it to 5432, as this drops the bucardo database! :)
+## This must be run from the root Bucardo source code directory
+
+export PGPORT=5492
+
+## Ensure we use the Bucardo.pm in the current directory
+export PERL5LIB=.
+
+## Quick check that our scripts compile cleanly
+perl -c bucardo || exit
+perl -c Bucardo.pm || exit
+
+## Just in case, stop any running Bucardos
+./bucardo stop --quiet 2>/dev/null
+
+## Bail if the cluster is not reachable
+psql -q -c 'select 1' >/dev/null 2>/dev/null
+
+if [[ $? -ne 0 ]];then
+  echo Could not connect to Postgres on port $PGPORT
+  echo Tried: psql -q -c 'select 1'
+  exit
+fi
+
+## Terminate any old connections, and drop databases
+echo Dropping existing test databases
+psql -AX -qt -c "select pg_terminate_backend(pid) FROM pg_stat_activity where datname IN ('mtest1','mtest2','mtest3','mtest4','bucardo')" >/dev/null
+psql -qc 'drop database mtest1' 2>/dev/null
+psql -qc 'drop database mtest2' 2>/dev/null
+psql -qc 'drop database mtest3' 2>/dev/null
+psql -qc 'drop database mtest4' 2>/dev/null
+psql -qc 'drop database bucardo' 2>/dev/null
+
+echo Creating test databases
+psql -qc 'create database mtest1'
+
+## Create tables foobar and foobar2. The latter will be removed from certain dbs
+psql mtest1 -qc 'create sequence mseq increment by 3 start with 1'
+psql mtest1 -qc "create table foobar(id int not null default nextval('mseq'), email text)"
+psql mtest1 -qc "create unique index foobar_unique on foobar(id)"
+psql mtest1 -qc 'create sequence mseq2 increment by 3 start with 1'
+psql mtest1 -qc "create table foobar2(id int not null default nextval('mseq2'), email text)"
+psql mtest1 -qc "create unique index foobar_unique2 on foobar2(id)"
+
+psql -qc 'create database mtest2 template mtest1'
+psql mtest2 -qc 'alter sequence mseq restart with 2'
+
+psql -qc 'create database mtest3 template mtest1'
+psql mtest3 -qc 'alter sequence mseq restart with 3'
+
+psql -qc 'create database mtest4 template mtest1'
+
+## Remove foobar from C and D
+#psql mtest3 -qc 'drop table foobar cascade'
+#psql mtest4 -qc 'drop table foobar cascade'
+
+## Now remove foobar2 from A and B
+psql mtest1 -qc 'drop table foobar2 cascade'
+psql mtest2 -qc 'drop table foobar2 cascade'
+
+echo Installing Bucardo
+./bucardo install --batch --quiet >/tmp/foobar
+if [[ $? -ne 0 ]];then
+  echo Failed to install Bucardo
+  exit
+fi
+
+./bucardo set log_level=debug --quiet
+
+./bucardo add db source_sg dbname=mtest1 --quiet
+./bucardo add db target_sg dbname=mtest2 --quiet
+./bucardo add table foobar relgroup=sgherd --quiet
+./bucardo add dbgroup sggroup source_sg:source target_sg:target
+./bucardo add sync sg_sync herd=sgherd dbs=sggroup
+
+./bucardo add db source_lg dbname=mtest3 --quiet
+./bucardo add db target_lg dbname=mtest4 --quiet
+./bucardo add table foobar2 relgroup=lgherd db=source_lg 
+./bucardo add dbgroup lggroup source_lg:source target_lg:target
+./bucardo add sync lg_sync herd=lgherd dbs=lggroup
+
+rm -f log.bucardo
+./bucardo start --logdest=.  --no-exit-on-nosync
+sleep 2
+
+./bucardo activate sync sg_sync
+./bucardo activate sync lg_sync
+
+./bucardo stop 
+sleep 2
+
+echo Restarting
+./bucardo start --logdest=.  --no-exit-on-nosync
+sleep 3
+./bucardo stop 
+sleep 2
+
+exit
+
+
+
+
+## Make a simple sync for table foobar2 going from B to C
+./bucardo add table foobar2 relgroup=mgroup2 db=B
+./bucardo add sync BC relgroup=mgroup2 dbs=C:source,B:source --quiet
+
+echo Starting Bucardo
+rm -f log.bucardo
+./bucardo start --logdest=. --quiet
+sleep 4
+
+./bucardo stop --quiet
+sleep 2
+./bucardo start --logdest=. --quiet
+sleep 4
+
+exit
+
+echo Makedelta is off, so row \"alice\" added to A will not make it to C
+psql -AX -qt mtest1 -c "insert into foobar(email) values ('alice')"
+sleep 2
+
+psql -A -t mtest1 -c "select 'A:', * from foobar"
+psql -A -t mtest2 -c "select 'B:', * from foobar"
+psql -A -t mtest3 -c "select 'C:', * from foobar"
+psql -A -t mtest4 -c "select 'D:', * from foobar"
+
+./bucardo update table foobar makedelta=B
+
+./bucardo stop --quiet
+sleep 2
+./bucardo start --logdest=. --quiet
+
+echo Makedelta is on for B, so row \"bob\" added to A will make it to C
+psql -AX -qt mtest1 -c "insert into foobar(email) values ('bob')"
+sleep 3
+
+psql -At mtest1 -c "select 'A:', * from foobar"
+psql -At mtest2 -c "select 'B:', * from foobar"
+psql -At mtest3 -c "select 'C:', * from foobar"
+psql -At mtest4 -c "select 'D:', * from foobar"
+
+./bucardo update table foobar set makedelta=A
+./bucardo message Changed makedelta
+./bucardo reload sync AB
+
+echo Makedelta is on for A only, so row \"bob\" deleted from A will not make it to C
+psql -AX -qt mtest1 -c "delete from foobar where email = 'bob'"
+sleep 3
+
+psql -At mtest1 -c "select 'A:', * from foobar"
+psql -At mtest2 -c "select 'B:', * from foobar"
+psql -At mtest3 -c "select 'C:', * from foobar"
+psql -At mtest4 -c "select 'D:', * from foobar"
+
+./bucardo update table foobar set makedelta=on
+./bucardo message Changed makedelta
+./bucardo reload sync AB
+
+echo Makedelta is on for everyone, so row \"mallory\" to A will not make it to B,C,D
+psql -AX -qt mtest1 -c "insert into foobar(email) values ('mallory')"
+sleep 3
+
+psql -At mtest1 -c "select 'A:', * from foobar"
+psql -At mtest2 -c "select 'B:', * from foobar"
+psql -At mtest3 -c "select 'C:', * from foobar"
+psql -At mtest4 -c "select 'D:', * from foobar"
+
+./bucardo update table foobar set makedelta=off
+./bucardo message Changed makedelta
+./bucardo reload sync AB
+
+echo Makedelta is off for everyone, so row \"mallory\" removed from A will stay on C
+psql -AX -qt mtest1 -c "delete from foobar where email = 'mallory'"
+sleep 3
+
+psql -At mtest1 -c "select 'A:', * from foobar"
+psql -At mtest2 -c "select 'B:', * from foobar"
+psql -At mtest3 -c "select 'C:', * from foobar"
+psql -At mtest4 -c "select 'D:', * from foobar"
+
+
+echo Stopping Bucardo
+./bucardo stop --quiet
+