1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test DB_NEXT_DUP Functionality.
10
proc test030 { method {nentries 10000} args } {
14
set args [convert_args $method $args]
15
set omethod [convert_method $method]
17
if { [is_record_based $method] == 1 ||
18
[is_rbtree $method] == 1 } {
19
puts "Test030 skipping for method $method"
22
berkdb srand $rand_init
24
# Create the database and open the dictionary
26
set eindex [lsearch -exact $args "-env"]
28
# If we are using an env, then testfile should just be the db name.
29
# Otherwise it is the test directory and the name.
30
if { $eindex == -1 } {
31
set testfile $testdir/test030.db
32
set cntfile $testdir/cntfile.db
35
set testfile test030.db
36
set cntfile cntfile.db
38
set env [lindex $args $eindex]
39
set txnenv [is_txnenv $env]
41
append args " -auto_commit "
43
# If we are using txns and running with the
44
# default, set the default down a bit.
46
if { $nentries == 10000 } {
50
set testdir [get_home $env]
53
puts "Test030: $method ($args) $nentries DB_NEXT_DUP testing"
59
set db [eval {berkdb_open -create \
60
-mode 0644 -dup} $args {$omethod $testfile}]
61
error_check_good dbopen [is_valid_db $db] TRUE
63
# Use a second DB to keep track of how many duplicates
66
set cntdb [eval {berkdb_open -create \
67
-mode 0644} $args {-btree $cntfile}]
68
error_check_good dbopen:cntfile [is_valid_db $db] TRUE
75
# Here is the loop where we put and get each key/data pair
76
# We will add between 1 and 10 dups with values 1 ... dups
77
# We'll verify each addition.
80
puts "\tTest030.a: put and get duplicate keys."
83
error_check_good txn [is_valid_txn $t $env] TRUE
86
set dbc [eval {$db cursor} $txn]
88
while { [gets $did str] != -1 && $count < $nentries } {
89
set ndup [berkdb random_int 1 10]
91
for { set i 1 } { $i <= $ndup } { incr i 1 } {
95
error_check_good txn \
96
[is_valid_txn $ct $env] TRUE
99
set ret [eval {$cntdb put} \
100
$ctxn $pflags {$str [chop_data $method $ndup]}]
101
error_check_good put_cnt $ret 0
102
if { $txnenv == 1 } {
103
error_check_good txn [$ct commit] 0
106
set ret [eval {$db put} \
107
$txn $pflags {$str [chop_data $method $datastr]}]
108
error_check_good put $ret 0
111
# Now retrieve all the keys matching this key
113
for {set ret [$dbc get -set $str]} \
114
{[llength $ret] != 0} \
115
{set ret [$dbc get -nextdup] } {
118
if { [llength $ret] == 0 } {
122
set k [lindex [lindex $ret 0] 0]
123
if { [string compare $k $str] != 0 } {
127
set datastr [lindex [lindex $ret 0] 1]
128
set d [data_of $datastr]
129
error_check_good Test030:put $d $str
131
set id [ id_of $datastr ]
132
error_check_good Test030:dup# $id $x
134
error_check_good Test030:numdups $x $ndup
139
# Verify on sequential pass of entire file
140
puts "\tTest030.b: sequential check"
142
# We can't just set lastkey to a null string, since that might
144
set lastkey "THIS STRING WILL NEVER BE A KEY"
146
for {set ret [$dbc get -first]} \
147
{[llength $ret] != 0} \
148
{set ret [$dbc get -next] } {
150
# Outer loop should always get a new key
152
set k [lindex [lindex $ret 0] 0]
153
error_check_bad outer_get_loop:key $k $lastkey
155
set datastr [lindex [lindex $ret 0] 1]
156
set d [data_of $datastr]
157
set id [ id_of $datastr ]
159
error_check_good outer_get_loop:data $d $k
160
error_check_good outer_get_loop:id $id 1
163
# Figure out how may dups we should have
164
if { $txnenv == 1 } {
166
error_check_good txn [is_valid_txn $ct $env] TRUE
169
set ret [eval {$cntdb get} $ctxn $pflags {$k}]
170
set ndup [lindex [lindex $ret 0] 1]
171
if { $txnenv == 1 } {
172
error_check_good txn [$ct commit] 0
176
for { set ret [$dbc get -nextdup] } \
177
{ [llength $ret] != 0 } \
178
{ set ret [$dbc get -nextdup] } {
181
set k [lindex [lindex $ret 0] 0]
182
error_check_good inner_get_loop:key $k $lastkey
184
set datastr [lindex [lindex $ret 0] 1]
185
set d [data_of $datastr]
186
set id [ id_of $datastr ]
188
error_check_good inner_get_loop:data $d $k
189
error_check_good inner_get_loop:id $id $howmany
192
error_check_good ndups_found $howmany $ndup
195
# Verify on key lookup
196
puts "\tTest030.c: keyed check"
197
set cnt_dbc [$cntdb cursor]
198
for {set ret [$cnt_dbc get -first]} \
199
{[llength $ret] != 0} \
200
{set ret [$cnt_dbc get -next] } {
201
set k [lindex [lindex $ret 0] 0]
203
set howmany [lindex [lindex $ret 0] 1]
204
error_check_bad cnt_seq:data [string length $howmany] 0
207
for {set ret [$dbc get -set $k]} \
208
{[llength $ret] != 0} \
209
{set ret [$dbc get -nextdup] } {
212
set k [lindex [lindex $ret 0] 0]
214
set datastr [lindex [lindex $ret 0] 1]
215
set d [data_of $datastr]
216
set id [ id_of $datastr ]
218
error_check_good inner_get_loop:data $d $k
219
error_check_good inner_get_loop:id $id $i
221
error_check_good keyed_count $i $howmany
224
error_check_good cnt_curs_close [$cnt_dbc close] 0
225
error_check_good db_curs_close [$dbc close] 0
226
if { $txnenv == 1 } {
227
error_check_good txn [$t commit] 0
229
error_check_good cnt_file_close [$cntdb close] 0
230
error_check_good db_file_close [$db close] 0