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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1999, 2000
# Sleepycat Software. All rights reserved.
#
# $Id: test068.tcl,v 11.11 2000/08/25 14:21:58 sue Exp $
#
# DB Test 68: Test of DB_BEFORE and DB_AFTER and partial puts.
# Make sure DB_BEFORE and DB_AFTER work properly with partial puts,
# and check that they return EINVAL if DB_DUPSORT is set or if DB_DUP is not.
proc test068 { method args } {
source ./include.tcl
global alphabet
global errorCode
set tnum 68
set nkeys 1000
set args [convert_args $method $args]
set omethod [convert_method $method]
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/test0$tnum.db
set env NULL
} else {
set testfile test0$tnum.db
incr eindex
set env [lindex $args $eindex]
}
puts "Test0$tnum:\
$method ($args) Test of DB_BEFORE/DB_AFTER and partial puts."
if { [is_record_based $method] == 1 } {
puts "\tTest0$tnum: skipping for method $method."
return
}
# Create a list of $nkeys words to insert into db.
puts "\tTest0$tnum.a: Initialize word list."
set wordlist {}
set count 0
set did [open $dict]
while { [gets $did str] != -1 && $count < $nkeys } {
lappend wordlist $str
incr count
}
close $did
# Sanity check: did we get $nkeys words?
error_check_good enough_keys [llength $wordlist] $nkeys
# rbtree can't handle dups, so just test the non-dup case
# if it's the current method.
if { [is_rbtree $method] == 1 } {
set dupoptlist { "" }
} else {
set dupoptlist { "" "-dup" "-dup -dupsort" }
}
foreach dupopt $dupoptlist {
cleanup $testdir $env
set db [eval {berkdb_open_noerr -create -truncate -mode 0644 \
$omethod} $args $dupopt {$testfile}]
error_check_good db_open [is_valid_db $db] TRUE
puts "\tTest0$tnum.b ($dupopt): DB initialization: put loop."
foreach word $wordlist {
error_check_good db_put [$db put $word $word] 0
}
puts "\tTest0$tnum.c ($dupopt): get loop."
foreach word $wordlist {
# Make sure that the Nth word has been correctly
# inserted, and also that the Nth word is the
# Nth one we pull out of the database using a cursor.
set dbt [$db get $word]
error_check_good get_key [list [list $word $word]] $dbt
}
set dbc [$db cursor]
error_check_good cursor_open [is_valid_cursor $dbc $db] TRUE
puts "\tTest0$tnum.d ($dupopt): DBC->put w/ DB_AFTER."
# Set cursor to the first key; make sure it succeeds.
# With an unsorted wordlist, we can't be sure that the
# first item returned will equal the first item in the
# wordlist, so we just make sure it got something back.
set dbt [eval {$dbc get -first}]
error_check_good \
dbc_get_first [llength $dbt] 1
# If -dup is not set, or if -dupsort is set too, we
# need to verify that DB_BEFORE and DB_AFTER fail
# and then move on to the next $dupopt.
if { $dupopt != "-dup" } {
set errorCode "NONE"
set ret [catch {eval $dbc put -after \
{-partial [list 6 0]} "after"} res]
error_check_good dbc_put_after_fail $ret 1
error_check_good dbc_put_after_einval \
[is_substr $errorCode EINVAL] 1
puts "\tTest0$tnum ($dupopt): DB_AFTER returns EINVAL."
set errorCode "NONE"
set ret [catch {eval $dbc put -before \
{-partial [list 6 0]} "before"} res]
error_check_good dbc_put_before_fail $ret 1
error_check_good dbc_put_before_einval \
[is_substr $errorCode EINVAL] 1
puts "\tTest0$tnum ($dupopt): DB_BEFORE returns EINVAL."
puts "\tTest0$tnum ($dupopt): Correct error returns,\
skipping further test."
# continue with broad foreach
error_check_good db_close [$db close] 0
continue
}
puts "\tTest0$tnum.e ($dupopt): DBC->put(DB_AFTER) loop."
foreach word $wordlist {
# set cursor to $word
set dbt [$dbc get -set $word]
error_check_good \
dbc_get_set $dbt [list [list $word $word]]
# put after it
set ret [$dbc put -after -partial {4 0} after]
error_check_good dbc_put_after $ret 0
}
puts "\tTest0$tnum.f ($dupopt): DBC->put(DB_BEFORE) loop."
foreach word $wordlist {
# set cursor to $word
set dbt [$dbc get -set $word]
error_check_good \
dbc_get_set $dbt [list [list $word $word]]
# put before it
set ret [$dbc put -before -partial {6 0} before]
error_check_good dbc_put_before $ret 0
}
error_check_good dbc_close [$dbc close] 0
eval $db sync
puts "\tTest0$tnum.g ($dupopt): Verify correctness."
set dbc [$db cursor]
error_check_good db_cursor [is_valid_cursor $dbc $db] TRUE
# loop through the whole db beginning to end,
# make sure we have, in order, {$word "\0\0\0\0\0\0before"},
# {$word $word}, {$word "\0\0\0\0after"} for each word.
set count 0
while { $count < $nkeys } {
# Get the first item of each set of three.
# We don't know what the word is, but set $word to
# the key and check that the data is
# "\0\0\0\0\0\0before".
set dbt [$dbc get -next]
set word [lindex [lindex $dbt 0] 0]
error_check_good dbc_get_one $dbt \
[list [list $word "\0\0\0\0\0\0before"]]
set dbt [$dbc get -next]
error_check_good \
dbc_get_two $dbt [list [list $word $word]]
set dbt [$dbc get -next]
error_check_good dbc_get_three $dbt \
[list [list $word "\0\0\0\0after"]]
incr count
}
error_check_good dbc_close [$dbc close] 0
error_check_good db_close [$db close] 0
}
}
|