1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1996,2008 Oracle. All rights reserved. 4# 5# $Id: test012.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST test012 8# TEST Large keys/small data 9# TEST Same as test003 except use big keys (source files and 10# TEST executables) and small data (the file/executable names). 11# TEST 12# TEST Take the source files and dbtest executable and enter their contents 13# TEST as the key with their names as data. After all are entered, retrieve 14# TEST all; compare output to original. Close file, reopen, do retrieve and 15# TEST re-verify. 16proc test012 { method args} { 17 global names 18 source ./include.tcl 19 20 set args [convert_args $method $args] 21 set omethod [convert_method $method] 22 23 if { [is_record_based $method] == 1 } { 24 puts "Test012 skipping for method $method" 25 return 26 } 27 28 puts "Test012: $method ($args) filename=data filecontents=key pairs" 29 30 # Create the database and open the dictionary 31 set txnenv 0 32 set eindex [lsearch -exact $args "-env"] 33 # 34 # If we are using an env, then testfile should just be the db name. 35 # Otherwise it is the test directory and the name. 36 if { $eindex == -1 } { 37 set testfile $testdir/test012.db 38 set env NULL 39 } else { 40 set testfile test012.db 41 incr eindex 42 set env [lindex $args $eindex] 43 set txnenv [is_txnenv $env] 44 if { $txnenv == 1 } { 45 append args " -auto_commit " 46 } 47 set testdir [get_home $env] 48 } 49 set t1 $testdir/t1 50 set t2 $testdir/t2 51 set t3 $testdir/t3 52 set t4 $testdir/t4 53 54 cleanup $testdir $env 55 56 set db [eval {berkdb_open \ 57 -create -mode 0644} $args {$omethod $testfile}] 58 error_check_good dbopen [is_valid_db $db] TRUE 59 60 set pflags "" 61 set gflags "" 62 set txn "" 63 64 # Here is the loop where we put and get each key/data pair 65 set file_list [get_file_list] 66 67 puts "\tTest012.a: put/get loop" 68 set count 0 69 foreach f $file_list { 70 if { $txnenv == 1 } { 71 set t [$env txn] 72 error_check_good txn [is_valid_txn $t $env] TRUE 73 set txn "-txn $t" 74 } 75 put_file_as_key $db $txn $pflags $f 76 77 set kd [get_file_as_key $db $txn $gflags $f] 78 if { $txnenv == 1 } { 79 error_check_good txn [$t commit] 0 80 } 81 incr count 82 } 83 84 # Now we will get each key from the DB and compare the results 85 # to the original. 86 puts "\tTest012.b: dump file" 87 if { $txnenv == 1 } { 88 set t [$env txn] 89 error_check_good txn [is_valid_txn $t $env] TRUE 90 set txn "-txn $t" 91 } 92 dump_binkey_file $db $txn $t1 test012.check 93 if { $txnenv == 1 } { 94 error_check_good txn [$t commit] 0 95 } 96 error_check_good db_close [$db close] 0 97 98 # Now compare the data to see if they match the .o and dbtest files 99 set oid [open $t2.tmp w] 100 foreach f $file_list { 101 puts $oid $f 102 } 103 close $oid 104 filesort $t2.tmp $t2 105 fileremove $t2.tmp 106 filesort $t1 $t3 107 108 error_check_good Test012:diff($t3,$t2) \ 109 [filecmp $t3 $t2] 0 110 111 # Now, reopen the file and run the last test again. 112 puts "\tTest012.c: close, open, and dump file" 113 open_and_dump_file $testfile $env $t1 test012.check \ 114 dump_binkey_file_direction "-first" "-next" 115 116 filesort $t1 $t3 117 118 error_check_good Test012:diff($t3,$t2) \ 119 [filecmp $t3 $t2] 0 120 121 # Now, reopen the file and run the last test again in reverse direction. 122 puts "\tTest012.d: close, open, and dump file in reverse direction" 123 open_and_dump_file $testfile $env $t1 test012.check\ 124 dump_binkey_file_direction "-last" "-prev" 125 126 filesort $t1 $t3 127 128 error_check_good Test012:diff($t3,$t2) \ 129 [filecmp $t3 $t2] 0 130} 131 132# Check function for test012; key should be file name; data should be contents 133proc test012.check { binfile tmpfile } { 134 source ./include.tcl 135 136 error_check_good Test012:diff($binfile,$tmpfile) \ 137 [filecmp $binfile $tmpfile] 0 138} 139