mariadb/bdb/test/test078.tcl

131 lines
3.4 KiB
Tcl
Raw Normal View History

2001-03-05 01:42:05 +01:00
# See the file LICENSE for redistribution information.
#
2002-10-30 12:57:05 +01:00
# Copyright (c) 2000-2002
2001-03-05 01:42:05 +01:00
# Sleepycat Software. All rights reserved.
#
2002-10-30 12:57:05 +01:00
# $Id: test078.tcl,v 1.18 2002/06/20 19:01:02 sue Exp $
2001-03-05 01:42:05 +01:00
#
2002-10-30 12:57:05 +01:00
# TEST test078
# TEST Test of DBC->c_count(). [#303]
2001-03-05 01:42:05 +01:00
proc test078 { method { nkeys 100 } { pagesize 512 } { tnum 78 } args } {
source ./include.tcl
global alphabet rand_init
set args [convert_args $method $args]
set omethod [convert_method $method]
puts "Test0$tnum: Test of key counts."
berkdb srand $rand_init
2002-10-30 12:57:05 +01:00
set txnenv 0
2001-03-05 01:42:05 +01:00
set eindex [lsearch -exact $args "-env"]
2002-10-30 12:57:05 +01:00
if { $eindex != -1 } {
incr eindex
}
2001-03-05 01:42:05 +01:00
if { $eindex == -1 } {
2002-10-30 12:57:05 +01:00
set testfile $testdir/test0$tnum-a.db
2001-03-05 01:42:05 +01:00
set env NULL
} else {
2002-10-30 12:57:05 +01:00
set testfile test0$tnum-a.db
2001-03-05 01:42:05 +01:00
set env [lindex $args $eindex]
2002-10-30 12:57:05 +01:00
set txnenv [is_txnenv $env]
if { $txnenv == 1 } {
append args " -auto_commit "
}
set testdir [get_home $env]
2001-03-05 01:42:05 +01:00
}
cleanup $testdir $env
puts "\tTest0$tnum.a: No duplicates, trivial answer."
set pgindex [lsearch -exact $args "-pagesize"]
if { $pgindex != -1 } {
puts "Test078: skipping for specific pagesizes"
return
}
2002-10-30 12:57:05 +01:00
set db [eval {berkdb_open -create -mode 0644\
2001-03-05 01:42:05 +01:00
-pagesize $pagesize} $omethod $args {$testfile}]
error_check_good db_open [is_valid_db $db] TRUE
2002-10-30 12:57:05 +01:00
set txn ""
2001-03-05 01:42:05 +01:00
for { set i 1 } { $i <= $nkeys } { incr i } {
2002-10-30 12:57:05 +01:00
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn [is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set ret [eval {$db put} $txn {$i\
[pad_data $method $alphabet$i]}]
error_check_good put.a($i) $ret 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
2001-03-05 01:42:05 +01:00
error_check_good count.a [$db count $i] 1
}
error_check_good db_close.a [$db close] 0
if { [is_record_based $method] == 1 || [is_rbtree $method] == 1 } {
puts \
"\tTest0$tnum.b: Duplicates not supported in $method, skipping."
return
}
foreach tuple {{b sorted "-dup -dupsort"} {c unsorted "-dup"}} {
set letter [lindex $tuple 0]
set dupopt [lindex $tuple 2]
2002-10-30 12:57:05 +01:00
if { $eindex == -1 } {
set testfile $testdir/test0$tnum-b.db
set env NULL
} else {
set testfile test0$tnum-b.db
set env [lindex $args $eindex]
set testdir [get_home $env]
}
cleanup $testdir $env
2001-03-05 01:42:05 +01:00
puts "\tTest0$tnum.$letter: Duplicates ([lindex $tuple 1])."
puts "\t\tTest0$tnum.$letter.1: Populating database."
2002-10-30 12:57:05 +01:00
set db [eval {berkdb_open -create -mode 0644\
2001-03-05 01:42:05 +01:00
-pagesize $pagesize} $dupopt $omethod $args {$testfile}]
error_check_good db_open [is_valid_db $db] TRUE
for { set i 1 } { $i <= $nkeys } { incr i } {
for { set j 0 } { $j < $i } { incr j } {
2002-10-30 12:57:05 +01:00
if { $txnenv == 1 } {
set t [$env txn]
error_check_good txn \
[is_valid_txn $t $env] TRUE
set txn "-txn $t"
}
set ret [eval {$db put} $txn {$i\
[pad_data $method $j$alphabet]}]
error_check_good put.$letter,$i $ret 0
if { $txnenv == 1 } {
error_check_good txn [$t commit] 0
}
2001-03-05 01:42:05 +01:00
}
}
puts -nonewline "\t\tTest0$tnum.$letter.2: "
puts "Verifying dup counts on first dup."
for { set i 1 } { $i < $nkeys } { incr i } {
error_check_good count.$letter,$i \
[$db count $i] $i
}
puts -nonewline "\t\tTest0$tnum.$letter.3: "
puts "Verifying dup counts on random dup."
for { set i 1 } { $i < $nkeys } { incr i } {
set key [berkdb random_int 1 $nkeys]
error_check_good count.$letter,$i \
[$db count $i] $i
}
error_check_good db_close.$letter [$db close] 0
}
}