1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2004,2008 Oracle. All rights reserved. 4# 5# $Id: sdb017.tcl,v 12.9 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST sdb017 8# TEST Test DB->rename() for in-memory named databases. 9proc sdb017 { method args } { 10 global errorCode 11 source ./include.tcl 12 13 if { [is_queueext $method] == 1 } { 14 puts "Subdb017: Skipping for method $method" 15 return 16 } 17 18 set omethod [convert_method $method] 19 set args [convert_args $method $args] 20 21 puts "Subdb017: $method ($args): DB->rename() for in-memory named dbs." 22 23 # Skip test if given an env - this test 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 "Subdb017 skipping for env $env" 29 return 30 } 31 32 # In-memory dbs never go to disk, so we can't do checksumming. 33 # If the test module sent in the -chksum arg, get rid of it. 34 set chkindex [lsearch -exact $args "-chksum"] 35 if { $chkindex != -1 } { 36 set args [lreplace $args $chkindex $chkindex] 37 } 38 39 # Make sure we're starting from a clean slate. 40 env_cleanup $testdir 41 42 # Set up env. 43 set env [berkdb_env_noerr -create -home $testdir -mode 0644] 44 error_check_good env_open [is_valid_env $env] TRUE 45 46 set oldsdb OLDDB 47 set newsdb NEWDB 48 49 puts "\tSubdb017.a: Create/rename file" 50 puts "\t\tSubdb017.a.1: create" 51 set testfile "" 52 set db [eval {berkdb_open_noerr -create -mode 0644}\ 53 $omethod -env $env $args {$testfile $oldsdb}] 54 error_check_good dbopen [is_valid_db $db] TRUE 55 56 # The nature of the key and data are unimportant; use numeric key 57 # so record-based methods don't need special treatment. 58 set key 1 59 set data [pad_data $method data] 60 61 error_check_good dbput [eval {$db put} $key $data] 0 62 error_check_good dbclose [$db close] 0 63 64 puts "\t\tSubdb017.a.2: rename" 65 error_check_good rename_file [eval {berkdb dbrename} -env $env \ 66 {$testfile $oldsdb $newsdb}] 0 67 68 puts "\t\tSubdb017.a.3: check" 69 # Open again with create to make sure we've really completely 70 # disassociated the subdb from the old name. 71 set odb [eval {berkdb_open_noerr -create -mode 0644}\ 72 $omethod -env $env $args {$testfile $oldsdb}] 73 error_check_good odb_open [is_valid_db $odb] TRUE 74 set odbt [$odb get $key] 75 error_check_good odb_close [$odb close] 0 76 77 set ndb [eval {berkdb_open_noerr -mode 0644}\ 78 $omethod -env $env $args {$testfile $newsdb}] 79 error_check_good ndb_open [is_valid_db $ndb] TRUE 80 set ndbt [$ndb get $key] 81 error_check_good ndb_close [$ndb close] 0 82 83 # The DBT from the "old" database should be empty, not the "new" one. 84 error_check_good odbt_empty [llength $odbt] 0 85 error_check_bad ndbt_empty [llength $ndbt] 0 86 error_check_good ndbt [lindex [lindex $ndbt 0] 1] $data 87 88 # Now there's both an old and a new. Rename the "new" to the "old" 89 # and make sure that fails. 90 puts "\tSubdb017.b: Make sure rename fails instead of overwriting" 91 set errorCode NONE 92 set ret [catch {eval {berkdb dbrename} -env $env \ 93 {$testfile $oldsdb $newsdb}} res] 94 error_check_bad rename_overwrite $ret 0 95 error_check_good rename_overwrite_ret [is_substr $errorCode EEXIST] 1 96 97 error_check_good env_close [$env close] 0 98} 99 100