class RTsung

Constants

DUMP_TRAFFIC
LOG_LEVEL
TSUNG_DTD

Public Class Methods

new(options = {}, &block) click to toggle source
# 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

Public Instance Methods

client(host, options = {}) click to toggle source
# File lib/rtsung.rb, line 26
def client(host, options = {})
  @clients << Client.new(host, options)
end
option(name, options = {}, &block) click to toggle source
# 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 = {}) click to toggle source
# 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 = {}) click to toggle source
# File lib/rtsung.rb, line 30
def server(host, options = {})
  @servers << Server.new(host, options)
end
session(name, options = {}, &block) click to toggle source
# File lib/rtsung.rb, line 56
def session(name, options = {}, &block)
  @sessions << Session.new(name, options, &block)
end
to_xml() click to toggle source
# 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) click to toggle source
# File lib/rtsung.rb, line 52
def user_agents(&block)
  @options << Option.new('user_agent', { :type => :ts_http }, &block)
end