]> git.sur5r.net Git - openldap/blob - tests/scripts/test036-meta-concurrency
ITS#5893
[openldap] / tests / scripts / test036-meta-concurrency
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2009 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 echo ""
20
21 if test $BACKMETA = metano ; then 
22         echo "meta backend not available, test skipped"
23         exit 0
24 fi
25
26 if test $BACKLDAP = ldapno ; then 
27         echo "ldap backend not available, test skipped"
28         exit 0
29 fi
30
31 if test x$TESTLOOPS = x ; then
32         TESTLOOPS=50
33 fi
34
35 rm -rf $TESTDIR
36
37 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
38
39 # NOTE: this could be added to all tests...
40 if test "$BACKEND" = "bdb" || test "$BACKEND" = "hdb" ; then
41         if test "x$DB_CONFIG" != "x" ; then \
42                 if test -f $DB_CONFIG ; then
43                         echo "==> using DB_CONFIG \"$DB_CONFIG\""
44                         cp $DB_CONFIG $DBDIR1
45                         cp $DB_CONFIG $DBDIR2
46                 else
47                         echo "==> DB_CONFIG must point to a valid file (ignored)"
48                 fi
49         else
50                 echo "==> set \"DB_CONFIG\" to the DB_CONFIG file you want to use for the test."
51         fi
52         echo ""
53 fi
54
55 echo "Starting slapd on TCP/IP port $PORT1..."
56 . $CONFFILTER $BACKEND $MONITORDB < $METACONF1 > $CONF1
57 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
58 PID=$!
59 if test $WAIT != 0 ; then
60     echo PID $PID
61     read foo
62 fi
63 KILLPIDS="$PID"
64
65 sleep 1
66
67 echo "Using ldapsearch to check that slapd is running..."
68 for i in 0 1 2 3 4 5; do
69         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
70                 'objectclass=*' > /dev/null 2>&1
71         RC=$?
72         if test $RC = 0 ; then
73                 break
74         fi
75         echo "Waiting 5 seconds for slapd to start..."
76         sleep 5
77 done
78 if test $RC != 0 ; then
79         echo "ldapsearch failed ($RC)!"
80         test $KILLSERVERS != no && kill -HUP $KILLPIDS
81         exit $RC
82 fi
83
84 echo "Using ldapadd to populate the database..."
85 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
86         $LDIFORDERED > $TESTOUT 2>&1
87 RC=$?
88 if test $RC != 0 ; then
89         echo "ldapadd failed ($RC)!"
90         test $KILLSERVERS != no && kill -HUP $KILLPIDS
91         exit $RC
92 fi
93
94 echo "Starting slapd on TCP/IP port $PORT2..."
95 . $CONFFILTER $BACKEND $MONITORDB < $METACONF2 > $CONF2
96 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
97 PID=$!
98 if test $WAIT != 0 ; then
99     echo PID $PID
100     read foo
101 fi
102 KILLPIDS="$KILLPIDS $PID"
103
104 sleep 1
105
106 echo "Using ldapsearch to check that slapd is running..."
107 for i in 0 1 2 3 4 5; do
108         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
109                 'objectclass=*' > /dev/null 2>&1
110         RC=$?
111         if test $RC = 0 ; then
112                 break
113         fi
114         echo "Waiting 5 seconds for slapd to start..."
115         sleep 5
116 done
117 if test $RC != 0 ; then
118         echo "ldapsearch failed ($RC)!"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit $RC
121 fi
122
123 echo "Using ldapadd to populate the database..."
124 $LDAPADD -D "$METAMANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD < \
125         $LDIFMETA >> $TESTOUT 2>&1
126 RC=$?
127 if test $RC != 0 ; then
128         echo "ldapadd failed ($RC)!"
129         test $KILLSERVERS != no && kill -HUP $KILLPIDS
130         exit $RC
131 fi
132
133 echo "Starting slapd on TCP/IP port $PORT3..."
134 . $CONFFILTER $BACKEND $MONITORDB < $METACONF > $CONF3
135 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
136 PID=$!
137 if test $WAIT != 0 ; then
138     echo PID $PID
139     read foo
140 fi
141 KILLPIDS="$KILLPIDS $PID"
142
143 sleep 1
144
145 echo "Using ldapsearch to check that slapd is running..."
146 for i in 0 1 2 3 4 5; do
147         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
148                 'objectclass=*' > /dev/null 2>&1
149         RC=$?
150         if test $RC = 0 ; then
151                 break
152         fi
153         echo "Waiting 5 seconds for slapd to start..."
154         sleep 5
155 done
156 if test $RC != 0 ; then
157         echo "ldapsearch failed ($RC)!"
158         test $KILLSERVERS != no && kill -HUP $KILLPIDS
159         exit $RC
160 fi
161
162 cat /dev/null > $SEARCHOUT
163
164 mkdir -p $TESTDIR/$DATADIR
165 METABASEDN="o=Example,c=US"
166 for f in $DATADIR/do_* ; do
167         sed -e "s;$BASEDN;$METABASEDN;" $f > $TESTDIR/$f
168 done
169
170 # add a read that matches only the local database, but selects 
171 # also the remote as candidate; this should be removed to compare
172 # execution times with test008...
173 for f in $TESTDIR/$DATADIR/do_read.* ; do
174         echo "ou=Meta,$METABASEDN" >> $f
175 done
176
177 # add a read that matches a referral in the local database only, 
178 # but selects also the remote as candidate; this should be removed 
179 # to compare execution times with test008...
180 for f in $TESTDIR/$DATADIR/do_read.* ; do
181         echo "cn=Somewhere,ou=Meta,$METABASEDN" >> $f
182 done
183
184 # add a bind that resolves to a referral
185 for f in $TESTDIR/$DATADIR/do_bind.* ; do
186         echo "cn=Foo,ou=Meta,$METABASEDN" >> $f
187         echo "bar" >> $f
188         echo "" >> $f
189         echo "" >> $f
190 done
191
192 # fix test data to include back-monitor, if available
193 # NOTE: copies do_* files from $TESTDIR/$DATADIR to $TESTDIR
194 $MONITORDATA "$MONITORDB" "$TESTDIR/$DATADIR" "$TESTDIR"
195
196 echo "Using tester for concurrent server access..."
197 $SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR" -h $LOCALHOST -p $PORT3 \
198         -D "cn=Manager,$METABASEDN" -w $PASSWD -l $TESTLOOPS -r 20 \
199         -i '!REFERRAL' -i '*INVALID_CREDENTIALS'
200 RC=$?
201
202 if test $RC != 0 ; then
203         echo "slapd-tester failed ($RC)!"
204         test $KILLSERVERS != no && kill -HUP $KILLPIDS
205         exit $RC
206 fi 
207
208 echo "Using ldapsearch to retrieve all the entries..."
209 $LDAPSEARCH -S "" -b "$METABASEDN" -h $LOCALHOST -p $PORT3 \
210                         'objectClass=*' > $SEARCHOUT 2>&1
211 RC=$?
212
213 test $KILLSERVERS != no && kill -HUP $KILLPIDS
214
215 if test $RC != 0 ; then
216         echo "ldapsearch failed ($RC)!"
217         exit $RC
218 fi
219
220 echo "Filtering ldapsearch results..."
221 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
222 echo "Filtering original ldif used to create database..."
223 . $LDIFFILTER < $METACONCURRENCYOUT > $LDIFFLT
224 echo "Comparing filter output..."
225 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
226
227 if test $? != 0 ; then
228         echo "comparison failed - slapd-meta search/modification didn't succeed"
229         exit 1
230 fi
231
232 echo ">>>>> Test succeeded"
233
234 test $KILLSERVERS != no && wait
235
236 exit 0