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