1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2001
4
# Sleepycat Software. All rights reserved.
6
# $Id: test062.tcl,v 11.15 2001/05/17 20:37:08 bostic Exp $
8
# DB Test 62: Test of partial puts onto duplicate pages.
9
# Insert the first 200 words into the dictionary 200 times each with
10
# self as key and <random letter>:self as data. Use partial puts to
11
# append self again to data; verify correctness.
12
proc test062 { method {nentries 200} {ndups 200} {tnum 62} args } {
17
berkdb srand $rand_init
19
set args [convert_args $method $args]
20
set omethod [convert_method $method]
22
# Create the database and open the dictionary
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.
27
if { $eindex == -1 } {
28
set testfile $testdir/test0$tnum.db
31
set testfile test0$tnum.db
33
set env [lindex $args $eindex]
38
$method ($args) Partial puts and duplicates."
39
if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
40
puts "Test0$tnum skipping for method $omethod"
43
set db [eval {berkdb_open -create -truncate -mode 0644 \
44
$omethod -dup} $args {$testfile} ]
45
error_check_good dbopen [is_valid_db $db] TRUE
53
# Here is the loop where we put each key/data pair
54
puts "\tTest0$tnum.a: Put loop (initialize database)"
55
set dbc [eval {$db cursor} $txn]
56
error_check_good cursor_open [is_substr $dbc $db] 1
57
while { [gets $did str] != -1 && $count < $nentries } {
58
for { set i 1 } { $i <= $ndups } { incr i } {
60
[string index $alphabet [berkdb random_int 0 25]]
61
set datastr $pref:$str
62
set ret [eval {$db put} \
63
$txn $pflags {$str [chop_data $method $datastr]}]
64
error_check_good put $ret 0
70
error_check_good cursor_close [$dbc close] 0
73
puts "\tTest0$tnum.b: Partial puts."
74
set dbc [eval {$db cursor} $txn]
75
error_check_good cursor_open [is_substr $dbc $db] 1
77
# Do a partial write to extend each datum in
78
# the regular db by the corresponding dictionary word.
79
# We have to go through each key's dup set using -set
80
# because cursors are not stable in the hash AM and we
81
# want to make sure we hit all the keys.
82
for { set i 0 } { $i < $count } { incr i } {
84
for {set ret [$dbc get -set $key]} \
85
{[llength $ret] != 0} \
86
{set ret [$dbc get -nextdup]} {
88
set k [lindex [lindex $ret 0] 0]
89
set orig_d [lindex [lindex $ret 0] 1]
90
set d [string range $orig_d 2 end]
91
set doff [expr [string length $d] + 2]
93
error_check_good data_and_key_sanity $d $k
95
set ret [$dbc get -current]
96
error_check_good before_sanity \
97
[lindex [lindex $ret 0] 0] \
98
[string range [lindex [lindex $ret 0] 1] 2 end]
100
error_check_good partial_put [eval {$dbc put -current \
101
-partial [list $doff $dlen] $d}] 0
103
set ret [$dbc get -current]
104
error_check_good partial_put_correct \
105
[lindex [lindex $ret 0] 1] $orig_d$d
109
puts "\tTest0$tnum.c: Double-checking get loop."
110
# Double-check that each datum in the regular db has
111
# been appropriately modified.
113
for {set ret [$dbc get -first]} \
114
{[llength $ret] != 0} \
115
{set ret [$dbc get -next]} {
117
set k [lindex [lindex $ret 0] 0]
118
set d [lindex [lindex $ret 0] 1]
119
error_check_good modification_correct \
120
[string range $d 2 end] [repeat $k 2]
123
error_check_good dbc_close [$dbc close] 0
124
error_check_good db_close [$db close] 0