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