Class: RubyJmeter::ExtendedDSL
- Inherits:
-
DSL
- Object
- DSL
- RubyJmeter::ExtendedDSL
show all
- Includes:
- Parser
- Defined in:
- lib/ruby-jmeter/dsl.rb,
lib/ruby-jmeter/extend/misc/flood.rb,
lib/ruby-jmeter/extend/misc/exists.rb,
lib/ruby-jmeter/extend/misc/aliases.rb,
lib/ruby-jmeter/extend/misc/with_helpers.rb,
lib/ruby-jmeter/extend/processors/extract.rb,
lib/ruby-jmeter/extend/timers/random_timer.rb,
lib/ruby-jmeter/extend/threads/thread_group.rb,
lib/ruby-jmeter/extend/samplers/http_request.rb,
lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb,
lib/ruby-jmeter/extend/threads/setup_thread_group.rb,
lib/ruby-jmeter/extend/controllers/loop_controller.rb,
lib/ruby-jmeter/extend/samplers/soapxmlrpc_request.rb,
lib/ruby-jmeter/extend/assertions/response_assertion.rb,
lib/ruby-jmeter/extend/controllers/module_controller.rb,
lib/ruby-jmeter/extend/config_elements/header_manager.rb,
lib/ruby-jmeter/extend/controllers/foreach_controller.rb,
lib/ruby-jmeter/extend/config_elements/user_parameters.rb,
lib/ruby-jmeter/extend/timers/constant_throughput_timer.rb,
lib/ruby-jmeter/extend/controllers/throughput_controller.rb,
lib/ruby-jmeter/extend/config_elements/http_cache_manager.rb,
lib/ruby-jmeter/extend/controllers/transaction_controller.rb,
lib/ruby-jmeter/extend/config_elements/http_cookie_manager.rb,
lib/ruby-jmeter/extend/config_elements/http_request_defaults.rb,
lib/ruby-jmeter/extend/config_elements/user_defined_variables.rb,
lib/ruby-jmeter/extend/processors/regular_expression_extractor.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#active_threads_over_time(params = {}, &block) ⇒ Object
(also: #active_threads)
-
#composite_graph(name, params = {}, &block) ⇒ Object
(also: #composite)
-
#console_status_logger(name = 'Console Status Logger', params = {}, &block) ⇒ Object
(also: #console)
-
#constant_throughput_timer(params, &block) ⇒ Object
-
#dummy_sampler(name = 'Dummy Sampler', params = {}, &block) ⇒ Object
(also: #dummy)
-
#exists(variable, &block) ⇒ Object
-
#extract(params, &block) ⇒ Object
(also: #web_reg_save_param)
-
#flood(token, params = {}) ⇒ Object
-
#foreach_controller(params = {}, &block) ⇒ Object
-
#http_cache_manager(params = {}, &block) ⇒ Object
(also: #cache)
-
#http_cookie_manager(params = {}, &block) ⇒ Object
(also: #cookies)
-
#http_header_manager(params, &block) ⇒ Object
(also: #header)
-
#http_request(*args, &block) ⇒ Object
(also: #request, #get, #visit, #post, #submit, #delete, #patch, #put, #head)
-
#http_request_defaults(params = {}, &block) ⇒ Object
(also: #defaults)
-
#http_request_node(params) ⇒ Object
-
#initialize(params = {}) ⇒ ExtendedDSL
constructor
A new instance of ExtendedDSL.
-
#jmx(params = {}) ⇒ Object
-
#latencies_over_time(name = 'Response Latencies Over Time', params = {}, &block) ⇒ Object
-
#loadosophia_uploader(name = "Loadosophia.org Uploader", params = {}, &block) ⇒ Object
(also: #loadosophia)
-
#loop_controller(params, &block) ⇒ Object
(also: #loops)
-
#module_controller(params, &block) ⇒ Object
-
#out(params = {}) ⇒ Object
-
#perfmon_collector(params = {}, &block) ⇒ Object
(also: #perfmon)
-
#random_timer(delay = 0, range = 0, &block) ⇒ Object
(also: #think_time)
-
#redis_data_set(params = {}, &block) ⇒ Object
-
#regular_expression_extractor(params, &block) ⇒ Object
(also: #regex)
-
#response_assertion(params, &block) ⇒ Object
(also: #assert, #web_reg_find)
-
#response_codes_per_second(name = 'Response Codes per Second', params = {}, &block) ⇒ Object
-
#response_times_distribution(name = 'Response Times Distribution', params = {}, &block) ⇒ Object
-
#response_times_over_time(name = 'Response Times Over Time', params = {}, &block) ⇒ Object
-
#response_times_percentiles(name = 'Response Times Percentiles', params = {}, &block) ⇒ Object
-
#run(params = {}) ⇒ Object
-
#setup_thread_group(*args, &block) ⇒ Object
-
#soap ⇒ Object
-
#soapxmlrpc_request(params, &block) ⇒ Object
-
#stepping_thread_group(params = {}, &block) ⇒ Object
(also: #step)
-
#thread_group(*args, &block) ⇒ Object
(also: #threads)
-
#throughput_controller(params = {}, &block) ⇒ Object
(also: #throughput)
-
#throughput_shaper(name = 'Throughput Shaping Timer', steps = [], params = {}, &block) ⇒ Object
(also: #shaper)
-
#to_doc ⇒ Object
-
#to_xml ⇒ Object
-
#transaction_controller(*args, &block) ⇒ Object
(also: #transaction)
-
#transactions_per_second(name = 'Transactions per Second', params = {}, &block) ⇒ Object
-
#ultimate_thread_group(threads = [], params = {}, &block) ⇒ Object
(also: #ultimate)
-
#user_defined_variables(params, &block) ⇒ Object
(also: #variables)
-
#user_parameters(params, &block) ⇒ Object
(also: #parameters)
-
#with_browser(device) ⇒ Object
-
#with_gzip ⇒ Object
-
#with_json ⇒ Object
-
#with_user_agent(device) ⇒ Object
-
#with_xhr ⇒ Object
Methods included from Parser
#files, #fill_in, #parse_http_request, #parse_test_type, #parse_uri, #parse_url, #raw_body
Methods inherited from DSL
#access_log_sampler, #aggregate_graph, #aggregate_report, #ajp13_sampler, #assertion_results, #beanshell_assertion, #beanshell_listener, #beanshell_postprocessor, #beanshell_preprocessor, #beanshell_sampler, #beanshell_timer, #bsf_assertion, #bsf_listener, #bsf_postprocessor, #bsf_preprocessor, #bsf_sampler, #bsf_timer, #compare_assertion, #comparison_assertion_visualizer, #constant_timer, #counter, #cssjquery_extractor, #csv_data_set_config, #debug_postprocessor, #debug_sampler, #distribution_graphalpha, #duration_assertion, #ftp_request, #ftp_request_defaults, #gaussian_random_timer, #generate_summary_results, #graph_results, #html_assertion, #html_link_parser, #html_parameter_mask, #http_authorization_manager, #http_url_rewriting_modifier, #if_controller, #include_controller, #java_request, #java_request_defaults, #jdbc_connection_configuration, #jdbc_postprocessor, #jdbc_preprocessor, #jdbc_request, #jms_pointtopoint, #jms_publisher, #jms_subscriber, #jsr223_assertion, #jsr223_listener, #jsr223_postprocessor, #jsr223_preprocessor, #jsr223_sampler, #jsr223_timer, #junit_request, #keystore_configuration, #ldap_extended_request, #ldap_extended_request_defaults, #ldap_request, #ldap_request_defaults, #login_config_element, #mail_reader_sampler, #mailer_visualizer, #md5hex_assertion, #monitor_results, #once_only_controller, #os_process_sampler, #poisson_random_timer, #random_controller, #random_order_controller, #random_variable, #recording_controller, #regex_user_parameters, #response_time_graph, #result_status_action_handler, #runtime_controller, #save_responses_to_a_file, #simple_config_element, #simple_controller, #simple_data_writer, #smime_assertion, #smtp_sampler, #spline_visualizer, #summary_report, #switch_controller, #synchronizing_timer, #tcp_sampler, #tcp_sampler_config, #test_action, #test_fragment, #test_plan, #uniform_random_timer, #view_results_in_table, #view_results_tree, #while_controller, #xml_assertion, #xml_schema_assertion, #xpath_assertion, #xpath_extractor
Constructor Details
#initialize(params = {}) ⇒ ExtendedDSL
Returns a new instance of ExtendedDSL.
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/ruby-jmeter/dsl.rb', line 6
def initialize(params = {})
@root = Nokogiri::XML(<<-EOF.strip_heredoc)
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.9" jmeter="3.0" ruby-jmeter="3.0">
<hashTree>
</hashTree>
</jmeterTestPlan>
EOF
node = RubyJmeter::TestPlan.new(params)
@current_node = @root.at_xpath('//jmeterTestPlan/hashTree')
@current_node = attach_to_last(node)
end
|
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
4
5
6
|
# File 'lib/ruby-jmeter/dsl.rb', line 4
def root
@root
end
|
Instance Method Details
#active_threads_over_time(params = {}, &block) ⇒ Object
Also known as:
active_threads
89
90
91
92
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 89
def active_threads_over_time(params = {}, &block)
node = RubyJmeter::Plugins::ActiveThreadsOverTime.new(params)
attach_node(node, &block)
end
|
#composite_graph(name, params = {}, &block) ⇒ Object
Also known as:
composite
82
83
84
85
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 82
def composite_graph(name, params = {}, &block)
node = RubyJmeter::Plugins::CompositeGraph.new(name, params)
attach_node(node, &block)
end
|
#console_status_logger(name = 'Console Status Logger', params = {}, &block) ⇒ Object
Also known as:
console
33
34
35
36
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 33
def console_status_logger(name = 'Console Status Logger', params = {}, &block)
node = RubyJmeter::Plugins::ConsoleStatusLogger.new(name, params)
attach_node(node, &block)
end
|
#constant_throughput_timer(params, &block) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/ruby-jmeter/extend/timers/constant_throughput_timer.rb', line 3
def constant_throughput_timer(params, &block)
params[:value] ||= params[:throughput] || 0.0
node = RubyJmeter::ConstantThroughputTimer.new(params)
node.doc.xpath('.//value').first.content = params[:value].to_f
attach_node(node, &block)
end
|
#dummy_sampler(name = 'Dummy Sampler', params = {}, &block) ⇒ Object
Also known as:
dummy
47
48
49
50
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 47
def dummy_sampler(name = 'Dummy Sampler', params = {}, &block)
node = RubyJmeter::Plugins::DummySampler.new(name, params)
attach_node(node, &block)
end
|
#exists(variable, &block) ⇒ Object
3
4
5
6
7
8
9
10
11
|
# File 'lib/ruby-jmeter/extend/misc/exists.rb', line 3
def exists(variable, &block)
params ||= {}
params[:condition] = "\"${#{variable}}\" != \"\\${#{variable}}\""
params[:useExpression] = false
params[:name] = "if ${#{variable}}"
node = RubyJmeter::IfController.new(params)
attach_node(node, &block)
end
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ruby-jmeter/extend/processors/extract.rb', line 3
def (params, &block)
node = if params[:regex]
params[:refname] = params[:name]
params[:regex] = params[:regex] params[:template] = params[:template] || "$1$"
RubyJmeter::RegularExpressionExtractor.new(params)
elsif params[:xpath]
params[:refname] = params[:name]
params[:xpathQuery] = params[:xpath]
RubyJmeter::XpathExtractor.new(params)
elsif params[:json]
params[:VAR] = params[:name]
params[:JSONPATH] = params[:json]
RubyJmeter::Plugins::JsonPathExtractor.new(params)
elsif params[:css]
params[:refname] = params[:name]
params[:expr] = params[:css]
RubyJmeter::CssjqueryExtractor.new(params)
end
attach_node(node, &block)
end
|
#flood(token, params = {}) ⇒ Object
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
|
# File 'lib/ruby-jmeter/extend/misc/flood.rb', line 3
def flood(token, params = {})
RestClient.proxy = params[:proxy] if params[:proxy]
begin
file = Tempfile.new(['ruby-jmeter', '.jmx'])
file.write(doc.to_xml(indent: 2))
file.rewind
flood_files = {
file: File.new("#{file.path}", 'rb')
}
if params[:files]
flood_files.merge!(Hash[params[:files].map.with_index { |value, index| [index, File.new(value, 'rb')] }])
params.delete(:files)
end
response = RestClient.post "#{params[:endpoint] ? params[:endpoint] : 'https://api.flood.io'}/floods?auth_token=#{token}",
{
flood: {
tool: 'jmeter',
name: params[:name],
notes: params[:notes],
tag_list: params[:tag_list],
project: params[:project],
threads: params[:threads],
rampup: params[:rampup],
duration: params[:duration],
override_parameters: params[:override_parameters],
started: params[:started],
stopped: params[:stopped],
privacy_flag: params[:privacy] || 'private',
},
flood_files: flood_files,
region: params[:region],
multipart: true,
content_type: 'application/octet-stream'
}.merge(params)
if response.code == 201
logger.info "Flood results at: #{JSON.parse(response)["permalink"]}"
else
logger.fatal "Sorry there was an error: #{JSON.parse(response)["error"]}"
end
rescue => e
logger.fatal "Sorry there was an error: #{JSON.parse(e.response)["error"]}"
end
end
|
#foreach_controller(params = {}, &block) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/ruby-jmeter/extend/controllers/foreach_controller.rb', line 3
def foreach_controller(params = {}, &block)
node = RubyJmeter::ForeachController.new(params).tap do |node|
if params[:start_index]
params[:startIndex] = params[:start_index]
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="ForeachController.startIndex"/>
EOS
)
end
if params[:end_index]
params[:endIndex] = params[:end_index]
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="ForeachController.endIndex"/>
EOS
)
end
end
attach_node(node, &block)
end
|
#http_cache_manager(params = {}, &block) ⇒ Object
Also known as:
cache
3
4
5
6
7
|
# File 'lib/ruby-jmeter/extend/config_elements/http_cache_manager.rb', line 3
def http_cache_manager(params = {}, &block)
params[:clearEachIteration] = true if params.keys.include? :clear_each_iteration
super
end
|
#http_cookie_manager(params = {}, &block) ⇒ Object
Also known as:
cookies
3
4
5
6
7
|
# File 'lib/ruby-jmeter/extend/config_elements/http_cookie_manager.rb', line 3
def http_cookie_manager(params = {}, &block)
params[:clearEachIteration] = true if params.keys.include? :clear_each_iteration
super
end
|
3
4
5
6
7
8
9
|
# File 'lib/ruby-jmeter/extend/config_elements/header_manager.rb', line 3
def (params, &block)
if params.is_a?(Hash)
params['Header.name'] = params[:name]
end
super
end
|
#http_request(*args, &block) ⇒ Object
Also known as:
request, get, visit, post, submit, delete, patch, put, head
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
|
# File 'lib/ruby-jmeter/extend/samplers/http_request.rb', line 3
def http_request(*args, &block)
params = args.shift || {}
params = { url: params }.merge(args.shift || {}) if params.class == String
params[:method] ||= case __callee__.to_s
when 'visit'
'GET'
when 'submit'
'POST'
else
__callee__.to_s.upcase
end
params[:name] ||= params[:url]
parse_http_request(params)
if params[:sample]
transaction name: params[:name], parent: true do
loops count: params[:sample].to_i do
params.delete(:sample)
attach_node(http_request_node(params), &block)
end
end
else
attach_node(http_request_node(params), &block)
end
end
|
#http_request_defaults(params = {}, &block) ⇒ Object
Also known as:
defaults
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
|
# File 'lib/ruby-jmeter/extend/config_elements/http_request_defaults.rb', line 3
def http_request_defaults(params = {}, &block)
params[:image_parser] = true if params.keys.include? :download_resources
params[:concurrentDwn] = true if params.keys.include? :use_concurrent_pool
params[:concurrentPool] = params[:use_concurrent_pool] if params.keys.include? :use_concurrent_pool
node = RubyJmeter::HttpRequestDefaults.new(params).tap do |node|
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="HTTPSampler.embedded_url_re">#{params[:urls_must_match]}</stringProp>
EOS
) if params[:urls_must_match]
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<boolProp name="HTTPSampler.md5">true</stringProp>
EOS
) if params[:md5]
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="HTTPSampler.proxyHost">#{params[:proxy_host]}</stringProp>
EOS
) if params[:proxy_host]
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="HTTPSampler.proxyPort">#{params[:proxy_port]}</stringProp>
EOS
) if params[:proxy_port]
end
attach_node(node, &block)
end
|
#http_request_node(params) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ruby-jmeter/extend/samplers/http_request.rb', line 32
def http_request_node(params)
RubyJmeter::HttpRequest.new(params).tap do |node|
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="HTTPSampler.implementation">#{params[:implementation]}</stringProp>
EOS
) if params[:implementation]
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="TestPlan.comments">#{params[:]}</stringProp>
EOS
) if params[:comments]
end
end
|
#jmx(params = {}) ⇒ Object
24
25
26
27
|
# File 'lib/ruby-jmeter/dsl.rb', line 24
def jmx(params = {})
file(params)
logger.info "Test plan saved to: #{params[:file]}"
end
|
#latencies_over_time(name = 'Response Latencies Over Time', params = {}, &block) ⇒ Object
28
29
30
31
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 28
def latencies_over_time(name = 'Response Latencies Over Time', params = {}, &block)
node = RubyJmeter::Plugins::LatenciesOverTime.new(name, params)
attach_node(node, &block)
end
|
#loadosophia_uploader(name = "Loadosophia.org Uploader", params = {}, &block) ⇒ Object
Also known as:
loadosophia
103
104
105
106
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 103
def loadosophia_uploader(name = "Loadosophia.org Uploader", params = {}, &block)
node = RubyJmeter::Plugins::LoadosophiaUploader.new(name, params)
attach_node(node, &block)
end
|
#loop_controller(params, &block) ⇒ Object
Also known as:
loops
3
4
5
6
7
|
# File 'lib/ruby-jmeter/extend/controllers/loop_controller.rb', line 3
def loop_controller(params, &block)
params[:loops] = params[:count] || 1
super
end
|
#module_controller(params, &block) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/ruby-jmeter/extend/controllers/module_controller.rb', line 3
def module_controller(params, &block)
node = RubyJmeter::ModuleController.new(params)
if params[:test_fragment]
params[:test_fragment].kind_of?(String) &&
params[:test_fragment].split('/')
elsif params[:node_path]
params[:node_path]
else
[]
end.each_with_index do |node_name, index|
node.doc.at_xpath('//collectionProp') <<
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="node_#{index}">#{node_name}</stringProp>
EOS
end
attach_node(node, &block)
end
|
#out(params = {}) ⇒ Object
20
21
22
|
# File 'lib/ruby-jmeter/dsl.rb', line 20
def out(params = {})
puts doc.to_xml(indent: 2)
end
|
#perfmon_collector(params = {}, &block) ⇒ Object
Also known as:
perfmon
96
97
98
99
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 96
def perfmon_collector(params = {}, &block)
node = RubyJmeter::Plugins::PerfmonCollector.new(params)
attach_node(node, &block)
end
|
#random_timer(delay = 0, range = 0, &block) ⇒ Object
Also known as:
think_time
3
4
5
6
7
8
9
10
|
# File 'lib/ruby-jmeter/extend/timers/random_timer.rb', line 3
def random_timer(delay=0, range=0, &block)
params = {}
params[:delay] = delay
params[:range] = range
node = RubyJmeter::GaussianRandomTimer.new(params)
attach_node(node, &block)
end
|
#redis_data_set(params = {}, &block) ⇒ Object
110
111
112
113
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 110
def redis_data_set(params = {}, &block)
node = RubyJmeter::Plugins::RedisDataSet.new(params)
attach_node(node, &block)
end
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/ruby-jmeter/extend/processors/regular_expression_extractor.rb', line 3
def (params, &block)
params[:refname] = params[:name]
params[:regex] = params[:pattern]
params[:template] = params[:template] || "$1$"
node = RubyJmeter::RegularExpressionExtractor.new(params).tap do |node|
if params[:variable]
node.doc.xpath("//stringProp[@name='Sample.scope']").first.content = 'variable'
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="Scope.variable">#{params[:variable]}</stringProp>
EOS
)
end
end
attach_node(node, &block)
end
|
#response_assertion(params, &block) ⇒ Object
Also known as:
assert, web_reg_find
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
|
# File 'lib/ruby-jmeter/extend/assertions/response_assertion.rb', line 3
def response_assertion(params, &block)
params[:test_type] = parse_test_type(params)
params['0'] = params.values.first
if params[:json]
params[:EXPECTED_VALUE] = params[:value]
params[:JSON_PATH] = params[:json]
node = RubyJmeter::Plugins::JsonPathAssertion.new(params)
end
node ||= RubyJmeter::ResponseAssertion.new(params).tap do |node|
if params[:variable]
params['Scope.variable'] = params[:variable]
node.doc.xpath("//stringProp[@name='Assertion.scope']").first.content = 'variable'
node.doc.children.first.add_child (
Nokogiri::XML(<<-EOS.strip_heredoc).children
<stringProp name="Scope.variable">#{params[:variable]}</stringProp>
EOS
)
end
if params[:scope] == 'main'
node.doc.xpath("//stringProp[@name='Assertion.scope']").remove
end
end
attach_node(node, &block)
end
|
#response_codes_per_second(name = 'Response Codes per Second', params = {}, &block) ⇒ Object
3
4
5
6
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 3
def response_codes_per_second(name = 'Response Codes per Second', params = {}, &block)
node = RubyJmeter::Plugins::ResponseCodesPerSecond.new(name, params)
attach_node(node, &block)
end
|
#response_times_distribution(name = 'Response Times Distribution', params = {}, &block) ⇒ Object
8
9
10
11
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 8
def response_times_distribution(name = 'Response Times Distribution', params = {}, &block)
node = RubyJmeter::Plugins::ResponseTimesDistribution.new(name, params)
attach_node(node, &block)
end
|
#response_times_over_time(name = 'Response Times Over Time', params = {}, &block) ⇒ Object
13
14
15
16
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 13
def response_times_over_time(name = 'Response Times Over Time', params = {}, &block)
node = RubyJmeter::Plugins::ResponseTimesOverTime.new(name, params)
attach_node(node, &block)
end
|
#response_times_percentiles(name = 'Response Times Percentiles', params = {}, &block) ⇒ Object
18
19
20
21
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 18
def response_times_percentiles(name = 'Response Times Percentiles', params = {}, &block)
node = RubyJmeter::Plugins::ResponseTimesPercentiles.new(name, params)
attach_node(node, &block)
end
|
#run(params = {}) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/ruby-jmeter/dsl.rb', line 37
def run(params = {})
file(params)
logger.warn 'Test executing locally ...'
cmd = "#{params[:path]}jmeter #{"-n" unless params[:gui] } -t #{params[:file]} -j #{params[:log] ? params[:log] : 'jmeter.log' } -l #{params[:jtl] ? params[:jtl] : 'jmeter.jtl' }"
logger.debug cmd if params[:debug]
Open3.popen2e("#{cmd}") do |stdin, stdout_err, wait_thr|
while line = stdout_err.gets
logger.debug line.chomp if params[:debug]
end
exit_status = wait_thr.value
abort "FAILED !!! #{cmd}" unless exit_status.success?
end
logger.info "Local Results at: #{params[:jtl] ? params[:jtl] : 'jmeter.jtl'}"
end
|
#setup_thread_group(*args, &block) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/ruby-jmeter/extend/threads/setup_thread_group.rb', line 3
def setup_thread_group(*args, &block)
params = args.shift || {}
params = { count: params }.merge(args.shift || {}) if params.class == Fixnum
params[:num_threads] = params[:count] || 1
params[:ramp_time] = params[:rampup] || (params[:num_threads]/2.0).ceil
params[:start_time] = params[:start_time] || Time.now.to_i * 1000
params[:end_time] = params[:end_time] || Time.now.to_i * 1000
params[:duration] ||= 60
params[:continue_forever] ||= false
params[:loops] = -1 if params[:continue_forever]
node = RubyJmeter::SetupThreadGroup.new(params)
attach_node(node, &block)
end
|
#soap ⇒ Object
4
|
# File 'lib/ruby-jmeter/extend/misc/aliases.rb', line 4
alias soap soapxmlrpc_request
|
#soapxmlrpc_request(params, &block) ⇒ Object
3
4
5
6
7
|
# File 'lib/ruby-jmeter/extend/samplers/soapxmlrpc_request.rb', line 3
def soapxmlrpc_request(params, &block)
params[:method] ||= 'POST'
super
end
|
#stepping_thread_group(params = {}, &block) ⇒ Object
Also known as:
step
54
55
56
57
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 54
def stepping_thread_group(params = {}, &block)
node = RubyJmeter::Plugins::SteppingThreadGroup.new(params)
attach_node(node, &block)
end
|
#thread_group(*args, &block) ⇒ Object
Also known as:
threads
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/ruby-jmeter/extend/threads/thread_group.rb', line 3
def thread_group(*args, &block)
params = args.shift || {}
params = { count: params }.merge(args.shift || {}) if params.class == Fixnum
params[:num_threads] = params[:count] || 1
params[:ramp_time] = params[:rampup] || (params[:num_threads]/2.0).ceil
params[:start_time] = params[:start_time] || Time.now.to_i * 1000
params[:end_time] = params[:end_time] || Time.now.to_i * 1000
params[:duration] ||= 60
params[:continue_forever] ||= false
params[:loops] = -1 if params[:continue_forever]
node = RubyJmeter::ThreadGroup.new(params)
attach_node(node, &block)
end
|
#throughput_controller(params = {}, &block) ⇒ Object
Also known as:
throughput
3
4
5
6
7
8
9
10
11
|
# File 'lib/ruby-jmeter/extend/controllers/throughput_controller.rb', line 3
def throughput_controller(params = {}, &block)
params[:style] = 1 if params[:percent]
params[:maxThroughput] = params[:total] || params[:percent] || 1
node = RubyJmeter::ThroughputController.new(params)
node.doc.xpath(".//FloatProperty/value").first.content = params[:maxThroughput].to_f
attach_node(node, &block)
end
|
#throughput_shaper(name = 'Throughput Shaping Timer', steps = [], params = {}, &block) ⇒ Object
Also known as:
shaper
40
41
42
43
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 40
def throughput_shaper(name = 'Throughput Shaping Timer', steps=[], params = {}, &block)
node = RubyJmeter::Plugins::ThroughputShapingTimer.new(name, steps)
attach_node(node, &block)
end
|
#to_doc ⇒ Object
33
34
35
|
# File 'lib/ruby-jmeter/dsl.rb', line 33
def to_doc
doc.clone
end
|
#to_xml ⇒ Object
29
30
31
|
# File 'lib/ruby-jmeter/dsl.rb', line 29
def to_xml
doc.to_xml(indent: 2)
end
|
#transaction_controller(*args, &block) ⇒ Object
Also known as:
transaction
3
4
5
6
7
8
9
10
|
# File 'lib/ruby-jmeter/extend/controllers/transaction_controller.rb', line 3
def transaction_controller(*args, &block)
params = args.shift || {}
params = { name: params }.merge(args.shift || {}) if params.class == String
params[:parent] = params[:parent] || false
params[:includeTimers] = params[:include_timers] || false
node = RubyJmeter::TransactionController.new(params)
attach_node(node, &block)
end
|
#transactions_per_second(name = 'Transactions per Second', params = {}, &block) ⇒ Object
23
24
25
26
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 23
def transactions_per_second(name = 'Transactions per Second', params = {}, &block)
node = RubyJmeter::Plugins::TransactionsPerSecond.new(name, params)
attach_node(node, &block)
end
|
#ultimate_thread_group(threads = [], params = {}, &block) ⇒ Object
Also known as:
ultimate
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/ruby-jmeter/extend/plugins/jmeter_plugins.rb', line 61
def ultimate_thread_group(threads = [], params = {}, &block)
node = RubyJmeter::Plugins::UltimateThreadGroup.new(params)
threads.each_with_index do |group, index|
node.doc.at_xpath('//collectionProp') <<
Nokogiri::XML(<<-EOS.strip_heredoc).children
<collectionProp name="index">
<stringProp name="#{group[:start_threads]}">#{group[:start_threads]}</stringProp>
<stringProp name="#{group[:initial_delay]}">#{group[:initial_delay]}</stringProp>
<stringProp name="#{group[:start_time]}">#{group[:start_time]}</stringProp>
<stringProp name="#{group[:hold_time]}">#{group[:hold_time]}</stringProp>
<stringProp name="#{group[:stop_time]}">#{group[:stop_time]}</stringProp>
</collectionProp>
EOS
end
attach_node(node, &block)
end
|
#user_defined_variables(params, &block) ⇒ Object
Also known as:
variables
3
4
5
6
7
8
9
|
# File 'lib/ruby-jmeter/extend/config_elements/user_defined_variables.rb', line 3
def user_defined_variables(params, &block)
if params.is_a?(Hash)
params['Argument.name'] = params[:name]
end
super
end
|
#user_parameters(params, &block) ⇒ Object
Also known as:
parameters
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
|
# File 'lib/ruby-jmeter/extend/config_elements/user_parameters.rb', line 3
def user_parameters(params, &block)
params['Argument.name'] = params[:name] if params.is_a?(Hash)
params[:names] = Nokogiri::XML::Builder.new do |b|
b.builder do
params[:names].each do |name|
b.stringProp name, name: name
end
end
end
params[:thread_values] = Nokogiri::XML::Builder.new do |b|
b.builder do
params[:thread_values].map do |user, values|
b.collectionProp name: user do
values.each_with_index.map do |value, index|
b.stringProp value, name: index
end
end
end
end
end
super
end
|
#with_browser(device) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/ruby-jmeter/extend/misc/with_helpers.rb', line 7
def with_browser(device)
name: 'User-Agent', value: RubyJmeter::UserAgent.new(device).string
[
{ name: 'Accept-Encoding', value: 'gzip,deflate,sdch' },
{ name: 'Accept', value: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' }
]
end
|
#with_gzip ⇒ Object
19
20
21
|
# File 'lib/ruby-jmeter/extend/misc/with_helpers.rb', line 19
def with_gzip
name: 'Accept-Encoding', value: 'gzip, deflate'
end
|
#with_json ⇒ Object
23
24
25
|
# File 'lib/ruby-jmeter/extend/misc/with_helpers.rb', line 23
def with_json
name: 'Accept', value: 'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8, application/json'
end
|
#with_user_agent(device) ⇒ Object
3
4
5
|
# File 'lib/ruby-jmeter/extend/misc/with_helpers.rb', line 3
def with_user_agent(device)
name: 'User-Agent', value: RubyJmeter::UserAgent.new(device).string
end
|
#with_xhr ⇒ Object
15
16
17
|
# File 'lib/ruby-jmeter/extend/misc/with_helpers.rb', line 15
def with_xhr
name: 'X-Requested-With', value: 'XMLHttpRequest'
end
|