1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Partial put test
10
# TEST Partial put where the datum gets shorter as a result of the put.
12
# TEST Partial put test where partial puts make the record smaller.
13
# TEST Use the first 10,000 entries from the dictionary.
14
# TEST Insert each with self as key and a fixed, medium length data string;
15
# TEST retrieve each. After all are entered, go back and do partial puts,
16
# TEST replacing a random-length string with the key value.
19
proc test016 { method {nentries 10000} args } {
25
berkdb srand $rand_init
27
set args [convert_args $method $args]
28
set omethod [convert_method $method]
30
if { [is_fixed_length $method] == 1 } {
31
puts "Test016: skipping for method $method"
35
# Create the database and open the dictionary
37
set eindex [lsearch -exact $args "-env"]
39
# If we are using an env, then testfile should just be the db name.
40
# Otherwise it is the test directory and the name.
41
if { $eindex == -1 } {
42
set testfile $testdir/test016.db
45
set testfile test016.db
47
set env [lindex $args $eindex]
48
set txnenv [is_txnenv $env]
50
append args " -auto_commit "
52
# If we are using txns and running with the
53
# default, set the default down a bit.
55
if { $nentries == 10000 } {
59
set testdir [get_home $env]
61
puts "Test016: $method ($args) $nentries partial put shorten"
67
set db [eval {berkdb_open \
68
-create -mode 0644} $args {$omethod $testfile}]
69
error_check_good dbopen [is_valid_db $db] TRUE
76
if { [is_record_based $method] == 1 } {
77
append gflags " -recno"
80
# Here is the loop where we put and get each key/data pair
81
puts "\tTest016.a: put/get loop"
83
while { [gets $did str] != -1 && $count < $nentries } {
84
if { [is_record_based $method] == 1 } {
85
set key [expr $count + 1]
91
error_check_good txn [is_valid_txn $t $env] TRUE
94
set ret [eval {$db put} \
95
$txn $pflags {$key [chop_data $method $datastr]}]
96
error_check_good put $ret 0
98
set ret [eval {$db get} $txn $gflags {$key}]
100
get $ret [list [list $key [pad_data $method $datastr]]]
101
if { $txnenv == 1 } {
102
error_check_good txn [$t commit] 0
108
# Next we will do a partial put replacement, making the data
110
puts "\tTest016.b: partial put loop"
113
set len [string length $datastr]
114
while { [gets $did str] != -1 && $count < $nentries } {
115
if { [is_record_based $method] == 1 } {
116
set key [expr $count + 1]
121
set repl_len [berkdb random_int [string length $key] $len]
122
set repl_off [berkdb random_int 0 [expr $len - $repl_len] ]
123
set s1 [string range $datastr 0 [ expr $repl_off - 1] ]
124
set s2 [string toupper $key]
125
set s3 [string range $datastr [expr $repl_off + $repl_len] end ]
126
set dvals($key) [pad_data $method $s1$s2$s3]
127
if { $txnenv == 1 } {
129
error_check_good txn [is_valid_txn $t $env] TRUE
132
set ret [eval {$db put} $txn {-partial \
133
[list $repl_off $repl_len] $key [chop_data $method $s2]}]
134
error_check_good put $ret 0
135
set ret [eval {$db get} $txn $gflags {$key}]
137
put $ret [list [list $key [pad_data $method $s1$s2$s3]]]
138
if { $txnenv == 1 } {
139
error_check_good txn [$t commit] 0
145
# Now we will get each key from the DB and compare the results
147
puts "\tTest016.c: dump file"
148
if { $txnenv == 1 } {
150
error_check_good txn [is_valid_txn $t $env] TRUE
153
dump_file $db $txn $t1 test016.check
154
if { $txnenv == 1 } {
155
error_check_good txn [$t commit] 0
157
error_check_good db_close [$db close] 0
159
# Now compare the keys to see if they match the dictionary
160
if { [is_record_based $method] == 1 } {
162
for {set i 1} {$i <= $nentries} {set i [incr i]} {
166
file rename -force $t1 $t3
169
filehead $nentries $dict $t3
174
error_check_good Test016:diff($t3,$t2) \
177
# Now, reopen the file and run the last test again.
178
puts "\tTest016.d: close, open, and dump file"
179
open_and_dump_file $testfile $env $t1 test016.check \
180
dump_file_direction "-first" "-next"
182
if { [ is_record_based $method ] == 0 } {
185
error_check_good Test016:diff($t3,$t2) \
188
# Now, reopen the file and run the last test again in reverse direction.
189
puts "\tTest016.e: close, open, and dump file in reverse direction"
190
open_and_dump_file $testfile $env $t1 test016.check \
191
dump_file_direction "-last" "-prev"
193
if { [ is_record_based $method ] == 0 } {
196
error_check_good Test016:diff($t3,$t2) \
200
# Check function for test016; data should be whatever is set in dvals
201
proc test016.check { key data } {
205
error_check_good key"$key"_exists [info exists dvals($key)] 1
206
error_check_good "data mismatch for key $key" $data $dvals($key)