1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1999,2008 Oracle. All rights reserved. 4# 5# $Id: sdb014.tcl,v 12.12 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST sdb014 8# TEST Tests mixing in-memory named and in-memory unnamed dbs. 9# TEST Create a regular in-memory db, add data. 10# TEST Create a named in-memory db. 11# TEST Try to create the same named in-memory db again (should fail). 12# TEST Try to create a different named in-memory db (should succeed). 13# TEST 14proc sdb014 { method args } { 15 source ./include.tcl 16 17 set tnum "014" 18 set orig_tdir $testdir 19 if { [is_queueext $method] == 1 } { 20 puts "Subdb$tnum: skipping for method $method" 21 return 22 } 23 24 set args [convert_args $method $args] 25 set omethod [convert_method $method] 26 27 # In-memory dbs never go to disk, so we can't do checksumming. 28 # If the test module sent in the -chksum arg, get rid of it. 29 set chkindex [lsearch -exact $args "-chksum"] 30 if { $chkindex != -1 } { 31 set args [lreplace $args $chkindex $chkindex] 32 } 33 34 puts "Subdb$tnum ($method $args):\ 35 In-memory named dbs with regular in-mem dbs." 36 37 # If we are given an env, use it. Otherwise, open one. 38 set txnenv 0 39 set eindex [lsearch -exact $args "-env"] 40 if { $eindex == -1 } { 41 env_cleanup $testdir 42 set env [berkdb_env -create -home $testdir] 43 error_check_good env_open [is_valid_env $env] TRUE 44 } else { 45 incr eindex 46 set env [lindex $args $eindex] 47 set envflags [$env get_open_flags] 48 set txnenv [is_txnenv $env] 49 if { $txnenv == 1 } { 50 append args " -auto_commit " 51 } 52 set testdir [get_home $env] 53 } 54 55 puts "\tSubdb$tnum.a: Create and populate in-memory unnamed database." 56 set testfile "" 57 set db [eval {berkdb_open -env $env -create -mode 0644} \ 58 $args {$omethod $testfile}] 59 error_check_good dbopen [is_valid_db $db] TRUE 60 set did [open $dict] 61 62 set pflags "" 63 set gflags "" 64 set count 0 65 66 if { [is_record_based $method] == 1 } { 67 append gflags " -recno" 68 } 69 while { [gets $did str] != -1 && $count < 5 } { 70 if { [is_record_based $method] == 1 } { 71 global kvals 72 73 set key [expr $count + 1] 74 set kvals($key) $str 75 } else { 76 set key $str 77 } 78 set ret [eval \ 79 {$db put} $pflags {$key [chop_data $method $str]}] 80 error_check_good put $ret 0 81 82 set ret [eval {$db get} $gflags {$key}] 83 error_check_good \ 84 get $ret [list [list $key [pad_data $method $str]]] 85 incr count 86 } 87 close $did 88 error_check_good db_close [$db close] 0 89 90 # Create named in-memory db. Try to create a second in-memory db of 91 # the same name. Should fail. 92 puts "\tSubdb$tnum.b: Create in-memory named database." 93 set subdb "SUBDB" 94 set db [eval {berkdb_open -env $env -create -excl -mode 0644} \ 95 $args $omethod {$testfile $subdb}] 96 error_check_good dbopen [is_valid_db $db] TRUE 97 98 puts "\tSubdb$tnum.c: Try to create second inmem database." 99 set ret [catch {eval {berkdb_open_noerr -env $env -create -excl \ 100 -mode 0644} $args {$omethod $testfile $subdb}} db1] 101 error_check_bad dbopen $ret 0 102 103 # Clean up. Close the env if this test created it. 104 error_check_good db_close [$db close] 0 105 if { $eindex == -1 } { 106 error_check_good env_close [$env close] 0 107 } 108 109 set testdir $orig_tdir 110 return 111} 112 113