1 # See the file LICENSE for redistribution information.
3 # Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
8 # TEST Test Automatic Resource Management. [#16188][#20281]
9 # TEST Open an environment, and open a database in it.
10 # TEST Do some operations in the database, including:
11 # TEST insert, dump, delete
12 # TEST Close the environment without closing the database.
13 # TEST Re-open the database and verify the records are the ones we expected.
15 proc test137 { method {nentries 1000} {start 0} {skip 0} {use_encrypt 0}
16 {tnum "137"} {envtype "ds"} args } {
21 # This test needs its own env.
22 set eindex [lsearch -exact $args "-env"]
23 if { $eindex != -1 } {
25 set env [lindex $args $eindex]
26 puts "Test$tnum skipping for env $env"
30 # Skip if use_encrypt and encryption is not supported.
31 if { $use_encrypt && $has_crypto == 0 } {
32 puts "Skipping test$tnum for non-crypto release."
36 # Do not use db encryption flags from the $args -- this test
37 # does its own encryption testing at the env level.
40 puts "Test$tnum skipping DB encryption"
44 # We can not specify chksum option to opening db when using
46 set chksum_indx [lsearch -exact $args "-chksum"]
47 if { $chksum_indx != -1 && $use_encrypt } {
48 puts "Test$tnum skipping DB chksum"
52 set encmsg "non-encrypt"
57 set args [convert_args $method $args]
58 set omethod [convert_method $method]
61 set env [test137_openenv $envtype $testdir $use_encrypt]
62 set envargs "-env $env"
63 set txnenv [string equal $envtype "tds"]
66 append args " -auto_commit"
69 set testfile test$tnum.db
73 puts "Test$tnum: $method \
74 ($envtype,$encmsg,$args) $nentries equal key/data pairs"
77 # The "start" variable determines the record number to start
78 # with, if we're using record numbers. The "skip" variable
79 # determines the dictionary entry to start with.
80 # In normal use, skip will match start.
81 puts "\tTest$tnum: Starting at $start with dictionary entry $skip"
83 for { set count 0 } { $count < $skip } { incr count } {
88 set db [eval {berkdb_open \
89 -create -mode 0644} $envargs $args $omethod $testfile]
90 error_check_good dbopen [is_valid_db $db] TRUE
95 error_check_good txn [is_valid_txn $t $env] TRUE
99 puts "\tTest$tnum.a: put loop"
100 # Here is the loop where we put and get each key/data pair
104 while { [gets $did str] != -1 && $count < $nentries } {
105 if { [is_record_based $method] == 1 } {
106 set key [expr $count + 1 + $start]
109 set str [reverse $str]
112 {$db put} $txn {$key [chop_data $method $str]}]
113 error_check_good db_put $ret 0
114 lappend key_list $key
115 lappend data_list $str
120 puts "\tTest$tnum.b: dump file and close env without closing database"
121 dump_file $db $txn $t1 NONE
122 if { $txnenv == 1 } {
123 error_check_good txn_commit [$t commit] 0
125 error_check_good env_close [$env close] 0
126 # Clean the tcl handle only.
127 catch {$db close -handle_only} res
129 puts "\tTest$tnum.c: open the env and database again"
130 set env [test137_openenv $envtype $testdir $use_encrypt]
131 set envargs "-env $env"
132 set db [eval {berkdb_open \
133 -create -mode 0644} $envargs $args $omethod $testfile]
134 error_check_good dbopen [is_valid_db $db] TRUE
136 if { $txnenv == 1 } {
138 error_check_good txn [is_valid_txn $t $env] TRUE
142 puts "\tTest$tnum.d: dump file and check"
143 dump_file $db $txn $t2 NONE
144 error_check_good Test$tnum:diff($t1,$t2) \
147 puts "\tTest$tnum.e: delete loop"
148 # We delete starting from the last record, since for rrecno, if we
149 # delete previous records, the ones after will change their keys.
150 for {set i [expr [llength $key_list] - 1]} {$i >= 0} \
151 {incr i -[berkdb random_int 1 5]} {
152 set key [lindex $key_list $i]
153 set ret [eval $db del $txn {$key}]
154 error_check_good db_del $ret 0
157 puts "\tTest$tnum.f:\
158 dump file and close env without closing database again"
159 dump_file $db $txn $t1 NONE
160 if { $txnenv == 1 } {
161 error_check_good txn_commit [$t commit] 0
163 error_check_good env_close [$env close -forcesync] 0
164 catch {$db close -handle_only} res
166 # We remove the environment to make sure the regions files
167 # are deleted(including mpool files), so we can verify if
168 # the database has been synced during a force-synced env close.
169 error_check_good env_remove [berkdb envremove -force -home $testdir] 0
171 puts "\tTest$tnum.g: open, dump and check again"
172 set env [test137_openenv $envtype $testdir $use_encrypt]
173 set envargs "-env $env"
174 set db [eval {berkdb_open \
175 -create -mode 0644} $envargs $args $omethod $testfile]
176 error_check_good dbopen [is_valid_db $db] TRUE
178 if { $txnenv == 1 } {
180 error_check_good txn [is_valid_txn $t $env] TRUE
184 dump_file $db $txn $t2 NONE
185 error_check_good Test$tnum:diff($t1,$t2) \
188 if { $txnenv == 1 } {
189 error_check_good txn_commit [$t commit] 0
191 error_check_good db_close [$db close] 0
192 error_check_good env_close [$env close] 0
195 proc test137_openenv {envtype testdir use_encrypt} {
200 set encargs " -encryptaes $passwd "
202 switch -exact "$envtype" {
204 set env [eval berkdb_env_noerr -create -mode 0644 \
205 $encargs -home $testdir]
208 set env [eval berkdb_env_noerr -create -mode 0644 \
209 $encargs -cdb -home $testdir]
212 set env [eval berkdb_env_noerr -create -mode 0644 \
213 $encargs -txn -lock -log -thread -home $testdir]
216 error_check_good env_open [is_valid_env $env] TRUE