-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupandtest.sh
More file actions
147 lines (111 loc) · 4.3 KB
/
setupandtest.sh
File metadata and controls
147 lines (111 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
#run all unit tests on linux, you can do each steps individually on other OSes
echo "setupandtest.sh with args: $*"
echo "setupandtest.sh: we are assuming postgres and mysql are local, and that binlog has been enabled in my.cnf and mysql has been restarted"
# origArgs=$*
postgresport=5432
if ! options=$(getopt -u -o r:d -l mysqlrootpass:,postgresport:,postgresuser:,postgrespass: -- "$@")
then
# something went wrong, getopt will put out an error message for us
exit 1
fi
set -- $options
while [ $# -gt 0 ]
do
case $1 in
# for options with required arguments, an additional shift is required
-r|--mysqlrootpass ) mysqlrootpass=$2; shift;;
-p|--postgresport ) postgresport=$2; shift;;
-U|--postgresuser ) postgresuser=$2; shift;;
-P|--postgrespass ) postgrespass=$2; shift;;
#-d|--ctScriptPath ) ctScriptPath=$2; shift;;
#(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
args="$*"
# make sure our deamon is not running
pkill -f 'node rosettable'
while [ $? -eq 0 ]; do
echo "deamon was running: wait for it to be dead"
sleep 1;
pkill -f 'node rosettable'
done
sleep 1;
#ifnot download
if [ -z "$mysqlrootpass" ]; then
echo "the mysql root pass is required to create the test database";
exit 1;
fi
echo 'SETUP:creating our test database in mysql'
mysqlargs="-u root -p$mysqlrootpass";
mysql $mysqlargs < setuptest_mysql_create_test_schema.sql
echo 'SETUP:creating our test database in postgres, our test user, our mapping and some triggers'
# this assumes we are running this script as root
#su postgres -c "psql -p 5433 -f setuptest_pg_import_fdw_create_triggers.sql"
#if that is not an option replace by where supuser has superuser rights
PGPASSWORD=$postgrespass psql -h localhost -p $postgresport -U $postgresuser -f setuptest_pg_import_fdw_create_triggers.sql
#start our binlog watching node process
node rosettable.js > watcher1.log & triggerwatcherpid=$!
echo "STARTED OUR WATCHING DEAMON: triggerwatcherpid: $triggerwatcherpid"
# lets wait 2 seconds for it to be ready
sleep 2
echo 'run mysql test'
mysql $mysqlargs < runtests_mysql.sql
echo 'run pg tests'
PGPASSWORD=this_1s_fdw_us3r psql -h localhost -p $postgresport -U fdw_user -d testdb_pg -f runtests_pg.sql > testres_mysql_then_pg.out
if [ ! -f testexp_mysql_then_pg ]; then
echo 'ERROR: missing testexp_mysql_then_pg cannot validate tests';
exit 1;
fi
testres=$(diff testres_mysql_then_pg.out testexp_mysql_then_pg );
if [ "$testres" != "" ]; then
echo "AT LEAST ONE PG TEST FAIED!"
sleep 1
kill "$triggerwatcherpid"
echo "$testres"
exit 1;
else
echo "All mysql then pg tests succeded"
fi
echo "now run with first edit in PG"
sleep 1
kill "$triggerwatcherpid"
sleep 2
echo 'SETUP:creating our test database in mysql'
mysqlargs="-u root -p$mysqlrootpass";
mysql $mysqlargs < setuptest_mysql_create_test_schema.sql
echo 'SETUP:creating our test database in postgres, our test user, our mapping and some triggers'
# this assumes we are running this script as root
#su postgres -c "psql -p 5433 -f setuptest_pg_import_fdw_create_triggers.sql"
#if that is not an option replace by where supuser has superuser rights
PGPASSWORD=$postgrespass psql -h localhost -p $postgresport -U $postgresuser -f setuptest_pg_import_fdw_create_triggers.sql
#start our binlog watching node process
node rosettable.js > watcher2.log & triggerwatcherpid=$!
echo "STARTED OUR WATCHING DEAMON: triggerwatcherpid: $triggerwatcherpid"
# lets wait 2 seconds for it to be ready
sleep 2
echo 'run pg tests'
PGPASSWORD=this_1s_fdw_us3r psql -h localhost -p $postgresport -U fdw_user -d testdb_pg -f runtests_pg.sql
echo 'run mysql test'
mysql $mysqlargs < runtests_mysql.sql
PGPASSWORD=this_1s_fdw_us3r psql -h localhost -p $postgresport -U fdw_user -d testdb_pg -c 'select emp_id,emp_name,emp_dept_id,trigg_count from fs_mqltestdb.employee;' > testres_pg_then_mysql.out
if [ ! -f testexp_pg_then_mysql ]; then
echo 'ERROR: missing testexp_pg_then_mysql cannot validate tests';
exit 1;
fi
testres=$(diff testres_pg_then_mysql.out testexp_pg_then_mysql );
if [ "$testres" != "" ]; then
echo "AT LEAST ONE PG TEST FAIED!"
echo "$testres"
sleep 1
kill "$triggerwatcherpid"
exit 1;
else
echo "All mysql then pg tests succeded"
fi
cat testres_pg_then_mysql.out
echo "ALL TESTS PASSED"
sleep 1
kill "$triggerwatcherpid"