summaryrefslogtreecommitdiff
path: root/src/test/extended-query-test/test.sh
blob: 3f7cfea39b78e595a15076897432ec99a9cdd06e (plain)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/usr/bin/env bash

dir=`pwd`
MODE=install
PG_INSTALL_DIR=/usr/local/pgsql/bin
PGPOOL_PATH=/usr/local
JDBC_DRIVER=/usr/local/pgsql/share/postgresql-9.2-1003.jdbc4.jar
export log=$dir/log
PGSOCKET_DIR=/tmp

timeout=30
export PGPORT=11000
export PGHOST=127.0.0.1
export PGDATABASE=test
#export PGPOOL_INSTALL_DIR=$HOME/work/pgpool-II/current
#export PGPOOLDEBUG=true
PGPROTO=/usr/local/bin/pgproto

testdir=$dir/tests
expected=$dir/expected
extra_scripts=$dir/extra_scripts
export PGPOOLLOG=$dir/testdata/log/pgpool.log
results=$dir/results

function install_pgpool
{
    echo "creating pgpool-II temporary installation ..."
    PGPOOL_PATH=$dir/temp/installed

    test -d $log || mkdir $log

    make install -C $dir/../../ -e prefix=${PGPOOL_PATH} >& regression.log 2>&1

    if [ $? != 0 ];then
	echo "make install failed"
	exit 1
    fi
    
    echo "moving pgpool_setup to temporary installation path ..."
    cp $dir/../pgpool_setup ${PGPOOL_PATH}/pgpool_setup
    export PGPOOL_SETUP=$PGPOOL_PATH/pgpool_setup
}

function verify_pginstallation
{
    # PostgreSQL bin directory
    PGBIN=`$PG_INSTALL_DIR/pg_config --bindir`
    if [ -z $PGBIN ]; then
	echo "$0: cannot locate pg_config"
	exit 1
    fi
}

function export_env_vars
{
    if [[ -z "$PGPOOL_PATH" ]]; then
	# check if pgpool is in the path
	PGPOOL_PATH=/usr/local
	export PGPOOL_SETUP=$HOME/bin/pgpool_setup
    fi

    if [[ -z "$PGBENCH_PATH" ]]; then
	if [ -x $PGBIN/pgbench ]; then
	    PGBENCH_PATH=$PGBIN/pgbench
	else
	    PGBENCH_PATH=`which pgbench`
	fi
    fi

    if [ ! -x $PGBENCH_PATH ]; then
	echo "$0] cannot locate pgbench"; exit 1
    fi

    echo "using pgpool-II at "$PGPOOL_PATH
    export PGPOOL_INSTALL_DIR=$PGPOOL_PATH

    PGPOOLLIB=${PGPOOL_INSTALL_DIR}/lib
    if [ -z "$LD_LIBRARY_PATH" ];then
	export LD_LIBRARY_PATH=$PGPOOLLIB
    else
	export LD_LIBRARY_PATH=${PGPOOLLIB}:${LD_LIBRARY_PATH}
    fi

    export TESTLIBS=$dir/libs.sh
    export PGBIN=$PGBIN
    export JDBC_DRIVER=$JDBC_DRIVER
    export PGBENCH_PATH=$PGBENCH_PATH
    export PGSOCKET_DIR=$PGSOCKET_DIR
}

function print_info
{
    echo ${CBLUE}"*************************"${CNORM}

    echo "REGRESSION MODE : "${CBLUE}$MODE${CNORM}
    echo "PGPOOL-II       : "${CBLUE}$PGPOOL_PATH${CNORM}
    echo "PostgreSQL bin  : "${CBLUE}$PGBIN${CNORM}
    echo "pgbench         : "${CBLUE}$PGBENCH_PATH${CNORM}
    echo "PostgreSQL jdbc : "${CBLUE}$JDBC_DRIVER${CNORM}
    echo ${CBLUE}"*************************"${CNORM}
}

install_pgpool
verify_pginstallation
export_env_vars
print_info

okcnt=0
failcnt=0
timeoutcnt=0

