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

« back to all changes in this revision

Viewing changes to db/test/test062.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: test062.tcl,v 11.15 2001/05/17 20:37:08 bostic Exp $
 
7
#
 
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 } {
 
13
        global alphabet
 
14
        global rand_init
 
15
        source ./include.tcl
 
16
 
 
17
        berkdb srand $rand_init
 
18
 
 
19
        set args [convert_args $method $args]
 
20
        set omethod [convert_method $method]
 
21
 
 
22
        # Create the database and open the dictionary
 
23
        set eindex [lsearch -exact $args "-env"]
 
24
        #
 
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
 
29
                set env NULL
 
30
        } else {
 
31
                set testfile test0$tnum.db
 
32
                incr eindex
 
33
                set env [lindex $args $eindex]
 
34
        }
 
35
        cleanup $testdir $env
 
36
 
 
37
        puts "Test0$tnum:\
 
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"
 
41
                return
 
42
        }
 
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
 
46
        set did [open $dict]
 
47
 
 
48
        set pflags ""
 
49
        set gflags ""
 
50
        set txn ""
 
51
        set count 0
 
52
 
 
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 } {
 
59
                        set pref \
 
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
 
65
                }
 
66
                set keys($count) $str
 
67
 
 
68
                incr count
 
69
        }
 
70
        error_check_good cursor_close [$dbc close] 0
 
71
        close $did
 
72
 
 
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
 
76
 
 
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 } {
 
83
                set key $keys($i)
 
84
                for {set ret [$dbc get -set $key]}  \
 
85
                    {[llength $ret] != 0} \
 
86
                    {set ret [$dbc get -nextdup]} {
 
87
 
 
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]
 
92
                        set dlen 0
 
93
                        error_check_good data_and_key_sanity $d $k
 
94
 
 
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]
 
99
 
 
100
                        error_check_good partial_put [eval {$dbc put -current \
 
101
                            -partial [list $doff $dlen] $d}] 0
 
102
 
 
103
                        set ret [$dbc get -current]
 
104
                        error_check_good partial_put_correct \
 
105
                            [lindex [lindex $ret 0] 1] $orig_d$d
 
106
                }
 
107
        }
 
108
 
 
109
        puts "\tTest0$tnum.c: Double-checking get loop."
 
110
        # Double-check that each datum in the regular db has
 
111
        # been appropriately modified.
 
112
 
 
113
        for {set ret [$dbc get -first]} \
 
114
            {[llength $ret] != 0} \
 
115
            {set ret [$dbc get -next]} {
 
116
 
 
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]
 
121
        }
 
122
 
 
123
        error_check_good dbc_close [$dbc close] 0
 
124
        error_check_good db_close [$db close] 0
 
125
}