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