From 0123425cd818c71ea32253ff453dc9998fec31e7 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 13 Apr 2009 20:12:54 +0300 Subject: [PATCH] tests/londiste: new tests --- tests/londiste/ddl.sql | 1 + tests/londiste/init.sh | 14 +++++ tests/londiste/regen.sh | 123 +++++++++++++++++++++++++++++++++++++++ tests/londiste/zcheck.sh | 4 ++ tests/londiste/zstop.sh | 14 +++++ 5 files changed, 156 insertions(+) create mode 100644 tests/londiste/ddl.sql create mode 100755 tests/londiste/init.sh create mode 100755 tests/londiste/regen.sh create mode 100755 tests/londiste/zcheck.sh create mode 100755 tests/londiste/zstop.sh diff --git a/tests/londiste/ddl.sql b/tests/londiste/ddl.sql new file mode 100644 index 00000000..5eb42d5e --- /dev/null +++ b/tests/londiste/ddl.sql @@ -0,0 +1 @@ +alter table mytable add column data2 text; diff --git a/tests/londiste/init.sh b/tests/londiste/init.sh new file mode 100755 index 00000000..b6519723 --- /dev/null +++ b/tests/londiste/init.sh @@ -0,0 +1,14 @@ +#! /bin/sh + +. ../env.sh + +lst="db1 db2 db3 db4" + +for db in $lst; do + echo dropdb $db + dropdb $db +done +for db in $lst; do + echo createdb $db + createdb $db +done diff --git a/tests/londiste/regen.sh b/tests/londiste/regen.sh new file mode 100755 index 00000000..21c7dce8 --- /dev/null +++ b/tests/londiste/regen.sh @@ -0,0 +1,123 @@ +#! /bin/sh + +. ../env.sh + +mkdir -p log pid conf + +./zstop.sh + +v= +v=-v +v=-q + +cleardb() { + echo "Clearing database $1" + psql -q -d $1 -c ' + set client_min_messages=warning; + drop schema if exists londiste cascade; + drop schema if exists pgq_ext cascade; + drop schema if exists pgq_node cascade; + drop schema if exists pgq cascade; + drop table if exists mytable; + drop table if exists footable; + drop sequence if exists footable_id_seq; + ' +} + +run() { + echo "$ $*" + "$@" +} + +msg() { + echo "#" + echo "# $*" + echo "#" +} + +db_list="db1 db2 db3 db4" + +echo " * create configs * " + +# create ticker conf +for db in $db_list; do +cat > conf/ticker_$db.ini << EOF +[pgqadm] +job_name = ticker_$db +db = dbname=$db +logfile = log/%(job_name)s.log +pidfile = pid/%(job_name)s.pid +EOF +done + +# londiste configs +for db in $db_list; do +cat > conf/londiste_$db.ini << EOF +[londiste] +job_name = londiste_$db +db = dbname=$db +queue_name = replika +logfile = log/%(job_name)s.log +pidfile = pid/%(job_name)s.pid +EOF +done + +for db in $db_list; do + cleardb $db +done + +echo "clean logs" +rm -f log/*.log + +set -e + +msg "Install PgQ and run ticker on each db" +for db in $db_list; do + run pgqadm $v conf/ticker_$db.ini install + run pgqadm $v -d conf/ticker_$db.ini ticker +done + +msg "Install Londiste and initialize nodes" +run londiste $v conf/londiste_db1.ini create-root node1 'dbname=db1' +run londiste $v conf/londiste_db2.ini create-branch node2 'dbname=db2' --provider='dbname=db1' +run londiste $v conf/londiste_db3.ini create-branch node3 'dbname=db3' --provider='dbname=db1' +run londiste $v conf/londiste_db4.ini create-leaf node4 'dbname=db4' --provider='dbname=db2' + +msg "See topology" +run londiste $v conf/londiste_db4.ini status + +msg "Run Londiste daemon for each node" +for db in $db_list; do + run londiste $v -d conf/londiste_$db.ini replay +done + +msg "Create table on root node and fill couple of rows" +run psql -d db1 -c "create table mytable (id int4 primary key, data text)" +for n in 1 2 3 4; do + run psql -d db1 -c "insert into mytable values ($n, 'row$n')" +done + +msg "Register table on root node" +run londiste $v conf/londiste_db1.ini add-table mytable + +msg "Register table on other node with creation" +for db in db2 db3 db4; do + run londiste $v conf/londiste_$db.ini add-table mytable --create +done + +msg "Add column on root" +run cat ddl.sql +run londiste $v conf/londiste_db1.ini execute ddl.sql + +msg "Insert data into new column" +for n in 5 6 7 8; do + run psql -d db1 -c "insert into mytable values ($n, 'row$n', 'data2')" +done +msg "Wait a bit" +run sleep 20 + +run psql -d db3 -c '\d mytable' +run psql -d db3 -c 'select * from mytable' + +./zcheck.sh + diff --git a/tests/londiste/zcheck.sh b/tests/londiste/zcheck.sh new file mode 100755 index 00000000..96f59aed --- /dev/null +++ b/tests/londiste/zcheck.sh @@ -0,0 +1,4 @@ +#! /bin/sh + +grep -E 'ERR|WARN|CRIT' log/*.log || echo "All OK" + diff --git a/tests/londiste/zstop.sh b/tests/londiste/zstop.sh new file mode 100755 index 00000000..69e574cb --- /dev/null +++ b/tests/londiste/zstop.sh @@ -0,0 +1,14 @@ +#! /bin/sh + +#. ../env.sh + +for p in pid/*.pid*; do + test -f "$p" || continue + pid=`cat "$p"` + test -d "/proc/$pid" || { + rm -f "$p" + continue + } + kill "$pid" +done + -- 2.39.5