ruby-jmeter 2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +22 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +27 -0
- data/LICENSE.txt +22 -0
- data/README.md +333 -0
- data/Rakefile +6 -0
- data/bin/grid +25 -0
- data/examples/basic_assertion.rb +13 -0
- data/examples/basic_auth.rb +11 -0
- data/examples/basic_cache.rb +11 -0
- data/examples/basic_cookies.rb +11 -0
- data/examples/basic_extract.rb +10 -0
- data/examples/basic_gc_dummy_sampler.rb +10 -0
- data/examples/basic_gc_results.rb +23 -0
- data/examples/basic_google.rb +8 -0
- data/examples/basic_grid.rb +8 -0
- data/examples/basic_header.rb +19 -0
- data/examples/basic_ldap_ext.rb +16 -0
- data/examples/basic_post.rb +15 -0
- data/examples/basic_query_params.rb +8 -0
- data/examples/basic_think_time.rb +15 -0
- data/examples/basic_throughput_controller.rb +14 -0
- data/examples/basic_throughput_shaping_timer.rb +21 -0
- data/examples/etsy_login_browse.rb +64 -0
- data/lib/ruby-jmeter.rb +18 -0
- data/lib/ruby-jmeter/DSL.md +237 -0
- data/lib/ruby-jmeter/dsl.rb +419 -0
- data/lib/ruby-jmeter/dsl/access_log_sampler.rb +32 -0
- data/lib/ruby-jmeter/dsl/aggregate_graph.rb +55 -0
- data/lib/ruby-jmeter/dsl/aggregate_report.rb +55 -0
- data/lib/ruby-jmeter/dsl/ajp13_sampler.rb +41 -0
- data/lib/ruby-jmeter/dsl/assertion_results.rb +55 -0
- data/lib/ruby-jmeter/dsl/beanshell_assertion.rb +28 -0
- data/lib/ruby-jmeter/dsl/beanshell_listener.rb +28 -0
- data/lib/ruby-jmeter/dsl/beanshell_postprocessor.rb +28 -0
- data/lib/ruby-jmeter/dsl/beanshell_preprocessor.rb +28 -0
- data/lib/ruby-jmeter/dsl/beanshell_sampler.rb +28 -0
- data/lib/ruby-jmeter/dsl/beanshell_timer.rb +28 -0
- data/lib/ruby-jmeter/dsl/bsf_assertion.rb +28 -0
- data/lib/ruby-jmeter/dsl/bsf_listener.rb +28 -0
- data/lib/ruby-jmeter/dsl/bsf_postprocessor.rb +28 -0
- data/lib/ruby-jmeter/dsl/bsf_preprocessor.rb +28 -0
- data/lib/ruby-jmeter/dsl/bsf_sampler.rb +28 -0
- data/lib/ruby-jmeter/dsl/bsf_timer.rb +28 -0
- data/lib/ruby-jmeter/dsl/compare_assertion.rb +27 -0
- data/lib/ruby-jmeter/dsl/comparison_assertion_visualizer.rb +55 -0
- data/lib/ruby-jmeter/dsl/constant_throughput_timer.rb +30 -0
- data/lib/ruby-jmeter/dsl/constant_timer.rb +25 -0
- data/lib/ruby-jmeter/dsl/counter.rb +31 -0
- data/lib/ruby-jmeter/dsl/cssjquery_extractor.rb +30 -0
- data/lib/ruby-jmeter/dsl/csv_data_set_config.rb +32 -0
- data/lib/ruby-jmeter/dsl/debug_postprocessor.rb +28 -0
- data/lib/ruby-jmeter/dsl/debug_sampler.rb +27 -0
- data/lib/ruby-jmeter/dsl/distribution_graphalpha.rb +55 -0
- data/lib/ruby-jmeter/dsl/duration_assertion.rb +25 -0
- data/lib/ruby-jmeter/dsl/foreach_controller.rb +29 -0
- data/lib/ruby-jmeter/dsl/ftp_request.rb +34 -0
- data/lib/ruby-jmeter/dsl/ftp_request_defaults.rb +32 -0
- data/lib/ruby-jmeter/dsl/gaussian_random_timer.rb +26 -0
- data/lib/ruby-jmeter/dsl/generate_summary_results.rb +23 -0
- data/lib/ruby-jmeter/dsl/graph_results.rb +55 -0
- data/lib/ruby-jmeter/dsl/html_assertion.rb +30 -0
- data/lib/ruby-jmeter/dsl/html_link_parser.rb +23 -0
- data/lib/ruby-jmeter/dsl/html_parameter_mask.rb +32 -0
- data/lib/ruby-jmeter/dsl/http_authorization_manager.rb +33 -0
- data/lib/ruby-jmeter/dsl/http_cache_manager.rb +26 -0
- data/lib/ruby-jmeter/dsl/http_cookie_manager.rb +27 -0
- data/lib/ruby-jmeter/dsl/http_header_manager.rb +30 -0
- data/lib/ruby-jmeter/dsl/http_request.rb +41 -0
- data/lib/ruby-jmeter/dsl/http_request_defaults.rb +44 -0
- data/lib/ruby-jmeter/dsl/http_url_rewriting_modifier.rb +29 -0
- data/lib/ruby-jmeter/dsl/if_controller.rb +27 -0
- data/lib/ruby-jmeter/dsl/include_controller.rb +25 -0
- data/lib/ruby-jmeter/dsl/java_request.rb +69 -0
- data/lib/ruby-jmeter/dsl/java_request_defaults.rb +69 -0
- data/lib/ruby-jmeter/dsl/jdbc_connection_configuration.rb +37 -0
- data/lib/ruby-jmeter/dsl/jdbc_postprocessor.rb +31 -0
- data/lib/ruby-jmeter/dsl/jdbc_preprocessor.rb +31 -0
- data/lib/ruby-jmeter/dsl/jdbc_request.rb +31 -0
- data/lib/ruby-jmeter/dsl/jms_pointtopoint.rb +40 -0
- data/lib/ruby-jmeter/dsl/jms_publisher.rb +41 -0
- data/lib/ruby-jmeter/dsl/jms_subscriber.rb +35 -0
- data/lib/ruby-jmeter/dsl/jsr223_assertion.rb +29 -0
- data/lib/ruby-jmeter/dsl/jsr223_listener.rb +29 -0
- data/lib/ruby-jmeter/dsl/jsr223_postprocessor.rb +29 -0
- data/lib/ruby-jmeter/dsl/jsr223_preprocessor.rb +29 -0
- data/lib/ruby-jmeter/dsl/jsr223_sampler.rb +29 -0
- data/lib/ruby-jmeter/dsl/jsr223_timer.rb +29 -0
- data/lib/ruby-jmeter/dsl/junit_request.rb +37 -0
- data/lib/ruby-jmeter/dsl/keystore_configuration.rb +27 -0
- data/lib/ruby-jmeter/dsl/ldap_extended_request.rb +42 -0
- data/lib/ruby-jmeter/dsl/ldap_extended_request_defaults.rb +42 -0
- data/lib/ruby-jmeter/dsl/ldap_request.rb +35 -0
- data/lib/ruby-jmeter/dsl/ldap_request_defaults.rb +40 -0
- data/lib/ruby-jmeter/dsl/login_config_element.rb +26 -0
- data/lib/ruby-jmeter/dsl/loop_controller.rb +26 -0
- data/lib/ruby-jmeter/dsl/mail_reader_sampler.rb +37 -0
- data/lib/ruby-jmeter/dsl/mailer_visualizer.rb +64 -0
- data/lib/ruby-jmeter/dsl/md5hex_assertion.rb +25 -0
- data/lib/ruby-jmeter/dsl/module_controller.rb +23 -0
- data/lib/ruby-jmeter/dsl/monitor_results.rb +55 -0
- data/lib/ruby-jmeter/dsl/once_only_controller.rb +23 -0
- data/lib/ruby-jmeter/dsl/os_process_sampler.rb +34 -0
- data/lib/ruby-jmeter/dsl/poisson_random_timer.rb +26 -0
- data/lib/ruby-jmeter/dsl/random_controller.rb +25 -0
- data/lib/ruby-jmeter/dsl/random_order_controller.rb +23 -0
- data/lib/ruby-jmeter/dsl/random_variable.rb +30 -0
- data/lib/ruby-jmeter/dsl/recording_controller.rb +23 -0
- data/lib/ruby-jmeter/dsl/regex_user_parameters.rb +27 -0
- data/lib/ruby-jmeter/dsl/regular_expression_extractor.rb +31 -0
- data/lib/ruby-jmeter/dsl/response_assertion.rb +31 -0
- data/lib/ruby-jmeter/dsl/response_time_graph.rb +55 -0
- data/lib/ruby-jmeter/dsl/result_status_action_handler.rb +25 -0
- data/lib/ruby-jmeter/dsl/runtime_controller.rb +25 -0
- data/lib/ruby-jmeter/dsl/save_responses_to_a_file.rb +29 -0
- data/lib/ruby-jmeter/dsl/simple_config_element.rb +23 -0
- data/lib/ruby-jmeter/dsl/simple_controller.rb +23 -0
- data/lib/ruby-jmeter/dsl/simple_data_writer.rb +55 -0
- data/lib/ruby-jmeter/dsl/smime_assertion.rb +35 -0
- data/lib/ruby-jmeter/dsl/smtp_sampler.rb +51 -0
- data/lib/ruby-jmeter/dsl/soapxmlrpc_request.rb +33 -0
- data/lib/ruby-jmeter/dsl/spline_visualizer.rb +55 -0
- data/lib/ruby-jmeter/dsl/summary_report.rb +55 -0
- data/lib/ruby-jmeter/dsl/switch_controller.rb +25 -0
- data/lib/ruby-jmeter/dsl/synchronizing_timer.rb +25 -0
- data/lib/ruby-jmeter/dsl/tcp_sampler.rb +33 -0
- data/lib/ruby-jmeter/dsl/tcp_sampler_config.rb +31 -0
- data/lib/ruby-jmeter/dsl/test_action.rb +27 -0
- data/lib/ruby-jmeter/dsl/test_plan.rb +31 -0
- data/lib/ruby-jmeter/dsl/thread_group.rb +36 -0
- data/lib/ruby-jmeter/dsl/throughput_controller.rb +32 -0
- data/lib/ruby-jmeter/dsl/transaction_controller.rb +26 -0
- data/lib/ruby-jmeter/dsl/uniform_random_timer.rb +26 -0
- data/lib/ruby-jmeter/dsl/user_defined_variables.rb +32 -0
- data/lib/ruby-jmeter/dsl/user_parameters.rb +29 -0
- data/lib/ruby-jmeter/dsl/view_results_in_table.rb +55 -0
- data/lib/ruby-jmeter/dsl/view_results_tree.rb +55 -0
- data/lib/ruby-jmeter/dsl/while_controller.rb +25 -0
- data/lib/ruby-jmeter/dsl/xml_assertion.rb +23 -0
- data/lib/ruby-jmeter/dsl/xml_schema_assertion.rb +25 -0
- data/lib/ruby-jmeter/dsl/xpath_assertion.rb +30 -0
- data/lib/ruby-jmeter/dsl/xpath_extractor.rb +30 -0
- data/lib/ruby-jmeter/helpers/fallback_content_proxy.rb +54 -0
- data/lib/ruby-jmeter/helpers/helper.rb +41 -0
- data/lib/ruby-jmeter/helpers/jmeter.properties +28 -0
- data/lib/ruby-jmeter/helpers/logger-colors.rb +48 -0
- data/lib/ruby-jmeter/helpers/parser.rb +106 -0
- data/lib/ruby-jmeter/helpers/strip-heredoc.rb +5 -0
- data/lib/ruby-jmeter/helpers/user-agents.rb +27 -0
- data/lib/ruby-jmeter/idl.rb +70 -0
- data/lib/ruby-jmeter/idl.xml +1513 -0
- data/lib/ruby-jmeter/plugins/gc_console_status_logger.rb +14 -0
- data/lib/ruby-jmeter/plugins/gc_dummy_sampler.rb +23 -0
- data/lib/ruby-jmeter/plugins/gc_latencies_over_time.rb +48 -0
- data/lib/ruby-jmeter/plugins/gc_response_codes_per_second.rb +48 -0
- data/lib/ruby-jmeter/plugins/gc_response_times_distribution.rb +47 -0
- data/lib/ruby-jmeter/plugins/gc_response_times_over_time.rb +48 -0
- data/lib/ruby-jmeter/plugins/gc_response_times_percentiles.rb +48 -0
- data/lib/ruby-jmeter/plugins/gc_transactions_per_second.rb +48 -0
- data/lib/ruby-jmeter/plugins/gc_variable_throughput_timer.rb +26 -0
- data/lib/ruby-jmeter/version.rb +3 -0
- data/ruby-jmeter.gemspec +22 -0
- data/spec/dsl_spec.rb +491 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/stub.rb +31 -0
- metadata +244 -0
@@ -0,0 +1,419 @@
|
|
1
|
+
module RubyJmeter
|
2
|
+
class ExtendedDSL < DSL
|
3
|
+
include Parser
|
4
|
+
attr_accessor :root
|
5
|
+
|
6
|
+
def initialize(params = {})
|
7
|
+
@root = Nokogiri::XML(<<-EOF.strip_heredoc)
|
8
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
9
|
+
<jmeterTestPlan version="1.2" properties="2.1">
|
10
|
+
<hashTree>
|
11
|
+
</hashTree>
|
12
|
+
</jmeterTestPlan>
|
13
|
+
EOF
|
14
|
+
node = RubyJmeter::TestPlan.new(params)
|
15
|
+
|
16
|
+
@current_node = @root.at_xpath("//jmeterTestPlan/hashTree")
|
17
|
+
@current_node = attach_to_last(node)
|
18
|
+
|
19
|
+
variables :name => 'testguid',
|
20
|
+
:value => '${__P(testguid,${__time(,)})}',
|
21
|
+
:comments => 'flood.io uuid automatically generated by DSL'
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Config Elements
|
26
|
+
|
27
|
+
def user_defined_variables(params, &block)
|
28
|
+
params['Argument.name'] = params[:name]
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :variables, :user_defined_variables
|
33
|
+
|
34
|
+
alias_method :defaults, :http_request_defaults
|
35
|
+
|
36
|
+
def http_cookie_manager(params={}, &block)
|
37
|
+
params[:clearEachIteration] = true if params.keys.include? 'clear_each_iteration'
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :cookies, :http_cookie_manager
|
42
|
+
|
43
|
+
def http_cache_manager(params={}, &block)
|
44
|
+
params[:clearEachIteration] = true if params.keys.include? 'clear_each_iteration'
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
alias_method :cache, :http_cache_manager
|
49
|
+
|
50
|
+
def with_user_agent(device)
|
51
|
+
http_header_manager name: 'User-Agent',
|
52
|
+
value: RubyJmeter::UserAgent.new(device).string
|
53
|
+
end
|
54
|
+
|
55
|
+
def http_header_manager(params, &block)
|
56
|
+
params['Header.name'] = params[:name]
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
alias_method :header, :http_header_manager
|
61
|
+
|
62
|
+
alias_method :auth, :http_authorization_manager
|
63
|
+
|
64
|
+
def thread_group(*args, &block)
|
65
|
+
params = args.shift || {}
|
66
|
+
params = { count: params }.merge(args.shift || {}) if params.class == Fixnum
|
67
|
+
params[:num_threads] = params[:count] || 1
|
68
|
+
params[:ramp_time] = params[:rampup] || (params[:num_threads]/2.0).ceil
|
69
|
+
params[:start_time] = params[:start_time] || Time.now.to_i * 1000
|
70
|
+
params[:end_time] = params[:end_time] || Time.now.to_i * 1000
|
71
|
+
params[:duration] ||= 60
|
72
|
+
params[:continue_forever] ||= false
|
73
|
+
params[:loops] = -1 if params[:continue_forever]
|
74
|
+
node = RubyJmeter::ThreadGroup.new(params)
|
75
|
+
attach_node(node, &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
alias_method :threads, :thread_group
|
79
|
+
|
80
|
+
##
|
81
|
+
# HTTP Samplers
|
82
|
+
|
83
|
+
def get(*args, &block)
|
84
|
+
params = args.shift || {}
|
85
|
+
params = { url: params }.merge(args.shift || {}) if params.class == String
|
86
|
+
params[:method] ||= 'GET'
|
87
|
+
params[:name] ||= params[:url]
|
88
|
+
parse_http_request(params)
|
89
|
+
node = RubyJmeter::HttpRequest.new(params)
|
90
|
+
attach_node(node, &block)
|
91
|
+
end
|
92
|
+
|
93
|
+
alias_method :visit, :get
|
94
|
+
|
95
|
+
def post(*args, &block)
|
96
|
+
params = args.shift || {}
|
97
|
+
params = { url: params }.merge(args.shift || {}) if params.class == String
|
98
|
+
params[:method] ||= 'POST'
|
99
|
+
params[:name] ||= params[:url]
|
100
|
+
parse_http_request(params)
|
101
|
+
node = RubyJmeter::HttpRequest.new(params)
|
102
|
+
attach_node(node, &block)
|
103
|
+
end
|
104
|
+
|
105
|
+
alias_method :submit, :post
|
106
|
+
|
107
|
+
def delete(*args, &block)
|
108
|
+
params = args.shift || {}
|
109
|
+
params = { url: params }.merge(args.shift || {}) if params.class == String
|
110
|
+
params[:method] ||= 'DELETE'
|
111
|
+
params[:name] ||= params[:url]
|
112
|
+
parse_http_request(params)
|
113
|
+
node = RubyJmeter::HttpRequest.new(params)
|
114
|
+
attach_node(node, &block)
|
115
|
+
end
|
116
|
+
|
117
|
+
def put(*args, &block)
|
118
|
+
params = args.shift || {}
|
119
|
+
params = { url: params }.merge(args.shift || {}) if params.class == String
|
120
|
+
params[:method] ||= 'PUT'
|
121
|
+
params[:name] ||= params[:url]
|
122
|
+
parse_http_request(params)
|
123
|
+
node = RubyJmeter::HttpRequest.new(params)
|
124
|
+
attach_node(node, &block)
|
125
|
+
end
|
126
|
+
|
127
|
+
def with_xhr
|
128
|
+
http_header_manager name: 'X-Requested-With',
|
129
|
+
value: 'XMLHttpRequest'
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# Other Samplers
|
134
|
+
|
135
|
+
def soapxmlrpc_request(params, &block)
|
136
|
+
params[:method] ||= 'POST'
|
137
|
+
super
|
138
|
+
end
|
139
|
+
|
140
|
+
alias_method :soap, :soapxmlrpc_request
|
141
|
+
|
142
|
+
alias_method :ldap, :ldap_request
|
143
|
+
|
144
|
+
alias_method :ldap_ext, :ldap_extended_request
|
145
|
+
|
146
|
+
alias_method :ldap_extended, :ldap_extended_request
|
147
|
+
|
148
|
+
|
149
|
+
##
|
150
|
+
# Controllers
|
151
|
+
|
152
|
+
def transaction_controller(*args, &block)
|
153
|
+
params = args.shift || {}
|
154
|
+
params = { name: params }.merge(args.shift || {}) if params.class == String
|
155
|
+
params[:parent] ||= true
|
156
|
+
params[:includeTimers] = params[:include_timers] || false
|
157
|
+
node = RubyJmeter::TransactionController.new(params)
|
158
|
+
attach_node(node, &block)
|
159
|
+
end
|
160
|
+
|
161
|
+
alias_method :transaction, :transaction_controller
|
162
|
+
|
163
|
+
def exists(variable, &block)
|
164
|
+
params ||= {}
|
165
|
+
params[:condition] = "'${#{variable}}'.length > 0"
|
166
|
+
node = RubyJmeter::IfController.new(params)
|
167
|
+
attach_node(node, &block)
|
168
|
+
end
|
169
|
+
|
170
|
+
alias_method :If, :if_controller
|
171
|
+
|
172
|
+
def loop_controller(params, &block)
|
173
|
+
params[:loops] = params[:count] || 1
|
174
|
+
super
|
175
|
+
end
|
176
|
+
|
177
|
+
alias_method :Loop, :loop_controller
|
178
|
+
|
179
|
+
def throughput_controller(params, &block)
|
180
|
+
params[:style] = 1 if params[:percent]
|
181
|
+
params[:maxThroughput] = params[:total] || params[:percent] || 1
|
182
|
+
|
183
|
+
node = RubyJmeter::ThroughputController.new(params)
|
184
|
+
node.doc.xpath(".//FloatProperty/value").first.content = params[:maxThroughput].to_f
|
185
|
+
|
186
|
+
attach_node(node, &block)
|
187
|
+
end
|
188
|
+
|
189
|
+
alias_method :Throughput, :throughput_controller
|
190
|
+
|
191
|
+
alias_method :Switch, :switch_controller
|
192
|
+
|
193
|
+
alias_method :While, :while_controller
|
194
|
+
|
195
|
+
alias_method :Interleave, :random_controller
|
196
|
+
|
197
|
+
alias_method :Random_order, :random_order_controller
|
198
|
+
|
199
|
+
alias_method :Simple, :simple_controller
|
200
|
+
|
201
|
+
alias_method :Once, :once_only_controller
|
202
|
+
|
203
|
+
##
|
204
|
+
# Listeners
|
205
|
+
|
206
|
+
alias_method :view_results, :view_results_tree
|
207
|
+
|
208
|
+
alias_method :log, :simple_data_writer
|
209
|
+
|
210
|
+
alias_method :response_graph, :response_time_graph
|
211
|
+
|
212
|
+
##
|
213
|
+
# Other Elements
|
214
|
+
|
215
|
+
alias_method :bsh_pre, :beanshell_preprocessor
|
216
|
+
|
217
|
+
alias_method :bsh_post, :beanshell_postprocessor
|
218
|
+
|
219
|
+
def extract(params, &block)
|
220
|
+
node = if params[:regex]
|
221
|
+
params[:refname] = params[:name]
|
222
|
+
params[:regex] = params[:regex] #CGI.escapeHTML
|
223
|
+
params[:template] = params[:template] || "$1$"
|
224
|
+
RubyJmeter::RegularExpressionExtractor.new(params)
|
225
|
+
else
|
226
|
+
params[:refname] = params[:name]
|
227
|
+
params[:xpathQuery] = params[:xpath]
|
228
|
+
RubyJmeter::XpathExtractor.new(params)
|
229
|
+
end
|
230
|
+
attach_node(node, &block)
|
231
|
+
end
|
232
|
+
|
233
|
+
alias_method :web_reg_save_param, :extract
|
234
|
+
|
235
|
+
def random_timer(delay=0, range=0, &block)
|
236
|
+
params={}
|
237
|
+
params[:delay] = delay
|
238
|
+
params[:range] = range
|
239
|
+
node = RubyJmeter::GaussianRandomTimer.new(params)
|
240
|
+
attach_node(node, &block)
|
241
|
+
end
|
242
|
+
|
243
|
+
alias_method :think_time, :random_timer
|
244
|
+
|
245
|
+
def response_assertion(params={}, &block)
|
246
|
+
params[:test_type] = parse_test_type(params)
|
247
|
+
params[:match] = params.values.first
|
248
|
+
node = RubyJmeter::ResponseAssertion.new(params)
|
249
|
+
node.doc.xpath("//stringProp[@name='Assertion.scope']").remove if
|
250
|
+
params[:scope] == 'main' || params['scope'] == 'main'
|
251
|
+
attach_node(node, &block)
|
252
|
+
end
|
253
|
+
|
254
|
+
alias_method :assert, :response_assertion
|
255
|
+
|
256
|
+
alias_method :web_reg_find, :response_assertion
|
257
|
+
|
258
|
+
##
|
259
|
+
# JMeter Plugins
|
260
|
+
|
261
|
+
def response_codes_per_second(name="jp@gc - Response Codes per Second", params={}, &block)
|
262
|
+
node = RubyJmeter::GCResponseCodesPerSecond.new(name, params)
|
263
|
+
attach_node(node, &block)
|
264
|
+
end
|
265
|
+
|
266
|
+
def response_times_distribution(name="jp@gc - Response Times Distribution", params={}, &block)
|
267
|
+
node = RubyJmeter::GCResponseTimesDistribution.new(name, params)
|
268
|
+
attach_node(node, &block)
|
269
|
+
end
|
270
|
+
|
271
|
+
def response_times_over_time(name="jp@gc - Response Times Over Time", params={}, &block)
|
272
|
+
node = RubyJmeter::GCResponseTimesOverTime.new(name, params)
|
273
|
+
attach_node(node, &block)
|
274
|
+
end
|
275
|
+
|
276
|
+
def response_times_percentiles(name="jp@gc - Response Times Percentiles", params={}, &block)
|
277
|
+
node = RubyJmeter::GCResponseTimesPercentiles.new(name, params)
|
278
|
+
attach_node(node, &block)
|
279
|
+
end
|
280
|
+
|
281
|
+
def transactions_per_second(name="jp@gc - Transactions per Second", params={}, &block)
|
282
|
+
node = RubyJmeter::GCTransactionsPerSecond.new(name, params)
|
283
|
+
attach_node(node, &block)
|
284
|
+
end
|
285
|
+
|
286
|
+
def latencies_over_time(name="jp@gc - Response Latencies Over Time", params={}, &block)
|
287
|
+
node = RubyJmeter::GCLatenciesOverTime.new(name, params)
|
288
|
+
attach_node(node, &block)
|
289
|
+
end
|
290
|
+
|
291
|
+
def console_status_logger(name="jp@gc - Console Status Logger", params={}, &block)
|
292
|
+
node = RubyJmeter::GCConsoleStatusLogger.new(name, params)
|
293
|
+
attach_node(node, &block)
|
294
|
+
end
|
295
|
+
|
296
|
+
alias_method :console, :console_status_logger
|
297
|
+
|
298
|
+
def throughput_shaper(name="jp@gc - Throughput Shaping Timer", steps=[], params={}, &block)
|
299
|
+
node = RubyJmeter::GCThroughputShapingTimer.new(name, steps)
|
300
|
+
attach_node(node, &block)
|
301
|
+
end
|
302
|
+
|
303
|
+
alias_method :shaper, :throughput_shaper
|
304
|
+
|
305
|
+
def dummy_sampler(name="jp@gc - Dummy Sampler", params={}, &block)
|
306
|
+
node = RubyJmeter::GCDummySampler.new(name, params)
|
307
|
+
attach_node(node, &block)
|
308
|
+
end
|
309
|
+
|
310
|
+
alias_method :dummy, :dummy_sampler
|
311
|
+
|
312
|
+
# API Methods
|
313
|
+
|
314
|
+
def out(params={})
|
315
|
+
puts doc.to_xml(:indent => 2)
|
316
|
+
end
|
317
|
+
|
318
|
+
def jmx(params={})
|
319
|
+
file(params)
|
320
|
+
logger.info "Test plan saved to: #{params[:file]}"
|
321
|
+
end
|
322
|
+
|
323
|
+
def to_xml
|
324
|
+
doc.to_xml(:indent => 2)
|
325
|
+
end
|
326
|
+
|
327
|
+
def to_doc
|
328
|
+
doc.clone
|
329
|
+
end
|
330
|
+
|
331
|
+
def run(params={})
|
332
|
+
file(params)
|
333
|
+
logger.warn "Test executing locally ..."
|
334
|
+
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' }"
|
335
|
+
logger.debug cmd if params[:debug]
|
336
|
+
Open3.popen2e("#{cmd} -q #{File.dirname(__FILE__)}/helpers/jmeter.properties") do |stdin, stdout_err, wait_thr|
|
337
|
+
while line = stdout_err.gets
|
338
|
+
logger.debug line.chomp if params[:debug]
|
339
|
+
end
|
340
|
+
|
341
|
+
exit_status = wait_thr.value
|
342
|
+
unless exit_status.success?
|
343
|
+
abort "FAILED !!! #{cmd}"
|
344
|
+
end
|
345
|
+
end
|
346
|
+
logger.info "Local Results at: #{params[:jtl] ? params[:jtl] : 'jmeter.jtl'}"
|
347
|
+
end
|
348
|
+
|
349
|
+
def grid(token, params={})
|
350
|
+
if params[:region] == 'local'
|
351
|
+
logger.info "Starting test ..."
|
352
|
+
params[:started] = Time.now
|
353
|
+
run params
|
354
|
+
params[:completed] = Time.now
|
355
|
+
logger.info "Completed test ..."
|
356
|
+
logger.debug "Uploading results ..." if params[:debug]
|
357
|
+
end
|
358
|
+
RestClient.proxy = params[:proxy] if params[:proxy]
|
359
|
+
begin
|
360
|
+
file = Tempfile.new(['jmeter', '.jmx'])
|
361
|
+
file.write(doc.to_xml(:indent => 2))
|
362
|
+
file.rewind
|
363
|
+
response = RestClient.post "#{params[:endpoint] ? params[:endpoint] : 'https://flood.io'}/api?token=#{token}",
|
364
|
+
{
|
365
|
+
:attachment => File.new("#{file.path}", 'rb'),
|
366
|
+
:results => (File.new("#{params[:jtl] ? params[:jtl] : 'jmeter.jtl'}", 'rb') if params[:region] == 'local'),
|
367
|
+
:multipart => true,
|
368
|
+
:content_type => 'application/octet-stream',
|
369
|
+
:started => params[:started],
|
370
|
+
:completed => params[:completed]
|
371
|
+
}.merge(params)
|
372
|
+
logger.info "Flood results at: #{JSON.parse(response)["results"]}" if response.code == 200
|
373
|
+
rescue => e
|
374
|
+
logger.fatal "Sorry there was an error: #{e.message}"
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
private
|
379
|
+
|
380
|
+
def hash_tree
|
381
|
+
Nokogiri::XML::Node.new("hashTree", @root)
|
382
|
+
end
|
383
|
+
|
384
|
+
def attach_to_last(node)
|
385
|
+
ht = hash_tree
|
386
|
+
last_node = @current_node
|
387
|
+
last_node << node.doc.children << ht
|
388
|
+
ht
|
389
|
+
end
|
390
|
+
|
391
|
+
def attach_node(node, &block)
|
392
|
+
ht = attach_to_last(node)
|
393
|
+
previous = @current_node
|
394
|
+
@current_node = ht
|
395
|
+
self.instance_exec(&block) if block
|
396
|
+
@current_node = previous
|
397
|
+
end
|
398
|
+
|
399
|
+
def file(params={})
|
400
|
+
params[:file] ||= 'jmeter.jmx'
|
401
|
+
File.open(params[:file], 'w') { |file| file.write(doc.to_xml(:indent => 2)) }
|
402
|
+
end
|
403
|
+
|
404
|
+
def doc
|
405
|
+
Nokogiri::XML(@root.to_s, &:noblanks)
|
406
|
+
end
|
407
|
+
|
408
|
+
def logger
|
409
|
+
@log ||= Logger.new(STDOUT)
|
410
|
+
@log.level = Logger::DEBUG
|
411
|
+
@log
|
412
|
+
end
|
413
|
+
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
def test(params = {}, &block)
|
418
|
+
RubyJmeter.dsl_eval(RubyJmeter::ExtendedDSL.new(params), &block)
|
419
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RubyJmeter
|
2
|
+
class DSL
|
3
|
+
def access_log_sampler(params={}, &block)
|
4
|
+
node = RubyJmeter::AccessLogSampler.new(params)
|
5
|
+
attach_node(node, &block)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class AccessLogSampler
|
10
|
+
attr_accessor :doc
|
11
|
+
include Helper
|
12
|
+
|
13
|
+
def initialize(params={})
|
14
|
+
params[:name] ||= 'AccessLogSampler'
|
15
|
+
@doc = Nokogiri::XML(<<-EOS.strip_heredoc)
|
16
|
+
<AccessLogSampler guiclass="TestBeanGUI" testclass="AccessLogSampler" testname="#{params[:name]}" enabled="true">
|
17
|
+
<elementProp name="HTTPsampler.Arguments" elementType="Arguments">
|
18
|
+
<collectionProp name="Arguments.arguments"/>
|
19
|
+
</elementProp>
|
20
|
+
<stringProp name="domain"/>
|
21
|
+
<boolProp name="imageParsing">false</boolProp>
|
22
|
+
<stringProp name="logFile"/>
|
23
|
+
<stringProp name="parserClassName">org.apache.jmeter.protocol.http.util.accesslog.TCLogParser</stringProp>
|
24
|
+
<stringProp name="portString"/>
|
25
|
+
</AccessLogSampler>)
|
26
|
+
EOS
|
27
|
+
update params
|
28
|
+
update_at_xpath params if params[:update_at_xpath]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|