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

« back to all changes in this revision

Viewing changes to db/test/sdbtest002.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: sdbtest002.tcl,v 11.20 2001/01/25 18:23:08 bostic Exp $
 
7
#
 
8
# Sub DB All-Method Test 2
 
9
# Make several subdb's of different access methods all in one DB.
 
10
# Fork of some child procs to each manipulate one subdb and when
 
11
# they are finished, verify the contents of the databases.
 
12
# Use the first 10,000 entries from the dictionary.
 
13
# Insert each with self as key and data; retrieve each.
 
14
# After all are entered, retrieve all; compare output to original.
 
15
# Close file, reopen, do retrieve and re-verify.
 
16
proc subdbtest002 { {nentries 10000} } {
 
17
        source ./include.tcl
 
18
 
 
19
        puts "Subdbtest002: many different subdb access methods in one"
 
20
 
 
21
        # Create the database and open the dictionary
 
22
        set testfile $testdir/subdbtest002.db
 
23
        set t1 $testdir/t1
 
24
        set t2 $testdir/t2
 
25
        set t3 $testdir/t3
 
26
        set t4 $testdir/t4
 
27
 
 
28
        set txn ""
 
29
        set count 0
 
30
 
 
31
        # Set up various methods to rotate through
 
32
        set methods \
 
33
            [list "-rbtree" "-recno" "-btree" "-btree" "-recno" "-rbtree"]
 
34
        cleanup $testdir NULL
 
35
        puts "\tSubdbtest002.a: create subdbs of different access methods:"
 
36
        puts "\t\t$methods"
 
37
        set psize {8192 4096}
 
38
        set nsubdbs [llength $methods]
 
39
        set duplist ""
 
40
        for { set i 0 } { $i < $nsubdbs } { incr i } {
 
41
                lappend duplist -1
 
42
        }
 
43
        set newent [expr $nentries / $nsubdbs]
 
44
 
 
45
        #
 
46
        # XXX We need dict sorted to figure out what was deleted
 
47
        # since things are stored sorted in the btree.
 
48
        #
 
49
        filesort $dict $t4
 
50
        set dictorig $dict
 
51
        set dict $t4
 
52
 
 
53
        build_all_subdb $testfile $methods $psize $duplist $newent
 
54
 
 
55
        # Now we will get each key from the DB and compare the results
 
56
        # to the original.
 
57
        set pidlist ""
 
58
        puts "\tSubdbtest002.b: create $nsubdbs procs to delete some keys"
 
59
        for { set subdb 0 } { $subdb < $nsubdbs } { incr subdb } {
 
60
                puts "$tclsh_path\
 
61
                    $test_path/sdbscript.tcl $testfile \
 
62
                    $subdb $nsubdbs >& $testdir/subdb002.log.$subdb"
 
63
                set p [exec $tclsh_path $test_path/wrap.tcl \
 
64
                    sdbscript.tcl \
 
65
                    $testdir/subdb002.log.$subdb $testfile $subdb $nsubdbs &]
 
66
                lappend pidlist $p
 
67
        }
 
68
        watch_procs 5
 
69
 
 
70
        for { set subdb 0 } { $subdb < $nsubdbs } { incr subdb } {
 
71
                set method [lindex $methods $subdb]
 
72
                set method [convert_method $method]
 
73
                if { [is_record_based $method] == 1 } {
 
74
                        set checkfunc subdbtest002_recno.check
 
75
                } else {
 
76
                        set checkfunc subdbtest002.check
 
77
                }
 
78
 
 
79
                puts "\tSubdbtest002.b: dump file sub$subdb.db"
 
80
                set db [berkdb_open -unknown $testfile sub$subdb.db]
 
81
                error_check_good db_open [is_valid_db $db] TRUE
 
82
                dump_file $db $txn $t1 $checkfunc
 
83
                error_check_good db_close [$db close] 0
 
84
                #
 
85
                # This is just so that t2 is there and empty
 
86
                # since we are only appending below.
 
87
                #
 
88
                exec > $t2
 
89
 
 
90
                # Now compare the keys to see if they match the dictionary (or ints)
 
91
                if { [is_record_based $method] == 1 } {
 
92
                        set oid [open $t2 w]
 
93
                        for {set i 1} {$i <= $newent} {incr i} {
 
94
                                set x [expr $i - $subdb]
 
95
                                if { [expr $x % $nsubdbs] != 0 } {
 
96
                                        puts $oid [expr $subdb * $newent + $i]
 
97
                                }
 
98
                        }
 
99
                        close $oid
 
100
                        file rename -force $t1 $t3
 
101
                } else {
 
102
                        set oid [open $t4 r]
 
103
                        for {set i 1} {[gets $oid line] >= 0} {incr i} {
 
104
                                set farr($i) $line
 
105
                        }
 
106
                        close $oid
 
107
 
 
108
                        set oid [open $t2 w]
 
109
                        for {set i 1} {$i <= $newent} {incr i} {
 
110
                                # Sed uses 1-based line numbers
 
111
                                set x [expr $i - $subdb]
 
112
                                if { [expr $x % $nsubdbs] != 0 } {
 
113
                                        set beg [expr $subdb * $newent]
 
114
                                        set beg [expr $beg + $i]
 
115
                                        puts $oid $farr($beg)
 
116
                                }
 
117
                        }
 
118
                        close $oid
 
119
                        filesort $t1 $t3
 
120
                }
 
121
 
 
122
                error_check_good Subdbtest002:diff($t3,$t2) \
 
123
                    [filecmp $t3 $t2] 0
 
124
 
 
125
                puts "\tSubdbtest002.c: sub$subdb.db: close, open, and dump file"
 
126
                # Now, reopen the file and run the last test again.
 
127
                open_and_dump_subfile $testfile NULL $txn $t1 $checkfunc \
 
128
                    dump_file_direction "-first" "-next" sub$subdb.db
 
129
                if { [string compare $method "-recno"] != 0 } {
 
130
                        filesort $t1 $t3
 
131
                }
 
132
 
 
133
                error_check_good Subdbtest002:diff($t2,$t3) \
 
134
                    [filecmp $t2 $t3] 0
 
135
 
 
136
                # Now, reopen the file and run the last test again in the
 
137
                # reverse direction.
 
138
                puts "\tSubdbtest002.d: sub$subdb.db: close, open, and dump file in reverse direction"
 
139
                open_and_dump_subfile $testfile NULL $txn $t1 $checkfunc \
 
140
                    dump_file_direction "-last" "-prev" sub$subdb.db
 
141
 
 
142
                if { [string compare $method "-recno"] != 0 } {
 
143
                        filesort $t1 $t3
 
144
                }
 
145
 
 
146
                error_check_good Subdbtest002:diff($t3,$t2) \
 
147
                    [filecmp $t3 $t2] 0
 
148
        }
 
149
        set dict $dictorig
 
150
        return
 
151
}
 
152
 
 
153
# Check function for Subdbtest002; keys and data are identical
 
154
proc subdbtest002.check { key data } {
 
155
        error_check_good "key/data mismatch" $data $key
 
156
}
 
157
 
 
158
proc subdbtest002_recno.check { key data } {
 
159
global dict
 
160
global kvals
 
161
        error_check_good key"$key"_exists [info exists kvals($key)] 1
 
162
        error_check_good "key/data mismatch, key $key" $data $kvals($key)
 
163
}