1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test036-meta-concurrency,v 1.17.2.11 2010/04/19 19:14:35 quanah Exp
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2010 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 $BACKMETA = metano ; then 
22	echo "meta backend not available, test skipped"
23	exit 0
24fi
25
26if test $BACKLDAP = ldapno ; then 
27	echo "ldap backend not available, test skipped"
28	exit 0
29fi
30
31if test x$TESTLOOPS = x ; then
32	TESTLOOPS=50
33fi
34
35rm -rf $TESTDIR
36
37mkdir -p $TESTDIR $DBDIR1 $DBDIR2
38
39# NOTE: this could be added to all tests...
40if 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 ""
53fi
54
55echo "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 &
58PID=$!
59if test $WAIT != 0 ; then
60    echo PID $PID
61    read foo
62fi
63KILLPIDS="$PID"
64
65sleep 1
66
67echo "Using ldapsearch to check that slapd is running..."
68for 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
77done
78if test $RC != 0 ; then
79	echo "ldapsearch failed ($RC)!"
80	test $KILLSERVERS != no && kill -HUP $KILLPIDS
81	exit $RC
82fi
83
84echo "Using ldapadd to populate the database..."
85$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
86	$LDIFORDERED > $TESTOUT 2>&1
87RC=$?
88if test $RC != 0 ; then
89	echo "ldapadd failed ($RC)!"
90	test $KILLSERVERS != no && kill -HUP $KILLPIDS
91	exit $RC
92fi
93
94echo "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 &
97PID=$!
98if test $WAIT != 0 ; then
99    echo PID $PID
100    read foo
101fi
102KILLPIDS="$KILLPIDS $PID"
103
104sleep 1
105
106echo "Using ldapsearch to check that slapd is running..."
107for 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
116done
117if test $RC != 0 ; then
118	echo "ldapsearch failed ($RC)!"
119	test $KILLSERVERS != no && kill -HUP $KILLPIDS
120	exit $RC
121fi
122
123echo "Using ldapadd to populate the database..."
124$LDAPADD -D "$METAMANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD < \
125	$LDIFMETA >> $TESTOUT 2>&1
126RC=$?
127if test $RC != 0 ; then
128	echo "ldapadd failed ($RC)!"
129	test $KILLSERVERS != no && kill -HUP $KILLPIDS
130	exit $RC
131fi
132
133echo "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 &
136PID=$!
137if test $WAIT != 0 ; then
138    echo PID $PID
139    read foo
140fi
141KILLPIDS="$KILLPIDS $PID"
142
143sleep 1
144
145echo "Using ldapsearch to check that slapd is running..."
146for 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
155done
156if test $RC != 0 ; then
157	echo "ldapsearch failed ($RC)!"
158	test $KILLSERVERS != no && kill -HUP $KILLPIDS
159	exit $RC
160fi
161
162cat /dev/null > $SEARCHOUT
163
164mkdir -p $TESTDIR/$DATADIR
165METABASEDN="o=Example,c=US"
166for f in $DATADIR/do_* ; do
167	sed -e "s;$BASEDN;$METABASEDN;" $f > $TESTDIR/$f
168done
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...
173for f in $TESTDIR/$DATADIR/do_read.* ; do
174	echo "ou=Meta,$METABASEDN" >> $f
175done
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...
180for f in $TESTDIR/$DATADIR/do_read.* ; do
181	echo "cn=Somewhere,ou=Meta,$METABASEDN" >> $f
182done
183
184# add a bind that resolves to a referral
185for 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
190done
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
196echo "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'
200RC=$?
201
202if test $RC != 0 ; then
203	echo "slapd-tester failed ($RC)!"
204	test $KILLSERVERS != no && kill -HUP $KILLPIDS
205	exit $RC
206fi 
207
208echo "Using ldapsearch to retrieve all the entries..."
209$LDAPSEARCH -S "" -b "$METABASEDN" -h $LOCALHOST -p $PORT3 \
210			'objectClass=*' > $SEARCHOUT 2>&1
211RC=$?
212
213test $KILLSERVERS != no && kill -HUP $KILLPIDS
214
215if test $RC != 0 ; then
216	echo "ldapsearch failed ($RC)!"
217	exit $RC
218fi
219
220echo "Filtering ldapsearch results..."
221$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
222echo "Filtering original ldif used to create database..."
223$LDIFFILTER < $METACONCURRENCYOUT > $LDIFFLT
224echo "Comparing filter output..."
225$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
226
227if test $? != 0 ; then
228	echo "comparison failed - slapd-meta search/modification didn't succeed"
229	exit 1
230fi
231
232echo ">>>>> Test succeeded"
233
234test $KILLSERVERS != no && wait
235
236exit 0
237