1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1999,2008 Oracle. All rights reserved. 4# 5# $Id: test061.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST test061 8# TEST Test of txn abort and commit for in-memory databases. 9# TEST a) Put + abort: verify absence of data 10# TEST b) Put + commit: verify presence of data 11# TEST c) Overwrite + abort: verify that data is unchanged 12# TEST d) Overwrite + commit: verify that data has changed 13# TEST e) Delete + abort: verify that data is still present 14# TEST f) Delete + commit: verify that data has been deleted 15proc test061 { method args } { 16 global alphabet 17 global encrypt 18 global errorCode 19 global passwd 20 source ./include.tcl 21 22 # 23 # If we are using an env, then skip this test. It needs its own. 24 set eindex [lsearch -exact $args "-env"] 25 if { $eindex != -1 } { 26 incr eindex 27 set env [lindex $args $eindex] 28 puts "Test061 skipping for env $env" 29 return 30 } 31 set args [convert_args $method $args] 32 set omethod [convert_method $method] 33 if { [is_queueext $method] == 1} { 34 puts "Test061 skipping for method $method" 35 return 36 } 37 set encargs "" 38 set args [split_encargs $args encargs] 39 40 puts "Test061: Transaction abort and commit test for in-memory data." 41 puts "Test061: $method $args" 42 43 set key "key" 44 set data "data" 45 set otherdata "otherdata" 46 set txn "" 47 set flags "" 48 set gflags "" 49 50 if { [is_record_based $method] == 1} { 51 set key 1 52 set gflags " -recno" 53 } 54 55 puts "\tTest061: Create environment and $method database." 56 env_cleanup $testdir 57 58 # create environment 59 set eflags "-create -txn $encargs -home $testdir" 60 set dbenv [eval {berkdb_env} $eflags] 61 error_check_good dbenv [is_valid_env $dbenv] TRUE 62 63 # db open -- no file specified, in-memory database 64 set flags "-auto_commit -create $args $omethod" 65 set db [eval {berkdb_open -env} $dbenv $flags] 66 error_check_good dbopen [is_valid_db $db] TRUE 67 68 # Here we go with the six test cases. Since we need to verify 69 # a different thing each time, and since we can't just reuse 70 # the same data if we're to test overwrite, we just 71 # plow through rather than writing some impenetrable loop code; 72 # each of the cases is only a few lines long, anyway. 73 74 puts "\tTest061.a: put/abort" 75 76 # txn_begin 77 set txn [$dbenv txn] 78 error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE 79 80 # put a key 81 set ret [eval {$db put} -txn $txn {$key [chop_data $method $data]}] 82 error_check_good db_put $ret 0 83 84 # check for existence 85 set ret [eval {$db get} -txn $txn $gflags {$key}] 86 error_check_good get $ret [list [list $key [pad_data $method $data]]] 87 88 # abort 89 error_check_good txn_abort [$txn abort] 0 90 91 # check for *non*-existence 92 set ret [eval {$db get} $gflags {$key}] 93 error_check_good get $ret {} 94 95 puts "\tTest061.b: put/commit" 96 97 # txn_begin 98 set txn [$dbenv txn] 99 error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE 100 101 # put a key 102 set ret [eval {$db put} -txn $txn {$key [chop_data $method $data]}] 103 error_check_good db_put $ret 0 104 105 # check for existence 106 set ret [eval {$db get} -txn $txn $gflags {$key}] 107 error_check_good get $ret [list [list $key [pad_data $method $data]]] 108 109 # commit 110 error_check_good txn_commit [$txn commit] 0 111 112 # check again for existence 113 set ret [eval {$db get} $gflags {$key}] 114 error_check_good get $ret [list [list $key [pad_data $method $data]]] 115 116 puts "\tTest061.c: overwrite/abort" 117 118 # txn_begin 119 set txn [$dbenv txn] 120 error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE 121 122 # overwrite {key,data} with {key,otherdata} 123 set ret [eval {$db put} -txn $txn {$key [chop_data $method $otherdata]}] 124 error_check_good db_put $ret 0 125 126 # check for existence 127 set ret [eval {$db get} -txn $txn $gflags {$key}] 128 error_check_good get $ret \ 129 [list [list $key [pad_data $method $otherdata]]] 130 131 # abort 132 error_check_good txn_abort [$txn abort] 0 133 134 # check that data is unchanged ($data not $otherdata) 135 set ret [eval {$db get} $gflags {$key}] 136 error_check_good get $ret [list [list $key [pad_data $method $data]]] 137 138 puts "\tTest061.d: overwrite/commit" 139 140 # txn_begin 141 set txn [$dbenv txn] 142 error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE 143 144 # overwrite {key,data} with {key,otherdata} 145 set ret [eval {$db put} -txn $txn {$key [chop_data $method $otherdata]}] 146 error_check_good db_put $ret 0 147 148 # check for existence 149 set ret [eval {$db get} -txn $txn $gflags {$key}] 150 error_check_good get $ret \ 151 [list [list $key [pad_data $method $otherdata]]] 152 153 # commit 154 error_check_good txn_commit [$txn commit] 0 155 156 # check that data has changed ($otherdata not $data) 157 set ret [eval {$db get} $gflags {$key}] 158 error_check_good get $ret \ 159 [list [list $key [pad_data $method $otherdata]]] 160 161 puts "\tTest061.e: delete/abort" 162 163 # txn_begin 164 set txn [$dbenv txn] 165 error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE 166 167 # delete 168 set ret [eval {$db del} -txn $txn {$key}] 169 error_check_good db_put $ret 0 170 171 # check for nonexistence 172 set ret [eval {$db get} -txn $txn $gflags {$key}] 173 error_check_good get $ret {} 174 175 # abort 176 error_check_good txn_abort [$txn abort] 0 177 178 # check for existence 179 set ret [eval {$db get} $gflags {$key}] 180 error_check_good get $ret \ 181 [list [list $key [pad_data $method $otherdata]]] 182 183 puts "\tTest061.f: delete/commit" 184 185 # txn_begin 186 set txn [$dbenv txn] 187 error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE 188 189 # put a key 190 set ret [eval {$db del} -txn $txn {$key}] 191 error_check_good db_put $ret 0 192 193 # check for nonexistence 194 set ret [eval {$db get} -txn $txn $gflags {$key}] 195 error_check_good get $ret {} 196 197 # commit 198 error_check_good txn_commit [$txn commit] 0 199 200 # check for continued nonexistence 201 set ret [eval {$db get} $gflags {$key}] 202 error_check_good get $ret {} 203 204 # We're done; clean up. 205 error_check_good db_close [eval {$db close}] 0 206 error_check_good env_close [eval {$dbenv close}] 0 207 208 # Now run db_recover and ensure that it runs cleanly. 209 set utilflag "" 210 if { $encrypt != 0 } { 211 set utilflag "-P $passwd" 212 } 213 puts "\tTest061.g: Running db_recover -h" 214 set ret [catch {eval {exec} $util_path/db_recover -h $testdir \ 215 $utilflag} res] 216 if { $ret != 0 } { 217 puts "FAIL: db_recover outputted $res" 218 } 219 error_check_good db_recover $ret 0 220 221 puts "\tTest061.h: Running db_recover -c -h" 222 set ret [catch {eval {exec} $util_path/db_recover -c -h $testdir \ 223 $utilflag} res] 224 error_check_good db_recover-c $ret 0 225} 226