1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1996,2008 Oracle. All rights reserved. 4# 5# $Id: test025.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST test025 8# TEST DB_APPEND flag test. 9proc test025 { method {nentries 10000} {start 0 } {tnum "025"} args} { 10 global kvals 11 source ./include.tcl 12 13 set args [convert_args $method $args] 14 set omethod [convert_method $method] 15 puts "Test$tnum: $method ($args)" 16 17 if { [string compare $omethod "-btree"] == 0 } { 18 puts "Test$tnum skipping for method BTREE" 19 return 20 } 21 if { [string compare $omethod "-hash"] == 0 } { 22 puts "Test$tnum skipping for method HASH" 23 return 24 } 25 26 # Create the database and open the dictionary 27 set txnenv 0 28 set eindex [lsearch -exact $args "-env"] 29 # 30 # If we are using an env, then testfile should just be the db name. 31 # Otherwise it is the test directory and the name. 32 if { $eindex == -1 } { 33 set testfile $testdir/test$tnum.db 34 set env NULL 35 } else { 36 set testfile test$tnum.db 37 incr eindex 38 set env [lindex $args $eindex] 39 set txnenv [is_txnenv $env] 40 if { $txnenv == 1 } { 41 append args " -auto_commit " 42 # 43 # If we are using txns and running with the 44 # default, set the default down a bit. 45 # 46 if { $nentries == 10000 } { 47 set nentries 100 48 } 49 } 50 set testdir [get_home $env] 51 } 52 set t1 $testdir/t1 53 54 cleanup $testdir $env 55 set db [eval {berkdb_open \ 56 -create -mode 0644} $args {$omethod $testfile}] 57 error_check_good dbopen [is_valid_db $db] TRUE 58 set did [open $dict] 59 60 puts "\tTest$tnum.a: put/get loop" 61 set gflags " -recno" 62 set pflags " -append" 63 set txn "" 64 set checkfunc test025_check 65 66 # Here is the loop where we put and get each key/data pair 67 set count $start 68 set nentries [expr $start + $nentries] 69 if { $count != 0 } { 70 gets $did str 71 set k [expr $count + 1] 72 set kvals($k) [pad_data $method $str] 73 if { $txnenv == 1 } { 74 set t [$env txn] 75 error_check_good txn [is_valid_txn $t $env] TRUE 76 set txn "-txn $t" 77 } 78 set ret [eval {$db put} $txn {$k [chop_data $method $str]}] 79 error_check_good db_put $ret 0 80 if { $txnenv == 1 } { 81 error_check_good txn [$t commit] 0 82 } 83 incr count 84 } 85 86 while { [gets $did str] != -1 && $count < $nentries } { 87 set k [expr $count + 1] 88 set kvals($k) [pad_data $method $str] 89 if { $txnenv == 1 } { 90 set t [$env txn] 91 error_check_good txn [is_valid_txn $t $env] TRUE 92 set txn "-txn $t" 93 } 94 set ret [eval {$db put} $txn $pflags {[chop_data $method $str]}] 95 error_check_good db_put $ret $k 96 97 set ret [eval {$db get} $txn $gflags {$k}] 98 error_check_good \ 99 get $ret [list [list $k [pad_data $method $str]]] 100 if { $txnenv == 1 } { 101 error_check_good txn [$t commit] 0 102 } 103 104 # The recno key will be count + 1, so when we hit 105 # UINT32_MAX - 1, reset to 0. 106 if { $count == [expr 0xfffffffe] } { 107 set count 0 108 } else { 109 incr count 110 } 111 } 112 close $did 113 114 # Now we will get each key from the DB and compare the results 115 # to the original. 116 puts "\tTest$tnum.b: dump file" 117 if { $txnenv == 1 } { 118 set t [$env txn] 119 error_check_good txn [is_valid_txn $t $env] TRUE 120 set txn "-txn $t" 121 } 122 dump_file $db $txn $t1 $checkfunc 123 if { $txnenv == 1 } { 124 error_check_good txn [$t commit] 0 125 } 126 error_check_good db_close [$db close] 0 127 128 puts "\tTest$tnum.c: close, open, and dump file" 129 # Now, reopen the file and run the last test again. 130 open_and_dump_file $testfile $env $t1 $checkfunc \ 131 dump_file_direction -first -next 132 133 # Now, reopen the file and run the last test again in the 134 # reverse direction. 135 puts "\tTest$tnum.d: close, open, and dump file in reverse direction" 136 open_and_dump_file $testfile $env $t1 $checkfunc \ 137 dump_file_direction -last -prev 138} 139 140proc test025_check { key data } { 141 global kvals 142 143 error_check_good key"$key"_exists [info exists kvals($key)] 1 144 error_check_good " key/data mismatch for |$key|" $data $kvals($key) 145} 146