#!/bin/sh
#
# Example program to run all tests
#

set -e

# XXX CENSOR
ORACLE_HOME=/proj/oracle
export ORACLE_HOME
PATH=.:$PATH
PATH=.:/proj/postgres/bin:/proj/oracle/bin:$PATH
NUMVECTORS=100000
PSQL_CONNECTSTRING="-h fruid"
PSQL_CONNECTSTRING="-h wonder"
PG_CONNECTSTRING="--dbhost fruid"
PG_CONNECTSTRING="--dbhost wonder"
ORA_CONNECTSTRING="--dbname=fruid --dbuser=foo --dbpass=bar"
ORA_CONNECTSTRING="--dbname=wonder --dbuser=awbtest --dbpass=awbtest"
SQLPLUS_CONNECTSTRING="foo/bar@fruid"
SQLPLUS_CONNECTSTRING="awbtest/awbtest@wonder"
# XXX CENSOR

echo Generate $NUMVECTORS random input vectors
test-genevent.pl $NUMVECTORS > /tmp/x.in 2>/tmp/x.out

x=`expr $NUMVECTORS '*' 2`
echo "Generating $x testing vectors ($NUMVECTORS dups)"
(cat /tmp/x.in; test-genevent.pl $NUMVECTORS 2>/dev/null) | randline -a > /tmp/x.search

echo
echo
echo "Starting simple insert/update method in perl"
echo "  Clearing database"
psql $PSQL_CONNECTSTRING -f test-sql
echo "  Performing insert"
time test-byperl.pl $PG_CONNECTSTRING /tmp/x.in
echo "  Performing data verification"
test-dump.pl $PG_CONNECTSTRING > /tmp/x.actual
diff /tmp/x.out /tmp/x.actual | head
echo "  Performing read test before analyze"
time test-getevent.pl $PG_CONNECTSTRING /tmp/x.search
echo "  Performing read test after analyze"
psql $PSQL_CONNECTSTRING -c "vacuum analyze;"
time test-getevent.pl $PG_CONNECTSTRING /tmp/x.search

echo
echo
echo "Starting simple insert/update method in perl using DBI prepared statement"
echo "  (Yes, it doesn't do anything interesting for postgres yet)"
echo "  Clearing database"
psql $PSQL_CONNECTSTRING -f test-sql
echo "  Performing insert"
time test-byperl.pl --preparedbi $PG_CONNECTSTRING /tmp/x.in
echo "  Performing data verification"
test-dump.pl $PG_CONNECTSTRING > /tmp/x.actual
diff /tmp/x.out /tmp/x.actual | head

echo
echo
echo "Starting simple insert/update method in perl using batching"
echo "  Clearing database"
psql $PSQL_CONNECTSTRING -f test-sql
echo "  Performing insert"
time test-byperl.pl --batch $PG_CONNECTSTRING /tmp/x.in
echo "  Performing data verification"
test-dump.pl $PG_CONNECTSTRING > /tmp/x.actual
diff /tmp/x.out /tmp/x.actual | head

echo
echo
echo "Starting simple insert/update method in perl using arrays"
echo "  Clearing database"
psql $PSQL_CONNECTSTRING -f test-sql
echo "  Performing insert"
time test-byperl.pl --array $PG_CONNECTSTRING /tmp/x.in
echo "  Performing data verification"
test-dump.pl --array $PG_CONNECTSTRING > /tmp/x.actual
diff /tmp/x.out /tmp/x.actual | head

echo
echo
echo "Starting insert/update method in perl using server-side function"
echo "  Clearing database"
psql $PSQL_CONNECTSTRING -f test-sql
echo "  Performing insert"
time test-thuperl.pl $PG_CONNECTSTRING /tmp/x.in
echo "  Performing data verification"
test-dump.pl $PG_CONNECTSTRING > /tmp/x.actual
diff /tmp/x.out /tmp/x.actual | head

echo
echo
echo "Starting insert/update method in perl using table trigger"
echo "  Clearing database"
psql $PSQL_CONNECTSTRING -f test-sql
echo "  Performing insert"
time test-thuperl.pl --trigger $PG_CONNECTSTRING /tmp/x.in
echo "  Performing data verification"
test-dump.pl $PG_CONNECTSTRING > /tmp/x.actual
diff /tmp/x.out /tmp/x.actual | head

echo
echo
echo "Starting simple insert/update method in C/libpq"
echo "  Clearing database"
psql $PSQL_CONNECTSTRING -f test-sql
echo "  Compiling program"
cc -O2 -I/usr/include/pgsql  -o test-byc test-byc.c -lpq -lcrypt
echo "  Performing insert"
time test-byc < /tmp/x.in # Sorry, hardcoded host
echo "  Performing data verification"
test-dump.pl $PG_CONNECTSTRING > /tmp/x.actual
diff /tmp/x.out /tmp/x.actual | head

echo
echo
echo "Starting simple insert/update method in Oracle"
echo "  Clearing database"
sqlplus $SQLPLUS_CONNECTSTRING @test-sql.ora < /dev/null
echo "  Performing insert"
time test-ora.pl $ORA_CONNECTSTRING /tmp/x.in
echo "  Performing data verification"
test-oradump.pl $ORA_CONNECTSTRING > /tmp/x.actual
diff /tmp/x.out /tmp/x.actual | head
echo "  Performing read test"
time test-oragetevent.pl $ORA_CONNECTSTRING /tmp/x.search

