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

« back to all changes in this revision

Viewing changes to libdb/test/test057.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  test057
9
 
# TEST  Cursor maintenance during key deletes.
10
 
# TEST  Check if we handle the case where we delete a key with the cursor on
11
 
# TEST  it and then add the same key.  The cursor should not get the new item
12
 
# TEST  returned, but the item shouldn't disappear.
13
 
# TEST  Run test tests, one where the overwriting put is done with a put and
14
 
# TEST  one where it's done with a cursor put.
15
 
proc test057 { method args } {
16
 
        global errorInfo
17
 
        source ./include.tcl
18
 
 
19
 
        set args [convert_args $method $args]
20
 
        set omethod [convert_method $method]
21
 
 
22
 
        append args " -create -mode 0644 -dup "
23
 
        if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
24
 
                puts "Test057: skipping for method $method"
25
 
                return
26
 
        }
27
 
        puts "Test057: $method delete and replace in presence of cursor."
28
 
 
29
 
        # Create the database and open the dictionary
30
 
        set txnenv 0
31
 
        set eindex [lsearch -exact $args "-env"]
32
 
        #
33
 
        # If we are using an env, then testfile should just be the db name.
34
 
        # Otherwise it is the test directory and the name.
35
 
        if { $eindex == -1 } {
36
 
                set testfile $testdir/test057.db
37
 
                set env NULL
38
 
        } else {
39
 
                set testfile test057.db
40
 
                incr eindex
41
 
                set env [lindex $args $eindex]
42
 
                set txnenv [is_txnenv $env]
43
 
                if { $txnenv == 1 } {
44
 
                        append args " -auto_commit "
45
 
                }
46
 
                set testdir [get_home $env]
47
 
        }
48
 
        cleanup $testdir $env
49
 
 
50
 
        set flags ""
51
 
        set txn ""
52
 
 
53
 
        set db [eval {berkdb_open} $args {$omethod $testfile}]
54
 
        error_check_good dbopen:dup [is_valid_db $db] TRUE
55
 
 
56
 
        puts "\tTest057.a: Set cursor, delete cursor, put with key."
57
 
        # Put three keys in the database
58
 
        for { set key 1 } { $key <= 3 } {incr key} {
59
 
                if { $txnenv == 1 } {
60
 
                        set t [$env txn]
61
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
62
 
                        set txn "-txn $t"
63
 
                }
64
 
                set r [eval {$db put} $txn $flags {$key datum$key}]
65
 
                error_check_good put $r 0
66
 
                if { $txnenv == 1 } {
67
 
                        error_check_good txn [$t commit] 0
68
 
                }
69
 
        }
70
 
 
71
 
        # Retrieve keys sequentially so we can figure out their order
72
 
        set i 1
73
 
        if { $txnenv == 1 } {
74
 
                set t [$env txn]
75
 
                error_check_good txn [is_valid_txn $t $env] TRUE
76
 
                set txn "-txn $t"
77
 
        }
78
 
        set curs [eval {$db cursor} $txn]
79
 
        error_check_good curs_open:dup [is_valid_cursor $curs $db] TRUE
80
 
 
81
 
        for {set d [$curs get -first] } {[llength $d] != 0 } \
82
 
            {set d [$curs get -next] } {
83
 
                set key_set($i) [lindex [lindex $d 0] 0]
84
 
                incr i
85
 
        }
86
 
 
87
 
        # Now put in a bunch of duplicates for key 2
88
 
        for { set d 1 } { $d <= 5 } {incr d} {
89
 
                set r [eval {$db put} $txn $flags {$key_set(2) dup_$d}]
90
 
                error_check_good dup:put $r 0
91
 
        }
92
 
 
93
 
        # Now put the cursor on key 1
94
 
 
95
 
        # Now set the cursor on the first of the duplicate set.
96
 
        set r [$curs get -set $key_set(1)]
97
 
        error_check_bad cursor_get:DB_SET [llength $r] 0
98
 
        set k [lindex [lindex $r 0] 0]
99
 
        set d [lindex [lindex $r 0] 1]
