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
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1999-2002
# Sleepycat Software. All rights reserved.
#
# $Id: test072.tcl,v 1.1.1.1 2003/11/20 22:14:02 toshok Exp $
#
# TEST test072
# TEST Test of cursor stability when duplicates are moved off-page.
proc test072 { method {pagesize 512} {ndups 20} {tnum 72} args } {
source ./include.tcl
global alphabet
set omethod [convert_method $method]
set args [convert_args $method $args]
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/test0$tnum.db
set env NULL
} else {
set testfile test0$tnum.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]
}
cleanup $testdir $env
# Keys must sort $prekey < $key < $postkey.
set prekey "a key"
set key "the key"
set postkey "z key"
# Make these distinguishable from each other and from the
# alphabets used for the $key's data.
set predatum "1234567890"
set postdatum "0987654321"
puts -nonewline "Test0$tnum $omethod ($args): "
if { [is_record_based $method] || [is_rbtree $method] } {
puts "Skipping for method $method."
return
} else {
puts "\n Test of cursor stability when\
duplicates are moved off-page."
}
set pgindex [lsearch -exact $args "-pagesize"]
if { $pgindex != -1 } {
puts "Test0$tnum: skipping for specific pagesizes"
return
}
append args " -pagesize $pagesize "
set txn ""
set dlist [list "-dup" "-dup -dupsort"]
set testid 0
foreach dupopt $dlist {
incr testid
set duptestfile $testfile$testid
set db [eval {berkdb_open -create -mode 0644} \
$omethod $args $dupopt {$duptestfile}]
error_check_good "db open" [is_valid_db $db] TRUE
puts \
"\tTest0$tnum.a: ($dupopt) Set up surrounding keys and cursors."
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 {$prekey $predatum}]
error_check_good pre_put $ret 0
set ret [eval {$db put} $txn {$postkey $postdatum}]
error_check_good post_put $ret 0
set precursor [eval {$db cursor} $txn]
error_check_good precursor [is_valid_cursor $precursor \
$db] TRUE
set postcursor [eval {$db cursor} $txn]
error_check_good postcursor [is_valid_cursor $postcursor \
$db] TRUE
error_check_good preset [$precursor get -set $prekey] \
[list [list $prekey $predatum]]
error_check_good postset [$postcursor get -set $postkey] \
[list [list $postkey $postdatum]]
puts "\tTest0$tnum.b: Put/create cursor/verify all cursor loop."
for { set i 0 } { $i < $ndups } { incr i } {
set datum [format "%4d$alphabet" [expr $i + 1000]]
set data($i) $datum
# Uncomment these lines to see intermediate steps.
# error_check_good db_sync($i) [$db sync] 0
# error_check_good db_dump($i) \
# [catch {exec $util_path/db_dump \
# -da $duptestfile > $testdir/out.$i}] 0
set ret [eval {$db put} $txn {$key $datum}]
error_check_good "db put ($i)" $ret 0
set dbc($i) [eval {$db cursor} $txn]
error_check_good "db cursor ($i)"\
[is_valid_cursor $dbc($i) $db] TRUE
error_check_good "dbc get -get_both ($i)"\
[$dbc($i) get -get_both $key $datum]\
[list [list $key $datum]]
for { set j 0 } { $j < $i } { incr j } {
set dbt [$dbc($j) get -current]
set k [lindex [lindex $dbt 0] 0]
set d [lindex [lindex $dbt 0] 1]
#puts "cursor $j after $i: $d"
eval {$db sync}
error_check_good\
"cursor $j key correctness after $i puts" \
$k $key
error_check_good\
"cursor $j data correctness after $i puts" \
$d $data($j)
}
# Check correctness of pre- and post- cursors. Do an
# error_check_good on the lengths first so that we don't
# spew garbage as the "got" field and screw up our
# terminal. (It's happened here.)
set pre_dbt [$precursor get -current]
set post_dbt [$postcursor get -current]
error_check_good \
"key earlier cursor correctness after $i puts" \
[string length [lindex [lindex $pre_dbt 0] 0]] \
[string length $prekey]
error_check_good \
"data earlier cursor correctness after $i puts" \
[string length [lindex [lindex $pre_dbt 0] 1]] \
[string length $predatum]
error_check_good \
"key later cursor correctness after $i puts" \
[string length [lindex [lindex $post_dbt 0] 0]] \
[string length $postkey]
error_check_good \
"data later cursor correctness after $i puts" \
[string length [lindex [lindex $post_dbt 0] 1]]\
[string length $postdatum]
error_check_good \
"earlier cursor correctness after $i puts" \
$pre_dbt [list [list $prekey $predatum]]
error_check_good \
"later cursor correctness after $i puts" \
$post_dbt [list [list $postkey $postdatum]]
}
puts "\tTest0$tnum.c: Reverse Put/create cursor/verify all cursor loop."
set end [expr $ndups * 2 - 1]
for { set i $end } { $i >= $ndups } { set i [expr $i - 1] } {
set datum [format "%4d$alphabet" [expr $i + 1000]]
set data($i) $datum
# Uncomment these lines to see intermediate steps.
# error_check_good db_sync($i) [$db sync] 0
# error_check_good db_dump($i) \
# [catch {exec $util_path/db_dump \
# -da $duptestfile > $testdir/out.$i}] 0
set ret [eval {$db put} $txn {$key $datum}]
error_check_good "db put ($i)" $ret 0
error_check_bad dbc($i)_stomped [info exists dbc($i)] 1
set dbc($i) [eval {$db cursor} $txn]
error_check_good "db cursor ($i)"\
[is_valid_cursor $dbc($i) $db] TRUE
error_check_good "dbc get -get_both ($i)"\
[$dbc($i) get -get_both $key $datum]\
[list [list $key $datum]]
for { set j $i } { $j < $end } { incr j } {
set dbt [$dbc($j) get -current]
set k [lindex [lindex $dbt 0] 0]
set d [lindex [lindex $dbt 0] 1]
#puts "cursor $j after $i: $d"
eval {$db sync}
error_check_good\
"cursor $j key correctness after $i puts" \
$k $key
error_check_good\
"cursor $j data correctness after $i puts" \
$d $data($j)
}
# Check correctness of pre- and post- cursors. Do an
# error_check_good on the lengths first so that we don't
# spew garbage as the "got" field and screw up our
# terminal. (It's happened here.)
set pre_dbt [$precursor get -current]
set post_dbt [$postcursor get -current]
error_check_good \
"key earlier cursor correctness after $i puts" \
[string length [lindex [lindex $pre_dbt 0] 0]] \
[string length $prekey]
error_check_good \
"data earlier cursor correctness after $i puts" \
[string length [lindex [lindex $pre_dbt 0] 1]] \
[string length $predatum]
error_check_good \
"key later cursor correctness after $i puts" \
[string length [lindex [lindex $post_dbt 0] 0]] \
[string length $postkey]
error_check_good \
"data later cursor correctness after $i puts" \
[string length [lindex [lindex $post_dbt 0] 1]]\
[string length $postdatum]
error_check_good \
"earlier cursor correctness after $i puts" \
$pre_dbt [list [list $prekey $predatum]]
error_check_good \
"later cursor correctness after $i puts" \
$post_dbt [list [list $postkey $postdatum]]
}
# Close cursors.
puts "\tTest0$tnum.d: Closing cursors."
for { set i 0 } { $i <= $end } { incr i } {
error_check_good "dbc close ($i)" [$dbc($i) close] 0
}
unset dbc
error_check_good precursor_close [$precursor close] 0
error_check_good postcursor_close [$postcursor close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
error_check_good "db close" [$db close] 0
}
}
|