~ubuntu-branches/ubuntu/natty/evolution-data-server/natty

« back to all changes in this revision

Viewing changes to libdb/test/sindex.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 2001-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# Secondary index test driver and maintenance routines.
9
 
#
10
 
# Breaking from the usual convention, we put the driver function
11
 
# for the secondary index tests here, in its own file.  The reason
12
 
# for this is that it's something which compartmentalizes nicely,
13
 
# has little in common with other driver functions, and
14
 
# is likely to be run on its own from time to time.
15
 
#
16
 
# The secondary index tests themselves live in si0*.tcl.
17
 
 
18
 
# Standard number of secondary indices to create if a single-element
19
 
# list of methods is passed into the secondary index tests.
20
 
global nsecondaries
21
 
set nsecondaries 2
22
 
 
23
 
# Run the secondary index tests.
24
 
proc sindex { {verbose 0} args } {
25
 
        global verbose_check_secondaries
26
 
        set verbose_check_secondaries $verbose
27
 
 
28
 
        # Run basic tests with a single secondary index and a small number
29
 
        # of keys, then again with a larger number of keys.  (Note that
30
 
        # we can't go above 5000, since we use two items from our
31
 
        # 10K-word list for each key/data pair.)
32
 
        foreach n { 200 5000 } {
33
 
                foreach pm { btree hash recno frecno queue queueext } {
34
 
                        foreach sm { dbtree dhash ddbtree ddhash btree hash } {
35
 
                                sindex001 [list $pm $sm $sm] $n
36
 
                                sindex002 [list $pm $sm $sm] $n
37
 
                                # Skip tests 3 & 4 for large lists;
38
 
                                # they're not that interesting.
39
 
                                if { $n < 1000 } {
40
 
                                        sindex003 [list $pm $sm $sm] $n
41
 
                                        sindex004 [list $pm $sm $sm] $n
42
 
                                }
43
 
 
44
 
                                sindex006 [list $pm $sm $sm] $n
45
 
                        }
46
 
                }
47
 
        }
48
 
 
49
 
        # Run secondary index join test.  (There's no point in running
50
 
        # this with both lengths, the primary is unhappy for now with fixed-
51
 
        # length records (XXX), and we need unsorted dups in the secondaries.)
52
 
        foreach pm { btree hash recno } {
53
 
                foreach sm { btree hash } {
54
 
                        sindex005 [list $pm $sm $sm] 1000
55
 
                }
56
 
                sindex005 [list $pm btree hash] 1000
57
 
                sindex005 [list $pm hash btree] 1000
58
 
        }
59
 
 
60
 
 
61
 
        # Run test with 50 secondaries.
62
 
        foreach pm { btree hash } {
63
 
                set methlist [list $pm]
64
 
                for { set i 0 } { $i < 50 } { incr i } {
65
 
                        # XXX this should incorporate hash after #3726
66
 
                        if { $i % 2 == 0 } {
67
 
                                lappend methlist "dbtree"
68
 
                        } else {
69
 
                                lappend methlist "ddbtree"
70
 
                        }
71
 
                }
72
 
                sindex001 $methlist 500
73
 
                sindex002 $methlist 500
74
 
                sindex003 $methlist 500
75
 
                sindex004 $methlist 500
76
 
        }
77
 
}
78
 
 
79
 
# The callback function we use for each given secondary in most tests
80
 
# is a simple function of its place in the list of secondaries (0-based)
81
 
# and the access method (since recnos may need different callbacks).
82
 
#
83
 
# !!!
84
 
# Note that callbacks 0-3 return unique secondary keys if the input data
85
 
# are unique;  callbacks 4 and higher may not, so don't use them with
86
 
# the normal wordlist and secondaries that don't support dups.
87
 
# The callbacks that incorporate a key don't work properly with recno
88
 
# access methods, at least not in the current test framework (the
89
 
# error_check_good lines test for e.g. 1foo, when the database has
90
 
# e.g. 0x010x000x000x00foo).
91
 
