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