1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test using set_bt_compare.
11
# TEST Use the first 10,000 entries from the dictionary.
12
# TEST Insert each with self as key and data; retrieve each.
13
# TEST After all are entered, retrieve all; compare output to original.
14
# TEST Close file, reopen, do retrieve and re-verify.
15
proc test093 { method {nentries 10000} {tnum "93"} args} {
21
set dbargs [convert_args $method $args]
22
set omethod [convert_method $method]
24
if { [is_btree $method] != 1 } {
25
puts "Test0$tnum: skipping for method $method."
29
set eindex [lsearch -exact $dbargs "-env"]
30
if { $eindex != -1 } {
31
set testfile test0$tnum.db
33
set env [lindex $dbargs $eindex]
34
set rpcenv [is_rpcenv $env]
36
puts "Test0$tnum: skipping for RPC"
39
set txnenv [is_txnenv $env]
41
append dbargs " -auto_commit "
42
if { $nentries == 10000 } {
46
set testdir [get_home $env]
49
puts "Test0$tnum: $method ($args) $nentries using btcompare"
52
test093_run $omethod $dbargs $nentries $tnum test093_cmp1 test093_sort1
53
test093_runbig $omethod $dbargs $nentries $tnum \
54
test093_cmp1 test093_sort1
55
test093_run $omethod $dbargs $nentries $tnum test093_cmp2 test093_sort2
57
# Don't bother running the second, really slow, comparison
58
# function on test093_runbig (file contents).
60
# Clean up so verification doesn't fail. (There's currently
61
# no way to specify a comparison function to berkdb dbverify.)
62
# If we are using an env, then testfile should just be the db name.
63
# Otherwise it is the test directory and the name.
64
set eindex [lsearch -exact $dbargs "-env"]
65
if { $eindex == -1 } {
69
set env [lindex $dbargs $eindex]
70
set testdir [get_home $env]
75
proc test093_run { method dbargs nentries tnum cmpfunc sortfunc } {
80
# Create the database and open the dictionary
81
set eindex [lsearch -exact $dbargs "-env"]
83
# If we are using an env, then testfile should just be the db name.
84
# Otherwise it is the test directory and the name.
86
if { $eindex == -1 } {
87
set testfile $testdir/test0$tnum.db
90
set testfile test0$tnum.db
92
set env [lindex $dbargs $eindex]
93
set txnenv [is_txnenv $env]
94
set testdir [get_home $env]
98
set db [eval {berkdb_open -btcompare $cmpfunc \
99
-create -mode 0644} $method $dbargs $testfile]
100
error_check_good dbopen [is_valid_db $db] TRUE
111
set checkfunc test093_check
112
puts "\tTest0$tnum.a: put/get loop"
113
# Here is the loop where we put and get each key/data pair
115
while { [gets $did str] != -1 && $count < $nentries } {
117
set str [reverse $str]
118
if { $txnenv == 1 } {
120
error_check_good txn [is_valid_txn $t $env] TRUE
124
{$db put} $txn $pflags {$key [chop_data $method $str]}]
125
error_check_good put $ret 0
126
if { $txnenv == 1 } {
127
error_check_good txn [$t commit] 0
132
set ret [eval {$db get} $gflags {$key}]
134
get $ret [list [list $key [pad_data $method $str]]]
139
# Now we will get each key from the DB and compare the results
141
puts "\tTest0$tnum.b: dump file"
142
if { $txnenv == 1 } {
144
error_check_good txn [is_valid_txn $t $env] TRUE
147
dump_file $db $txn $t1 $checkfunc
148
if { $txnenv == 1 } {
149
error_check_good txn [$t commit] 0
151
error_check_good db_close [$db close] 0
153
# Now compare the keys to see if they match the dictionary (or ints)
155
filehead $nentries $dict $t2
157
file rename -force $t3 $t2
160
error_check_good Test0$tnum:diff($t3,$t2) \
163
puts "\tTest0$tnum.c: dump file in order"
164
# Now, reopen the file and run the last test again.
165
# We open it here, ourselves, because all uses of the db
166
# need to have the correct comparison func set. Then
167
# call dump_file_direction directly.
169
set db [eval {berkdb_open -btcompare $cmpfunc -rdonly} \
170
$dbargs $method $testfile]
171
error_check_good dbopen [is_valid_db $db] TRUE
172
if { $txnenv == 1 } {
174
error_check_good txn [is_valid_txn $t $env] TRUE
177
dump_file_direction $db $txn $t1 $checkfunc "-first" "-next"
178
if { $txnenv == 1 } {
179
error_check_good txn [$t commit] 0
181
error_check_good db_close [$db close] 0
184
# We need to sort btvals according to the comparison function.
185
# Once that is done, btvalsck and btvals should be the same.
186
puts "\tTest0$tnum.d: check file order"
190
error_check_good btvals:len [llength $btvals] [llength $btvalsck]
191
for {set i 0} {$i < $nentries} {incr i} {
192
error_check_good vals:$i [lindex $btvals $i] \
193
[lindex $btvalsck $i]
197
proc test093_runbig { method dbargs nentries tnum cmpfunc sortfunc } {
202
# Create the database and open the dictionary
203
set eindex [lsearch -exact $dbargs "-env"]
205
# If we are using an env, then testfile should just be the db name.
206
# Otherwise it is the test directory and the name.
208
if { $eindex == -1 } {
209
set testfile $testdir/test0$tnum.db
212
set testfile test0$tnum.db
214
set env [lindex $dbargs $eindex]
215
set txnenv [is_txnenv $env]
216
set testdir [get_home $env]
218
cleanup $testdir $env
220
set db [eval {berkdb_open -btcompare $cmpfunc \
221
-create -mode 0644} $method $dbargs $testfile]
222
error_check_good dbopen [is_valid_db $db] TRUE
234
set checkfunc test093_checkbig
235
puts "\tTest0$tnum.e:\
236
big key put/get loop key=filecontents data=filename"
238
# Here is the loop where we put and get each key/data pair
239
set file_list [get_file_list 1]
242
foreach f $file_list {
244
fconfigure $fid -translation binary
250
set fcopy [open $t5 w]
251
fconfigure $fcopy -translation binary
252
puts -nonewline $fcopy $key
255
if { $txnenv == 1 } {
257
error_check_good txn [is_valid_txn $t $env] TRUE
260
set ret [eval {$db put} $txn $pflags {$key \
261
[chop_data $method $f]}]
262
error_check_good put_file $ret 0
263
if { $txnenv == 1 } {
264
error_check_good txn [$t commit] 0
269
# Should really catch errors
271
fconfigure $fid -translation binary
272
if [catch {eval {$db get} $gflags {$key}} data] {
273
puts -nonewline $fid $data
275
# Data looks like {{key data}}
276
set key [lindex [lindex $data 0] 0]
277
puts -nonewline $fid $key
281
Test093:diff($t5,$t4) [filecmp $t5 $t4] 0
286
# Now we will get each key from the DB and compare the results
288
puts "\tTest0$tnum.f: big dump file"
289
if { $txnenv == 1 } {
291
error_check_good txn [is_valid_txn $t $env] TRUE
294
dump_file $db $txn $t1 $checkfunc
295
if { $txnenv == 1 } {
296
error_check_good txn [$t commit] 0
298
error_check_good db_close [$db close] 0
300
puts "\tTest0$tnum.g: dump file in order"
301
# Now, reopen the file and run the last test again.
302
# We open it here, ourselves, because all uses of the db
303
# need to have the correct comparison func set. Then
304
# call dump_file_direction directly.
307
set db [eval {berkdb_open -btcompare $cmpfunc -rdonly} \
308
$dbargs $method $testfile]
309
error_check_good dbopen [is_valid_db $db] TRUE
310
if { $txnenv == 1 } {
312
error_check_good txn [is_valid_txn $t $env] TRUE
315
dump_file_direction $db $txn $t1 $checkfunc "-first" "-next"
316
if { $txnenv == 1 } {
317
error_check_good txn [$t commit] 0
319
error_check_good db_close [$db close] 0
322
# We need to sort btvals according to the comparison function.
323
# Once that is done, btvalsck and btvals should be the same.
324
puts "\tTest0$tnum.h: check file order"
327
error_check_good btvals:len [llength $btvals] [llength $btvalsck]
329
set end [llength $btvals]
330
for {set i 0} {$i < $end} {incr i} {
331
error_check_good vals:$i [lindex $btvals $i] \
332
[lindex $btvalsck $i]
336
# Simple bt comparison.
337
proc test093_cmp1 { a b } {
338
return [string compare $b $a]
342
proc test093_sort1 {} {
345
# This one is easy, just sort in reverse.
347
set btvals [lsort -decreasing $btvals]
350
proc test093_cmp2 { a b } {
351
set arev [reverse $a]
352
set brev [reverse $b]
353
return [string compare $arev $brev]
356
proc test093_sort2 {} {
359
# We have to reverse them, then sorts them.
360
# Then reverse them back to real words.
363
lappend rbtvals [reverse $i]
365
set rbtvals [lsort -increasing $rbtvals]
368
lappend newbtvals [reverse $i]
370
set btvals $newbtvals
373
# Check function for test093; keys and data are identical
374
proc test093_check { key data } {
377
error_check_good "key/data mismatch" $data [reverse $key]
378
lappend btvalsck $key
381
# Check function for test093 big keys;
382
proc test093_checkbig { key data } {
386
set fid [open $data r]
387
fconfigure $fid -translation binary
390
error_check_good "key/data mismatch" $key $data$cont
391
lappend btvalsck $key