~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/test029.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) 1996-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# TEST  test029
9
 
# TEST  Test the Btree and Record number renumbering.
10
 
proc test029 { method {nentries 10000} args} {
11
 
        source ./include.tcl
12
 
 
13
 
        set do_renumber [is_rrecno $method]
14
 
        set args [convert_args $method $args]
15
 
        set omethod [convert_method $method]
16
 
 
17
 
        puts "Test029: $method ($args)"
18
 
 
19
 
        if { [string compare $omethod "-hash"] == 0 } {
20
 
                puts "Test029 skipping for method HASH"
21
 
                return
22
 
        }
23
 
        if { [is_record_based $method] == 1 && $do_renumber != 1 } {
24
 
                puts "Test029 skipping for method RECNO (w/out renumbering)"
25
 
                return
26
 
        }
27
 
 
28
 
        # Create the database and open the dictionary
29
 
        set txnenv 0
30
 
        set eindex [lsearch -exact $args "-env"]
31
 
        #
32
 
        # If we are using an env, then testfile should just be the db name.
33
 
        # Otherwise it is the test directory and the name.
34
 
        if { $eindex == -1 } {
35
 
                set testfile $testdir/test029.db
36
 
                set env NULL
37
 
        } else {
38
 
                set testfile test029.db
39
 
                incr eindex
40
 
                set env [lindex $args $eindex]
41
 
                set txnenv [is_txnenv $env]
42
 
                if { $txnenv == 1 } {
43
 
                        append args " -auto_commit "
44
 
                        #
45
 
                        # If we are using txns and running with the
46
 
                        # default, set the default down a bit.
47
 
                        #
48
 
                        if { $nentries == 10000 } {
49
 
                                # Do not set nentries down to 100 until we
50
 
                                # fix SR #5958.
51
 
                                set nentries 1000
52
 
                        }
53
 
                }
54
 
                set testdir [get_home $env]
55
 
        }
56
 
        cleanup $testdir $env
57
 
 
58
 
        # Read the first nentries dictionary elements and reverse them.
59
 
        # Keep a list of these (these will be the keys).
60
 
        puts "\tTest029.a: initialization"
61
 
        set keys ""
62
 
        set did [open $dict]
63
 
        set count 0
64
 
        while { [gets $did str] != -1 && $count < $nentries } {
65
 
                lappend keys [reverse $str]
66
 
                incr count
67
 
        }
68
 
        close $did
69
 
 
70
 
        # Generate sorted order for the keys
71
 
        set sorted_keys [lsort $keys]
72
 
 
73
 
        # Save the first and last keys
74
 
        set last_key [lindex $sorted_keys end]
75
 
        set last_keynum [llength $sorted_keys]
76
 
 
77
 
        set first_key [lindex $sorted_keys 0]
78
 
        set first_keynum 1
79
 
 
80
 
        # Create the database
81
 
        if { [string compare $omethod "-btree"] == 0 } {
82
 
                set db [eval {berkdb_open -create \
83
 
                        -mode 0644 -recnum} $args {$omethod $testfile}]
84
 
           error_check_good dbopen [is_valid_db $db] TRUE
85
 
        } else {
86
 
                set db [eval {berkdb_open -create \
87
 
                        -mode 0644} $args {$omethod $testfile}]
88
 
           error_check_good dbopen [is_valid_db $db] TRUE
89
 
        }
90
 
 
91
 
        set pflags ""
92
 
        set gflags ""
93
 
        set txn ""
94
 
 
95
 
        if { [is_record_based $method] == 1 } {
96
 
                append gflags " -recno"
97
 
        }
98
 
 
99
 
        puts "\tTest029.b: put/get loop"
100
 
        foreach k $keys {
101
 
                if { [is_record_based $method] == 1 } {
102
 
                        set key [lsearch $sorted_keys $k]
103
 
                        incr key
104
 
                } else {
105
 
                        set key $k
106
 
                }
107
 
                if { $txnenv == 1 } {
108
 
                        set t [$env txn]
109
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
110
 
                        set txn "-txn $t"
111
 
                }
112
 
                set ret [eval {$db put} \
113
 
                    $txn $pflags {$key [chop_data $method $k]}]
114
 
                error_check_good dbput $ret 0
115
 
 
116
 
                set ret [eval {$db get} $txn $gflags {$key}]
117
 
                error_check_good dbget [lindex [lindex $ret 0] 1] $k
118
 
                if { $txnenv == 1 } {
119
 
                        error_check_good txn [$t commit] 0
120
 
                }
121
 
        }
122
 
 
123
 
        # Now delete the first key in the database
124
 
        puts "\tTest029.c: delete and verify renumber"
125
 
 
126
 
        # Delete the first key in the file
127
 
        if { [is_record_based $method] == 1 } {
128
 
                set key $first_keynum
129
 
        } else {
130
 
                set key $first_key
131
 
        }
132
 
 
133
 
        if { $txnenv == 1 } {
134
 
                set t [$env txn]
135
 
                error_check_good txn [is_valid_txn $t $env] TRUE
136
 
                set txn "-txn $t"
137
 
        }
138
 
        set ret [eval {$db del} $txn {$key}]
139
 
        error_check_good db_del $ret 0
140
 
        if { $txnenv == 1 } {
141
 
                error_check_good txn [$t commit] 0
142
 
        }
143
 
 
144
 
        # Now we are ready to retrieve records based on
145
 
        # record number
146
 
        if { [string compare $omethod "-btree"] == 0 } {
147
 
                append gflags " -recno"
148
 
        }
149
 
 
150
 
        # First try to get the old last key (shouldn't exist)
151
 
        if { $txnenv == 1 } {
152
 
                set t [$env txn]
153
 
                error_check_good txn [is_valid_txn $t $env] TRUE
154
 
                set txn "-txn $t"
155
 
        }
156
 
        set ret [eval {$db get} $txn $gflags {$last_keynum}]
157
 
        error_check_good get_after_del $ret [list]
158
 
        if { $txnenv == 1 } {
159
 
                error_check_good txn [$t commit] 0
160
 
        }
161
 
 
162
 
        # Now try to get what we think should be the last key
163
 
        if { $txnenv == 1 } {
164
 
                set t [$env txn]
165
 
                error_check_good txn [is_valid_txn $t $env] TRUE
166
 
                set txn "-txn $t"
167
 
        }
168
 
        set ret [eval {$db get} $txn $gflags {[expr $last_keynum - 1]}]
169
 
        error_check_good \
170
 
            getn_last_after_del [lindex [lindex $ret 0] 1] $last_key
171
 
        if { $txnenv == 1 } {
172
 
                error_check_good txn [$t commit] 0
173
 
        }
174
 
 
175
 
        # Create a cursor; we need it for the next test and we
176
 
        # need it for recno here.
177
 
        if { $txnenv == 1 } {
178
 
                set t [$env txn]
179
 
                error_check_good txn [is_valid_txn $t $env] TRUE
180
 
                set txn "-txn $t"
181
 
        }
182
 
        set dbc [eval {$db cursor} $txn]
183
 
        error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
184
 
 
185
 
        # OK, now re-put the first key and make sure that we
186
 
        # renumber the last key appropriately.
187
 
        if { [string compare $omethod "-btree"] == 0 } {
188
 
                set ret [eval {$db put} $txn \
189
 
                    {$key [chop_data $method $first_key]}]
190
 
                error_check_good db_put $ret 0
191
 
        } else {
192
 
                # Recno
193
 
                set ret [$dbc get -first]
194
 
                set ret [eval {$dbc put} $pflags {-before $first_key}]
195
 
                error_check_bad dbc_put:DB_BEFORE $ret 0
196
 
        }
197
 
 
198
 
        # Now check that the last record matches the last record number
199
 
        set ret [eval {$db get} $txn $gflags {$last_keynum}]
200
 
        error_check_good \
201
 
            getn_last_after_put [lindex [lindex $ret 0] 1] $last_key
202
 
 
203
 
        # Now delete the first key in the database using a cursor
204
 
        puts "\tTest029.d: delete with cursor and verify renumber"
205
 
 
206
 
        set ret [$dbc get -first]
207
 
        error_check_good dbc_first $ret [list [list $key $first_key]]
208
 
 
209
 
        # Now delete at the cursor
210
 
        set ret [$dbc del]
211
 
        error_check_good dbc_del $ret 0
212
 
 
213
 
        # Now check the record numbers of the last keys again.
214
 
        # First try to get the old last key (shouldn't exist)
215
 
        set ret [eval {$db get} $txn $gflags {$last_keynum}]
216
 
        error_check_good get_last_after_cursor_del:$ret $ret [list]
217
 
 
218
 
        # Now try to get what we think should be the last key
219
 
        set ret [eval {$db get} $txn $gflags {[expr $last_keynum - 1]}]
220
 
        error_check_good \
221
 
            getn_after_cursor_del [lindex [lindex $ret 0] 1] $last_key
222
 
 
223
 
        # Re-put the first key and make sure that we renumber the last
224
 
        # key appropriately.
225
 
        puts "\tTest029.e: put with cursor and verify renumber"
226
 
        if { [string compare $omethod "-btree"] == 0 } {
227
 
                set ret [eval {$dbc put} \
228
 
                    $pflags {-current $first_key}]
229
 
                error_check_good dbc_put:DB_CURRENT $ret 0
230
 
        } else {
231
 
                set ret [eval {$dbc put} $pflags {-before $first_key}]
232
 
                error_check_bad dbc_put:DB_BEFORE $ret 0
233
 
        }
234
 
 
235
 
        # Now check that the last record matches the last record number
236
 
        set ret [eval {$db get} $txn $gflags {$last_keynum}]
237
 
        error_check_good \
238
 
            get_after_cursor_reput [lindex [lindex $ret 0] 1] $last_key
239
 
 
240
 
        error_check_good dbc_close [$dbc close] 0
241
 
        if { $txnenv == 1 } {
242
 
                error_check_good txn [$t commit] 0
243
 
        }
244
 
        error_check_good db_close [$db close] 0
245
 
}