~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/test044.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 1996-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# TEST  test044
9
 
# TEST  Small system integration tests
10
 
# TEST          Test proper functioning of the checkpoint daemon,
11
 
# TEST          recovery, transactions, etc.
12
 
# TEST
13
 
# TEST  System integration DB test: verify that locking, recovery, checkpoint,
14
 
# TEST  and all the other utilities basically work.
15
 
# TEST
16
 
# TEST  The test consists of $nprocs processes operating on $nfiles files.  A
17
 
# TEST  transaction consists of adding the same key/data pair to some random
18
 
# TEST  number of these files.  We generate a bimodal distribution in key size
19
 
# TEST  with 70% of the keys being small (1-10 characters) and the remaining
20
 
# TEST  30% of the keys being large (uniform distribution about mean $key_avg).
21
 
# TEST  If we generate a key, we first check to make sure that the key is not
22
 
# TEST  already in the dataset.  If it is, we do a lookup.
23
 
#
24
 
# XXX
25
 
# This test uses grow-only files currently!
26
 
proc test044 { method {nprocs 5} {nfiles 10} {cont 0} args } {
27
 
        source ./include.tcl
28
 
        global encrypt
29
 
        global rand_init
30
 
 
31
 
        set args [convert_args $method $args]
32
 
        set omethod [convert_method $method]
33
 
 
34
 
        berkdb srand $rand_init
35
 
 
36
 
        # If we are using an env, then skip this test.  It needs its own.
37
 
        set eindex [lsearch -exact $args "-env"]
38
 
        if { $eindex != -1 } {
39
 
                incr eindex
40
 
                set env [lindex $args $eindex]
41
 
                puts "Test044 skipping for env $env"
42
 
                return
43
 
        }
44
 
        if { $encrypt != 0 } {
45
 
                puts "Test044 skipping for security"
46
 
                return
47
 
        }
48
 
 
49
 
        puts "Test044: system integration test db $method $nprocs processes \
50
 
            on $nfiles files"
51
 
 
52
 
        # Parse options
53
 
        set otherargs ""
54
 
        set key_avg 10
55
 
        set data_avg 20
56
 
        set do_exit 0
57
 
        for { set i 0 } { $i < [llength $args] } {incr i} {
58
 
                switch -regexp -- [lindex $args $i] {
59
 
                        -key_avg { incr i; set key_avg [lindex $args $i] }
60
 
                        -data_avg { incr i; set data_avg [lindex $args $i] }
61
 
                        -testdir { incr i; set testdir [lindex $args $i] }
62
 
                        -x.* { set do_exit 1 }
63
 
                        default {
64
 
                                lappend otherargs [lindex $args $i]
65
 
                        }
66
 
                }
67
 
        }
68
 
 
69
 
        if { $cont == 0 } {
70
 
                # Create the database and open the dictionary
71
 
                env_cleanup $testdir
72
 
 
73
 
                # Create an environment
74
 
                puts "\tTest044.a: creating environment and $nfiles files"
75
 
                set dbenv [berkdb_env -create -txn -home $testdir]
76
 
                error_check_good env_open [is_valid_env $dbenv] TRUE
77
 
 
78
 
                # Create a bunch of files
79
 
                set m $method
80
 
 
81
 
                for { set i 0 } { $i < $nfiles } { incr i } {
82
 
                        if { $method == "all" } {
83
 
                                switch [berkdb random_int 1 2] {
84
 
                                1 { set m -btree }
85
 
                                2 { set m -hash }
86
 
                                }
87
 
                        } else {
88
 
                                set m $omethod
89
 
                        }
90
 
 
91
 
                        set db [eval {berkdb_open -env $dbenv -create \
92
 
                            -mode 0644 $m} $otherargs {test044.$i.db}]
93
 
                        error_check_good dbopen [is_valid_db $db] TRUE
94
 
                        error_check_good db_close [$db close] 0
95
 
                }
96
 
        }
97
 
 
98
 
        # Close the environment
99
 
        $dbenv close
100
 
 
101
 
        if { $do_exit == 1 } {
102
 
                return
103
 
        }
104
 
 
105
 
        # Database is created, now fork off the kids.
106
 
        puts "\tTest044.b: forking off $nprocs processes and utilities"
107
 
        set cycle 1
108
 
        set ncycles 3
109
 
        while { $cycle <= $ncycles } {
110
 
                set dbenv [berkdb_env -create -txn -home $testdir]
111
 
                error_check_good env_open [is_valid_env $dbenv] TRUE
112
 
 
113
 
                # Fire off deadlock detector and checkpointer
114
 
                puts "Beginning cycle $cycle"
115
 
                set ddpid [exec $util_path/db_deadlock -h $testdir -t 5 &]
116
 
                set cppid [exec $util_path/db_checkpoint -h $testdir -p 2 &]
117
 
                puts "Deadlock detector: $ddpid Checkpoint daemon $cppid"
118
 
 
119
 
                set pidlist {}
120
 
                for { set i 0 } {$i < $nprocs} {incr i} {
121
 
                        set p [exec $tclsh_path \
122
 
                            $test_path/sysscript.tcl $testdir \
123
 
                            $nfiles $key_avg $data_avg $omethod \
124
 
                            >& $testdir/test044.$i.log &]
125
 
                        lappend pidlist $p
126
 
                }
127
 
                set sleep [berkdb random_int 300 600]
128
 
                puts \
129
 
"[timestamp] $nprocs processes running $pidlist for $sleep seconds"
130
 
                tclsleep $sleep
131
 
 
132
 
                # Now simulate a crash
133
 
                puts "[timestamp] Crashing"
134
 
 
135
 
                #
136
 
                # The environment must remain open until this point to get
137
 
                # proper sharing (using the paging file) on Win/9X.  [#2342]
138
 
                #
139
 
                error_check_good env_close [$dbenv close] 0
140
 
 
141
 
                tclkill $ddpid
142
 
                tclkill $cppid
143
 
 
144
 
                foreach p $pidlist {
145
 
                        tclkill $p
146
 
                }
147
 
 
148
 
                # Check for test failure
149
 
                set e [eval findfail [glob $testdir/test044.*.log]]
150
 
                error_check_good "FAIL: error message(s) in log files" $e 0
151
 
 
152
 
                # Now run recovery
153
 
                test044_verify $testdir $nfiles
154
 
                incr cycle
155
 
        }
156
 
}
157
 
 
158
 
