1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test of DB_BEFORE and DB_AFTER with partial puts.
10
# TEST Make sure DB_BEFORE and DB_AFTER work properly with partial puts, and
11
# TEST check that they return EINVAL if DB_DUPSORT is set or if DB_DUP is not.
12
proc test068 { method args } {
19
set args [convert_args $method $args]
20
set omethod [convert_method $method]
23
set eindex [lsearch -exact $args "-env"]
25
# If we are using an env, then testfile should just be the db name.
26
# Otherwise it is the test directory and the name.
28
if { $eindex == -1 } {
29
set testfile $testdir/test0$tnum.db
32
set testfile test0$tnum.db
34
set env [lindex $args $eindex]
35
set txnenv [is_txnenv $env]
37
append args " -auto_commit "
40
set testdir [get_home $env]
44
$method ($args) Test of DB_BEFORE/DB_AFTER and partial puts."
45
if { [is_record_based $method] == 1 } {
46
puts "\tTest0$tnum: skipping for method $method."
50
# Create a list of $nkeys words to insert into db.
51
puts "\tTest0$tnum.a: Initialize word list."
56
while { [gets $did str] != -1 && $count < $nkeys } {
62
# Sanity check: did we get $nkeys words?
63
error_check_good enough_keys [llength $wordlist] $nkeys
65
# rbtree can't handle dups, so just test the non-dup case
66
# if it's the current method.
67
if { [is_rbtree $method] == 1 } {
70
set dupoptlist { "" "-dup" "-dup -dupsort" }
73
foreach dupopt $dupoptlist {
75
# Testdir might be reset in the loop by some proc sourcing
76
# include.tcl. Reset it to the env's home here, before
78
if { $env != "NULL" } {
79
set testdir [get_home $env]
82
set db [eval {berkdb_open_noerr -create -mode 0644 \
83
$omethod} $args $dupopt {$testfile}]
84
error_check_good db_open [is_valid_db $db] TRUE
86
puts "\tTest0$tnum.b ($dupopt): DB initialization: put loop."
87
foreach word $wordlist {
90
error_check_good txn [is_valid_txn $t $env] TRUE
93
set ret [eval {$db put} $txn {$word $word}]
94
error_check_good db_put $ret 0
96
error_check_good txn [$t commit] 0
100
puts "\tTest0$tnum.c ($dupopt): get loop."
101
foreach word $wordlist {
102
# Make sure that the Nth word has been correctly
103
# inserted, and also that the Nth word is the
104
# Nth one we pull out of the database using a cursor.
106
set dbt [$db get $word]
107
error_check_good get_key [list [list $word $word]] $dbt
110
if { $txnenv == 1 } {
112
error_check_good txn [is_valid_txn $t $env] TRUE
115
set dbc [eval {$db cursor} $txn]
116
error_check_good cursor_open [is_valid_cursor $dbc $db] TRUE
118
puts "\tTest0$tnum.d ($dupopt): DBC->put w/ DB_AFTER."
120
# Set cursor to the first key; make sure it succeeds.
121
# With an unsorted wordlist, we can't be sure that the
122
# first item returned will equal the first item in the
123
# wordlist, so we just make sure it got something back.
124
set dbt [eval {$dbc get -first}]
126
dbc_get_first [llength $dbt] 1
128
# If -dup is not set, or if -dupsort is set too, we
129
# need to verify that DB_BEFORE and DB_AFTER fail
130
# and then move on to the next $dupopt.
131
if { $dupopt != "-dup" } {
133
set ret [catch {eval $dbc put -after \
134
{-partial [list 6 0]} "after"} res]
135
error_check_good dbc_put_after_fail $ret 1
136
error_check_good dbc_put_after_einval \
137
[is_substr $errorCode EINVAL] 1
138
puts "\tTest0$tnum ($dupopt): DB_AFTER returns EINVAL."
140
set ret [catch {eval $dbc put -before \
141
{-partial [list 6 0]} "before"} res]
142
error_check_good dbc_put_before_fail $ret 1
143
error_check_good dbc_put_before_einval \
144
[is_substr $errorCode EINVAL] 1
145
puts "\tTest0$tnum ($dupopt): DB_BEFORE returns EINVAL."
146
puts "\tTest0$tnum ($dupopt): Correct error returns,\
147
skipping further test."
148
# continue with broad foreach
149
error_check_good dbc_close [$dbc close] 0
150
if { $txnenv == 1 } {
151
error_check_good txn [$t commit] 0
153
error_check_good db_close [$db close] 0
157
puts "\tTest0$tnum.e ($dupopt): DBC->put(DB_AFTER) loop."
158
foreach word $wordlist {
159
# set cursor to $word
160
set dbt [$dbc get -set $word]
162
dbc_get_set $dbt [list [list $word $word]]
164
set ret [$dbc put -after -partial {4 0} after]
165
error_check_good dbc_put_after $ret 0
168
puts "\tTest0$tnum.f ($dupopt): DBC->put(DB_BEFORE) loop."
169
foreach word $wordlist {
170
# set cursor to $word
171
set dbt [$dbc get -set $word]
173
dbc_get_set $dbt [list [list $word $word]]
175
set ret [$dbc put -before -partial {6 0} before]
176
error_check_good dbc_put_before $ret 0
179
error_check_good dbc_close [$dbc close] 0
180
if { $txnenv == 1 } {
181
error_check_good txn [$t commit] 0
185
puts "\tTest0$tnum.g ($dupopt): Verify correctness."
187
if { $txnenv == 1 } {
189
error_check_good txn [is_valid_txn $t $env] TRUE
192
set dbc [eval {$db cursor} $txn]
193
error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
195
# loop through the whole db beginning to end,
196
# make sure we have, in order, {$word "\0\0\0\0\0\0before"},
197
# {$word $word}, {$word "\0\0\0\0after"} for each word.
199
while { $count < $nkeys } {
200
# Get the first item of each set of three.
201
# We don't know what the word is, but set $word to
202
# the key and check that the data is
203
# "\0\0\0\0\0\0before".
204
set dbt [$dbc get -next]
205
set word [lindex [lindex $dbt 0] 0]
207
error_check_good dbc_get_one $dbt \
208
[list [list $word "\0\0\0\0\0\0before"]]
210
set dbt [$dbc get -next]
212
dbc_get_two $dbt [list [list $word $word]]
214
set dbt [$dbc get -next]
215
error_check_good dbc_get_three $dbt \
216
[list [list $word "\0\0\0\0after"]]
220
error_check_good dbc_close [$dbc close] 0
221
if { $txnenv == 1 } {
222
error_check_good txn [$t commit] 0
224
error_check_good db_close [$db close] 0