]> git.sur5r.net Git - openldap/blob - tests/scripts/test036-meta-concurrency
d430732638be13369703645656feee7a1d04e546
[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-2005 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$TEST_META" != "xyes" ; then
27         echo "### this test is currently disabled;"
28         echo "### set \"TEST_META=yes\" to enable (at own risk)."
29         exit 0
30 else
31         echo "### this test is __very__ experimental; enable at own risk"
32 fi
33
34 rm -rf $TESTDIR
35
36 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
37
38 if test "x$DB_CONFIG" != "x" -a -f $DB_CONFIG ; then
39         echo "==> using DB_CONFIG $DB_CONFIG"
40         cp $DB_CONFIG $DBDIR1
41         cp $DB_CONFIG $DBDIR2
42 else
43         echo "==> set \"DB_CONFIG\" to the location of the DB_CONFIG file"
44         echo "==> you want to use for the test."
45 fi
46
47 echo "Starting slapd on TCP/IP port $PORT1..."
48 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
49 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
50 PID=$!
51 if test $WAIT != 0 ; then
52     echo PID $PID
53     read foo
54 fi
55 KILLPIDS="$PID"
56
57 echo "Using ldapsearch to check that slapd is running..."
58 for i in 0 1 2 3 4 5; do
59         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
60                 'objectclass=*' > /dev/null 2>&1
61         RC=$?
62         if test $RC = 0 ; then
63                 break
64         fi
65         echo "Waiting 5 seconds for slapd to start..."
66         sleep 5
67 done
68 if test $RC != 0 ; then
69         echo "ldapsearch failed ($RC)!"
70         test $KILLSERVERS != no && kill -HUP $KILLPIDS
71         exit $RC
72 fi
73
74 echo "Using ldapadd to populate the database..."
75 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
76         $LDIFORDERED > $TESTOUT 2>&1
77 RC=$?
78 if test $RC != 0 ; then
79         echo "ldapadd failed ($RC)!"
80         test $KILLSERVERS != no && kill -HUP $KILLPIDS
81         exit $RC
82 fi
83
84 echo "Starting slapd on TCP/IP port $PORT2..."
85 . $CONFFILTER $BACKEND $MONITORDB < $METACONF > $CONF2
86 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
87 PID=$!
88 if test $WAIT != 0 ; then
89     echo PID $PID
90     read foo
91 fi
92 KILLPIDS="$KILLPIDS $PID"
93
94 echo "Using ldapsearch to check that slapd is running..."
95 for 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
104 done
105 if test $RC != 0 ; then
106         echo "ldapsearch failed ($RC)!"
107         test $KILLSERVERS != no && kill -HUP $KILLPIDS
108         exit $RC
109 fi
110
111 echo "Using ldapadd to populate the database..."
112 $LDAPADD -D "$METAMANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD < \
113         $LDIFMETA >> $TESTOUT 2>&1
114 RC=$?
115 if test $RC != 0 ; then
116         echo "ldapadd failed ($RC)!"
117         test $KILLSERVERS != no && kill -HUP $KILLPIDS
118         exit $RC
119 fi
120
121 cat /dev/null > $SEARCHOUT
122
123 mkdir -p $TESTDIR/$DATADIR
124 METABASEDN="o=Example,c=US"
125 for f in $DATADIR/do_* ; do
126         sed -e "s;$BASEDN;$METABASEDN;" $f > $TESTDIR/$f
127 done
128
129 for f in $TESTDIR/$DATADIR/do_read.* ; do
130         echo "ou=Meta,$METABASEDN" >> $f
131 done
132
133 echo "Using tester for concurrent server access..."
134 $SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR/$DATADIR" -h $LOCALHOST -p $PORT2 -D "cn=Manager,$METABASEDN" -w $PASSWD -l 100 -r 20
135 RC=$?
136
137 if test $RC != 0 ; then
138         echo "slapd-tester failed ($RC)!"
139         test $KILLSERVERS != no && kill -HUP $KILLPIDS
140         exit $RC
141 fi 
142
143 echo "Using ldapsearch to retrieve all the entries..."
144 $LDAPSEARCH -S "" -b "$METABASEDN" -h $LOCALHOST -p $PORT2 \
145                         'objectClass=*' > $SEARCHOUT 2>&1
146 RC=$?
147
148 test $KILLSERVERS != no && kill -HUP $KILLPIDS
149
150 if test $RC != 0 ; then
151         echo "ldapsearch failed ($RC)!"
152         exit $RC
153 fi
154
155 echo "Filtering ldapsearch results..."
156 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
157 echo "Filtering original ldif used to create database..."
158 . $LDIFFILTER < $METACONCURRENCYOUT > $LDIFFLT
159 echo "Comparing filter output..."
160 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
161         
162 if test $? != 0 ; then
163         echo "comparison failed - meta search/modification didn't succeed"
164         exit 1
165 fi
166
167 echo ">>>>> Test succeeded"
168 exit 0
169