proc test119 { method {tnum "119"} args} {
source ./include.tcl
global alphabet
global errorCode
set args [convert_args $method $args]
set omethod [convert_method $method]
puts "Test$tnum: $method ($args) Test of DB_BUFFER_SMALL."
if { [is_queue $method] == 1 } {
puts "Skipping test$tnum for method $method"
return
}
set txnenv 0
set txn ""
set eindex [lsearch -exact $args "-env"]
if { $eindex == -1 } {
set testfile $testdir/test$tnum.db
set env NULL
} else {
set testfile test$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
puts "\tTest$tnum.a: Set up database."
set db [eval \
{berkdb_open_noerr -create -mode 0644} $args $omethod $testfile]
error_check_good dbopen [is_valid_db $db] TRUE
puts "\tTest$tnum.b: Test db get with -data_buf_size."
set datalength 20
set data [repeat "a" $datalength]
set key 1
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
error_check_good db_put \
[eval {$db put} $txn {$key [chop_data $method $data]}] 0
set ret [eval {$db get} $txn -data_buf_size $datalength $key]
error_check_good db_get_key [lindex [lindex $ret 0] 0] $key
error_check_good db_get_data [lindex [lindex $ret 0] 1] $data
catch {eval {$db get}\
$txn -data_buf_size [expr $datalength - 1] $key} res
error_check_good buffer_small_error [is_substr $res DB_BUFFER_SMALL] 1
error_check_good db_del [eval {$db del} $txn $key] 0
if { $txnenv == 1 } {
error_check_good txn_commit [$t commit] 0
}
puts "\tTest$tnum.c:\
Test cursor get with -data_buf_size and -key_buf_size."
set key $alphabet
set data $alphabet
set nentries 100
set start 100
set bigkey [repeat $key 8192]
set bigdata [repeat $data 8192]
set buffer [expr 64 * 1024]
set bigbuf [expr $buffer * 8]
puts "\tTest$tnum.c1: Populate database."
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set x 5
set y 7
for { set i $start } { $i < [expr $nentries + $start] } { incr i } {
if { [is_record_based $method] == 1 } {
set k $i
} else {
if { [expr $i % $x] == 1 } {
set k $i.$bigkey
} else {
set k $i.$key
}
}
if { [expr $i % $y] == 1 } {
set d $i.$bigdata
} else {
set d $i.$data
}
error_check_good db_put \
[eval {$db put} $txn {$k [chop_data $method $d]}] 0
}
if { $txnenv == 1 } {
error_check_good txn_commit [$t commit] 0
}
puts "\tTest$tnum.c2: Walk the database with a cursor."
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 cursor [is_valid_cursor $curs $db] TRUE
set hashitems {}
set count $start
for { set kd [catch {eval $curs get \
-key_buf_size $buffer -data_buf_size $buffer -first} res] } \
{ $count < [expr $nentries + $start] } \
{ set kd [catch {eval $curs get \
-key_buf_size $buffer -data_buf_size $buffer -next} res] } {
if { $kd == 1 } {
error_check_good buffer_small_error \
[is_substr $errorCode DB_BUFFER_SMALL] 1
if { [expr $count % $x] == 1 } {
set key_buf $bigbuf
} else {
set key_buf $buffer
}
if { [expr $count % $y] == 1 } {
set data_buf $bigbuf
} else {
set data_buf $buffer
}
if { [is_hash $method] == 1 } {
set data_buf $bigbuf
set key_buf $bigbuf
}
set nextbig [catch {eval $curs get -key_buf_size \
$key_buf -data_buf_size $data_buf -next} res]
error_check_good data_big_buffer_get $nextbig 0
set key [lindex [lindex $res 0] 0]
set data [lindex [lindex $res 0] 1]
if { [string first . $key] != -1 } {
set keyindex [string first . $key]
set keynumber \
[string range $key 0 [expr $keyindex - 1]]
} else {
set keynumber $key
}
set dataindex [string first . $data]
set datanumber \
[string range $data 0 [expr $dataindex - 1]]
if { [is_hash $method] == 0 } {
error_check_good key_number $keynumber $count
error_check_good data_number $datanumber $count
} else {
lappend hashitems $keynumber
}
} else {
if { [is_hash $method] == 1 } {
set key [lindex [lindex $res 0] 0]
set keyindex [string first . $key]
set keynumber \
[string range $key 0 [expr $keyindex - 1]]
lappend hashitems $keynumber
}
}
incr count
set errorCode NONE
}
error_check_good curs_close [$curs close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
if { [is_hash $method] == 1 } {
set sortedhashitems [lsort $hashitems]
for { set i $start } \
{ $i < [expr $nentries + $start] } { incr i } {
set hashitem \
[lindex $sortedhashitems [expr $i - $start]]
error_check_good hash_check $hashitem $i
}
}
error_check_good db_close [$db close] 0
}