rtsung 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6e00ba6e47dd13bfbc4ab175c9bb1c4b94d391e
4
+ data.tar.gz: 90783de29e11f74d50ec57e07447931de6d155e3
5
+ SHA512:
6
+ metadata.gz: 4bd07c4d1c5051e331d0b8dd4681f8019cc8bd4e74f961dafe3a30fc40ed34dc1215f651121974e04fcea8418cc203e06ea1f21d99c770316cab5e7a20f8d7bf
7
+ data.tar.gz: 1d4fc1ae3a6db35d91e26b99c87dff0e7fa3809e4a723a386b6c1cd5612cd369e54ae668c039eb9f6d66f7f4a5a72c43b0ac05bd815a7b7f3e97b084f72e5ca6
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rtsung.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Maxim Pechnikov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,36 @@
1
+ require 'rtsung'
2
+
3
+ rtsung = RTsung.new do
4
+ client 'localhost', :vm => true
5
+
6
+ client 'router', :max_users => 32
7
+
8
+ client 'db1', :cpu => 2, :ip => '192.168.2.1', :weight => 1
9
+ client 'db2', :cpu => 2, :ip => ['192.168.2.3', '192.168.2.4'], :weight => 2
10
+
11
+ server 'example.com'
12
+ server 'www.example.com', :port => 8080
13
+
14
+ phase
15
+ phase 2, :rate => 30
16
+ phase 3, 30, :second, { :interval => 2 }
17
+
18
+ user_agents do
19
+ name 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Galeon/1.3.21', :probability => 30
20
+ name 'Mozilla/5.0 (Windows; U; Windows NT 5.2; fr-FR; rv:1.7.8) Gecko/20050511 Firefox/1.0.4', :probability => 70
21
+ end
22
+
23
+ session :search do
24
+ request '/'
25
+
26
+ think_time 1..5
27
+
28
+ request '/signin', :params => { :uniq => true }
29
+
30
+ think 5
31
+
32
+ request '/signin', :method => :POST, :params => { :email => 'test@example.com', :password => 'ov7Feift' }
33
+ end
34
+ end
35
+
36
+ print rtsung.to_xml
@@ -0,0 +1,29 @@
1
+ # Rtsung
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rtsung'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rtsung
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ $: << '../lib'
2
+
3
+ require 'rtsung'
4
+
5
+ rtsung = RTsung.new do
6
+ server 'google.com'
7
+
8
+ session :search do
9
+ request '/'
10
+ end
11
+ end
12
+
13
+ print rtsung.to_xml
@@ -0,0 +1,93 @@
1
+ require 'builder'
2
+
3
+ require 'rtsung/client'
4
+ require 'rtsung/server'
5
+ require 'rtsung/phase'
6
+ require 'rtsung/option'
7
+ require 'rtsung/session'
8
+
9
+ class RTsung
10
+ LOG_LEVEL = :notice
11
+ DUMP_TRAFFIC = false
12
+
13
+ TSUNG_DTD = '/usr/share/tsung/tsung-1.0.dtd'
14
+
15
+ def initialize(options = {}, &block)
16
+ @log_level = options[:log_level] || LOG_LEVEL
17
+ @dump_traffic = options[:dump_traffic] || DUMP_TRAFFIC
18
+
19
+ @clients, @servers = [], []
20
+ @phases, @options = [], []
21
+ @sessions = []
22
+
23
+ instance_eval(&block) if block_given?
24
+ end
25
+
26
+ def client(host, options = {})
27
+ @clients << Client.new(host, options)
28
+ end
29
+
30
+ def server(host, options = {})
31
+ @servers << Server.new(host, options)
32
+ end
33
+
34
+ def phase(name = 1, duration = nil, unit = nil, options = {})
35
+ if duration.is_a? Hash
36
+ options = duration
37
+ duration, unit = nil, nil
38
+ end
39
+
40
+ if unit.is_a? Hash
41
+ options = unit
42
+ unit = nil
43
+ end
44
+
45
+ @phases << Phase.new(name, duration, unit, options)
46
+ end
47
+
48
+ def option(name, options = {}, &block)
49
+ @options << Option.new(name, options, &block)
50
+ end
51
+
52
+ def user_agents(&block)
53
+ @options << Option.new('user_agent', { :type => :ts_http }, &block)
54
+ end
55
+
56
+ def session(name, options = {}, &block)
57
+ @sessions << Session.new(name, options, &block)
58
+ end
59
+
60
+ def to_xml
61
+ output = ''
62
+
63
+ xml = ::Builder::XmlMarkup.new(:target => output, :indent => 2)
64
+
65
+ xml.instruct!
66
+ xml.declare! :DOCTYPE, :tsung, :SYSTEM, TSUNG_DTD, :'[]'
67
+
68
+ xml.tsung(:loglevel => @log_level) do
69
+ xml.clients do
70
+ if @clients.empty?
71
+ Client.new.to_xml(xml)
72
+ else
73
+ @clients.each { |client| client.to_xml(xml) }
74
+ end
75
+ end
76
+
77
+ xml.servers { @servers.each { |server| server.to_xml(xml) } }
78
+
79
+ xml.load do
80
+ if @phases.empty?
81
+ Phase.new.to_xml(xml)
82
+ else
83
+ @phases.each { |phase| phase.to_xml(xml) }
84
+ end
85
+ end
86
+
87
+ xml.options { @options.each { |o| o.to_xml(xml) } }
88
+ xml.sessions { @sessions.each { |s| s.to_xml(xml) } }
89
+ end
90
+
91
+ output
92
+ end
93
+ end
@@ -0,0 +1,32 @@
1
+ class RTsung
2
+ class Client
3
+ HOST = 'localhost'
4
+ OPTIONS = { :vm => true }
5
+
6
+ def initialize(host = HOST, options = OPTIONS)
7
+ @attrs = { :host => host }
8
+
9
+ @attrs[:use_controller_vm] = options[:vm] if options[:vm]
10
+ @attrs[:maxusers] = options[:max_users] if options[:max_users]
11
+ @attrs[:weight] = options[:weight] if options[:weight]
12
+ @attrs[:cpu] = options[:cpu] if options[:cpu]
13
+
14
+ if ip = options[:ip]
15
+ @ips = ip.is_a?(Array) ? ip : [ip]
16
+ else
17
+ @ips = []
18
+ end
19
+ end
20
+
21
+ def to_xml(xml)
22
+ if @ips.empty?
23
+ xml.client @attrs
24
+ else
25
+ xml.client(@attrs) do
26
+ @ips.each { |i| xml.ip({ :value => i }) }
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ class RTsung
2
+ class Option
3
+ TYPE = :ts_http
4
+
5
+ USER_AGENT_PROBABILITY = 100
6
+
7
+ def initialize(name, options = {}, &block)
8
+ @attrs = {
9
+ :name => name,
10
+ :type => options[:type] || TYPE
11
+ }
12
+
13
+ @user_agents = []
14
+
15
+ instance_eval(&block) if block_given?
16
+ end
17
+
18
+ def user_agent(name, options = {})
19
+ @user_agents << {
20
+ :name => name,
21
+ :probability => options[:probability] || USER_AGENT_PROBABILITY
22
+ }
23
+ end
24
+
25
+ def name(name, options = {})
26
+ user_agent(name, options)
27
+ end
28
+
29
+ def to_xml(xml)
30
+ if @user_agents.empty?
31
+ xml.option @attrs
32
+ else
33
+ xml.option(@attrs) do
34
+ @user_agents.each { |u|
35
+ xml.user_agent({ :probability => u[:probability] }) do
36
+ xml.text! u[:name]
37
+ end
38
+ }
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,39 @@
1
+ class RTsung
2
+ class Phase
3
+ OPTIONS = { :interval => 1 }
4
+
5
+ PHASE_DURATION = 1
6
+ PHASE_UNIT = :minute
7
+
8
+ USERS_UNIT = :second
9
+
10
+ def initialize(name = 1, duration = nil, unit = nil, options = {})
11
+ @attrs = {
12
+ :phase => name,
13
+ :duration => duration || PHASE_DURATION,
14
+ :unit => unit || PHASE_UNIT
15
+ }
16
+
17
+ options = OPTIONS if options.empty?
18
+
19
+ if options[:rate]
20
+ @users = {
21
+ :arrivalrate => options[:rate],
22
+ :unit => options[:unit] || USERS_UNIT
23
+ }
24
+ else
25
+ @users = {
26
+ :interarrival => options[:interval],
27
+ :unit => options[:unit] || USERS_UNIT
28
+ }
29
+ end
30
+ end
31
+
32
+ def to_xml(xml)
33
+ xml.arrivalphase(@attrs) do
34
+ xml.users @users
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ class RTsung
2
+ class Server
3
+ PORT = 80
4
+ TYPE = :tcp
5
+
6
+ def initialize(host, options = {})
7
+ @attrs = {
8
+ :host => host,
9
+ :port => options[:port] || PORT,
10
+ :type => options[:type] || TYPE
11
+ }
12
+ end
13
+
14
+ def to_xml(xml)
15
+ xml.server @attrs
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,90 @@
1
+ class RTsung
2
+ class Session
3
+ PROBABILITY = 100
4
+ TYPE = :ts_http
5
+
6
+ HTTP_VERSION = '1.1'
7
+ HTTP_METHOD = :GET
8
+
9
+ THINK_TIME_RANDOM = true
10
+
11
+
12
+ def initialize(name, options = {}, &block)
13
+ @attrs = {
14
+ :name => name,
15
+ :probability => options[:probability] || PROBABILITY,
16
+ :type => options[:type] || TYPE
17
+ }
18
+
19
+ @steps = []
20
+
21
+ instance_eval(&block) if block_given?
22
+ end
23
+
24
+ def request(url, options = {})
25
+ attrs = {
26
+ :url => url,
27
+ :version => options[:version] || HTTP_VERSION,
28
+ :method => options[:method] || HTTP_METHOD
29
+ }
30
+
31
+ if options[:params]
32
+ params = []
33
+ options[:params].keys.each { |k| params << "#{k}=#{options[:params][k]}" }
34
+
35
+ params = params.join('&amp;')
36
+
37
+ if attrs[:method] == :GET
38
+ attrs[:url] = "#{attrs[:url]}?#{params}"
39
+ elsif attrs[:method] == :POST
40
+ attrs[:contents] = params
41
+ end
42
+ end
43
+
44
+ attrs[:content_type] = options[:content_type] if options[:content_type]
45
+
46
+ @steps << {
47
+ :type => :request,
48
+ :attrs => attrs
49
+ }
50
+ end
51
+
52
+ def think_time(value, options = {})
53
+ if value.is_a?(Range)
54
+ attrs = {
55
+ :min => value.min,
56
+ :max => value.max
57
+ }
58
+ else
59
+ attrs = { :value => value }
60
+ end
61
+
62
+ attrs[:random] = options[:random] || THINK_TIME_RANDOM
63
+
64
+ @steps << {
65
+ :type => :think_time,
66
+ :attrs => attrs
67
+ }
68
+ end
69
+ alias :think :think_time
70
+
71
+ def to_xml xml
72
+ if @steps.empty?
73
+ xml.session @attrs
74
+ else
75
+ xml.session(@attrs) do
76
+ @steps.each { |s|
77
+ if s[:type] == :request
78
+ xml.request do
79
+ xml.http(s[:attrs])
80
+ end
81
+ elsif s[:type] == :think_time
82
+ xml.thinktime(s[:attrs])
83
+ end
84
+ }
85
+ end
86
+ end
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ class RTsung
2
+ class Version
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rtsung/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rtsung"
8
+ spec.version = RTsung::Version::VERSION
9
+ spec.authors = ["Tema Ivanov"]
10
+ spec.email = []
11
+ spec.description = %q{XML generator for Tsung}
12
+ spec.summary = %q{XML generator for Tsung}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "builder", "~> 3.2.2"
25
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtsung
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tema Ivanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: builder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.2
55
+ description: XML generator for Tsung
56
+ email: []
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - Gemfile
63
+ - LICENSE.txt
64
+ - README
65
+ - README.md
66
+ - Rakefile
67
+ - examples/google.rb
68
+ - lib/rtsung.rb
69
+ - lib/rtsung/client.rb
70
+ - lib/rtsung/option.rb
71
+ - lib/rtsung/phase.rb
72
+ - lib/rtsung/server.rb
73
+ - lib/rtsung/session.rb
74
+ - lib/rtsung/version.rb
75
+ - rtsung.gemspec
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.14
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: XML generator for Tsung
100
+ test_files: []