proc test054 { method args } {
global errorInfo
source ./include.tcl
set args [convert_args $method $args]
set omethod [convert_method $method]
append args " -create -mode 0644"
puts "Test054 ($method $args):\
interspersed cursor and normal operations"
if { [is_record_based $method] == 1 } {
puts "Test054 skipping for method $method"
return
}
set txnenv 0
set eindex [lsearch -exact $args "-env"]
if { $eindex != -1 } {
incr eindex
}
if { $eindex == -1 } {
set testfile $testdir/test054-nodup.db
set env NULL
} else {
set testfile test054-nodup.db
set env [lindex $args $eindex]
set txnenv [is_txnenv $env]
if { $txnenv == 1 } {
append args " -auto_commit "
}
set testdir [get_home $env]
}
cleanup $testdir $env
set flags ""
set txn ""
puts "\tTest054.a: No Duplicate Tests"
set db [eval {berkdb_open} $args {$omethod $testfile}]
error_check_good db_open:nodup [is_valid_db $db] TRUE
for { set key 1 } { $key <= 3 } {incr key} {
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set r [eval {$db put} $txn $flags {$key datum$key}]
error_check_good put $r 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
}
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set curs [eval {$db cursor} $txn]
error_check_good curs_open:nodup [is_valid_cursor $curs $db] TRUE
set i 1
for {set d [$curs get -first] } \
{[llength $d] != 0 } \
{set d [$curs get -next] } {
set key_set($i) [lindex [lindex $d 0] 0]
incr i
}
puts "\tTest054.a1: Delete w/cursor, regular get"
set r [$curs get -set $key_set(2)]
error_check_bad cursor_get:DB_SET [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_SET:key $k $key_set(2)
error_check_good curs_get:DB_SET:data $d datum$key_set(2)
set r [$curs del]
error_check_good curs_del $r 0
set r [eval {$db get} $txn {$key_set(2)}]
error_check_good get_after_del [llength $r] 0
error_check_good cursor_close [eval {$curs close}] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
puts "\tTest054.a2: Cursor before K, delete K, cursor next"
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set r [eval {$db put} $txn {$key_set(2) datum$key_set(2)}]
error_check_good put $r 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set curs [eval {$db cursor} $txn]
error_check_good curs_open:nodup [is_valid_cursor $curs $db] TRUE
set i 1
for {set d [eval {$curs get} -first] } \
{[llength $d] != 0 } \
{set d [$curs get -nextdup] } {
set key_set($i) [lindex [lindex $d 0] 0]
incr i
}
set r [eval {$curs get} -set {$key_set(1)} ]
error_check_bad cursor_get:DB_SET [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_SET:key $k $key_set(1)
error_check_good curs_get:DB_SET:data $d datum$key_set(1)
error_check_good \
db_del:$key_set(2) [eval {$db del} $txn {$key_set(2)}] 0
set r [$curs get -next]
error_check_bad cursor_get:DB_NEXT [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_NEXT:key $k $key_set(3)
error_check_good curs_get:DB_NEXT:data $d datum$key_set(3)
puts "\tTest054.a3: Cursor on K, delete K, cursor current"
error_check_good \
db_del:$key_set(3) [eval {$db del} $txn {$key_set(3)}] 0
set ret [$curs get -current]
error_check_good current_after_del $ret [list [list [] []]]
error_check_good cursor_close [$curs close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
puts "\tTest054.a4: Cursor on K, delete K, cursor next"
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set r [eval {$db put} $txn {$key_set(2) datum$key_set(2)}]
error_check_good put $r 0
set r [eval {$db put} $txn {$key_set(3) datum$key_set(3)}]
error_check_good put $r 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set curs [eval {$db cursor} $txn]
error_check_good curs_open:nodup [is_valid_cursor $curs $db] TRUE
set r [$curs get -set $key_set(1)]
error_check_bad cursor_get:DB_SET [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_SET:key $k $key_set(1)
error_check_good curs_get:DB_SET:data $d datum$key_set(1)
error_check_good \
db_del:$key_set(2) [eval {$db del} $txn {$key_set(2)}] 0
set r [$curs get -next]
error_check_bad cursor_get:DB_NEXT [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_NEXT:key $k $key_set(3)
error_check_good curs_get:DB_NEXT:data $d datum$key_set(3)
error_check_good curs_close [$curs close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
error_check_good db_close [$db close] 0
if { [is_rbtree $method] == 1 } {
puts "Test054: skipping remainder of test for method $method."
return
}
puts "\tTest054.b: Duplicate Tests"
append args " -dup"
if { $eindex == -1 } {
set testfile $testdir/test054-dup.db
set env NULL
} else {
set testfile test054-dup.db
set env [lindex $args $eindex]
set testdir [get_home $env]
}
cleanup $testdir $env
set flags ""
set txn ""
set db [eval {berkdb_open} $args {$omethod $testfile}]
error_check_good db_open:dup [is_valid_db $db] TRUE
for { set key 1 } { $key <= 3 } {incr key} {
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set r [eval {$db put} $txn $flags {$key datum$key}]
error_check_good put $r 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
}
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set curs [eval {$db cursor} $txn]
error_check_good curs_open:dup [is_valid_cursor $curs $db] TRUE
set i 1
for {set d [$curs get -first] } \
{[llength $d] != 0 } \
{set d [$curs get -nextdup] } {
set key_set($i) [lindex [lindex $d 0] 0]
incr i
}
for { set d 1 } { $d <= 5 } {incr d} {
set r [eval {$db put} $txn $flags {$key_set(2) dup_$d}]
error_check_good dup:put $r 0
}
puts "\tTest054.b1: Delete dup w/cursor on first item. Get on key."
set r [eval {$curs get} -set {$key_set(2)}]
error_check_bad cursor_get:DB_SET [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_SET:key $k $key_set(2)
error_check_good curs_get:DB_SET:data $d datum$key_set(2)
set r [$curs del]
error_check_good curs_del $r 0
set r [eval {$db get} $txn {$key_set(2)}]
error_check_good get_after_del [lindex [lindex $r 0] 1] dup_1
puts "\tTest054.b2: Now get the next duplicate from the cursor."
set r [$curs get -nextdup]
error_check_bad cursor_get:DB_NEXT [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_NEXT:key $k $key_set(2)
error_check_good curs_get:DB_NEXT:data $d dup_1
puts "\tTest054.b3: Two cursors in set; each delete different items"
set curs2 [eval {$db cursor} $txn]
error_check_good curs_open [is_valid_cursor $curs2 $db] TRUE
set r [$curs2 get -set $key_set(3)]
error_check_bad cursor_get:DB_SET [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_SET:key $k $key_set(3)
error_check_good curs_get:DB_SET:data $d datum$key_set(3)
set r [$curs2 get -prev]
error_check_bad cursor_get:DB_PREV [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_PREV:key $k $key_set(2)
error_check_good curs_get:DB_PREV:data $d dup_5
error_check_good curs1_del [$curs del] 0
set ret [$curs get -current]
error_check_good \
curs1_get_after_del $ret [list [list [] []]]
set r [$curs2 get -current]
error_check_bad curs2_get [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_CURRENT:key $k $key_set(2)
error_check_good curs_get:DB_CURRENT:data $d dup_5
error_check_good curs2_del [$curs2 del] 0
set ret [$curs get -current]
error_check_good curs1_get:del2 $ret [list [list [] []]]
set ret [$curs2 get -current]
error_check_good curs2_get:del2 $ret [list [list [] []]]
set r [$curs2 get -prev]
error_check_bad cursor_get:DB_PREV [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_PREV:key $k $key_set(2)
error_check_good curs_get:DB_PREV:data $d dup_4
set r [$curs get -next]
error_check_bad cursor_get:DB_NEXT [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_NEXT:key $k $key_set(2)
error_check_good curs_get:DB_NEXT:data $d dup_2
puts "\tTest054.b4: Two cursors same item, one delete, one get"
set r [$curs2 get -prev]
error_check_bad cursor_get:DB_PREV [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_PREV:key $k $key_set(2)
error_check_good curs_get:DB_PREV:data $d dup_3
set r [$curs2 get -prev]
error_check_bad cursor_get:DB_PREV [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_PREV:key $k $key_set(2)
error_check_good curs_get:DB_PREV:data $d dup_2
error_check_good curs1_del [$curs del] 0
set ret [$curs get -current]
error_check_good \
curs1_get:deleted $ret [list [list [] []]]
set ret [$curs2 get -current]
error_check_good \
curs2_get:deleted $ret [list [list [] []]]
puts "\tTest054.b5: Now do a next on both cursors"
set r [$curs get -next]
error_check_bad cursor_get:DB_NEXT [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_NEXT:key $k $key_set(2)
error_check_good curs_get:DB_NEXT:data $d dup_3
set r [$curs2 get -next]
error_check_bad cursor_get:DB_NEXT [llength $r] 0
set k [lindex [lindex $r 0] 0]
set d [lindex [lindex $r 0] 1]
error_check_good curs_get:DB_NEXT:key $k $key_set(2)
error_check_good curs_get:DB_NEXT:data $d dup_3
error_check_good curs_close [$curs close] 0
error_check_good curs2_close [$curs2 close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
error_check_good db_close [$db close] 0
}