~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/test/test095.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 2000-2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: test095.tcl,v 1.1.2.1 2001/07/23 20:40:23 jbj Exp $
 
7
#
 
8
# DB Test 95 {access method}
 
9
# Bulk get test.
 
10
#
 
11
proc test095 { method {nsets 1000} {noverflows 25} {tnum 95} args } {
 
12
        source ./include.tcl
 
13
        set args [convert_args $method $args]
 
14
        set omethod [convert_method $method]
 
15
 
 
16
        set eindex [lsearch -exact $args "-env"]
 
17
        #
 
18
        # If we are using an env, then testfile should just be the db name.
 
19
        # Otherwise it is the test directory and the name.
 
20
        if { $eindex == -1 } {
 
21
                set basename $testdir/test0$tnum
 
22
                set env NULL
 
23
                # If we've our own env, no reason to swap--this isn't
 
24
                # an mpool test.
 
25
                set carg { -cachesize {0 25000000 0} }
 
26
        } else {
 
27
                set basename test0$tnum
 
28
                incr eindex
 
29
                set env [lindex $args $eindex]
 
30
                set carg {}
 
31
        }
 
32
        cleanup $testdir $env
 
33
 
 
34
        puts "Test0$tnum: $method ($args) Bulk get test"
 
35
 
 
36
        if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
 
37
                puts "Test0$tnum skipping for method $method"
 
38
                return
 
39
        }
 
40
 
 
41
        # We run the meat of the test twice: once with unsorted dups,
 
42
        # once with sorted dups.
 
43
        for { set dflag "-dup"; set sort "unsorted"; set diter 0 } \
 
44
            { $diter < 2 } \
 
45
            { set dflag "-dup -dupsort"; set sort "sorted"; incr diter } {
 
46
                set testfile $basename-$sort.db
 
47
                set did [open $dict]
 
48
 
 
49
                # Open and populate the database with $nsets sets of dups.
 
50
                # Each set contains as many dups as its number
 
51
                puts "\tTest0$tnum.a:\
 
52
                    Creating database with $nsets sets of $sort dups."
 
53
                set dargs "$dflag $carg $args"
 
54
                set db [eval {berkdb_open -create} $omethod $dargs $testfile]
 
55
                error_check_good db_open [is_valid_db $db] TRUE
 
56
                t95_populate $db $did $nsets 0
 
57
 
 
58
                # Run basic get tests.
 
59
                t95_gettest $db $tnum b [expr 8192] 1
 
60
                t95_gettest $db $tnum c [expr 10 * 8192] 0
 
61
 
 
62
                # Run cursor get tests.
 
63
                t95_cgettest $db $tnum d [expr 100] 1
 
64
                t95_cgettest $db $tnum e [expr 10 * 8192] 0
 
65
 
 
66
                set m [expr 4000 * $noverflows]
 
67
                puts "\tTest0$tnum.f: Growing\
 
68
                    database with $noverflows overflow sets (max item size $m)"
 
69
                t95_populate $db $did $noverflows 4000
 
70
 
 
71
                # Run overflow get tests.
 
72
                t95_gettest $db $tnum g [expr 10 * 8192] 1
 
73
                t95_gettest $db $tnum h [expr $m * 2] 1
 
74
                t95_gettest $db $tnum i [expr $m * $noverflows * 2] 0
 
75
 
 
76
                # Run cursor get tests.
 
77
                t95_cgettest $db $tnum j [expr 10 * 8192] 1
 
78
                t95_cgettest $db $tnum k [expr $m * 2] 0
 
79
 
 
80
                error_check_good db_close [$db close] 0
 
81
                close $did
 
82
        }
 
83
 
 
84
}
 
85
 
 
86
proc t95_gettest { db tnum letter bufsize expectfail } {
 
87
        t95_gettest_body $db $tnum $letter $bufsize $expectfail 0
 
88
}
 
89
proc t95_cgettest { db tnum letter bufsize expectfail } {
 
90
        t95_gettest_body $db $tnum $letter $bufsize $expectfail 1
 
91
}
 
