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 test where the key does not initially exist.
11
proc test015 { method {nentries 7500} { start 0 } args } {
12
global fixed_len testdir
18
if { [is_fixed_length $method] } {
19
set low_range [expr $fixed_len/2 - 2]
20
set mid_range [expr $fixed_len/2]
21
set high_range $fixed_len
27
{ 3 { 1 1 $low_range } }
28
{ 4 { 1 $mid_range 1 } }
29
{ 5 { $mid_range $high_range 5 } }
30
{ 6 { 1 $mid_range $low_range } }
34
$method ($args) $nentries equal key/data pairs, partial put test"
37
set start { 1 2 3 4 5 6 }
39
foreach entry $t_table {
40
set this [lindex $entry 0]
41
if { [lsearch $start $this] == -1 } {
44
puts -nonewline "$this: "
45
eval [concat test015_body $method [lindex $entry 1] \
47
set eindex [lsearch -exact $args "-env"]
48
if { $eindex != -1 } {
50
set env [lindex $args $eindex]
51
set testdir [get_home $env]
53
puts "Verifying testdir $testdir"
55
error_check_good verify [verify_dir $testdir "\tTest015.e: "] 0
59
proc test015_init { } {
62
berkdb srand $rand_init
65
proc test015_body { method off_low off_hi rcount {nentries 10000} args } {
71
set args [convert_args $method $args]
72
set omethod [convert_method $method]
74
set checkfunc test015.check
76
if { [is_fixed_length $method] && \
77
[string compare $omethod "-recno"] == 0} {
78
# is fixed recno method
79
set checkfunc test015.check
82
puts "Put $rcount strings random offsets between $off_low and $off_hi"
84
# Create the database and open the dictionary
86
set eindex [lsearch -exact $args "-env"]
88
# If we are using an env, then testfile should just be the db name.
89
# Otherwise it is the test directory and the name.
90
if { $eindex == -1 } {
91
set testfile $testdir/test015.db
94
set testfile test015.db
96
set env [lindex $args $eindex]
97
set txnenv [is_txnenv $env]
99
append args " -auto_commit "
101
# If we are using txns and running with the
102
# default, set the default down a bit.
104
if { $nentries > 5000 } {
108
set testdir [get_home $env]
114
cleanup $testdir $env
116
set db [eval {berkdb_open \
117
-create -mode 0644} $args {$omethod $testfile}]
118
error_check_good dbopen [is_valid_db $db] TRUE
125
puts "\tTest015.a: put/get loop for $nentries entries"
127
# Here is the loop where we put and get each key/data pair
128
# Each put is a partial put of a record that does not exist.
130
while { [gets $did str] != -1 && $count < $nentries } {
131
if { [is_record_based $method] == 1 } {
132
if { [string length $str] > $fixed_len } {
135
set key [expr $count + 1]
141
set data [replicate $str $rcount]
142
set off [ berkdb random_int $off_low $off_hi ]
143
set offn [expr $off + 1]
144
if { [is_fixed_length $method] && \
145
[expr [string length $data] + $off] >= $fixed_len} {
146
set data [string range $data 0 [expr $fixed_len-$offn]]
148
set dvals($key) [partial_shift $data $off right]
150
set data [chop_data $method [replicate $str $rcount]]
152
# This is a hack. In DB we will store the records with
153
# some padding, but these will get lost if we just return
154
# them in TCL. As a result, we're going to have to hack
155
# get to check for 0 padding and return a list consisting
156
# of the number of 0's and the actual data.
157
set off [ berkdb random_int $off_low $off_hi ]
159
# There is no string concatenation function in Tcl
160
# (although there is one in TclX), so we have to resort
162
set slen [string length $data]
163
if {[is_fixed_length $method] && \
164
$slen > $fixed_len - $off} {
165
set $slen [expr $fixed_len - $off]
168
set dvals($key) [pad_data \
169
$method [eval "binary format x$off$a$slen" {$data}]]
171
if {[is_fixed_length $method] && \
172
[string length $data] > ($fixed_len - $off)} {
173
set slen [expr $fixed_len - $off]
174
set data [eval "binary format a$slen" {$data}]
176
if { $txnenv == 1 } {
178
error_check_good txn [is_valid_txn $t $env] TRUE
181
set ret [eval {$db put} $txn \
182
{-partial [list $off [string length $data]] $key $data}]
183
error_check_good put $ret 0
184
if { $txnenv == 1 } {
185
error_check_good txn [$t commit] 0
192
# Now make sure that everything looks OK
193
puts "\tTest015.b: check entire file contents"
194
if { $txnenv == 1 } {
196
error_check_good txn [is_valid_txn $t $env] TRUE
199
dump_file $db $txn $t1 $checkfunc
200
if { $txnenv == 1 } {
201
error_check_good txn [$t commit] 0
203
error_check_good db_close [$db close] 0
205
# Now compare the keys to see if they match the dictionary (or ints)
206
if { [is_record_based $method] == 1 } {
208
for {set i 1} {$i <= $nentries} {set i [incr i]} {
213
file rename -force $t3 $t2
217
filehead $nentries $dict $t3
222
error_check_good Test015:diff($t3,$t2) \
225
puts "\tTest015.c: close, open, and dump file"
226
# Now, reopen the file and run the last test again.
227
open_and_dump_file $testfile $env $t1 \
228
$checkfunc dump_file_direction "-first" "-next"
230
if { [string compare $omethod "-recno"] != 0 } {
234
error_check_good Test015:diff($t3,$t2) \
237
# Now, reopen the file and run the last test again in the
239
puts "\tTest015.d: close, open, and dump file in reverse direction"
240
open_and_dump_file $testfile $env $t1 \
241
$checkfunc dump_file_direction "-last" "-prev"
243
if { [string compare $omethod "-recno"] != 0 } {
247
error_check_good Test015:diff($t3,$t2) \
253
# Check function for test015; keys and data are identical
254
proc test015.check { key data } {
257
error_check_good key"$key"_exists [info exists dvals($key)] 1
258
binary scan $data "c[string length $data]" a
259
binary scan $dvals($key) "c[string length $dvals($key)]" b
260
error_check_good "mismatch on padding for key $key" $a $b
263
proc test015.fixed.check { key data } {
267
error_check_good key"$key"_exists [info exists dvals($key)] 1
268
if { [string length $data] > $fixed_len } {
270
"data length:[string length $data] \
271
for fixed:$fixed_len" 1 1
273
puts "$data : $dvals($key)"
274
error_check_good compare_data($data,$dvals($key) \