100
 
        error_check_good curs_get:DB_SET:key $k $key_set(1)
101
 
        error_check_good curs_get:DB_SET:data $d datum$key_set(1)
102
 
 
103
 
        # Now do the delete
104
 
        set r [$curs del]
105
 
        error_check_good delete $r 0
106
 
 
107
 
        # Now check the get current on the cursor.
108
 
        error_check_good curs_get:del [$curs get -current] [list [list [] []]]
109
 
 
110
 
        # Now do a put on the key
111
 
        set r [eval {$db put} $txn $flags {$key_set(1) new_datum$key_set(1)}]
112
 
        error_check_good put $r 0
113
 
 
114
 
        # Do a get
115
 
        set r [eval {$db get} $txn {$key_set(1)}]
116
 
        error_check_good get [lindex [lindex $r 0] 1] new_datum$key_set(1)
117
 
 
118
 
        # Recheck cursor
119
 
        error_check_good curs_get:deleted [$curs get -current] [list [list [] []]]
120
 
 
121
 
        # Move cursor and see if we get the key.
122
 
        set r [$curs get -first]
123
 
        error_check_bad cursor_get:DB_FIRST [llength $r] 0
124
 
        set k [lindex [lindex $r 0] 0]
125
 
        set d [lindex [lindex $r 0] 1]
126
 
        error_check_good curs_get:DB_FIRST:key $k $key_set(1)
127
 
        error_check_good curs_get:DB_FIRST:data $d new_datum$key_set(1)
128
 
 
129
 
        puts "\tTest057.b: Set two cursor on a key, delete one, overwrite other"
130
 
        set curs2 [eval {$db cursor} $txn]
131
 
        error_check_good curs2_open [is_valid_cursor $curs2 $db] TRUE
132
 
 
133
 
        # Set both cursors on the 4rd key
134
 
        set r [$curs get -set $key_set(3)]
135
 
        error_check_bad cursor_get:DB_SET [llength $r] 0
136
 
        set k [lindex [lindex $r 0] 0]
137
 
        set d [lindex [lindex $r 0] 1]
138
 
        error_check_good curs_get:DB_SET:key $k $key_set(3)
139
 
        error_check_good curs_get:DB_SET:data $d datum$key_set(3)
140
 
 
141
 
        set r [$curs2 get -set $key_set(3)]
142
 
        error_check_bad cursor2_get:DB_SET [llength $r] 0
143
 
        set k [lindex [lindex $r 0] 0]
144
 
        set d [lindex [lindex $r 0] 1]
145
 
        error_check_good curs2_get:DB_SET:key $k $key_set(3)
146
 
        error_check_good curs2_get:DB_SET:data $d datum$key_set(3)
147
 
 
148
 
        # Now delete through cursor 1
149
 
        error_check_good curs1_del [$curs del] 0
150
 
 
151
 
        # Verify gets on both 1 and 2
152
 
        error_check_good curs_get:deleted [$curs get -current] \
153
 
            [list [list [] []]]
154
 
        error_check_good curs_get:deleted [$curs2 get -current] \
155
 
            [list [list [] []]]
156
 
 
157
 
        # Now do a replace through cursor 2
158
 
        set pflags "-current"
159
 
        if {[is_hash $method] == 1} {
160
 
                error_check_good curs1_get_after_del [is_substr \
161
 
                    [$curs2 put $pflags new_datum$key_set(3)] "DB_NOTFOUND"] 1
162
 
 
163
 
                # Gets fail
164
 
                error_check_good curs1_get:deleted  \
165
 
                    [$curs get -current] \
166
 
                    [list [list [] []]]
167
 
                error_check_good curs2_get:deleted  \
168
 
                    [$curs get -current] \
169
 
                    [list [list [] []]]
170
 
        } else {
171
 
                # btree only, recno is skipped this test
172
 
                set ret [$curs2 put $pflags new_datum$key_set(3)]
173
 
                error_check_good curs_replace $ret 0
174
 
        }
175
 
 
176
 
        # Gets fail
