1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1999,2008 Oracle. All rights reserved. 4# 5# $Id: sdb020.tcl,v 12.9 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST sdb020 8# TEST Tests in-memory subdatabases. 9# TEST Create an in-memory subdb with one page size. Close, and 10# TEST open with a different page size: should fail. 11 12proc sdb020 { method { nentries 10 } args } { 13 source ./include.tcl 14 global errorCode 15 16 set tnum "020" 17 set args [convert_args $method $args] 18 set omethod [convert_method $method] 19 20 if { [is_queueext $method] == 1 } { 21 puts "Subdb$tnum: skipping for method $method" 22 return 23 } 24 25 set pgindex [lsearch -exact $args "-pagesize"] 26 if { $pgindex != -1 } { 27 puts "Subdb$tnum: skipping for specific page sizes." 28 return 29 } 30 31 # If we are using an env, then skip this test. It needs its own. 32 set eindex [lsearch -exact $args "-env"] 33 if { $eindex != -1 } { 34 set env NULL 35 incr eindex 36 set env [lindex $args $eindex] 37 puts "Subdb020 skipping for env $env" 38 return 39 } 40 41 # In-memory dbs never go to disk, so we can't do checksumming. 42 # If the test module sent in the -chksum arg, get rid of it. 43 set chkindex [lsearch -exact $args "-chksum"] 44 if { $chkindex != -1 } { 45 set args [lreplace $args $chkindex $chkindex] 46 } 47 48 puts "Subdb$tnum: $method ($args) \ 49 in-memory named db tests with different pagesizes" 50 51 # Create the env. 52 env_cleanup $testdir 53 set env [berkdb_env_noerr -create -home $testdir -txn] 54 error_check_good dbenv [is_valid_env $env] TRUE 55 56 # Set filename to NULL; this causes the creation of an in-memory 57 # subdb. 58 set testfile "" 59 set name NAME 60 61 puts "\tSubdb$tnum.a: Create in-mem named db with default page size." 62 set db [eval {berkdb_open_noerr -create -mode 0644} \ 63 $args -env $env {$omethod $testfile $name}] 64 error_check_good dbopen [is_valid_db $db] TRUE 65 66 # Figure out the default page size so we can try to open 67 # later with a different value. 68 set psize [stat_field $db stat "Page size"] 69 if { $psize == 512 } { 70 set psize2 2048 71 } else { 72 set psize2 512 73 } 74 75 error_check_good db_close [$db close] 0 76 77 # Try to open again with a different page size (should fail). 78 puts "\tSubdb$tnum.b: Try to reopen with different page size." 79 set errorCode NONE 80 catch {set db [eval {berkdb_open_noerr} $args -env $env \ 81 -pagesize $psize2 {$omethod $testfile $name}]} res 82 error_check_good expect_error [is_substr $errorCode EINVAL] 1 83 84 # Try to open again with the correct pagesize (should succeed). 85 puts "\tSubdb$tnum.c: Reopen with original page size." 86 set db [eval {berkdb_open_noerr} $args -env $env \ 87 -pagesize $psize {$omethod $testfile $name}] 88 # Close DB 89 error_check_good db_close [$db close] 0 90 91 puts "\tSubdb$tnum.d: Create in-mem named db with specific page size." 92 set psize 8192 93 set db [eval {berkdb_open_noerr -create -mode 0644} \ 94 $args -env $env -pagesize $psize {$omethod $testfile $name}] 95 error_check_good dbopen [is_valid_db $db] TRUE 96 error_check_good db_close [$db close] 0 97 98 # Try to open again with a different page size (should fail). 99 set psize2 [expr $psize / 2] 100 puts "\tSubdb$tnum.e: Try to reopen with different page size." 101 set errorCode NONE 102 catch {set db [eval {berkdb_open_noerr} $args -env $env \ 103 -pagesize $psize2 {$omethod $testfile $name}]} res 104 error_check_good expect_error [is_substr $errorCode EINVAL] 1 105 106 # Try to open again with the correct pagesize (should succeed). 107 puts "\tSubdb$tnum.f: Reopen with original page size." 108 set db [eval {berkdb_open} $args -env $env \ 109 -pagesize $psize {$omethod $testfile $name}] 110 111 # Try to open a different database with a different page size 112 # (should succeed). 113 puts "\tSubdb$tnum.g: Open different db with different page size." 114 set newname NEWNAME 115 set db2 [eval {berkdb_open} -create $args -env $env \ 116 -pagesize $psize2 {$omethod $testfile $newname}] 117 118 # Clean up. 119 error_check_good db_close [$db close] 0 120 error_check_good db2_close [$db2 close] 0 121 error_check_good env_close [$env close] 0 122} 123 124 125