Class: RTsung
- Inherits:
-
Object
show all
- Defined in:
- lib/rtsung.rb,
lib/rtsung/phase.rb,
lib/rtsung/client.rb,
lib/rtsung/option.rb,
lib/rtsung/server.rb,
lib/rtsung/session.rb,
lib/rtsung/version.rb
Defined Under Namespace
Classes: Client, Option, Phase, Server, Session, Version
Constant Summary
collapse
- LOG_LEVEL =
:notice
- DUMP_TRAFFIC =
false
- TSUNG_DTD =
'/usr/share/tsung/tsung-1.0.dtd'
Instance Method Summary
collapse
-
#client(host, options = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ RTsung
constructor
A new instance of RTsung.
-
#option(name, options = {}, &block) ⇒ Object
-
#phase(name = 1, duration = nil, unit = nil, options = {}) ⇒ Object
-
#server(host, options = {}) ⇒ Object
-
#session(name, options = {}, &block) ⇒ Object
-
#to_xml ⇒ Object
-
#user_agents(&block) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ RTsung
Returns a new instance of RTsung.
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rtsung.rb', line 15
def initialize(options = {}, &block)
@log_level = options[:log_level] || LOG_LEVEL
@dump_traffic = options[:dump_traffic] || DUMP_TRAFFIC
@clients, @servers = [], []
@phases, @options = [], []
@sessions = []
instance_eval(&block) if block_given?
end
|
Instance Method Details
#client(host, options = {}) ⇒ Object
26
27
28
|
# File 'lib/rtsung.rb', line 26
def client(host, options = {})
@clients << Client.new(host, options)
end
|
#option(name, options = {}, &block) ⇒ Object
48
49
50
|
# File 'lib/rtsung.rb', line 48
def option(name, options = {}, &block)
@options << Option.new(name, options, &block)
end
|
#phase(name = 1, duration = nil, unit = nil, options = {}) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rtsung.rb', line 34
def phase(name = 1, duration = nil, unit = nil, options = {})
if duration.is_a? Hash
options = duration
duration, unit = nil, nil
end
if unit.is_a? Hash
options = unit
unit = nil
end
@phases << Phase.new(name, duration, unit, options)
end
|
#server(host, options = {}) ⇒ Object
30
31
32
|
# File 'lib/rtsung.rb', line 30
def server(host, options = {})
@servers << Server.new(host, options)
end
|
#session(name, options = {}, &block) ⇒ Object
56
57
58
|
# File 'lib/rtsung.rb', line 56
def session(name, options = {}, &block)
@sessions << Session.new(name, options, &block)
end
|
#to_xml ⇒ Object
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
|
# File 'lib/rtsung.rb', line 60
def to_xml
output = ''
xml = ::Builder::XmlMarkup.new(:target => output, :indent => 2)
xml.instruct!
xml.declare! :DOCTYPE, :tsung, :SYSTEM, TSUNG_DTD, :'[]'
xml.tsung(:loglevel => @log_level) do
xml.clients do
if @clients.empty?
Client.new.to_xml(xml)
else
@clients.each { |client| client.to_xml(xml) }
end
end
xml.servers { @servers.each { |server| server.to_xml(xml) } }
xml.load do
if @phases.empty?
Phase.new.to_xml(xml)
else
@phases.each { |phase| phase.to_xml(xml) }
end
end
xml.options { @options.each { |o| o.to_xml(xml) } }
xml.sessions { @sessions.each { |s| s.to_xml(xml) } }
end
output
end
|
#user_agents(&block) ⇒ Object
52
53
54
|
# File 'lib/rtsung.rb', line 52
def user_agents(&block)
@options << Option.new('user_agent', { :type => :ts_http }, &block)
end
|