1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Tests large subdb names
10
# TEST subdb name = filecontents,
11
# TEST key = filename, data = filecontents
12
# TEST Put/get per key
14
# TEST Dump subdbs, verify data and subdb name match
16
# TEST Create 1 db with many large subdbs. Use the contents as subdb names.
17
# TEST Take the source files and dbtest executable and enter their names as
18
# TEST the key with their contents as data. After all are entered, retrieve
19
# TEST all; compare output to original. Close file, reopen, do retrieve and
21
proc subdb004 { method args} {
25
set args [convert_args $method $args]
26
set omethod [convert_method $method]
28
if { [is_queue $method] == 1 || [is_fixed_length $method] == 1 } {
29
puts "Subdb004: skipping for method $method"
33
puts "Subdb004: $method ($args) \
34
filecontents=subdbname filename=key filecontents=data pairs"
38
set eindex [lsearch -exact $args "-env"]
40
# If we are using an env, then testfile should just be the db name.
41
# Otherwise it is the test directory and the name.
42
if { $eindex == -1 } {
43
set testfile $testdir/subdb004.db
46
set testfile subdb004.db
48
set env [lindex $args $eindex]
49
set envargs " -env $env "
50
set txnenv [is_txnenv $env]
52
append args " -auto_commit "
53
append envargs " -auto_commit "
55
set testdir [get_home $env]
57
# Create the database and open the dictionary
67
if { [is_record_based $method] == 1 } {
68
set checkfunc subdb004_recno.check
69
append gflags "-recno"
71
set checkfunc subdb004.check
74
# Here is the loop where we put and get each key/data pair
75
# Note that the subdatabase name is passed in as a char *, not
76
# in a DBT, so it may not contain nulls; use only source files.
77
set file_list [glob $src_root/*/*.c]
78
set fcount [llength $file_list]
79
if { $txnenv == 1 && $fcount > 100 } {
80
set file_list [lrange $file_list 0 99]
85
if { [is_record_based $method] == 1 } {
87
for {set i 1} {$i <= $fcount} {set i [incr i]} {
92
set oid [open $t2.tmp w]
93
foreach f $file_list {
99
puts "\tSubdb004.a: Set/Check each subdb"
100
foreach f $file_list {
101
if { [is_record_based $method] == 1 } {
102
set key [expr $count + 1]
103
set names([expr $count + 1]) $f
107
# Should really catch errors
109
fconfigure $fid -translation binary
113
set db [eval {berkdb_open -create -mode 0644} \
114
$args {$omethod $testfile $subdb}]
115
error_check_good dbopen [is_valid_db $db] TRUE
116
if { $txnenv == 1 } {
118
error_check_good txn [is_valid_txn $t $env] TRUE
122
{$db put} $txn $pflags {$key [chop_data $method $data]}]
123
error_check_good put $ret 0
124
if { $txnenv == 1 } {
125
error_check_good txn [$t commit] 0
128
# Should really catch errors
130
fconfigure $fid -translation binary
131
if [catch {eval {$db get} $gflags {$key}} data] {
132
puts -nonewline $fid $data
134
# Data looks like {{key data}}
135
set key [lindex [lindex $data 0] 0]
136
set data [lindex [lindex $data 0] 1]
137
puts -nonewline $fid $data
141
error_check_good Subdb004:diff($f,$t4) \
146
# Now we will get each key from the DB and compare the results
148
# puts "\tSubdb004.b: dump file"
149
if { $txnenv == 1 } {
151
error_check_good txn [is_valid_txn $t $env] TRUE
154
dump_bin_file $db $txn $t1 $checkfunc
155
if { $txnenv == 1 } {
156
error_check_good txn [$t commit] 0
158
error_check_good db_close [$db close] 0
163
# Now for each file, check that the subdb name is the same
164
# as the data in that subdb and that the filename is the key.
166
puts "\tSubdb004.b: Compare subdb names with key/data"
167
set db [eval {berkdb_open -rdonly} $envargs {$testfile}]
168
error_check_good dbopen [is_valid_db $db] TRUE
169
if { $txnenv == 1 } {
171
error_check_good txn [is_valid_txn $t $env] TRUE
174
set c [eval {$db cursor} $txn]
175
error_check_good db_cursor [is_valid_cursor $c $db] TRUE
177
for {set d [$c get -first] } { [llength $d] != 0 } \
178
{set d [$c get -next] } {
179
set subdbname [lindex [lindex $d 0] 0]
180
set subdb [eval {berkdb_open} $args {$testfile $subdbname}]
181
error_check_good dbopen [is_valid_db $db] TRUE
183
# Output the subdb name
184
set ofid [open $t3 w]
185
fconfigure $ofid -translation binary
186
if { [string compare "\0" \
187
[string range $subdbname end end]] == 0 } {
188
set slen [expr [string length $subdbname] - 2]
189
set subdbname [string range $subdbname 1 $slen]
191
puts -nonewline $ofid $subdbname
195
set subc [eval {$subdb cursor} $txn]
196
error_check_good db_cursor [is_valid_cursor $subc $subdb] TRUE
197
set d [$subc get -first]
198
error_check_good dbc_get [expr [llength $d] != 0] 1
199
set key [lindex [lindex $d 0] 0]
200
set data [lindex [lindex $d 0] 1]
202
set ofid [open $t1 w]
203
fconfigure $ofid -translation binary
204
puts -nonewline $ofid $data
210
error_check_good Subdb004:diff($t3,$t1) \
212
error_check_good curs_close [$subc close] 0
213
error_check_good db_close [$subdb close] 0
215
error_check_good curs_close [$c close] 0
216
if { $txnenv == 1 } {
217
error_check_good txn [$t commit] 0
219
error_check_good db_close [$db close] 0
221
if { [is_record_based $method] != 1 } {
226
# Check function for subdb004; key should be file name; data should be contents
227
proc subdb004.check { binfile tmpfile } {
230
error_check_good Subdb004:datamismatch($binfile,$tmpfile) \
231
[filecmp $binfile $tmpfile] 0
233
proc subdb004_recno.check { binfile tmpfile } {
237
set fname $names($binfile)
238
error_check_good key"$binfile"_exists [info exists names($binfile)] 1
239
error_check_good Subdb004:datamismatch($fname,$tmpfile) \
240
[filecmp $fname $tmpfile] 0