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

« back to all changes in this revision

Viewing changes to libdb/test/test054.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  test054
9
 
# TEST  Cursor maintenance during key/data deletion.
10
 
# TEST
11
 
# TEST  This test checks for cursor maintenance in the presence of deletes.
12
 
# TEST  There are N different scenarios to tests:
13
 
# TEST   1. No duplicates.  Cursor A deletes a key, do a  GET for the key.
14
 
# TEST   2. No duplicates.  Cursor is positioned right before key K, Delete K,
15
 
# TEST      do a next on the cursor.
16
 
# TEST   3. No duplicates.  Cursor is positioned on key K, do a regular delete
17
 
# TEST      of K, do a current get on K.
18
 
# TEST   4. Repeat 3 but do a next instead of current.
19
 
# TEST   5. Duplicates. Cursor A is on the first item of a duplicate set, A
20
 
# TEST      does a delete.  Then we do a non-cursor get.
21
 
# TEST   6. Duplicates.  Cursor A is in a duplicate set and deletes the item.
22
 
# TEST      do a delete of the entire Key. Test cursor current.
23
 
# TEST   7. Continue last test and try cursor next.
24
 
# TEST   8. Duplicates.  Cursor A is in a duplicate set and deletes the item.
25
 
# TEST      Cursor B is in the same duplicate set and deletes a different item.
26
 
# TEST      Verify that the cursor is in the right place.
27
 
# TEST   9. Cursors A and B are in the place in the same duplicate set.  A
28
 
# TEST      deletes its item.  Do current on B.
29
 
# TEST  10. Continue 8 and do a next on B.
30
 
