~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/test/test053.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 1999-2001
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: test053.tcl,v 11.13 2001/01/25 18:23:12 bostic Exp $
 
7
#
 
8
# Test53: test of the DB_REVSPLITOFF flag in the btree and
 
9
# Btree-w-recnum methods
 
10
proc test053 { method args } {
 
11
        global alphabet
 
12
        global errorCode
 
13
        source ./include.tcl
 
14
 
 
15
        set args [convert_args $method $args]
 
16
        set omethod [convert_method $method]
 
17
 
 
18
        puts "\tTest053: Test of cursor stability across btree splits."
 
19
        if { [is_btree $method] != 1 && [is_rbtree $method] != 1 } {
 
20
                puts "Test053: skipping for method $method."
 
21
                return
 
22
        }
 
23
 
 
24
        set pgindex [lsearch -exact $args "-pagesize"]
 
25
        if { $pgindex != -1 } {
 
26
                puts "Test053: skipping for specific pagesizes"
 
27
                return
 
28
        }
 
29
 
 
30
        set txn ""
 
31
        set flags ""
 
32
 
 
33
        puts "\tTest053.a: Create $omethod $args database."
 
34
        set eindex [lsearch -exact $args "-env"]
 
35
        #
 
36
        # If we are using an env, then testfile should just be the db name.
 
37
        # Otherwise it is the test directory and the name.
 
38
        if { $eindex == -1 } {
 
39
                set testfile $testdir/test053.db
 
40
                set env NULL
 
41
        } else {
 
42
                set testfile test053.db
 
43
                incr eindex
 
44
                set env [lindex $args $eindex]
 
45
        }
 
46
        set t1 $testdir/t1
 
47
        cleanup $testdir $env
 
48
 
 
49
        set oflags \
 
50
            "-create -truncate -revsplitoff -pagesize 1024 $args $omethod"
 
51
        set db [eval {berkdb_open} $oflags $testfile]
 
52
        error_check_good dbopen [is_valid_db $db] TRUE
 
53
 
 
54
        set nkeys 8
 
55
        set npages 15
 
56
 
 
57
        # We want to create a db with npages leaf pages, and have each page
 
58
        # be near full with keys that we can predict. We set pagesize above
 
59
        # to 1024 bytes, it should breakdown as follows (per page):
 
60
        #
 
61
        #       ~20 bytes overhead
 
62
        #       key: ~4 bytes overhead, XXX0N where X is a letter, N is 0-9
 
63
        #       data: ~4 bytes overhead, + 100 bytes
 
64
        #
 
65
        # then, with 8 keys/page we should be just under 1024 bytes
 
66
        puts "\tTest053.b: Create $npages pages with $nkeys pairs on each."
 
67
        set keystring [string range $alphabet 0 [expr $npages -1]]
 
68
        set data [repeat DATA 22]
 
69
        for { set i 0 } { $i < $npages } {incr i } {
 
70
                set key ""
 
71
                set keyroot \
 
72
                    [repeat [string toupper [string range $keystring $i $i]] 3]
 
73
                set key_set($i) $keyroot
 
74
                for {set j 0} { $j < $nkeys} {incr j} {
 
75
                        if { $j < 10 } {
 
76
                                set key [set keyroot]0$j
 
77
                        } else {
 
78
                                set key $keyroot$j
 
79
                        }
 
80
                        set ret [$db put $key $data]
 
81
                        error_check_good dbput $ret 0
 
82
                }
 
83
        }
 
84
 
 
85
        puts "\tTest053.c: Check page count."
 
86
        error_check_good page_count:check \
 
87
            [is_substr [$db stat] "{Leaf pages} $npages"] 1
 
88
 
 
89
        puts "\tTest053.d: Delete all but one key per page."
 
90
        for {set i 0} { $i < $npages } {incr i } {
 
91
                for {set j 1} { $j < $nkeys } {incr j } {
 
92
                        set ret [$db del $key_set($i)0$j]
 
93
                        error_check_good dbdel $ret 0
 
94
                }
 
95
        }
 
96
        puts "\tTest053.e: Check to make sure all pages are still there."
 
97
        error_check_good page_count:check \
 
98
            [is_substr [$db stat] "{Leaf pages} $npages"] 1
 
99
 
 
100
        set dbc [$db cursor]
 
101
        error_check_good db:cursor [is_substr $dbc $db] 1
 
102
 
 
103
        # walk cursor through tree forward, backward.
 
104
        # delete one key, repeat
 
105
        for {set i 0} { $i < $npages} {incr i} {
 
106
                puts -nonewline \
 
107
                    "\tTest053.f.$i: Walk curs through tree: forward..."
 
108
                for { set j $i; set curr [$dbc get -first]} { $j < $npages} { \
 
109
                    incr j; set curr [$dbc get -next]} {
 
110
                        error_check_bad dbc:get:next [llength $curr] 0
 
111
                        error_check_good dbc:get:keys \
 
112
                            [lindex [lindex $curr 0] 0] $key_set($j)00
 
113
                }
 
114
                puts -nonewline "backward..."
 
115
                for { set j [expr $npages - 1]; set curr [$dbc get -last]} { \
 
116
                    $j >= $i } { \
 
117
                    set j [incr j -1]; set curr [$dbc get -prev]} {
 
118
                        error_check_bad dbc:get:prev [llength $curr] 0
 
119
                        error_check_good dbc:get:keys \
 
120
                            [lindex [lindex $curr 0] 0] $key_set($j)00
 
121
                }
 
122
                puts "complete."
 
123
 
 
124
                if { [is_rbtree $method] == 1} {
 
125
                        puts "\t\tTest053.f.$i:\
 
126
                            Walk through tree with record numbers."
 
127
                        for {set j 1} {$j <= [expr $npages - $i]} {incr j} {
 
128
                                set curr [$db get -recno $j]
 
129
                                error_check_bad \
 
130
                                    db_get:recno:$j [llength $curr] 0
 
131
                                error_check_good db_get:recno:keys:$j \
 
132
                                    [lindex [lindex $curr 0] 0] \
 
133
                                    $key_set([expr $j + $i - 1])00
 
134
                        }
 
135
                }
 
136
                puts "\tTest053.g.$i:\
 
137
                    Delete single key ([expr $npages - $i] keys left)."
 
138
                set ret [$db del $key_set($i)00]
 
139
                error_check_good dbdel $ret 0
 
140
                error_check_good del:check \
 
141
                    [llength [$db get $key_set($i)00]] 0
 
142
        }
 
143
 
 
144
        # end for loop, verify db_notfound
 
145
        set ret [$dbc get -first]
 
146
        error_check_good dbc:get:verify [llength $ret] 0
 
147
 
 
148
        # loop: until single key restored on each page
 
149
        for {set i 0} { $i < $npages} {incr i} {
 
150
                puts "\tTest053.i.$i:\
 
151
                    Restore single key ([expr $i + 1] keys in tree)."
 
152
                set ret [$db put $key_set($i)00 $data]
 
153
                error_check_good dbput $ret 0
 
154
 
 
155
                puts -nonewline \
 
156
                    "\tTest053.j: Walk cursor through tree: forward..."
 
157
                for { set j 0; set curr [$dbc get -first]} { $j <= $i} {\
 
158
                                  incr j; set curr [$dbc get -next]} {
 
159
                        error_check_bad dbc:get:next [llength $curr] 0
 
160
                        error_check_good dbc:get:keys \
 
161
                            [lindex [lindex $curr 0] 0] $key_set($j)00
 
162
                }
 
163
                error_check_good dbc:get:next [llength $curr] 0
 
164
 
 
165
                puts -nonewline "backward..."
 
166
                for { set j $i; set curr [$dbc get -last]} { \
 
167
                    $j >= 0 } { \
 
168
                    set j [incr j -1]; set curr [$dbc get -prev]} {
 
169
                        error_check_bad dbc:get:prev [llength $curr] 0
 
170
                        error_check_good dbc:get:keys \
 
171
                            [lindex [lindex $curr 0] 0] $key_set($j)00
 
172
                }
 
173
                puts "complete."
 
174
                error_check_good dbc:get:prev [llength $curr] 0
 
175
 
 
176
                if { [is_rbtree $method] == 1} {
 
177
                        puts "\t\tTest053.k.$i:\
 
178
                            Walk through tree with record numbers."
 
179
                        for {set j 1} {$j <= [expr $i + 1]} {incr j} {
 
180
                                set curr [$db get -recno $j]
 
181
                                error_check_bad \
 
182
                                    db_get:recno:$j [llength $curr] 0
 
183
                                error_check_good db_get:recno:keys:$j \
 
184
                                    [lindex [lindex $curr 0] 0] \
 
185
                                    $key_set([expr $j - 1])00
 
186
                        }
 
187
                }
 
188
        }
 
189
 
 
190
        error_check_good dbc_close [$dbc close] 0
 
191
        error_check_good db_close [$db close] 0
 
192
 
 
193
        puts "Test053 complete."
 
194
}