blob: d6f5e3374433170ea4043d6c2d6ac502bfbb7e17 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1996,2007 Oracle. All rights reserved.
#
# $Id: test026.tcl,v 12.5 2007/05/17 15:15:56 bostic Exp $
#
# TEST test026
# TEST Small keys/medium data w/duplicates
# TEST Put/get per key.
# TEST Loop through keys -- delete each key
# TEST ... test that cursors delete duplicates correctly
# TEST
# TEST Keyed delete test through cursor. If ndups is small; this will
# TEST test on-page dups; if it's large, it will test off-page dups.
proc test026 { method {nentries 2000} {ndups 5} {tnum "026"} args} {
source ./include.tcl
set args [convert_args $method $args]
set omethod [convert_method $method]
if { [is_record_based $method] == 1 || \
[is_rbtree $method] == 1 } {
puts "Test$tnum skipping for method $method"
return
}
# Create the database and open the dictionary
set txnenv 0
set eindex [lsearch -exact $args "-env"]
#
# If we are using an env, then testfile should just be the db name.
# Otherwise it is the test directory and the name.
if { $eindex == -1 } {
set testfile $testdir/test$tnum.db
set env NULL
} else {
set testfile test$tnum.db
incr eindex
set env [lindex $args $eindex]
set txnenv [is_txnenv $env]
if { $txnenv == 1 } {
append args " -auto_commit "
#
# If we are using txns and running with the
# default, set the defaults down a bit.
# If we are wanting a lot of dups, set that
# down a bit or repl testing takes very long.
#
if { $nentries == 2000 } {
set nentries 100
}
reduce_dups nentries ndups
}
set testdir [get_home $env]
}
cleanup $testdir $env
puts "Test$tnum: $method ($args) $nentries keys\
with $ndups dups; cursor delete test"
set pflags ""
set gflags ""
set txn ""
set count 0
# Here is the loop where we put and get each key/data pair
puts "\tTest$tnum.a: Put loop"
set db [eval {berkdb_open -create \
-mode 0644} $args {$omethod -dup $testfile}]
error_check_good dbopen [is_valid_db $db] TRUE
set did [open $dict]
while { [gets $did str] != -1 && $count < [expr $nentries * $ndups] } {
set datastr [ make_data_str $str ]
for { set j 1 } { $j <= $ndups} {incr j} {
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set ret [eval {$db put} \
$txn $pflags {$str [chop_data $method $j$datastr]}]
error_check_good db_put $ret 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
incr count
}
}
close $did
error_check_good db_close [$db close] 0
set db [eval {berkdb_open} $args $testfile]
error_check_good dbopen [is_valid_db $db] TRUE
# Now we will sequentially traverse the database getting each
# item and deleting it.
set count 0
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set dbc [eval {$db cursor} $txn]
error_check_good db_cursor [is_substr $dbc $db] 1
puts "\tTest$tnum.b: Get/delete loop"
set i 1
for { set ret [$dbc get -first] } {
[string length $ret] != 0 } {
set ret [$dbc get -next] } {
set key [lindex [lindex $ret 0] 0]
set data [lindex [lindex $ret 0] 1]
if { $i == 1 } {
set curkey $key
}
error_check_good seq_get:key $key $curkey
error_check_good \
seq_get:data $data [pad_data $method $i[make_data_str $key]]
if { $i == $ndups } {
set i 1
} else {
incr i
}
# Now delete the key
set ret [$dbc del]
error_check_good db_del:$key $ret 0
}
error_check_good dbc_close [$dbc close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
error_check_good db_close [$db close] 0
puts "\tTest$tnum.c: Verify empty file"
# Double check that file is now empty
set db [eval {berkdb_open} $args $testfile]
error_check_good dbopen [is_valid_db $db] TRUE
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set dbc [eval {$db cursor} $txn]
error_check_good db_cursor [is_substr $dbc $db] 1
set ret [$dbc get -first]
error_check_good get_on_empty [string length $ret] 0
error_check_good dbc_close [$dbc close] 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
error_check_good db_close [$db close] 0
}
|