~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

Viewing changes to bdb/test/conscript.tcl

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See the file LICENSE for redistribution information.
 
2
#
 
3
# Copyright (c) 1999-2002
 
4
#       Sleepycat Software.  All rights reserved.
 
5
#
 
6
# $Id: conscript.tcl,v 11.17 2002/03/22 21:43:06 krinsky Exp $
 
7
#
 
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
 
15
# tnum: test number
 
16
 
 
17
proc consumescript_produce { db_cmd nitems tnum args } {
 
18
        source ./include.tcl
 
19
        global mydata
 
20
 
 
21
        set pid [pid]
 
22
        puts "\tTest0$tnum: Producer $pid starting, producing $nitems items."
 
23
 
 
24
        set db [eval $db_cmd]
 
25
        error_check_good db_open:$pid [is_valid_db $db] TRUE
 
26
 
 
27
        set oret -1
 
28
        set ret 0
 
29
        for { set ndx 0 } { $ndx < $nitems } { incr ndx } {
 
30
                set oret $ret
 
31
                if { 0xffffffff > 0 && $oret > 0x7fffffff } {
 
32
                        incr oret [expr 0 - 0x100000000]
 
33
                }
 
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
 
38
 
 
39
        }
 
40
 
 
41
        set ret [catch {$db close} res]
 
42
        error_check_good db_close:$pid $ret 0
 
43
        puts "\t\tTest0$tnum: Producer $pid finished."
 
44
}
 
45
 
 
46
proc consumescript_consume { db_cmd nitems tnum outputfile mode args } {
 
47
        source ./include.tcl
 
48
        global mydata
 
49
        set pid [pid]
 
50
        puts "\tTest0$tnum: Consumer $pid starting, seeking $nitems items."
 
51
 
 
52
        set db [eval $db_cmd]
 
53
        error_check_good db_open:$pid [is_valid_db $db] TRUE
 
54
 
 
55
        set oid [open $outputfile w]
 
56
 
 
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]
 
63
                        puts $oid $rno
 
64
                        incr ndx
 
65
                } else {
 
66
                        # No data to consume;  wait.
 
67
                }
 
68
        }
 
69
 
 
70
        error_check_good output_close:$pid [close $oid] ""
 
71
 
 
72
        set ret [catch {$db close} res]
 
73
        error_check_good db_close:$pid $ret 0
 
74
        puts "\t\tTest0$tnum: Consumer $pid finished."
 
75
}
 
76
 
 
77
source ./include.tcl
 
78
source $test_path/test.tcl
 
79
 
 
80
# Verify usage
 
81
if { $argc < 6 } {
 
82
        puts stderr "FAIL:[timestamp] Usage: $usage"
 
83
        exit
 
84
}
 
85
 
 
86
set usage "conscript.tcl dir file runtype nitems outputfile tnum"
 
87
 
 
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]
 
98
 
 
99
set mydata "consumer data"
 
100
 
 
101
# Open env
 
102
set dbenv [berkdb_env -home $dir ]
 
103
error_check_good db_env_create [is_valid_env $dbenv] TRUE
 
104
 
 
105
# Figure out db opening command.
 
106
set db_cmd [concat {berkdb_open -create -mode 0644 -queue -env}\
 
107
        $dbenv $args $file]
 
108
 
 
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 \
 
118
                $args
 
119
} else {
 
120
        error_check_good bad_args $runtype "either PRODUCE, CONSUME or WAIT"
 
121
}
 
122
error_check_good env_close [$dbenv close] 0
 
123
exit