proc callback_n { n } {
92
 
        switch $n {
93
 
                0 { return _s_reversedata }
94
 
                1 { return _s_noop }
95
 
                2 { return _s_concatkeydata }
96
 
                3 { return _s_concatdatakey }
97
 
                4 { return _s_reverseconcat }
98
 
                5 { return _s_truncdata }
99
 
                6 { return _s_alwayscocacola }
100
 
        }
101
 
        return _s_noop
102
 
}
103
 
 
104
 
proc _s_reversedata { a b } { return [reverse $b] }
105
 
proc _s_truncdata { a b } { return [string range $b 1 end] }
106
 
proc _s_concatkeydata { a b } { return $a$b }
107
 
proc _s_concatdatakey { a b } { return $b$a }
108
 
proc _s_reverseconcat { a b } { return [reverse $a$b] }
109
 
proc _s_alwayscocacola { a b } { return "Coca-Cola" }
110
 
proc _s_noop { a b } { return $b }
111
 
 
112
 
# Should the check_secondary routines print lots of output?
113
 
set verbose_check_secondaries 0
114
 
 
115
 
# Given a primary database handle, a list of secondary handles, a
116
 
# number of entries, and arrays of keys and data, verify that all
117
 
# databases have what they ought to.
118
 
proc check_secondaries { pdb sdbs nentries keyarr dataarr {pref "Check"} } {
119
 
        upvar $keyarr keys
120
 
        upvar $dataarr data
121
 
        global verbose_check_secondaries
122
 
 
123
 
        # Make sure each key/data pair is in the primary.
124
 
        if { $verbose_check_secondaries } {
125
 
                puts "\t\t$pref.1: Each key/data pair is in the primary"
126
 
        }
127
 
        for { set i 0 } { $i < $nentries } { incr i } {
128
 
                error_check_good pdb_get($i) [$pdb get $keys($i)] \
129
 
                    [list [list $keys($i) $data($i)]]
130
 
        }
131
 
 
132
 
        for { set j 0 } { $j < [llength $sdbs] } { incr j } {
133
 
                # Make sure each key/data pair is in this secondary.
134
 
                if { $verbose_check_secondaries } {
135
 
                        puts "\t\t$pref.2:\
136
 
                            Each skey/key/data tuple is in secondary #$j"
137
 
                }
138
 
                for { set i 0 } { $i < $nentries } { incr i } {
139
 
                        set sdb [lindex $sdbs $j]
140
 
                        set skey [[callback_n $j] $keys($i) $data($i)]
141
 
                        error_check_good sdb($j)_pget($i) \
142
 
                            [$sdb pget -get_both $skey $keys($i)] \
143
 
                            [list [list $skey $keys($i) $data($i)]]
144
 
                }
145
 
 
146
 
                # Make sure this secondary contains only $nentries
147
 
                # items.
148
 
                if { $verbose_check_secondaries } {
149
 
                        puts "\t\t$pref.3: Secondary #$j has $nentries items"
150
 
                }
151
 
                set dbc [$sdb cursor]
152
 
                error_check_good dbc($i) \
153
 
                    [is_valid_cursor $dbc $sdb] TRUE
154
 
                for { set k 0 } { [llength [$dbc get -next]] > 0 } \
155
 
                    { incr k } { }
156
 
                error_check_good numitems($i) $k $nentries
157
 
                error_check_good dbc($i)_close [$dbc close] 0
158
 
        }
159
 
 
160
 
        if { $verbose_check_secondaries } {
161
 
                puts "\t\t$pref.4: Primary has $nentries items"
162
 
        }
163
 
        set dbc [$pdb cursor]
164
 
        error_check_good pdbc [is_valid_cursor $dbc $pdb] TRUE
165
 
        for { set k 0 } { [llength [$dbc get -next]] > 0 } { incr k } { }
166
 
        error_check_good numitems $k $nentries
167
 
        error_check_good pdbc_close [$dbc close] 0
168
 
}
169
 
 
170
 
# Given a primary database handle and a list of secondary handles, walk
171
 
# through the primary and make sure all the secondaries are correct,
172
 
# then walk through the secondaries and make sure the primary is correct.
173
 
#
174
 
# This is slightly less rigorous than the normal check_secondaries--we
175
 
# use it whenever we don't have up-to-date "keys" and "data" arrays.
176
 
