1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test094.tcl,v 11.5 2001/07/12 16:31:48 sue Exp $
8
# DB Test 94 {access method}
9
# Test bt comparison proc.
10
# Use the first 10,000 entries from the dictionary.
11
# Insert each with self as key and data; retrieve each.
12
# After all are entered, retrieve all; compare output to original.
13
# Close file, reopen, do retrieve and re-verify.
14
proc test094 { method {nentries 10000} {ndups 10} {tnum "94"} args} {
18
set dbargs [convert_args $method $args]
19
set omethod [convert_method $method]
21
puts "Test0$tnum: $method ($args) $ndups dups using dupcompare"
23
if { [is_btree $method] != 1 && [is_hash $method] != 1 } {
24
puts "Skipping for method $method."
28
# Create the database and open the dictionary
29
set eindex [lsearch -exact $dbargs "-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/test0$tnum.db
37
set testfile test0$tnum.db
39
set env [lindex $dbargs $eindex]
43
set stat [catch {eval {berkdb_open_noerr -dupcompare test094_cmp \
45
-create -truncate -mode 0644} $omethod $dbargs $testfile} db]
48
# Only failure we expect is for RPC. We want to skip
49
# for RPC, but we cannot tell if we are using RPC except
50
# by the error message.
52
error_check_good dbopen \
53
[is_substr $errorInfo "meaningless in RPC env"] 1
54
puts "Skipping for RPC"
57
error_check_good dbopen [is_valid_db $db] TRUE
64
puts "\tTest0$tnum.a: $nentries put/get duplicates loop"
65
# Here is the loop where we put and get each key/data pair
68
for {set i 0} {$i < $ndups} {incr i} {
69
set dlist [linsert $dlist 0 $i]
71
while { [gets $did str] != -1 && $count < $nentries } {
73
for {set i 0} {$i < $ndups} {incr i} {
75
set ret [eval {$db put} \
76
$txn $pflags {$key [chop_data $omethod $data]}]
77
error_check_good put $ret 0
80
set ret [eval {$db get} $gflags {$key}]
81
error_check_good get [llength $ret] $ndups
85
# Now we will get each key from the DB and compare the results
87
puts "\tTest0$tnum.b: traverse checking duplicates before close"
88
dup_check $db $txn $t1 $dlist
89
error_check_good db_close [$db close] 0
92
# Test dupcompare with data items big enough to force offpage dups.
94
puts "\tTest0$tnum.c: big key put/get dup loop key=filename data=filecontents"
95
set db [eval {berkdb_open -dupcompare test094_cmp -dup -dupsort \
96
-create -truncate -mode 0644} $omethod $dbargs $testfile]
97
error_check_good dbopen [is_valid_db $db] TRUE
99
# Here is the loop where we put and get each key/data pair
100
set file_list [get_file_list 1]
103
foreach f $file_list {
105
fconfigure $fid -translation binary
110
for {set i 0} {$i < $ndups} {incr i} {
112
set ret [eval {$db put} \
113
$txn $pflags {$key [chop_data $omethod $data]}]
114
error_check_good put $ret 0
117
set ret [eval {$db get} $gflags {$key}]
118
error_check_good get [llength $ret] $ndups
122
puts "\tTest0$tnum.d: traverse checking duplicates before close"
123
dup_file_check $db $txn $t1 $dlist
124
error_check_good db_close [$db close] 0
126
# Clean up the test directory, since there's currently
127
# no way to specify a dup_compare function to berkdb dbverify
128
# and without one it will fail.
129
cleanup $testdir $env
132
# Simple dup comparison.
133
proc test094_cmp { a b } {
134
return [string compare $b $a]
137
# Check if each key appears exactly [llength dlist] times in the file with
138
# the duplicate tags matching those that appear in dlist.
139
proc test094_dup_big { db txn tmpfile dlist {extra 0}} {
142
set outf [open $tmpfile w]
143
# Now we will get each key from the DB and dump to outfile
144
set c [eval {$db cursor} $txn]
147
while { $done != 1} {
149
set rec [$c get "-next"]
150
if { [string length $rec] == 0 } {
154
set key [lindex [lindex $rec 0] 0]
155
set fulldata [lindex [lindex $rec 0] 1]
156
set id [id_of $fulldata]
157
set d [data_of $fulldata]
158
if { [string compare $key $lastkey] != 0 && \
159
$id != [lindex $dlist 0] } {
160
set e [lindex $dlist 0]
162
$key, expected dup id $e, got $id"
164
error_check_good dupget.data $d $key
165
error_check_good dupget.id $id $did
169
# Some tests add an extra dup (like overflow entries)
170
# Check id if it exists.
173
set rec [$c get "-next"]
174
if { [string length $rec] != 0 } {
175
set key [lindex [lindex $rec 0] 0]
177
# If this key has no extras, go back for
179
if { [string compare $key $lastkey] != 0 } {
181
set rec [$c get "-prev"]
183
set fulldata [lindex [lindex $rec 0] 1]
184
set id [id_of $fulldata]
185
set d [data_of $fulldata]
186
error_check_bad dupget.data1 $d $key
187
error_check_good dupget.id1 $id $extra
196
error_check_good curs_close [$c close] 0