1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Small system integration tests
10
# TEST Test proper functioning of the checkpoint daemon,
11
# TEST recovery, transactions, etc.
13
# TEST System integration DB test: verify that locking, recovery, checkpoint,
14
# TEST and all the other utilities basically work.
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.
25
# This test uses grow-only files currently!
26
proc test044 { method {nprocs 5} {nfiles 10} {cont 0} args } {
31
set args [convert_args $method $args]
32
set omethod [convert_method $method]
34
berkdb srand $rand_init
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 } {
40
set env [lindex $args $eindex]
41
puts "Test044 skipping for env $env"
44
if { $encrypt != 0 } {
45
puts "Test044 skipping for security"
49
puts "Test044: system integration test db $method $nprocs processes \
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 }
64
lappend otherargs [lindex $args $i]
70
# Create the database and open the dictionary
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
78
# Create a bunch of files
81
for { set i 0 } { $i < $nfiles } { incr i } {
82
if { $method == "all" } {
83
switch [berkdb random_int 1 2] {
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
98
# Close the environment
101
if { $do_exit == 1 } {
105
# Database is created, now fork off the kids.
106
puts "\tTest044.b: forking off $nprocs processes and utilities"
109
while { $cycle <= $ncycles } {
110
set dbenv [berkdb_env -create -txn -home $testdir]
111
error_check_good env_open [is_valid_env $dbenv] TRUE
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"
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 &]
127
set sleep [berkdb random_int 300 600]
129
"[timestamp] $nprocs processes running $pidlist for $sleep seconds"
132
# Now simulate a crash
133
puts "[timestamp] Crashing"
136
# The environment must remain open until this point to get
137
# proper sharing (using the paging file) on Win/9X. [#2342]
139
error_check_good env_close [$dbenv close] 0
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
153
test044_verify $testdir $nfiles
158
proc test044_usage { } {
159
puts -nonewline "test044 method nentries [-d directory] [-i iterations]"
160
puts " [-p procs] -x"
163
proc test044_verify { dir nfiles } {
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
170
# foreach f [glob $dir/log.*] {
171
# if { [is_substr $f save] == 0 } {
172
# file copy -force $f $f.save1
176
# Run recovery and then read through all the database files to make
177
# sure that they all look good.
179
puts "\tTest044.verify: Running recovery and verifying file contents"
180
set stat [catch {exec $util_path/db_recover -h $dir} result]
182
error "FAIL: Recovery error: $result."
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
189
# foreach f [glob $dir/log.*] {
190
# if { [is_substr $f save] == 0 } {
191
# file copy -force $f $f.save2
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
199
set cursors($f) [$db($f) cursor]
200
error_check_bad $f:cursor_open $cursors($f) NULL
202
$f:cursor_open [is_substr $cursors($f) $db($f)] 1
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] } {
210
set k [lindex [lindex $d 0] 0]
211
set d [lindex [lindex $d 0] 1]
213
set flist [zero_list $nfiles]
215
while { [set ndx [string first : $r]] != -1 } {
216
set fnum [string range $r 0 [expr $ndx - 1]]
217
if { [lindex $flist $fnum] == 0 } {
223
if { $fl != "-set" || $fnum != $f } {
224
if { [string compare $fl "-set"] == 0} {
225
set full [$cursors($fnum) \
228
set full [$cursors($fnum) \
231
set key [lindex [lindex $full 0] 0]
232
set rec [lindex [lindex $full 0] 1]
234
$f:dbget_$fnum:key $key $k
236
$f:dbget_$fnum:data $rec $d
239
set flist [lreplace $flist $fnum $fnum 1]
241
set r [string range $r $ndx end]
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