proc test044_usage { } {
159
 
        puts -nonewline "test044 method nentries [-d directory] [-i iterations]"
160
 
        puts " [-p procs] -x"
161
 
}
162
 
 
163
 
proc test044_verify { dir nfiles } {
164
 
        source ./include.tcl
165
 
 
166
 
        # Save everything away in case something breaks
167
 
#       for { set f 0 } { $f < $nfiles } {incr f} {
168
 
#               file copy -force $dir/test044.$f.db $dir/test044.$f.save1
169
 
#       }
170
 
#       foreach f [glob $dir/log.*] {
171
 
#               if { [is_substr $f save] == 0 } {
172
 
#                       file copy -force $f $f.save1
173
 
#               }
174
 
#       }
175
 
 
176
 
        # Run recovery and then read through all the database files to make
177
 
        # sure that they all look good.
178
 
 
179
 
        puts "\tTest044.verify: Running recovery and verifying file contents"
180
 
        set stat [catch {exec $util_path/db_recover -h $dir} result]
181
 
        if { $stat == 1 } {
182
 
                error "FAIL: Recovery error: $result."
183
 
        }
184
 
 
185
 
        # Save everything away in case something breaks
186
 
#       for { set f 0 } { $f < $nfiles } {incr f} {
187
 
#               file copy -force $dir/test044.$f.db $dir/test044.$f.save2
188
 
#       }
189
 
#       foreach f [glob $dir/log.*] {
190
 
#               if { [is_substr $f save] == 0 } {
191
 
#                       file copy -force $f $f.save2
192
 
#               }
193
 
#       }
194
 
 
195
 
        for { set f 0 } { $f < $nfiles } { incr f } {
196
 
                set db($f) [berkdb_open $dir/test044.$f.db]
197
 
                error_check_good $f:dbopen [is_valid_db $db($f)] TRUE
198
 
 
199
 
                set cursors($f) [$db($f) cursor]
200
 
                error_check_bad $f:cursor_open $cursors($f) NULL
201
 
                error_check_good \
202
 
                    $f:cursor_open [is_substr $cursors($f) $db($f)] 1
203
 
        }
204
 
 
205
 
        for { set f 0 } { $f < $nfiles } { incr f } {
206
 
                for {set d [$cursors($f) get -first] } \
207
 
                    { [string length $d] != 0 } \
208
 
                    { set d [$cursors($f) get -next] } {
209
 
 
210
 
                        set k [lindex [lindex $d 0] 0]
211
 
                        set d [lindex [lindex $d 0] 1]
212
 
 
213
 
                        set flist [zero_list $nfiles]
214
 
                        set r $d
215
 
                        while { [set ndx [string first : $r]] != -1 } {
216
 
                                set fnum [string range $r 0 [expr $ndx - 1]]
217
 
                                if { [lindex $flist $fnum] == 0 } {
218
 
                                        set fl "-set"
219
 
                                } else {
220
 
                                        set fl "-next"
221
 
                                }
222
 
 
223
 
                                if { $fl != "-set" || $fnum != $f } {
224
 
                                        if { [string compare $fl "-set"] == 0} {
225
 
                                                set full [$cursors($fnum) \
226
 
                                                    get -set $k]
227
 
                                        } else  {
228
 
                                                set full [$cursors($fnum) \
229
 
                                                    get -next]
230
 
                                        }
231
 
                                        set key [lindex [lindex $full 0] 0]
232
 
                                        set rec [lindex [lindex $full 0] 1]
233
 
                                        error_check_good \
234
 
                                            $f:dbget_$fnum:key $key $k
235
 
                                        error_check_good \
236
 
                                            $f:dbget_$fnum:data $rec $d
237
 
                                }
238
 
 
239
 
                                set flist [lreplace $flist $fnum $fnum 1]
240
 
                                incr ndx
241
 
                                set r [string range $r $ndx end]
242
 
                        }
243
 
                }
244
 
        }
245
 
 
246
 
        for { set f 0 } { $f < $nfiles } { incr f } {
247
 
                error_check_good $cursors($f) [$cursors($f) close] 0
248
 
                error_check_good db_close:$f [$db($f) close] 0
249
 
        }
250
 
}