1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Small keys/medium data
10
# TEST Put/get per key
15
# TEST Use the first 10,000 entries from the dictionary.
16
# TEST Insert each with self as key and a fixed, medium length data string;
17
# TEST retrieve each. After all are entered, retrieve all; compare output
18
# TEST to original. Close file, reopen, do retrieve and re-verify.
20
proc test002 { method {nentries 10000} args } {
25
set args [convert_args $method $args]
26
set omethod [convert_method $method]
29
set eindex [lsearch -exact $args "-env"]
31
# If we are using an env, then testfile should just be the db name.
32
# Otherwise it is the test directory and the name.
33
if { $eindex == -1 } {
34
set testfile $testdir/test002.db
37
set testfile test002.db
39
set env [lindex $args $eindex]
40
set txnenv [is_txnenv $env]
42
append args " -auto_commit "
44
# If we are using txns and running with the
45
# default, set the default down a bit.
47
if { $nentries == 10000 } {
51
set testdir [get_home $env]
53
# Create the database and open the dictionary
54
puts "Test002: $method ($args) $nentries key <fixed data> pairs"
60
set db [eval {berkdb_open \
61
-create -mode 0644} $args {$omethod $testfile}]
62
error_check_good dbopen [is_valid_db $db] TRUE
70
# Here is the loop where we put and get each key/data pair
72
if { [is_record_based $method] == 1 } {
73
append gflags "-recno"
75
set pad_datastr [pad_data $method $datastr]
76
puts "\tTest002.a: put/get loop"
77
while { [gets $did str] != -1 && $count < $nentries } {
78
if { [is_record_based $method] == 1 } {
79
set key [expr $count + 1]
85
error_check_good txn [is_valid_txn $t $env] TRUE
88
set ret [eval {$db put} $txn $pflags {$key [chop_data $method $datastr]}]
89
error_check_good put $ret 0
91
error_check_good txn [$t commit] 0
94
set ret [eval {$db get} $gflags {$key}]
96
error_check_good get $ret [list [list $key [pad_data $method $datastr]]]
101
# Now we will get each key from the DB and compare the results
103
puts "\tTest002.b: dump file"
104
if { $txnenv == 1 } {
106
error_check_good txn [is_valid_txn $t $env] TRUE
109
dump_file $db $txn $t1 test002.check
110
if { $txnenv == 1 } {
111
error_check_good txn [$t commit] 0
113
error_check_good db_close [$db close] 0
115
# Now compare the keys to see if they match the dictionary
116
if { [is_record_based $method] == 1 } {
118
for {set i 1} {$i <= $nentries} {set i [incr i]} {
123
file rename -force $t3 $t2
126
filehead $nentries $dict $t3
131
error_check_good Test002:diff($t3,$t2) \
134
# Now, reopen the file and run the last test again.
135
puts "\tTest002.c: close, open, and dump file"
136
open_and_dump_file $testfile $env $t1 test002.check \
137
dump_file_direction "-first" "-next"
139
if { [string compare $omethod "-recno"] != 0 } {
142
error_check_good Test002:diff($t3,$t2) \
145
# Now, reopen the file and run the last test again in reverse direction.
146
puts "\tTest002.d: close, open, and dump file in reverse direction"
147
open_and_dump_file $testfile $env $t1 test002.check \
148
dump_file_direction "-last" "-prev"
150
if { [string compare $omethod "-recno"] != 0 } {
153
error_check_good Test002:diff($t3,$t2) \
157
# Check function for test002; data should be fixed are identical
158
proc test002.check { key data } {
160
error_check_good "data mismatch for key $key" $data $pad_datastr