proc fop001 { } {
source ./include.tcl
puts "\nFop001: Multiple file system ops in one transaction"
set exists {a b}
set noexist {foo bar}
set open {}
set cases {}
set ops {rename remove open open_create open_excl truncate}
foreach retval { 0 "file exists" "no such file" "file is open" } {
foreach op1 {rename remove open open_excl \
open_create truncate} {
foreach op2 $ops {
append cases " " [create_tests $op1 $op2 \
$exists $noexist $open $retval]
}
}
}
foreach retval { 0 "file exists" "no such file" "file is open" } {
foreach op1 { rename remove open open_excl } {
foreach op2 $ops {
append cases " " [create_badtests $op1 $op2 \
$exists $noexist $open $retval]
}
}
}
set testid 0
foreach case $cases {
env_cleanup $testdir
incr testid
set op1 [lindex [lindex $case 0] 0]
set args1 [lindex [lindex $case 0] 1]
set res1 [lindex [lindex $case 0] 2]
set op2 [lindex [lindex $case 1] 0]
set args2 [lindex [lindex $case 1] 1]
set res2 [lindex [lindex $case 1] 2]
puts "\tFop001.$testid: $op1 ($args1), then $op2 ($args2)."
set env [berkdb_env -create -home $testdir -txn]
error_check_good is_valid_env [is_valid_env $env] TRUE
set dba [berkdb_open -create -btree -env $env -auto_commit a.db]
error_check_good dba_open [is_valid_db $dba] TRUE
error_check_good dba_put [$dba put -auto_commit 1 a] 0
error_check_good dba_close [$dba close] 0
set dbb [berkdb_open -create -btree -env $env -auto_commit b.db]
error_check_good dbb_open [is_valid_db $dbb] TRUE
error_check_good dbb_put [$dbb put -auto_commit 1 b] 0
error_check_good dbb_close [$dbb close] 0
foreach end {abort commit} {
set txn [$env txn]
set result1 [do_op $op1 $args1 $txn $env]
if {$res1 == 0} {
error_check_good op1_should_succeed $result1 $res1
} else {
set error [extract_error $result1]
error_check_good op1_wrong_failure $error $res1
}
set result2 [do_op $op2 $args2 $txn $env]
if {$res2 == 0} {
error_check_good op2_should_succeed $result2 $res2
} else {
set error [extract_error $result2]
error_check_good op2_wrong_failure $error $res2
}
error_check_good txn_$end [$txn $end] 0
if {$end == "abort"} {
error_check_good a_exists \
[file exists $testdir/a.db] 1
error_check_good b_exists \
[file exists $testdir/b.db] 1
}
}
set handles [berkdb handles]
foreach handle $handles {
if {[string range $handle 0 1] == "db" } {
error_check_good db_close [$handle close] 0
}
}
error_check_good env_close [$env close] 0
error_check_good envremove [berkdb envremove -home $testdir] 0
env_cleanup $testdir
}
}