1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
6
# $Id: conscript.tcl,v 11.17 2002/03/22 21:43:06 krinsky Exp $
8
# Script for DB_CONSUME test (test070.tcl).
9
# Usage: conscript dir file runtype nitems outputfile tnum args
10
# dir: DBHOME directory
11
# file: db file on which to operate
12
# runtype: PRODUCE or CONSUME--which am I?
13
# nitems: number of items to put or get
14
# outputfile: where to log consumer results
17
proc consumescript_produce { db_cmd nitems tnum args } {
22
puts "\tTest0$tnum: Producer $pid starting, producing $nitems items."
25
error_check_good db_open:$pid [is_valid_db $db] TRUE
29
for { set ndx 0 } { $ndx < $nitems } { incr ndx } {
31
if { 0xffffffff > 0 && $oret > 0x7fffffff } {
32
incr oret [expr 0 - 0x100000000]
34
set ret [$db put -append [chop_data q $mydata]]
35
error_check_good db_put \
36
[expr $ret > 0 ? $oret < $ret : \
37
$oret < 0 ? $oret < $ret : $oret > $ret] 1
41
set ret [catch {$db close} res]
42
error_check_good db_close:$pid $ret 0
43
puts "\t\tTest0$tnum: Producer $pid finished."
46
proc consumescript_consume { db_cmd nitems tnum outputfile mode args } {
50
puts "\tTest0$tnum: Consumer $pid starting, seeking $nitems items."
53
error_check_good db_open:$pid [is_valid_db $db] TRUE
55
set oid [open $outputfile w]
57
for { set ndx 0 } { $ndx < $nitems } { } {
58
set ret [$db get $mode]
59
if { [llength $ret] > 0 } {
60
error_check_good correct_data:$pid \
61
[lindex [lindex $ret 0] 1] [pad_data q $mydata]
62
set rno [lindex [lindex $ret 0] 0]
66
# No data to consume; wait.
70
error_check_good output_close:$pid [close $oid] ""
72
set ret [catch {$db close} res]
73
error_check_good db_close:$pid $ret 0
74
puts "\t\tTest0$tnum: Consumer $pid finished."
78
source $test_path/test.tcl
82
puts stderr "FAIL:[timestamp] Usage: $usage"
86
set usage "conscript.tcl dir file runtype nitems outputfile tnum"
88
# Initialize arguments
89
set dir [lindex $argv 0]
90
set file [lindex $argv 1]
91
set runtype [lindex $argv 2]
92
set nitems [lindex $argv 3]
93
set outputfile [lindex $argv 4]
94
set tnum [lindex $argv 5]
95
# args is the string "{ -len 20 -pad 0}", so we need to extract the
96
# " -len 20 -pad 0" part.
97
set args [lindex [lrange $argv 6 end] 0]
99
set mydata "consumer data"
102
set dbenv [berkdb_env -home $dir ]
103
error_check_good db_env_create [is_valid_env $dbenv] TRUE
105
# Figure out db opening command.
106
set db_cmd [concat {berkdb_open -create -mode 0644 -queue -env}\
109
# Invoke consumescript_produce or consumescript_consume based on $runtype
110
if { $runtype == "PRODUCE" } {
111
# Producers have nothing to log; make sure outputfile is null.
112
error_check_good no_producer_outputfile $outputfile ""
113
consumescript_produce $db_cmd $nitems $tnum $args
114
} elseif { $runtype == "CONSUME" } {
115
consumescript_consume $db_cmd $nitems $tnum $outputfile -consume $args
116
} elseif { $runtype == "WAIT" } {
117
consumescript_consume $db_cmd $nitems $tnum $outputfile -consume_wait \
120
error_check_good bad_args $runtype "either PRODUCE, CONSUME or WAIT"
122
error_check_good env_close [$dbenv close] 0