proc test054 { method args } {
31
 
        global errorInfo
32
 
        source ./include.tcl
33
 
 
34
 
        set args [convert_args $method $args]
35
 
        set omethod [convert_method $method]
36
 
 
37
 
        append args " -create -mode 0644"
38
 
        puts "Test054 ($method $args):\
39
 
            interspersed cursor and normal operations"
40
 
        if { [is_record_based $method] == 1 } {
41
 
                puts "Test054 skipping for method $method"
42
 
                return
43
 
        }
44
 
 
45
 
        # Find the environment in the argument list, we'll need it
46
 
        # later.
47
 
        set txnenv 0
48
 
        set eindex [lsearch -exact $args "-env"]
49
 
        if { $eindex != -1 } {
50
 
                incr eindex
51
 
        }
52
 
 
53
 
        # Create the database and open the dictionary
54
 
        #
55
 
        # If we are using an env, then testfile should just be the db name.
56
 
        # Otherwise it is the test directory and the name.
57
 
        if { $eindex == -1 } {
58
 
                set testfile $testdir/test054-nodup.db
59
 
                set env NULL
60
 
        } else {
61
 
                set testfile test054-nodup.db
62
 
                set env [lindex $args $eindex]
63
 
                set txnenv [is_txnenv $env]
64
 
                if { $txnenv == 1 } {
65
 
                        append args " -auto_commit "
66
 
                }
67
 
                set testdir [get_home $env]
68
 
        }
69
 
        cleanup $testdir $env
70
 
 
71
 
        set flags ""
72
 
        set txn ""
73
 
 
74
 
        puts "\tTest054.a: No Duplicate Tests"
75
 
        set db [eval {berkdb_open} $args {$omethod $testfile}]
76
 
        error_check_good db_open:nodup [is_valid_db $db] TRUE
77
 
 
78
 
        # Put three keys in the database
79
 
        for { set key 1 } { $key <= 3 } {incr key} {
80
 
                if { $txnenv == 1 } {
81
 
                        set t [$env txn]
82
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
83
 
                        set txn "-txn $t"
84
 
                }
85
 
                set r [eval {$db put} $txn $flags {$key datum$key}]
86
 
                error_check_good put $r 0
87
 
                if { $txnenv == 1 } {
88
 
                        error_check_good txn [$t commit] 0
89
 
                }
90
 
        }
91
 
 
92
 
        if { $txnenv == 1 } {
93
 
                set t [$env txn]
94
 
                error_check_good txn [is_valid_txn $t $env] TRUE
95
 
                set txn "-txn $t"
96
 
        }
97
 
        set curs [eval {$db cursor} $txn]
98
 
        error_check_good curs_open:nodup [is_valid_cursor $curs $db] TRUE
99
 
 
100
 
        # Retrieve keys sequentially so we can figure out their order
101
 
        set i 1
102
 
        for {set d [$curs get -first] } \
103
 
            {[llength $d] != 0 } \
104
 
                 {set d [$curs get -next] } {
105
 
                set key_set($i) [lindex [lindex $d 0] 0]
106
 
                incr i
107
 
        }
108
 
 
109
 
        # Test case #1.
110
 
        puts "\tTest054.a1: Delete w/cursor, regular get"
111
 
 
112
 
        # Now set the cursor on the middle on.
113
 
        set r [$curs get -set $key_set(2)]
114
 
        error_check_bad cursor_get:DB_SET [llength $r] 0
115
 
        set k [lindex [lindex $r 0] 0]
116
 
        set d [lindex [lindex $r 0] 1]
117
 
        error_check_good curs_get:DB_SET:key $k $key_set(2)
118
 
        error_check_good curs_get:DB_SET:data $d datum$key_set(2)
119
 
 
120
 
        # Now do the delete
121
 
        set r [$curs del]
122
 
        error_check_good curs_del $r 0
123
 
 
124
 
        # Now do the get
125
 
        set r [eval {$db get} $txn {$key_set(2)}]
126
 
        error_check_good get_after_del [llength $r] 0
127
 
 
128
 
        # Free up the cursor.
129
 
        error_check_good cursor_close [eval {$curs close}] 0
130
 
        if { $txnenv == 1 } {
131
 
                error_check_good txn [$t commit] 0
132
 
        }
133
 
 
134
 
        # Test case #2.
135
 
        puts "\tTest054.a2: Cursor before K, delete K, cursor next"
136
 
 
137
 
        # Replace key 2
138
 
        if { $txnenv == 1 } {
139
 
                set t [$env txn]
140
 
                error_check_good txn [is_valid_txn $t $env] TRUE
141
 
                set txn "-txn $t"
142
 
        }
143
 
        set r [eval {$db put} $txn {$key_set(2) datum$key_set(2)}]
144
 
        error_check_good put $r 0
145
 
        if { $txnenv == 1 } {
146
 
                error_check_good txn [$t commit] 0
147
 
        }
148
 
 
149
 
        # Open and position cursor on first item.
150
 
        if { $txnenv == 1 } {
151
 
                set t [$env txn]
152
 
                error_check_good txn [is_valid_txn $t $env] TRUE
153
 
                set txn "-txn $t"
154
 
        }
155
 
        set curs [eval {$db cursor} $txn]
156
 
        error_check_good curs_open:nodup [is_valid_cursor $curs $db] TRUE
157
 
 
158
 
        # Retrieve keys sequentially so we can figure out their order
159
 
        set i 1
160
 
        for {set d [eval {$curs get} -first] } \
161
 
            {[llength $d] != 0 } \
162
 
                 {set d [$curs get -nextdup] } {
163
 
                set key_set($i) [lindex [lindex $d 0] 0]
164
 
                incr i
165
 
        }
166
 
 
167
 
        set r [eval {$curs get} -set {$key_set(1)} ]
168
 
        error_check_bad cursor_get:DB_SET [llength $r] 0
169
 
        set k [lindex [lindex $r 0] 0]
170
 
        set d [lindex [lindex $r 0] 1]
171
 
        error_check_good curs_get:DB_SET:key $k $key_set(1)
172
 
        error_check_good curs_get:DB_SET:data $d datum$key_set(1)
173
 
 
174
 
        # Now delete (next item) $key_set(2)
175
 
        error_check_good \
176
 
            db_del:$key_set(2) [eval {$db del} $txn {$key_set(2)}] 0
177
 
 
178
 
        # Now do next on cursor
179
 
        set r [$curs get -next]
180
 
        error_check_bad cursor_get:DB_NEXT [llength $r] 0
181
 
        set k [lindex [lindex $r 0] 0]
182
 
        set d [lindex [lindex $r 0] 1]
183
 
        error_check_good curs_get:DB_NEXT:key $k $key_set(3)
184
 
        error_check_good curs_get:DB_NEXT:data $d datum$key_set(3)
185
 
 
186
 
        # Test case #3.
187
 
        puts "\tTest054.a3: Cursor on K, delete K, cursor current"
188
 
 
189
 
        # delete item 3
190
 
        error_check_good \
191
 
            db_del:$key_set(3) [eval {$db del} $txn {$key_set(3)}] 0
192
 
        # NEEDS TO COME BACK IN, BUG CHECK
193
 
        set ret [$curs get -current]
194
 
        error_check_good current_after_del $ret [list [list [] []]]
195
 
        error_check_good cursor_close [$curs close] 0
196
 
        if { $txnenv == 1 } {
197
 
                error_check_good txn [$t commit] 0
198
 
        }
199
 
 
200
 
        puts "\tTest054.a4: Cursor on K, delete K, cursor next"
201
 
 
202
 
        # Restore keys 2 and 3
203
 
        if { $txnenv == 1 } {
204
 
                set t [$env txn]
205
 
                error_check_good txn [is_valid_txn $t $env] TRUE
206
 
                set txn "-txn $t"
207
 
        }
208
 
        set r [eval {$db put} $txn {$key_set(2) datum$key_set(2)}]
209
 
        error_check_good put $r 0
210
 
        set r [eval {$db put} $txn {$key_set(3) datum$key_set(3)}]
211
 
        error_check_good put $r 0
212
 
        if { $txnenv == 1 } {
213
 
                error_check_good txn [$t commit] 0
214
 
        }
215
 
 
216
 
        if { $txnenv == 1 } {
217
 
                set t [$env txn]
218
 
                error_check_good txn [is_valid_txn $t $env] TRUE
219
 
                set txn "-txn $t"
220
 
        }
221
 
        # Create the new cursor and put it on 1
222
 
        set curs [eval {$db cursor} $txn]
223
 
        error_check_good curs_open:nodup [is_valid_cursor $curs $db] TRUE
224
 
        set r [$curs get -set $key_set(1)]
225
 
        error_check_bad cursor_get:DB_SET [llength $r] 0
226
 
        set k [lindex [lindex $r 0] 0]
227
 
        set d [lindex [lindex $r 0] 1]
228
 
        error_check_good curs_get:DB_SET:key $k $key_set(1)
229
 
        error_check_good curs_get:DB_SET:data $d datum$key_set(1)
230
 
 
231
 
        # Delete 2
232
 
        error_check_good \
233
 
            db_del:$key_set(2) [eval {$db del} $txn {$key_set(2)}] 0
234
 
 
235
 
        # Now do next on cursor
236
 
        set r [$curs get -next]
237
 
        error_check_bad cursor_get:DB_NEXT [llength $r] 0
238
 
        set k [lindex [lindex $r 0] 0]
239
 
        set d [lindex [lindex $r 0] 1]
240
 
        error_check_good curs_get:DB_NEXT:key $k $key_set(3)
241
 
        error_check_good curs_get:DB_NEXT:data $d datum$key_set(3)
242
 
 
243
 
        # Close cursor
244
 
        error_check_good curs_close [$curs close] 0
245
 
        if { $txnenv == 1 } {
246
 
                error_check_good txn [$t commit] 0
247
 
        }
248
 
        error_check_good db_close [$db close] 0
249
 
 
250
 
        # Now get ready for duplicate tests
251
 
 
252
 
        if { [is_rbtree $method] == 1 } {
253
 
                puts "Test054: skipping remainder of test for method $method."
254
 
                return
255
 
        }
256
 
 
257
 
        puts "\tTest054.b: Duplicate Tests"
258
 
        append args " -dup"
259
 
 
260
 
        # Open a new database for the dup tests so -truncate is not needed.
261
 
        # If we are using an env, then testfile should just be the db name.
262
 
        # Otherwise it is the test directory and the name.
263
 
        if { $eindex == -1 } {
264
 
                set testfile $testdir/test054-dup.db
265
 
                set env NULL
266
 
        } else {
267
 
                set testfile test054-dup.db
268
 
                set env [lindex $args $eindex]
269
 
                set testdir [get_home $env]
270
 
        }
271
 
        cleanup $testdir $env
272
 
 
273
 
        set flags ""
274
 
        set txn ""
275
 
 
276
 
        set db [eval {berkdb_open} $args {$omethod $testfile}]
277
 
        error_check_good db_open:dup [is_valid_db $db] TRUE
278
 
 
279
 
        # Put three keys in the database
280
 
        for { set key 1 } { $key <= 3 } {incr key} {
281
 
                if { $txnenv == 1 } {
282
 
                        set t [$env txn]
283
 
                        error_check_good txn [is_valid_txn $t $env] TRUE
284
 
                        set txn "-txn $t"
285
 
                }
286
 
                set r [eval {$db put} $txn $flags {$key datum$key}]
287
 
                error_check_good put $r 0
288
 
                if { $txnenv == 1 } {
289
 
                        error_check_good txn [$t commit] 0
290
 
                }
291
 
        }
292
 
 
293
 
        # Retrieve keys sequentially so we can figure out their order
294
 
        if { $txnenv == 1 } {
295
 
                set t [$env txn]
296
 
                error_check_good txn [is_valid_txn $t $env] TRUE
297
 
                set txn "-txn $t"
298
 
        }
299
 
        set curs [eval {$db cursor} $txn]
300
 
        error_check_good curs_open:dup [is_valid_cursor $curs $db] TRUE
301
 
 
302
 
        set i 1
303
 
        for {set d [$curs get -first] } \
304
 
            {[llength $d] != 0 } \
305
 
                 {set d [$curs get -nextdup] } {
306
 
                set key_set($i) [lindex [lindex $d 0] 0]
307
 
                incr i
308
 
        }
309
 
 
310
 
        # Now put in a bunch of duplicates for key 2
311
 
        for { set d 1 } { $d <= 5 } {incr d} {
312
 
                set r [eval {$db put} $txn $flags {$key_set(2) dup_$d}]
313
 
                error_check_good dup:put $r 0
314
 
        }
315
 
 
316
 
        # Test case #5.
317
 
        puts "\tTest054.b1: Delete dup w/cursor on first item.  Get on key."
318
 
 
319
 
        # Now set the cursor on the first of the duplicate set.
320
 
        set r [eval {$curs get} -set {$key_set(2)}]
321
 
        error_check_bad cursor_get:DB_SET [llength $r] 0
322
 
        set k [lindex [lindex $r 0] 0]
323
 
        set d [lindex [lindex $r 0] 1]
324
 
        error_check_good curs_get:DB_SET:key $k $key_set(2)
325
 
        error_check_good curs_get:DB_SET:data $d datum$key_set(2)
326
 
 
327
 
        # Now do the delete
328
 
        set r [$curs del]
329
 
        error_check_good curs_del $r 0
330
 
 
331
 
        # Now do the get
332
 
        set r [eval {$db get} $txn {$key_set(2)}]
333
 
        error_check_good get_after_del [lindex [lindex $r 0] 1] dup_1
334
 
 
335
 
        # Test case #6.
336
 
        puts "\tTest054.b2: Now get the next duplicate from the cursor."
337
 
 
338
 
        # Now do next on cursor
339
 
        set r [$curs get -nextdup]
340
 
        error_check_bad cursor_get:DB_NEXT [llength $r] 0
341
 
        set k [lindex [lindex $r 0] 0]
342
 
        set d [lindex [lindex $r 0] 1]
343
 
        error_check_good curs_get:DB_NEXT:key $k $key_set(2)
344
 
        error_check_good curs_get:DB_NEXT:data $d dup_1
345
 
 
346
 
        # Test case #3.
347
 
        puts "\tTest054.b3: Two cursors in set; each delete different items"
348
 
 
349
 
        # Open a new cursor.
350
 
        set curs2 [eval {$db cursor} $txn]
351
 
        error_check_good curs_open [is_valid_cursor $curs2 $db] TRUE
352
 
 
353
 
        # Set on last of duplicate set.
354
 
        set r [$curs2 get -set $key_set(3)]
355
 
        error_check_bad cursor_get:DB_SET [llength $r] 0
356
 
        set k [lindex [lindex $r 0] 0]
357
 
        set d [lindex [lindex $r 0] 1]
358
 
        error_check_good curs_get:DB_SET:key $k $key_set(3)
359
 
        error_check_good curs_get:DB_SET:data $d datum$key_set(3)
360
 
 
361
 
        set r [$curs2 get -prev]
362
 
        error_check_bad cursor_get:DB_PREV [llength $r] 0
363
 
        set k [lindex [lindex $r 0] 0]
364
 
        set d [lindex [lindex $r 0] 1]
365
 
        error_check_good curs_get:DB_PREV:key $k $key_set(2)
366
 
        error_check_good curs_get:DB_PREV:data $d dup_5
367
 
 
368
 
        # Delete the item at cursor 1 (dup_1)
369
 
        error_check_good curs1_del [$curs del] 0
370
 
 
371
 
        # Verify curs1 and curs2
372
 
        # current should fail
373
 
        set ret [$curs get -current]
374
 
        error_check_good \
375
 
            curs1_get_after_del $ret [list [list [] []]]
376
 
 
377
 
        set r [$curs2 get -current]
378
 
        error_check_bad curs2_get [llength $r] 0
379
 
        set k [lindex [lindex $r 0] 0]
380
 
        set d [lindex [lindex $r 0] 1]
381
 
        error_check_good curs_get:DB_CURRENT:key $k $key_set(2)
382
 
        error_check_good curs_get:DB_CURRENT:data $d dup_5
383
 
 
384
 
        # Now delete the item at cursor 2 (dup_5)
385
 
        error_check_good curs2_del [$curs2 del] 0
386
 
 
387
 
        # Verify curs1 and curs2
388
 
        set ret [$curs get -current]
389
 
        error_check_good curs1_get:del2 $ret [list [list [] []]]
390
 
 
391
 
        set ret [$curs2 get -current]
392
 
        error_check_good curs2_get:del2 $ret [list [list [] []]]
393
 
 
394
 
        # Now verify that next and prev work.
395
 
 
396
 
        set r [$curs2 get -prev]
397
 
        error_check_bad cursor_get:DB_PREV [llength $r] 0
398
 
        set k [lindex [lindex $r 0] 0]
399
 
        set d [lindex [lindex $r 0] 1]
400
 
        error_check_good curs_get:DB_PREV:key $k $key_set(2)
401
 
        error_check_good curs_get:DB_PREV:data $d dup_4
402
 
 
403
 
        set r [$curs get -next]
404
 
        error_check_bad cursor_get:DB_NEXT [llength $r] 0
405
 
        set k [lindex [lindex $r 0] 0]
406
 
        set d [lindex [lindex $r 0] 1]
407
 
        error_check_good curs_get:DB_NEXT:key $k $key_set(2)
408
 
        error_check_good curs_get:DB_NEXT:data $d dup_2
409
 
 
410
 
        puts "\tTest054.b4: Two cursors same item, one delete, one get"
411
 
 
412
 
        # Move curs2 onto dup_2
413
 
        set r [$curs2 get -prev]
414
 
        error_check_bad cursor_get:DB_PREV [llength $r] 0
415
 
        set k [lindex [lindex $r 0] 0]
416
 
        set d [lindex [lindex $r 0] 1]
417
 
        error_check_good curs_get:DB_PREV:key $k $key_set(2)
418
 
        error_check_good curs_get:DB_PREV:data $d dup_3
419
 
 
420
 
        set r [$curs2 get -prev]
421
 
        error_check_bad cursor_get:DB_PREV [llength $r] 0
422
 
        set k [lindex [lindex $r 0] 0]
423
 
        set d [lindex [lindex $r 0] 1]
424
 
        error_check_good curs_get:DB_PREV:key $k $key_set(2)
425
 
        error_check_good curs_get:DB_PREV:data $d dup_2
426
 
 
427
 
        # delete on curs 1
428
 
        error_check_good curs1_del [$curs del] 0
429
 
 
430
 
        # Verify gets on both 1 and 2
431
 
        set ret [$curs get -current]
432
 
        error_check_good \
433
 
            curs1_get:deleted $ret [list [list [] []]]
434
 
        set ret [$curs2 get -current]
435
 
        error_check_good \
436
 
            curs2_get:deleted $ret [list [list [] []]]
437
 
 
438
 
        puts "\tTest054.b5: Now do a next on both cursors"
439
 
 
440
 
        set r [$curs get -next]
441
 
        error_check_bad cursor_get:DB_NEXT [llength $r] 0
442
 
        set k [lindex [lindex $r 0] 0]
443
 
        set d [lindex [lindex $r 0] 1]
444
 
        error_check_good curs_get:DB_NEXT:key $k $key_set(2)
445
 
        error_check_good curs_get:DB_NEXT:data $d dup_3
446
 
 
447
 
        set r [$curs2 get -next]
448
 
        error_check_bad cursor_get:DB_NEXT [llength $r] 0
449
 
        set k [lindex [lindex $r 0] 0]
450
 
        set d [lindex [lindex $r 0] 1]
451
 
        error_check_good curs_get:DB_NEXT:key $k $key_set(2)
452
 
        error_check_good curs_get:DB_NEXT:data $d dup_3
453
 
 
454
 
        # Close cursor
455
 
        error_check_good curs_close [$curs close] 0
456
 
        error_check_good curs2_close [$curs2 close] 0
457
 
        if { $txnenv == 1 } {
458
 
                error_check_good txn [$t commit] 0
459
 
        }
460
 
        error_check_good db_close [$db close] 0
461
 
}