tests/londiste: new tests
authorMarko Kreen <markokr@gmail.com>
Mon, 13 Apr 2009 17:12:54 +0000 (20:12 +0300)
committerMarko Kreen <markokr@gmail.com>
Mon, 13 Apr 2009 17:12:54 +0000 (20:12 +0300)
tests/londiste/ddl.sql [new file with mode: 0644]
tests/londiste/init.sh [new file with mode: 0755]
tests/londiste/regen.sh [new file with mode: 0755]
tests/londiste/zcheck.sh [new file with mode: 0755]
tests/londiste/zstop.sh [new file with mode: 0755]

diff --git a/tests/londiste/ddl.sql b/tests/londiste/ddl.sql
new file mode 100644 (file)
index 0000000..5eb42d5
--- /dev/null
@@ -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 (executable)
index 0000000..b651972
--- /dev/null
@@ -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 (executable)
index 0000000..21c7dce
--- /dev/null
@@ -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 (executable)
index 0000000..96f59ae
--- /dev/null
@@ -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 (executable)
index 0000000..69e574c
--- /dev/null
@@ -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
+