]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test001-concurrency
add (optional) concurrency test for back-sql
[openldap] / tests / scripts / sql-test001-concurrency
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2004 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $BACKSQL = "sqlno" ; then 
20         echo "SQL backend not available, test skipped"
21         exit 0
22 fi 
23
24 if test $RDBMS = "rdbmsno" ; then
25         echo "SQL test not requested, test skipped"
26         exit 0
27 fi
28
29 SQLDATADIR=$TESTDIR/sql-concurrency
30 mkdir -p $SQLDATADIR
31
32 echo "Starting slapd on TCP/IP port $PORT1..."
33 . $CONFFILTER $BACKEND $MONITORDB < $SQLCONF > $CONF1
34 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
35 PID=$!
36 if test $WAIT != 0 ; then
37     echo PID $PID
38     read foo
39 fi
40 KILLPIDS="$PID"
41
42 echo "Testing SQL backend concurrency..."
43 for i in 0 1 2 3 4 5; do
44         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
45                 'objectclass=*' > /dev/null 2>&1
46         RC=$?
47         if test $RC = 0 ; then
48                 break
49         fi
50         echo "Waiting 5 seconds for slapd to start..."
51         sleep 5
52 done
53
54 if test $RC != 0 ; then
55         echo "ldapsearch failed ($RC)!"
56         test $KILLSERVERS != no && kill -HUP $KILLPIDS
57         exit $RC
58 fi
59
60 echo "Using ldapsearch to retrieve all the entries..."
61 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
62                         '(objectClass=*)' > $SEARCHOUT 2>&1
63 RC=$?
64
65 if test $RC != 0 ; then
66         echo "ldapsearch failed ($RC)!"
67         test $KILLSERVERS != no && kill -HUP $KILLPIDS
68         exit $RC
69 fi
70
71 echo "Filtering original ldif used to create database..."
72 . $LDIFFILTER < $SEARCHOUT > $LDIFFLT
73
74 if test "${RDBMSWRITE}" != "yes"; then
75         echo "write test disabled for ${RDBMS}; set SLAPD_USE_SQLWRITE=yes to enable"
76         cp $SQLCONCURRENCYDIR/do_read* $SQLCONCURRENCYDIR/do_search* \
77                 $SQLDATADIR
78 else
79         case ${RDBMS} in
80                 # list here the RDBMSes whose mapping allows writes
81         pgsql|ibmdb2)
82                 cp $SQLCONCURRENCYDIR/do_* $SQLDATADIR
83                 ;;
84         *)
85                 cp $SQLCONCURRENCYDIR/do_read* $SQLCONCURRENCYDIR/do_search* \
86                         $SQLDATADIR
87                 ;;
88         esac
89 fi
90
91 echo "Using tester for concurrent server access..."
92 $SLAPDTESTER -P "$PROGDIR" -d "$DATADIR/sql-concurrency" \
93         -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD -l 5 -j 4
94 RC=$?
95
96 if test $RC != 0 ; then
97         echo "slapd-tester failed ($RC)!"
98         test $KILLSERVERS != no && kill -HUP $KILLPIDS
99         exit $RC
100 fi 
101
102 echo "Using ldapsearch to retrieve all the entries..."
103 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
104                         '(objectClass=*)' > $SEARCHOUT 2>&1
105 RC=$?
106
107 test $KILLSERVERS != no && kill -HUP $KILLPIDS
108
109 if test $RC != 0 ; then
110         echo "ldapsearch failed ($RC)!"
111         exit $RC
112 fi
113
114 echo "Filtering ldapsearch results..."
115 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
116 echo "Comparing filter output..."
117 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
118
119 if test $? != 0 ; then
120         echo "comparison failed - database was not created correctly"
121         exit 1
122 fi
123
124 echo ">>>>> Test succeeded"
125 exit 0
126