177
 
        #error_check_good curs1_get:deleted [catch {$curs get -current} r] 1
178
 
        #error_check_good curs1_get_after_del \
179
 
            [is_substr $errorInfo "DB_KEYEMPTY"] 1
180
 
        #error_check_good curs2_get:deleted [catch {$curs2 get -current} r] 1
181
 
        #error_check_good curs2_get_after_del \
182
 
            [is_substr $errorInfo "DB_KEYEMPTY"] 1
183
 
 
184
 
        puts "\tTest057.c:\
185
 
            Set two cursors on a dup, delete one, overwrite other"
186
 
 
187
 
        # Set both cursors on the 2nd duplicate of key 2
188
 
        set r [$curs get -set $key_set(2)]
189
 
        error_check_bad cursor_get:DB_SET [llength $r] 0
190
 
        set k [lindex [lindex $r 0] 0]
191
 
        set d [lindex [lindex $r 0] 1]
192
 
        error_check_good curs_get:DB_SET:key $k $key_set(2)
193
 
        error_check_good curs_get:DB_SET:data $d datum$key_set(2)
194
 
 
195
 
        set r [$curs get -next]
196
 
        error_check_bad cursor_get:DB_NEXT [llength $r] 0
197
 
        set k [lindex [lindex $r 0] 0]
198
 
        set d [lindex [lindex $r 0] 1]
199
 
        error_check_good curs_get:DB_NEXT:key $k $key_set(2)
200
 
        error_check_good curs_get:DB_NEXT:data $d dup_1
201
 
 
202
 
        set r [$curs2 get -set $key_set(2)]
203
 
        error_check_bad cursor2_get:DB_SET [llength $r] 0
204
 
        set k [lindex [lindex $r 0] 0]
205
 
        set d [lindex [lindex $r 0] 1]
206
 
        error_check_good curs2_get:DB_SET:key $k $key_set(2)
207
 
        error_check_good curs2_get:DB_SET:data $d datum$key_set(2)
208
 
 
209
 
        set r [$curs2 get -next]
210
 
        error_check_bad cursor2_get:DB_NEXT [llength $r] 0
211
 
        set k [lindex [lindex $r 0] 0]
212
 
        set d [lindex [lindex $r 0] 1]
213
 
        error_check_good curs2_get:DB_NEXT:key $k $key_set(2)
214
 
        error_check_good curs2_get:DB_NEXT:data $d dup_1
215
 
 
216
 
        # Now delete through cursor 1
217
 
        error_check_good curs1_del [$curs del] 0
218
 
 
219
 
        # Verify gets on both 1 and 2
220
 
        error_check_good curs_get:deleted [$curs get -current] \
221
 
            [list [list [] []]]
222
 
        error_check_good curs_get:deleted [$curs2 get -current] \
223
 
            [list [list [] []]]
224
 
 
225
 
        # Now do a replace through cursor 2 -- this will work on btree but
226
 
        # not on hash
227
 
        if {[is_hash $method] == 1} {
228
 
                error_check_good hash_replace \
229
 
                    [is_substr [$curs2 put -current new_dup_1] "DB_NOTFOUND"] 1
230
 
        } else {
231
 
                error_check_good curs_replace [$curs2 put -current new_dup_1] 0
232
 
        }
233
 
 
234
 
        # Both gets should fail
235
 
        #error_check_good curs1_get:deleted [catch {$curs get -current} r] 1
236
 
        #error_check_good curs1_get_after_del \
237
 
            [is_substr $errorInfo "DB_KEYEMPTY"] 1
238
 
        #error_check_good curs2_get:deleted [catch {$curs2 get -current} r] 1
239
 
        #error_check_good curs2_get_after_del \
240
 
            [is_substr $errorInfo "DB_KEYEMPTY"] 1
241
 
 
242
 
        error_check_good curs2_close [$curs2 close] 0
243
 
        error_check_good curs_close [$curs close] 0
244
 
        if { $txnenv == 1 } {
245
 
                error_check_good txn [$t commit] 0
246
 
        }
247
 
        error_check_good db_close [$db close] 0
248
 
}