proc cursor_check_secondaries { pdb sdbs nentries { pref "Check" } } {
177
 
        global verbose_check_secondaries
178
 
 
179
 
        # Make sure each key/data pair in the primary is in each secondary.
180
 
        set pdbc [$pdb cursor]
181
 
        error_check_good ccs_pdbc [is_valid_cursor $pdbc $pdb] TRUE
182
 
        set i 0
183
 
        if { $verbose_check_secondaries } {
184
 
                puts "\t\t$pref.1:\
185
 
                    Key/data in primary => key/data in secondaries"
186
 
        }
187
 
 
188
 
        for { set dbt [$pdbc get -first] } { [llength $dbt] > 0 } \
189
 
            { set dbt [$pdbc get -next] } {
190
 
                incr i
191
 
                set pkey [lindex [lindex $dbt 0] 0]
192
 
                set pdata [lindex [lindex $dbt 0] 1]
193
 
                for { set j 0 } { $j < [llength $sdbs] } { incr j } {
194
 
                        set sdb [lindex $sdbs $j]
195
 
                        set sdbt [$sdb pget -get_both \
196
 
                            [[callback_n $j] $pkey $pdata] $pkey]
197
 
                        error_check_good pkey($pkey,$j) \
198
 
                            [lindex [lindex $sdbt 0] 1] $pkey
199
 
                        error_check_good pdata($pdata,$j) \
200
 
                            [lindex [lindex $sdbt 0] 2] $pdata
201
 
                }
202
 
        }
203
 
        error_check_good ccs_pdbc_close [$pdbc close] 0
204
 
        error_check_good primary_has_nentries $i $nentries
205
 
 
206
 
        for { set j 0 } { $j < [llength $sdbs] } { incr j } {
207
 
                if { $verbose_check_secondaries } {
208
 
                        puts "\t\t$pref.2:\
209
 
                            Key/data in secondary #$j => key/data in primary"
210
 
                }
211
 
                set sdb [lindex $sdbs $j]
212
 
                set sdbc [$sdb cursor]
213
 
                error_check_good ccs_sdbc($j) [is_valid_cursor $sdbc $sdb] TRUE
214
 
                set i 0
215
 
                for { set dbt [$sdbc pget -first] } { [llength $dbt] > 0 } \
216
 
                    { set dbt [$sdbc pget -next] } {
217
 
                        incr i
218
 
                        set pkey [lindex [lindex $dbt 0] 1]
219
 
                        set pdata [lindex [lindex $dbt 0] 2]
220
 
                        error_check_good pdb_get($pkey/$pdata,$j) \
221
 
                            [$pdb get -get_both $pkey $pdata] \
222
 
                            [list [list $pkey $pdata]]
223
 
                }
224
 
                error_check_good secondary($j)_has_nentries $i $nentries
225
 
 
226
 
                # To exercise pget -last/pget -prev, we do it backwards too.
227
 
                set i 0
228
 
                for { set dbt [$sdbc pget -last] } { [llength $dbt] > 0 } \
229
 
                    { set dbt [$sdbc pget -prev] } {
230
 
                        incr i
231
 
                        set pkey [lindex [lindex $dbt 0] 1]
232
 
                        set pdata [lindex [lindex $dbt 0] 2]
233
 
                        error_check_good pdb_get_bkwds($pkey/$pdata,$j) \
234
 
                            [$pdb get -get_both $pkey $pdata] \
235
 
                            [list [list $pkey $pdata]]
236
 
                }
237
 
                error_check_good secondary($j)_has_nentries_bkwds $i $nentries
238
 
 
239
 
                error_check_good ccs_sdbc_close($j) [$sdbc close] 0
240
 
        }
241
 
}
242
 
 
243
 
# The secondary index tests take a list of the access methods that
244
 
# each array ought to use.  Convert at one blow into a list of converted
245
 
# argses and omethods for each method in the list.
246
 
proc convert_argses { methods largs } {
247
 
        set ret {}
248
 
        foreach m $methods {
249
 
                lappend ret [convert_args $m $largs]
250
 
        }
251
 
        return $ret
252
 
}
253
 
proc convert_methods { methods } {
254
 
        set ret {}
255
 
        foreach m $methods {
256
 
                lappend ret [convert_method $m]
257
 
        }
258
 
        return $ret
259
 
}