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

« back to all changes in this revision

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