1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2000,2008 Oracle. All rights reserved. 4# 5# $Id: fop005.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST fop005 8# TEST Test of DB->remove() 9# TEST Formerly test080. 10# TEST Test use of dbremove with and without envs, with absolute 11# TEST and relative paths, and with subdirectories. 12 13proc fop005 { method args } { 14 source ./include.tcl 15 16 set tnum "005" 17 set args [convert_args $method $args] 18 set omethod [convert_method $method] 19 20 puts "Fop$tnum: ($method $args): Test of DB->remove()" 21 22 # Determine full path 23 set curdir [pwd] 24 cd $testdir 25 set fulldir [pwd] 26 cd $curdir 27 set reldir $testdir 28 29 # If we are using an env, then skip this test. 30 # It needs its own. 31 set eindex [lsearch -exact $args "-env"] 32 if { $eindex != -1 } { 33 incr eindex 34 set env [lindex $args $eindex] 35 puts "Skipping fop$tnum for env $env" 36 return 37 } 38 cleanup $testdir NULL 39 40 # Set up absolute and relative pathnames, and a subdirectory. 41 set subdira A 42 set filename fop$tnum.db 43 set extentname __dbq.$filename.0 44 set paths [list $fulldir $reldir] 45 set files [list "$filename $extentname"\ 46 "$subdira/$filename $subdira/$extentname"] 47 48 foreach path $paths { 49 foreach fileset $files { 50 set filename [lindex $fileset 0] 51 set extentname [lindex $fileset 1] 52 53 # Loop through test using the following options: 54 # 1. no environment, not in transaction 55 # 2. with environment, not in transaction 56 # 3. remove with auto-commit 57 # 4. remove in committed transaction 58 # 5. remove in aborted transaction 59 60 foreach op "noenv env auto commit abort" { 61 file mkdir $testdir/$subdira 62 if { $op == "noenv" } { 63 set file $path/$filename 64 set extentfile $path/$extentname 65 set env NULL 66 set envargs "" 67 } else { 68 set file $filename 69 set extentfile $extentname 70 set largs " -txn" 71 if { $op == "env" } { 72 set largs "" 73 } 74 set env [eval {berkdb_env -create \ 75 -home $path} $largs] 76 set envargs " -env $env " 77 error_check_good \ 78 env_open [is_valid_env $env] TRUE 79 } 80 81 puts "\tFop$tnum: dbremove with $op\ 82 in path $path" 83 puts "\t\tFop$tnum.a.1: Create file $file" 84 set db [eval {berkdb_open -create -mode 0644} \ 85 $omethod $envargs $args {$file}] 86 error_check_good db_open [is_valid_db $db] TRUE 87 88 # Use a numeric key so record-based methods 89 # don't need special treatment. 90 set key 1 91 set data [pad_data $method data] 92 93 error_check_good dbput \ 94 [$db put $key [chop_data $method $data]] 0 95 error_check_good dbclose [$db close] 0 96 check_file_exist $file $env $path 1 97 if { [is_queueext $method] == 1 } { 98 check_file_exist \ 99 $extentfile $env $path 1 100 } 101 102 # Use berkdb dbremove for non-txn tests 103 # and $env dbremove for transactional tests 104 puts "\t\tFop$tnum.a.2: Remove file" 105 if { $op == "noenv" || $op == "env" } { 106 error_check_good remove_$op \ 107 [eval {berkdb dbremove} \ 108 $envargs $file] 0 109 } elseif { $op == "auto" } { 110 error_check_good remove_$op \ 111 [eval {$env dbremove} \ 112 -auto_commit $file] 0 113 } else { 114 # $op is "abort" or "commit" 115 set txn [$env txn] 116 error_check_good remove_$op \ 117 [eval {$env dbremove} \ 118 -txn $txn $file] 0 119 error_check_good txn_$op [$txn $op] 0 120 } 121 122 puts "\t\tFop$tnum.a.3: Check that file is gone" 123 # File should now be gone, unless the op is an 124 # abort. Check extent files if necessary. 125 if { $op != "abort" } { 126 check_file_exist $file $env $path 0 127 if { [is_queueext $method] == 1 } { 128 check_file_exist \ 129 $extentfile $env $path 0 130 } 131 } else { 132 check_file_exist $file $env $path 1 133 if { [is_queueext $method] == 1 } { 134 check_file_exist \ 135 $extentfile $env $path 1 136 } 137 } 138 139 if { $env != "NULL" } { 140 error_check_good envclose [$env close] 0 141 } 142 env_cleanup $path 143 check_file_exist $file $env $path 0 144 } 145 } 146 } 147} 148