1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1996,2008 Oracle. All rights reserved. 4# 5# $Id: test026.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST test026 8# TEST Small keys/medium data w/duplicates 9# TEST Put/get per key. 10# TEST Loop through keys -- delete each key 11# TEST ... test that cursors delete duplicates correctly 12# TEST 13# TEST Keyed delete test through cursor. If ndups is small; this will 14# TEST test on-page dups; if it's large, it will test off-page dups. 15proc test026 { method {nentries 2000} {ndups 5} {tnum "026"} args} { 16 source ./include.tcl 17 18 set args [convert_args $method $args] 19 set omethod [convert_method $method] 20 21 if { [is_record_based $method] == 1 || \ 22 [is_rbtree $method] == 1 } { 23 puts "Test$tnum skipping for method $method" 24 return 25 } 26 # Create the database and open the dictionary 27 set txnenv 0 28 set eindex [lsearch -exact $args "-env"] 29 # 30 # If we are using an env, then testfile should just be the db name. 31 # Otherwise it is the test directory and the name. 32 if { $eindex == -1 } { 33 set testfile $testdir/test$tnum.db 34 set env NULL 35 } else { 36 set testfile test$tnum.db 37 incr eindex 38 set env [lindex $args $eindex] 39 set txnenv [is_txnenv $env] 40 if { $txnenv == 1 } { 41 append args " -auto_commit " 42 # 43 # If we are using txns and running with the 44 # default, set the defaults down a bit. 45 # If we are wanting a lot of dups, set that 46 # down a bit or repl testing takes very long. 47 # 48 if { $nentries == 2000 } { 49 set nentries 100 50 } 51 reduce_dups nentries ndups 52 } 53 set testdir [get_home $env] 54 } 55 cleanup $testdir $env 56 puts "Test$tnum: $method ($args) $nentries keys\ 57 with $ndups dups; cursor delete test" 58 59 set pflags "" 60 set gflags "" 61 set txn "" 62 set count 0 63 64 # Here is the loop where we put and get each key/data pair 65 66 puts "\tTest$tnum.a: Put loop" 67 set db [eval {berkdb_open -create \ 68 -mode 0644} $args {$omethod -dup $testfile}] 69 error_check_good dbopen [is_valid_db $db] TRUE 70 set did [open $dict] 71 while { [gets $did str] != -1 && $count < [expr $nentries * $ndups] } { 72 set datastr [ make_data_str $str ] 73 for { set j 1 } { $j <= $ndups} {incr j} { 74 if { $txnenv == 1 } { 75 set t [$env txn] 76 error_check_good txn [is_valid_txn $t $env] TRUE 77 set txn "-txn $t" 78 } 79 set ret [eval {$db put} \ 80 $txn $pflags {$str [chop_data $method $j$datastr]}] 81 error_check_good db_put $ret 0 82 if { $txnenv == 1 } { 83 error_check_good txn [$t commit] 0 84 } 85 incr count 86 } 87 } 88 close $did 89 90 error_check_good db_close [$db close] 0 91 set db [eval {berkdb_open} $args $testfile] 92 error_check_good dbopen [is_valid_db $db] TRUE 93 94 # Now we will sequentially traverse the database getting each 95 # item and deleting it. 96 set count 0 97 if { $txnenv == 1 } { 98 set t [$env txn] 99 error_check_good txn [is_valid_txn $t $env] TRUE 100 set txn "-txn $t" 101 } 102 set dbc [eval {$db cursor} $txn] 103 error_check_good db_cursor [is_substr $dbc $db] 1 104 105 puts "\tTest$tnum.b: Get/delete loop" 106 set i 1 107 for { set ret [$dbc get -first] } { 108 [string length $ret] != 0 } { 109 set ret [$dbc get -next] } { 110 111 set key [lindex [lindex $ret 0] 0] 112 set data [lindex [lindex $ret 0] 1] 113 if { $i == 1 } { 114 set curkey $key 115 } 116 error_check_good seq_get:key $key $curkey 117 error_check_good \ 118 seq_get:data $data [pad_data $method $i[make_data_str $key]] 119 120 if { $i == $ndups } { 121 set i 1 122 } else { 123 incr i 124 } 125 126 # Now delete the key 127 set ret [$dbc del] 128 error_check_good db_del:$key $ret 0 129 } 130 error_check_good dbc_close [$dbc close] 0 131 if { $txnenv == 1 } { 132 error_check_good txn [$t commit] 0 133 } 134 error_check_good db_close [$db close] 0 135 136 puts "\tTest$tnum.c: Verify empty file" 137 # Double check that file is now empty 138 set db [eval {berkdb_open} $args $testfile] 139 error_check_good dbopen [is_valid_db $db] TRUE 140 if { $txnenv == 1 } { 141 set t [$env txn] 142 error_check_good txn [is_valid_txn $t $env] TRUE 143 set txn "-txn $t" 144 } 145 set dbc [eval {$db cursor} $txn] 146 error_check_good db_cursor [is_substr $dbc $db] 1 147 set ret [$dbc get -first] 148 error_check_good get_on_empty [string length $ret] 0 149 error_check_good dbc_close [$dbc close] 0 150 if { $txnenv == 1 } { 151 error_check_good txn [$t commit] 0 152 } 153 error_check_good db_close [$db close] 0 154} 155