# Selecting load balancing node per session or per statement
lb_level=(session statement)
specified_tests=$1
for lb in ${lb_level[@]}
do
    cd $dir
    rm -f $results/*
    test ! -d $results && mkdir $results

    diffs=$dir/diffs
    rm -f $diffs

    if [ $# -gt 0 ];then
	tests=`(cd tests;ls |grep $specified_tests)`
    else
	tests=`(cd tests;ls)`
    fi
    rm -fr testdata
    mkdir testdata
    cd testdata
    echo -n "*** creating test database with 2 nodes..."
    $PGPOOL_SETUP > /dev/null 2>&1
    echo "done."
    cp etc/pgpool.conf pgpool.conf.back

    # change load balancing level
    if [ $lb == 'statement' ]; then
	echo "statement_level_load_balance = on"
	echo "statement_level_load_balance = on" >> etc/pgpool.conf
    else
	echo "statement_level_load_balance = off"
    fi

    for i in $tests
    do
	echo -n "testing $i ... "

	# check if modification to pgpool.conf specified.
	d=/tmp/diff$$
	grep '^##' $testdir/$i > $d
	if [ -s $d ]
	then
	    sed -e 's/^##//' $d >> etc/pgpool.conf
	fi
	rm -f $d

	./startall >/dev/null 2>&1

	while :
	do
	    psql -c "select 1" test >/dev/null 2>&1
	    if [ $? = 0 ]
	    then
		break
	    fi
	    sleep 1
	done

	timeout $timeout $PGPROTO -f $testdir/$i > $results/$i 2>&1
	if [ $? = 124 ]
	then
	    echo "timeout."
	    timeoutcnt=`expr $timeoutcnt + 1`
	else
	    sed -e 's/L [0-9]*/L xxx/g' $expected/$i > expected_tmp
	    sed -e 's/L [0-9]*/L xxx/g' $results/$i > results_tmp
	    cmp expected_tmp results_tmp >/dev/null 2>&1
	    if [ $? != 0 ]
	    then
		echo "failed."
		echo "=== $i ===" >> $diffs
		diff -c expected_tmp results_tmp >> $diffs
		failcnt=`expr $failcnt + 1`
	    else
		extra_fail=0
		# execute extra scripts if exists.
		if [ -x $extra_scripts/$i ]
		then
		    $extra_scripts/$i > $results/$i.extra 2>&1

		    if [ $? != 0 ]
		    then
			echo "extra test failed."
			extra_fail=1
			failcnt=`expr $failcnt + 1`
		    fi
		fi

		if [ $extra_fail = 0 ]
		then
		    echo "ok."
		    okcnt=`expr $okcnt + 1`
		fi
	    fi
	    rm expected_tmp results_tmp
	fi
	grep pool_check_pending_message_and_reply log/pgpool.log
	./shutdownall >/dev/null 2>&1
	cp pgpool.conf.back etc/pgpool.conf
	process=`ps x|grep pgpool|grep idle`
	if [ ! -z $process ]
	then
	    echo "Some process remains. Aborting tests"
	    exit 1
	fi
    done
done

## Test statement_level_load_balance with 3 nodes

cd $dir
testdir=$dir/tests_n3
if [ $# -gt 0 ];then
    tests_n3=`(cd tests_n3;ls | grep $specified_tests)`
else
    tests_n3=`(cd tests_n3;ls)`
fi

if [ "$tests_n3" = "" ];then
    echo "No test data for 3 nodes. Skipping 3 nodes tests."
else
    rm -fr testdata
    mkdir testdata
    cd testdata
    echo -n "creating test database with 3 nodes..."
    $PGPOOL_SETUP -n 3 > /dev/null 2>&1
    echo "done."
    cp etc/pgpool.conf pgpool.conf.back

    for i in $tests_n3
    do
	echo -n "testing $i ... "

	# check if modification to pgpool.conf specified.
	d=/tmp/diff$$
	grep '^##' $testdir/$i > $d
	if [ -s $d ]
	then
	    sed -e 's/^##//' $d >> etc/pgpool.conf
	fi
	rm -f $d

	./startall >/dev/null 2>&1

	while :
	do
	    psql -c "select 1" test >/dev/null 2>&1
	    if [ $? = 0 ]
	    then
		break
	    fi
	    sleep 1
	done

	timeout $timeout $PGPROTO -f $testdir/$i > $results/$i 2>&1
	if [ $? = 124 ]
	then
	    echo "timeout."
	    timeoutcnt=`expr $timeoutcnt + 1`
	else
	    sed -e 's/L [0-9]*/L xxx/g' $expected/$i > expected_tmp
	    sed -e 's/L [0-9]*/L xxx/g' $results/$i > results_tmp
	    cmp expected_tmp results_tmp >/dev/null 2>&1
	    if [ $? != 0 ]
	    then
		echo "failed."
		echo "=== $i ===" >> $diffs
		diff -c expected_tmp results_tmp >> $diffs
		failcnt=`expr $failcnt + 1`
	    else
		extra_fail=0
		# execute extra scripts if exists.
		if [ -x $extra_scripts/$i ]
		then
		    $extra_scripts/$i > $results/$i.extra 2>&1

		    if [ $? != 0 ]
		    then
			echo "extra test failed."
			extra_fail=1
			failcnt=`expr $failcnt + 1`
		    fi
		fi

		if [ $extra_fail = 0 ]
		then
		    echo "ok."
		    okcnt=`expr $okcnt + 1`
		fi
	    fi
	    rm expected_tmp results_tmp
	fi
	grep pool_check_pending_message_and_reply log/pgpool.log
	./shutdownall >/dev/null 2>&1
	cp pgpool.conf.back etc/pgpool.conf
	process=`ps x|grep pgpool|grep idle`
	if [ ! -z "$process" ]
	then
	    echo "Some process remains. Aborting tests"
	    exit 1
	fi

    done
fi
######
total=`expr $okcnt + $failcnt + $timeoutcnt`
echo "out of $total ok: $okcnt failed: $failcnt timeout: $timeoutcnt."