1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1999-2002
# Sleepycat Software. All rights reserved.
#
# $Id: test052.tcl,v 1.1.1.1 2003/11/20 22:14:01 toshok Exp $
#
# TEST test052
# TEST Renumbering record Recno test.
proc test052 { method args } {
global alphabet
global errorInfo
global errorCode
source ./include.tcl
set args [convert_args $method $args]
set omethod [convert_method $method]
puts "Test052: Test of renumbering recno."
if { [is_rrecno $method] != 1} {
puts "Test052: skipping for method $method."
return
}
set data "data"
set txn ""
set flags ""
puts "\tTest052: Create $method database."
set txnenv 0
set eindex [lsearch -exact $args "-env"]
#
# If we are using an env, then testfile should just be the db name.
# Otherwise it is the test directory and the name.
if { $eindex == -1 } {
set testfile $testdir/test052.db
set env NULL
} else {
set testfile test052.db
incr eindex
set env [lindex $args $eindex]
set txnenv [is_txnenv $env]
if { $txnenv == 1 } {
append args " -auto_commit "
}
set testdir [get_home $env]
}
set t1 $testdir/t1
cleanup $testdir $env
set oflags "-create -mode 0644 $args $omethod"
set db [eval {berkdb_open} $oflags $testfile]
error_check_good dbopen [is_valid_db $db] TRUE
# keep nkeys even
set nkeys 20
# Fill page w/ small key/data pairs
puts "\tTest052: Fill page with $nkeys small key/data pairs."
for { set i 1 } { $i <= $nkeys } { incr i } {
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set ret [eval {$db put} $txn {$i $data$i}]
error_check_good dbput $ret 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
}
# open curs to db
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set dbc [eval {$db cursor} $txn]
error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
# get db order of keys
for {set i 1; set ret [$dbc get -first]} { [llength $ret] != 0} { \
set ret [$dbc get -next]} {
set keys($i) [lindex [lindex $ret 0] 0]
set darray($i) [lindex [lindex $ret 0] 1]
incr i
}
puts "\tTest052: Deletes by key."
puts "\t Test052.a: Get data with SET, then delete before cursor."
# get key in middle of page, call this the nth set curr to it
set i [expr $nkeys/2]
set k $keys($i)
set ret [$dbc get -set $k]
error_check_bad dbc_get:set [llength $ret] 0
error_check_good dbc_get:set [lindex [lindex $ret 0] 1] $darray($i)
# delete by key before current
set i [incr i -1]
error_check_good db_del:before [eval {$db del} $txn {$keys($i)}] 0
# with renumber, current's data should be constant, but key==--key
set i [incr i +1]
error_check_good dbc:data \
[lindex [lindex [$dbc get -current] 0] 1] $darray($i)
error_check_good dbc:keys \
[lindex [lindex [$dbc get -current] 0] 0] $keys([expr $nkeys/2 - 1])
puts "\t Test052.b: Delete cursor item by key."
set i [expr $nkeys/2 ]
set ret [$dbc get -set $keys($i)]
error_check_bad dbc:get [llength $ret] 0
error_check_good dbc:get:curs [lindex [lindex $ret 0] 1] \
$darray([expr $i + 1])
error_check_good db_del:curr [eval {$db del} $txn {$keys($i)}] 0
set ret [$dbc get -current]
# After a delete, cursor should return DB_NOTFOUND.
error_check_good dbc:get:key [llength [lindex [lindex $ret 0] 0]] 0
error_check_good dbc:get:data [llength [lindex [lindex $ret 0] 1]] 0
# And the item after the cursor should now be
# key: $nkeys/2, data: $nkeys/2 + 2
set ret [$dbc get -next]
error_check_bad dbc:getnext [llength $ret] 0
error_check_good dbc:getnext:data \
[lindex [lindex $ret 0] 1] $darray([expr $i + 2])
error_check_good dbc:getnext:keys \
[lindex [lindex $ret 0] 0] $keys($i)
puts "\t Test052.c: Delete item after cursor."
# should be { keys($nkeys/2), darray($nkeys/2 + 2) }
set i [expr $nkeys/2]
# deleting data for key after current (key $nkeys/2 + 1)
error_check_good db_del [eval {$db del} $txn {$keys([expr $i + 1])}] 0
# current should be constant
set ret [$dbc get -current]
error_check_bad dbc:get:current [llength $ret] 0
error_check_good dbc:get:keys [lindex [lindex $ret 0] 0] \
$keys($i)
error_check_good dbc:get:data [lindex [lindex $ret 0] 1] \
$darray([expr $i + 2])
puts "\tTest052: Deletes by cursor."
puts "\t Test052.d: Delete, do DB_NEXT."
set i 1
set ret [$dbc get -first]
error_check_bad dbc_get:first [llength $ret] 0
error_check_good dbc_get:first [lindex [lindex $ret 0] 1] $darray($i)
error_check_good dbc_del [$dbc del] 0
set ret [$dbc get -current]
error_check_bad dbc_get:current [llength $ret] 0
error_check_good dbc:getcurrent:key \
[llength [lindex [lindex $ret 0] 0]] 0
error_check_good dbc:getcurrent:data \
[llength [lindex [lindex $ret 0] 1]] 0
set ret [$dbc get -next]
error_check_bad dbc_get:next [llength $ret] 0
error_check_good dbc:get:curs \
[lindex [lindex $ret 0] 1] $darray([expr $i + 1])
error_check_good dbc:get:keys \
[lindex [lindex $ret 0] 0] $keys($i)
# Move one more forward, so we're not on the first item.
error_check_bad dbc:getnext [llength [$dbc get -next]] 0
puts "\t Test052.e: Delete, do DB_PREV."
error_check_good dbc:del [$dbc del] 0
set ret [$dbc get -current]
error_check_bad dbc:get:curr [llength $ret] 0
error_check_good dbc:getcurrent:key \
[llength [lindex [lindex $ret 0] 0]] 0
error_check_good dbc:getcurrent:data \
[llength [lindex [lindex $ret 0] 1]] 0
# next should now reference the record that was previously after
# old current
set ret [$dbc get -next]
error_check_bad get:next [llength $ret] 0
error_check_good dbc:get:next:data \
[lindex [lindex $ret 0] 1] $darray([expr $i + 3])
error_check_good dbc:get:next:keys \
[lindex [lindex $ret 0] 0] $keys([expr $i + 1])
set ret [$dbc get -prev]
error_check_bad dbc:get:curr [llength $ret] 0
error_check_good dbc:get:curr:compare \
[lindex [lindex $ret 0] 1] $darray([expr $i + 1])
error_check_good dbc:get:curr:keys \
[lindex [lindex $ret 0] 0] $keys($i)
# The rest of the test was written with the old rrecno semantics,
# which required a separate c_del(CURRENT) test; to leave
# the database in the expected state, we now delete the first item.
set ret [$dbc get -first]
error_check_bad getfirst [llength $ret] 0
error_check_good delfirst [$dbc del] 0
puts "\tTest052: Inserts."
puts "\t Test052.g: Insert before (DB_BEFORE)."
set i 1
set ret [$dbc get -first]
error_check_bad dbc:get:first [llength $ret] 0
error_check_good dbc_get:first \
[lindex [lindex $ret 0] 0] $keys($i)
error_check_good dbc_get:first:data \
[lindex [lindex $ret 0] 1] $darray([expr $i + 3])
set ret [$dbc put -before $darray($i)]
# should return new key, which should be $keys($i)
error_check_good dbc_put:before $ret $keys($i)
# cursor should adjust to point to new item
set ret [$dbc get -current]
error_check_bad dbc_get:curr [llength $ret] 0
error_check_good dbc_put:before:keys \
[lindex [lindex $ret 0] 0] $keys($i)
error_check_good dbc_put:before:data \
[lindex [lindex $ret 0] 1] $darray($i)
set ret [$dbc get -next]
error_check_bad dbc_get:next [llength $ret] 0
error_check_good dbc_get:next:compare \
$ret [list [list $keys([expr $i + 1]) $darray([expr $i + 3])]]
set ret [$dbc get -prev]
error_check_bad dbc_get:prev [llength $ret] 0
puts "\t Test052.h: Insert by cursor after (DB_AFTER)."
set i [incr i]
set ret [$dbc put -after $darray($i)]
# should return new key, which should be $keys($i)
error_check_good dbcput:after $ret $keys($i)
# cursor should reference new item
set ret [$dbc get -current]
error_check_good dbc:get:current:keys \
[lindex [lindex $ret 0] 0] $keys($i)
error_check_good dbc:get:current:data \
[lindex [lindex $ret 0] 1] $darray($i)
# items after curs should be adjusted
set ret [$dbc get -next]
error_check_bad dbc:get:next [llength $ret] 0
error_check_good dbc:get:next:compare \
$ret [list [list $keys([expr $i + 1]) $darray([expr $i + 2])]]
puts "\t Test052.i: Insert (overwrite) current item (DB_CURRENT)."
set i 1
set ret [$dbc get -first]
error_check_bad dbc_get:first [llength $ret] 0
# choose a datum that is not currently in db
set ret [$dbc put -current $darray([expr $i + 2])]
error_check_good dbc_put:curr $ret 0
# curs should be on new item
set ret [$dbc get -current]
error_check_bad dbc_get:current [llength $ret] 0
error_check_good dbc_get:curr:keys \
[lindex [lindex $ret 0] 0] $keys($i)
error_check_good dbc_get:curr:data \
[lindex [lindex $ret 0] 1] $darray([expr $i + 2])
set ret [$dbc get -next]
error_check_bad dbc_get:next [llength $ret] 0
set i [incr i]
error_check_good dbc_get:next \
$ret [list [list $keys($i) $darray($i)]]
error_check_good dbc_close [$dbc close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
error_check_good db_close [$db close] 0
puts "\tTest052 complete."
}
|