92
 
 
93
proc t95_gettest_body { db tnum letter bufsize expectfail usecursor } {
 
94
        global errorCode
 
95
 
 
96
        if { $usecursor == 0 } {
 
97
                set action "db get -multi"
 
98
        } else {
 
99
                set action "dbc get -multi -set/-next"
 
100
        }
 
101
        puts "\tTest0$tnum.$letter: $action with bufsize $bufsize"
 
102
 
 
103
        set allpassed TRUE
 
104
        set saved_err ""
 
105
 
 
106
        # Cursor for $usecursor.
 
107
        if { $usecursor != 0 } {
 
108
                set getcurs [$db cursor]
 
109
                error_check_good getcurs [is_valid_cursor $getcurs $db] TRUE
 
110
        }
 
111
 
 
112
        # Traverse DB with cursor;  do get/c_get(DB_MULTIPLE) on each item.
 
113
        set dbc [$db cursor]
 
114
        error_check_good is_valid_dbc [is_valid_cursor $dbc $db] TRUE
 
115
        for { set dbt [$dbc get -first] } { [llength $dbt] != 0 } \
 
116
            { set dbt [$dbc get -nextnodup] } {
 
117
                set key [lindex [lindex $dbt 0] 0]
 
118
                set datum [lindex [lindex $dbt 0] 1]
 
119
 
 
120
                if { $usecursor == 0 } {
 
121
                        set ret [catch {eval $db get -multi $bufsize $key} res]
 
122
                } else {
 
123
                        set res {}
 
124
                        for { set ret [catch {eval $getcurs get -multi $bufsize\
 
125
                            -set $key} tres] } \
 
126
                            { $ret == 0 && [llength $tres] != 0 } \
 
127
                            { set ret [catch {eval $getcurs get -multi $bufsize\
 
128
                            -nextdup} tres]} {
 
129
                                eval lappend res $tres
 
130
                        }
 
131
                }
 
132
 
 
133
                # If we expect a failure, be more tolerant if the above fails;
 
134
                # just make sure it's an ENOMEM, mark it, and move along.
 
135
                if { $expectfail != 0 && $ret != 0 } {
 
136
                        error_check_good multi_failure_errcode \
 
137
                            [is_substr $errorCode ENOMEM] 1
 
138
                        set allpassed FALSE
 
139
                        continue
 
140
                }
 
141
                error_check_good get_multi($key) $ret 0
 
142
                t95_verify $res FALSE
 
143
        }
 
144
 
 
145
        set ret [catch {eval $db get -multi $bufsize} res]
 
146
 
 
147
        if { $expectfail == 1 } {
 
148
                error_check_good allpassed $allpassed FALSE
 
149
                puts "\t\tTest0$tnum.$letter:\
 
150
                    returned at least one ENOMEM (as expected)"
 
151
        } else {
 
152
                error_check_good allpassed $allpassed TRUE
 
153
                puts "\t\tTest0$tnum.$letter: succeeded (as expected)"
 
154
        }
 
155
 
 
156
        error_check_good dbc_close [$dbc close] 0
 
157
        if { $usecursor != 0 } {
 
158
                error_check_good getcurs_close [$getcurs close] 0
 
159
        }
 
160
}
 
161
 
 
162
# Verify that a passed-in list of key/data pairs all match the predicted
 
163
# structure (e.g. {{thing1 thing1.0}}, {{key2 key2.0} {key2 key2.1}}).
 
164
proc t95_verify { res multiple_keys } {
 
165
        global alphabet
 
166
 
 
167
        set i 0
 
168
 
 
169
        set orig_key [lindex [lindex $res 0] 0]
 
170
        set nkeys [string trim $orig_key $alphabet']
 
171
        set base_key [string trim $orig_key 0123456789]
 
172
        set datum_count 0
 
173
 
 
174
        while { 1 } {
 
175
                set key [lindex [lindex $res $i] 0]
 
176
                set datum [lindex [lindex $res $i] 1]
 
177
 
 
178
                if { $datum_count >= $nkeys } {
 
179
                        if { [llength $key] != 0 } {
 
180
                                # If there are keys beyond $nkeys, we'd
 
181
                                # better have multiple_keys set.
 
182
                                error_check_bad "keys beyond number $i allowed"\
 
183
                                    $multiple_keys FALSE
 
184
 
 
185
                                # If multiple_keys is set, accept the new key.
 
186
                                set orig_key $key
 
187
                                set nkeys [eval string trim \
 
188
                                    $orig_key {$alphabet'}]
 
189
                                set base_key [eval string trim \
 
190
                                    $orig_key 0123456789]
 
191
                                set datum_count 0
 
192
                        } else {
 
193
                                # datum_count has hit nkeys.  We're done.
 
194
                                return
 
195
                        }
 
196
                }
 
197
 
 
198
                error_check_good returned_key($i) $key $orig_key
 
199
                error_check_good returned_datum($i) \
 
200
                    $datum $base_key.[format %4u $datum_count]
 
201
                incr datum_count
 
202
                incr i
 
203
        }
 
204
}
 
205
 
 
206
# Add nsets dup sets, each consisting of {word$ndups word$n} pairs,
 
207
# with "word" having (i * pad_bytes)  bytes extra padding.
 
208
proc t95_populate { db did nsets pad_bytes } {
 
209
        for { set i 1 } { $i <= $nsets } { incr i } {
 
210
                # basekey is a padded dictionary word
 
211
                gets $did basekey
 
212
 
 
213
                append basekey [repeat "a" [expr $pad_bytes * $i]]
 
214
 
 
215
                # key is basekey with the number of dups stuck on.
 
216
                set key $basekey$i
 
217
 
 
218
                for { set j 0 } { $j < $i } { incr j } {
 
219
                        set data $basekey.[format %4u $j]
 
220
                        error_check_good db_put($key,$data) \
 
221
                            [$db put $key $data] 0
 
222
                }
 
223
        }
 
224
 
 
225
        # This will make debugging easier, and since the database is
 
226
        # read-only from here out, it's cheap.
 
227
        error_check_good db_sync [$db sync] 0
 
228
}