jmeter-ruby 3.0.0

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.
Files changed (266) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +22 -0
  3. data/.github/workflows/ci.yml +54 -0
  4. data/.gitignore +24 -0
  5. data/.rspec +1 -0
  6. data/.ruby-version +1 -0
  7. data/CHANGES.md +77 -0
  8. data/Gemfile +23 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +434 -0
  11. data/Rakefile +18 -0
  12. data/examples/OS_process_sampler.rb +24 -0
  13. data/examples/assertion_results.rb +18 -0
  14. data/examples/basic_auth.rb +11 -0
  15. data/examples/browser_headers.rb +7 -0
  16. data/examples/composite_graph.rb +29 -0
  17. data/examples/constant_throughput_timer.rb +11 -0
  18. data/examples/csv_data_set.rb +11 -0
  19. data/examples/dummy_sampler.rb +9 -0
  20. data/examples/duration_assertion.rb +10 -0
  21. data/examples/etsy_login_browse.rb +61 -0
  22. data/examples/extract.rb +12 -0
  23. data/examples/foreach_controller.rb +29 -0
  24. data/examples/header_manager.rb +29 -0
  25. data/examples/http_cache_manager.rb +11 -0
  26. data/examples/http_cookie_manager.rb +11 -0
  27. data/examples/http_request_defaults.rb +11 -0
  28. data/examples/http_request_post.rb +11 -0
  29. data/examples/http_request_with_files.rb +13 -0
  30. data/examples/http_request_with_query_params.rb +8 -0
  31. data/examples/jmeter_plugins_graphs.rb +22 -0
  32. data/examples/json_path_assertions.rb +11 -0
  33. data/examples/json_path_extractor.rb +10 -0
  34. data/examples/json_path_postprocessor.rb +10 -0
  35. data/examples/jsr223_assertion.rb +13 -0
  36. data/examples/ldap_sampler.rb +16 -0
  37. data/examples/loadosophia.rb +18 -0
  38. data/examples/loop_controller.rb +10 -0
  39. data/examples/loops_with_counter.rb +15 -0
  40. data/examples/once_only_controller.rb +15 -0
  41. data/examples/perfmon.rb +46 -0
  42. data/examples/real_custom_methods.rb +19 -0
  43. data/examples/real_page_objects.rb +41 -0
  44. data/examples/real_redis_data_set_with_setup.rb +123 -0
  45. data/examples/real_user_objects_github.rb +112 -0
  46. data/examples/regular_expression_extractor.rb +12 -0
  47. data/examples/response_assertion.rb +15 -0
  48. data/examples/response_time_percentiles_graph.rb +11 -0
  49. data/examples/rsync.rb +16 -0
  50. data/examples/sample_transaction.rb +18 -0
  51. data/examples/simple_data_writer_listener.rb +11 -0
  52. data/examples/stepping_thread_group.rb +30 -0
  53. data/examples/test_fragment.rb +14 -0
  54. data/examples/think_time.rb +15 -0
  55. data/examples/thread_groups.rb +7 -0
  56. data/examples/throughput_controller.rb +14 -0
  57. data/examples/throughput_shaping_timer.rb +20 -0
  58. data/examples/ultimate_thread_group.rb +39 -0
  59. data/examples/unicode.rb +8 -0
  60. data/examples/user_defined_variables.rb +10 -0
  61. data/examples/user_parameters.rb +28 -0
  62. data/examples/uuid_per_iteration.rb +15 -0
  63. data/jmeter-ruby.gemspec +28 -0
  64. data/lib/jmeter-ruby/DSL.md +235 -0
  65. data/lib/jmeter-ruby/dsl/access_log_sampler.rb +32 -0
  66. data/lib/jmeter-ruby/dsl/aggregate_graph.rb +55 -0
  67. data/lib/jmeter-ruby/dsl/aggregate_report.rb +55 -0
  68. data/lib/jmeter-ruby/dsl/ajp13_sampler.rb +41 -0
  69. data/lib/jmeter-ruby/dsl/assertion_results.rb +55 -0
  70. data/lib/jmeter-ruby/dsl/beanshell_assertion.rb +28 -0
  71. data/lib/jmeter-ruby/dsl/beanshell_listener.rb +28 -0
  72. data/lib/jmeter-ruby/dsl/beanshell_postprocessor.rb +28 -0
  73. data/lib/jmeter-ruby/dsl/beanshell_preprocessor.rb +28 -0
  74. data/lib/jmeter-ruby/dsl/beanshell_sampler.rb +28 -0
  75. data/lib/jmeter-ruby/dsl/beanshell_timer.rb +28 -0
  76. data/lib/jmeter-ruby/dsl/bsf_assertion.rb +28 -0
  77. data/lib/jmeter-ruby/dsl/bsf_listener.rb +28 -0
  78. data/lib/jmeter-ruby/dsl/bsf_postprocessor.rb +28 -0
  79. data/lib/jmeter-ruby/dsl/bsf_preprocessor.rb +28 -0
  80. data/lib/jmeter-ruby/dsl/bsf_sampler.rb +28 -0
  81. data/lib/jmeter-ruby/dsl/bsf_timer.rb +28 -0
  82. data/lib/jmeter-ruby/dsl/compare_assertion.rb +27 -0
  83. data/lib/jmeter-ruby/dsl/comparison_assertion_visualizer.rb +55 -0
  84. data/lib/jmeter-ruby/dsl/constant_throughput_timer.rb +26 -0
  85. data/lib/jmeter-ruby/dsl/constant_timer.rb +25 -0
  86. data/lib/jmeter-ruby/dsl/counter.rb +31 -0
  87. data/lib/jmeter-ruby/dsl/cssjquery_extractor.rb +31 -0
  88. data/lib/jmeter-ruby/dsl/csv_data_set_config.rb +33 -0
  89. data/lib/jmeter-ruby/dsl/debug_postprocessor.rb +28 -0
  90. data/lib/jmeter-ruby/dsl/debug_sampler.rb +27 -0
  91. data/lib/jmeter-ruby/dsl/distribution_graphalpha.rb +55 -0
  92. data/lib/jmeter-ruby/dsl/duration_assertion.rb +25 -0
  93. data/lib/jmeter-ruby/dsl/foreach_controller.rb +27 -0
  94. data/lib/jmeter-ruby/dsl/ftp_request.rb +34 -0
  95. data/lib/jmeter-ruby/dsl/ftp_request_defaults.rb +32 -0
  96. data/lib/jmeter-ruby/dsl/gaussian_random_timer.rb +26 -0
  97. data/lib/jmeter-ruby/dsl/generate_summary_results.rb +23 -0
  98. data/lib/jmeter-ruby/dsl/graph_results.rb +55 -0
  99. data/lib/jmeter-ruby/dsl/html_assertion.rb +30 -0
  100. data/lib/jmeter-ruby/dsl/html_link_parser.rb +23 -0
  101. data/lib/jmeter-ruby/dsl/html_parameter_mask.rb +32 -0
  102. data/lib/jmeter-ruby/dsl/http_authorization_manager.rb +33 -0
  103. data/lib/jmeter-ruby/dsl/http_cache_manager.rb +26 -0
  104. data/lib/jmeter-ruby/dsl/http_cookie_manager.rb +28 -0
  105. data/lib/jmeter-ruby/dsl/http_header_manager.rb +30 -0
  106. data/lib/jmeter-ruby/dsl/http_request.rb +41 -0
  107. data/lib/jmeter-ruby/dsl/http_request_defaults.rb +41 -0
  108. data/lib/jmeter-ruby/dsl/http_url_rewriting_modifier.rb +30 -0
  109. data/lib/jmeter-ruby/dsl/if_controller.rb +27 -0
  110. data/lib/jmeter-ruby/dsl/include_controller.rb +25 -0
  111. data/lib/jmeter-ruby/dsl/java_request.rb +69 -0
  112. data/lib/jmeter-ruby/dsl/java_request_defaults.rb +69 -0
  113. data/lib/jmeter-ruby/dsl/jdbc_connection_configuration.rb +37 -0
  114. data/lib/jmeter-ruby/dsl/jdbc_postprocessor.rb +33 -0
  115. data/lib/jmeter-ruby/dsl/jdbc_preprocessor.rb +33 -0
  116. data/lib/jmeter-ruby/dsl/jdbc_request.rb +33 -0
  117. data/lib/jmeter-ruby/dsl/jms_pointtopoint.rb +41 -0
  118. data/lib/jmeter-ruby/dsl/jms_publisher.rb +43 -0
  119. data/lib/jmeter-ruby/dsl/jms_subscriber.rb +35 -0
  120. data/lib/jmeter-ruby/dsl/json_path_postprocessor.rb +27 -0
  121. data/lib/jmeter-ruby/dsl/jsr223_assertion.rb +29 -0
  122. data/lib/jmeter-ruby/dsl/jsr223_listener.rb +29 -0
  123. data/lib/jmeter-ruby/dsl/jsr223_postprocessor.rb +29 -0
  124. data/lib/jmeter-ruby/dsl/jsr223_preprocessor.rb +29 -0
  125. data/lib/jmeter-ruby/dsl/jsr223_sampler.rb +29 -0
  126. data/lib/jmeter-ruby/dsl/jsr223_timer.rb +29 -0
  127. data/lib/jmeter-ruby/dsl/junit_request.rb +37 -0
  128. data/lib/jmeter-ruby/dsl/keystore_configuration.rb +28 -0
  129. data/lib/jmeter-ruby/dsl/ldap_extended_request.rb +42 -0
  130. data/lib/jmeter-ruby/dsl/ldap_extended_request_defaults.rb +42 -0
  131. data/lib/jmeter-ruby/dsl/ldap_request.rb +35 -0
  132. data/lib/jmeter-ruby/dsl/ldap_request_defaults.rb +39 -0
  133. data/lib/jmeter-ruby/dsl/login_config_element.rb +26 -0
  134. data/lib/jmeter-ruby/dsl/loop_controller.rb +26 -0
  135. data/lib/jmeter-ruby/dsl/mail_reader_sampler.rb +37 -0
  136. data/lib/jmeter-ruby/dsl/mailer_visualizer.rb +64 -0
  137. data/lib/jmeter-ruby/dsl/md5hex_assertion.rb +25 -0
  138. data/lib/jmeter-ruby/dsl/module_controller.rb +25 -0
  139. data/lib/jmeter-ruby/dsl/monitor_results.rb +55 -0
  140. data/lib/jmeter-ruby/dsl/once_only_controller.rb +23 -0
  141. data/lib/jmeter-ruby/dsl/os_process_sampler.rb +34 -0
  142. data/lib/jmeter-ruby/dsl/poisson_random_timer.rb +26 -0
  143. data/lib/jmeter-ruby/dsl/random_controller.rb +25 -0
  144. data/lib/jmeter-ruby/dsl/random_order_controller.rb +23 -0
  145. data/lib/jmeter-ruby/dsl/random_variable.rb +30 -0
  146. data/lib/jmeter-ruby/dsl/recording_controller.rb +23 -0
  147. data/lib/jmeter-ruby/dsl/regex_user_parameters.rb +27 -0
  148. data/lib/jmeter-ruby/dsl/regular_expression_extractor.rb +32 -0
  149. data/lib/jmeter-ruby/dsl/response_assertion.rb +31 -0
  150. data/lib/jmeter-ruby/dsl/response_time_graph.rb +55 -0
  151. data/lib/jmeter-ruby/dsl/result_status_action_handler.rb +25 -0
  152. data/lib/jmeter-ruby/dsl/runtime_controller.rb +25 -0
  153. data/lib/jmeter-ruby/dsl/save_responses_to_a_file.rb +29 -0
  154. data/lib/jmeter-ruby/dsl/setup_thread_group.rb +36 -0
  155. data/lib/jmeter-ruby/dsl/simple_config_element.rb +23 -0
  156. data/lib/jmeter-ruby/dsl/simple_controller.rb +23 -0
  157. data/lib/jmeter-ruby/dsl/simple_data_writer.rb +55 -0
  158. data/lib/jmeter-ruby/dsl/smime_assertion.rb +35 -0
  159. data/lib/jmeter-ruby/dsl/smtp_sampler.rb +51 -0
  160. data/lib/jmeter-ruby/dsl/soapxmlrpc_request.rb +33 -0
  161. data/lib/jmeter-ruby/dsl/spline_visualizer.rb +55 -0
  162. data/lib/jmeter-ruby/dsl/summary_report.rb +55 -0
  163. data/lib/jmeter-ruby/dsl/switch_controller.rb +25 -0
  164. data/lib/jmeter-ruby/dsl/synchronizing_timer.rb +26 -0
  165. data/lib/jmeter-ruby/dsl/tcp_sampler.rb +33 -0
  166. data/lib/jmeter-ruby/dsl/tcp_sampler_config.rb +31 -0
  167. data/lib/jmeter-ruby/dsl/test_action.rb +27 -0
  168. data/lib/jmeter-ruby/dsl/test_fragment.rb +23 -0
  169. data/lib/jmeter-ruby/dsl/test_plan.rb +31 -0
  170. data/lib/jmeter-ruby/dsl/thread_group.rb +37 -0
  171. data/lib/jmeter-ruby/dsl/throughput_controller.rb +32 -0
  172. data/lib/jmeter-ruby/dsl/transaction_controller.rb +26 -0
  173. data/lib/jmeter-ruby/dsl/uniform_random_timer.rb +26 -0
  174. data/lib/jmeter-ruby/dsl/user_defined_variables.rb +33 -0
  175. data/lib/jmeter-ruby/dsl/user_parameters.rb +30 -0
  176. data/lib/jmeter-ruby/dsl/view_results_in_table.rb +55 -0
  177. data/lib/jmeter-ruby/dsl/view_results_tree.rb +55 -0
  178. data/lib/jmeter-ruby/dsl/while_controller.rb +25 -0
  179. data/lib/jmeter-ruby/dsl/xml_assertion.rb +23 -0
  180. data/lib/jmeter-ruby/dsl/xml_schema_assertion.rb +25 -0
  181. data/lib/jmeter-ruby/dsl/xpath_assertion.rb +31 -0
  182. data/lib/jmeter-ruby/dsl/xpath_extractor.rb +31 -0
  183. data/lib/jmeter-ruby/dsl.rb +102 -0
  184. data/lib/jmeter-ruby/extend/assertions/response_assertion.rb +36 -0
  185. data/lib/jmeter-ruby/extend/config_elements/header_manager.rb +13 -0
  186. data/lib/jmeter-ruby/extend/config_elements/http_cache_manager.rb +12 -0
  187. data/lib/jmeter-ruby/extend/config_elements/http_cookie_manager.rb +36 -0
  188. data/lib/jmeter-ruby/extend/config_elements/http_request_defaults.rb +39 -0
  189. data/lib/jmeter-ruby/extend/config_elements/user_defined_variables.rb +13 -0
  190. data/lib/jmeter-ruby/extend/config_elements/user_parameters.rb +31 -0
  191. data/lib/jmeter-ruby/extend/controllers/foreach_controller.rb +27 -0
  192. data/lib/jmeter-ruby/extend/controllers/loop_controller.rb +11 -0
  193. data/lib/jmeter-ruby/extend/controllers/module_controller.rb +23 -0
  194. data/lib/jmeter-ruby/extend/controllers/throughput_controller.rb +15 -0
  195. data/lib/jmeter-ruby/extend/controllers/transaction_controller.rb +14 -0
  196. data/lib/jmeter-ruby/extend/misc/aliases.rb +21 -0
  197. data/lib/jmeter-ruby/extend/misc/exists.rb +13 -0
  198. data/lib/jmeter-ruby/extend/misc/rsync.rb +24 -0
  199. data/lib/jmeter-ruby/extend/misc/uuid.rb +12 -0
  200. data/lib/jmeter-ruby/extend/misc/with_helpers.rb +27 -0
  201. data/lib/jmeter-ruby/extend/plugins/jmeter_plugins.rb +120 -0
  202. data/lib/jmeter-ruby/extend/processors/extract.rb +28 -0
  203. data/lib/jmeter-ruby/extend/processors/regular_expression_extractor.rb +25 -0
  204. data/lib/jmeter-ruby/extend/samplers/http_request.rb +58 -0
  205. data/lib/jmeter-ruby/extend/samplers/jms_pointtopoint.rb +26 -0
  206. data/lib/jmeter-ruby/extend/samplers/soapxmlrpc_request.rb +9 -0
  207. data/lib/jmeter-ruby/extend/threads/setup_thread_group.rb +18 -0
  208. data/lib/jmeter-ruby/extend/threads/thread_group.rb +19 -0
  209. data/lib/jmeter-ruby/extend/timers/constant_throughput_timer.rb +11 -0
  210. data/lib/jmeter-ruby/extend/timers/random_timer.rb +14 -0
  211. data/lib/jmeter-ruby/helpers/fallback_content_proxy.rb +54 -0
  212. data/lib/jmeter-ruby/helpers/helper.rb +75 -0
  213. data/lib/jmeter-ruby/helpers/logger-colors.rb +48 -0
  214. data/lib/jmeter-ruby/helpers/parser.rb +135 -0
  215. data/lib/jmeter-ruby/helpers/strip-heredoc.rb +5 -0
  216. data/lib/jmeter-ruby/helpers/user-agents.rb +27 -0
  217. data/lib/jmeter-ruby/idl.rb +70 -0
  218. data/lib/jmeter-ruby/idl.xml +1488 -0
  219. data/lib/jmeter-ruby/plugins/active_threads_over_time.rb +57 -0
  220. data/lib/jmeter-ruby/plugins/composite_graph.rb +71 -0
  221. data/lib/jmeter-ruby/plugins/console_status_logger.rb +15 -0
  222. data/lib/jmeter-ruby/plugins/dummy_sampler.rb +26 -0
  223. data/lib/jmeter-ruby/plugins/jmx_collector.rb +73 -0
  224. data/lib/jmeter-ruby/plugins/json_path_assertion.rb +19 -0
  225. data/lib/jmeter-ruby/plugins/json_path_extractor.rb +20 -0
  226. data/lib/jmeter-ruby/plugins/latencies_over_time.rb +49 -0
  227. data/lib/jmeter-ruby/plugins/loadosophia_uploader.rb +63 -0
  228. data/lib/jmeter-ruby/plugins/perfmon_collector.rb +80 -0
  229. data/lib/jmeter-ruby/plugins/redis_data_set.rb +39 -0
  230. data/lib/jmeter-ruby/plugins/response_codes_per_second.rb +49 -0
  231. data/lib/jmeter-ruby/plugins/response_times_distribution.rb +49 -0
  232. data/lib/jmeter-ruby/plugins/response_times_over_time.rb +50 -0
  233. data/lib/jmeter-ruby/plugins/response_times_percentiles.rb +51 -0
  234. data/lib/jmeter-ruby/plugins/stepping_thread_group.rb +30 -0
  235. data/lib/jmeter-ruby/plugins/transactions_per_second.rb +50 -0
  236. data/lib/jmeter-ruby/plugins/ultimate_thread_group.rb +23 -0
  237. data/lib/jmeter-ruby/plugins/variable_throughput_timer.rb +27 -0
  238. data/lib/jmeter-ruby/version.rb +12 -0
  239. data/lib/jmeter-ruby.rb +27 -0
  240. data/mise.toml +2 -0
  241. data/script/release +162 -0
  242. data/spec/constant_throughput_timer_spec.rb +20 -0
  243. data/spec/csv_data_set_config_spec.rb +33 -0
  244. data/spec/header_manager_spec.rb +37 -0
  245. data/spec/http_cache_manager_spec.rb +29 -0
  246. data/spec/http_cookie_manager_spec.rb +169 -0
  247. data/spec/http_request_defaults_spec.rb +57 -0
  248. data/spec/http_request_spec.rb +305 -0
  249. data/spec/jmeter_plugins_spec.rb +245 -0
  250. data/spec/json_extractor_spec.rb +19 -0
  251. data/spec/json_path_assertion_spec.rb +28 -0
  252. data/spec/logic_controller_spec.rb +148 -0
  253. data/spec/loop_controller_spec.rb +19 -0
  254. data/spec/module_controller_spec.rb +56 -0
  255. data/spec/regular_expression_extractor_spec.rb +63 -0
  256. data/spec/response_assertion_spec.rb +69 -0
  257. data/spec/setup_thread_group_spec.rb +31 -0
  258. data/spec/spec_helper.rb +19 -0
  259. data/spec/thread_group_spec.rb +57 -0
  260. data/spec/throughput_controller_spec.rb +24 -0
  261. data/spec/transaction_controller_spec.rb +30 -0
  262. data/spec/user_defined_variables_spec.rb +22 -0
  263. data/spec/user_parameters_spec.rb +45 -0
  264. data/spec/with_helpers_spec.rb +57 -0
  265. data/spec/xpath_extractor_spec.rb +15 -0
  266. metadata +360 -0
@@ -0,0 +1,123 @@
1
+ ################################################################################
2
+ # This is an example of how to use a Redis data set with CSV data.
3
+ # The test plan defines a setup thread group with a JSR223 sampler (scripted in
4
+ # Groovy), which pre-populates Redis with the data used for the actual test.
5
+ # The test itself simply calls a REST API with data seeded from Redis.
6
+ #
7
+ # The redis key is "test_data" and the format of the CSV data is:
8
+ # user_id,start_date,end_date
9
+ #
10
+ # Requires:
11
+ # JMeter (recommended version: 2.13 or later)
12
+ # jmeter-plugins extras with libs (this gives us the redis data set config)
13
+ # Groovy 2.4 or later (put the groovy-all jar into $JMETER_HOME/lib)
14
+ ################################################################################
15
+
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
+ require 'jmeter-ruby'
18
+
19
+ # For redis dataset config.
20
+ redis_host = 'localhost'
21
+ redis_port = 6379
22
+ redis_key = 'test_data'
23
+ num_records = 1000 # how many rows of test data to generate
24
+
25
+ # for HTTP request defaults
26
+ protocol = 'http'
27
+ host = 'localhost'
28
+ port = 8080
29
+
30
+ # JMeter test plan begins here.
31
+ test do
32
+
33
+ # Setup the data set we will use to run the tests.
34
+ setup_thread_group name: 'Redis Fill',
35
+ loops: 1 do
36
+ jsr223_sampler name: 'redis fill',
37
+ scriptLanguage: 'groovy',
38
+ cacheKey: 'prefill_user_ids',
39
+ script: <<-EOS.strip_heredoc
40
+ import redis.clients.jedis.JedisPoolConfig;
41
+ import redis.clients.jedis.JedisPool;
42
+ import redis.clients.jedis.Jedis;
43
+
44
+ import java.util.Random;
45
+ import java.util.Date;
46
+ import java.text.DateFormat;
47
+ import java.text.SimpleDateFormat;
48
+
49
+ JedisPoolConfig config = new JedisPoolConfig();
50
+ JedisPool pool = new JedisPool(config, "#{redis_host}", #{redis_port});
51
+ Jedis jedis = null;
52
+ try {
53
+ jedis = pool.getResource();
54
+
55
+ //delete old data, if it exists
56
+ jedis.del("#{redis_key}");
57
+
58
+ // Create a list of the last 90 days. We will seed our test data from this.
59
+ Date now = new Date();
60
+ Date oldest = now - 90;
61
+ Range days = oldest..now;
62
+
63
+ Random random = new Random();
64
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
65
+
66
+ /*
67
+ * Generate CSV data in the form of:
68
+ * user_id,start_date,end_date
69
+ */
70
+ for (int i = 1; i <= #{num_records}; i++) {
71
+ Date day = days[random.nextInt(days.size())]
72
+ String data = [i, df.format(day), df.format(day)].join(',')
73
+ jedis.sadd("#{redis_key}", data);
74
+ }
75
+ }finally {
76
+ if(jedis != null) {
77
+ pool.returnResource(jedis);
78
+ }
79
+ }
80
+ EOS
81
+ end
82
+
83
+ # Defines a thread group. We allow certain parameters to be passed in
84
+ # as system properties.
85
+ threads name: 'Test Scenario - REST API query',
86
+ count: '${__P(threads,1)}',
87
+ rampup: '${__P(rampup,600)}',
88
+ duration: '${__P(duration, 600)}' do
89
+
90
+ # HTTP request defaults
91
+ defaults domain: host, # default domain if not specified in URL
92
+ protocol: protocol, # default protocol if not specified in URL
93
+ port: port,
94
+ download_resources: false # download images/CSS/JS (no)
95
+
96
+ cookies # om nom nom
97
+
98
+ cache clear_each_iteration: true # each thread iteration mimics a new user with an empty browser cache
99
+
100
+ with_gzip # add HTTP request headers to allow GZIP compression. Most sites support this nowadays.
101
+
102
+ # Test data. Note how the variableNames match the variables used by the
103
+ # sampler below.
104
+ redis_data_set 'test data',
105
+ redisKey: redis_key,
106
+ host: redis_host,
107
+ port: redis_port,
108
+ variableNames: 'user_id,start_date,end_date'
109
+
110
+ # User workflow begins here.
111
+ visit name: 'REST API query',
112
+ url: '/rest/query',
113
+ always_encode: true,
114
+ fill_in: {
115
+ 'user_id' => '${user_id}',
116
+ 'start' => '${start_date}',
117
+ 'end' => '${end_date}'
118
+ }
119
+ end
120
+
121
+ response_time_graph
122
+ view_results_tree
123
+ end.jmx(file: 'real_redis_data_set_with_setup.jmx')
@@ -0,0 +1,112 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ # Virtual user definitions
5
+ class VirtualUser
6
+
7
+ # initializes the VirtualUser object and adds some default test
8
+ # components.
9
+ # @param dsl the dsl
10
+ def initialize(dsl)
11
+ @dsl = dsl
12
+
13
+ defaults domain: 'github.com', # default domain if not specified in URL
14
+ protocol: 'http', # default protocol if not specified in URL
15
+ download_resources: true, # download images/CSS/JS
16
+ use_concurrent_pool: 6, # mimic Chrome/IE parallelism for images/CSS/JS
17
+ urls_must_match: '(https?.\/\/)?([^\.]*\.)*(github\.com)?\/.*' # only download resources for the target domain
18
+
19
+ cookies # om nom nom
20
+
21
+ cache clear_each_iteration: true # each thread iteration mimics a new user with an empty browser cache
22
+
23
+ with_user_agent 'ie9' # send IE9 browser headers
24
+
25
+ with_gzip # add HTTP request headers to allow GZIP compression. Most sites support this nowadays.
26
+
27
+ end
28
+
29
+ # Adds a user think time. Note that this is slightly different than the
30
+ # default JMeter think time, in that it executes sequentially with test steps.
31
+ # @param delay [int] the target pause time, in milliseconds
32
+ # @param deviation [int] the pause deviation, in milliseconds
33
+ def pause(delay=30000, deviation=5000)
34
+ test_action name: 'Think Time', action: 1, target: 0, duration: 0 do
35
+ think_time delay, deviation
36
+ end
37
+ end
38
+
39
+ # Requests the home page.
40
+ def home_page
41
+ visit name: 'Home page', url: '/'
42
+ pause
43
+ end
44
+
45
+ # Searches for a repository.
46
+ # @param repo [String] the repository to search for
47
+ def search_for_repository(repo)
48
+ visit name: 'Search for project', url: '/search',
49
+ always_encode: true,
50
+ fill_in: {
51
+ 'q' => repo,
52
+ 'ref' => 'cmdform'
53
+ }
54
+ pause
55
+ end
56
+
57
+ # Visits a repository page.
58
+ # @param repo_path [String] the repository URL path
59
+ def view_repository(repo_path)
60
+ visit name: 'Repository page', url: repo_path
61
+ pause
62
+ end
63
+
64
+ # Views a branch/tag page.
65
+ # @param branch_path [String] the branch URL path
66
+ def view_branch(branch_path)
67
+ visit name: 'Branch page', url: branch_path
68
+ pause
69
+ end
70
+
71
+ ####################################################################
72
+ private
73
+
74
+ # Passes method calls through to the underlying DSL.
75
+ # @param method the method
76
+ # @param args the arguments
77
+ # @param block the block
78
+ def method_missing method, *args, &block
79
+ @dsl.__send__ method, *args, &block
80
+ end
81
+ ####################################################################
82
+ end
83
+
84
+ # JMeter test plan begins here.
85
+ test do
86
+
87
+ # Defines a thread group. We allow certain parameters to be passed in
88
+ # as system properties.
89
+ threads count: '${__P(threads,1)}',
90
+ rampup: '${__P(rampup,600)}',
91
+ name: 'Test Scenario - GitHub project navigation',
92
+ duration: '${__P(duration, 600)}' do
93
+
94
+ user = VirtualUser.new(self) # This will add a bunch of test components.
95
+
96
+ # In the event of an error, the thread will start a new loop. If this
97
+ # happens on the first request, we could start flooding the site with
98
+ # requests.
99
+ # To prevent this from happening, we insert a quick pause before the
100
+ # first request.
101
+ user.pause 1000,0
102
+
103
+ # User workflow begins here.
104
+ # Note that think times are defined inside the page methods.
105
+ user.home_page
106
+ user.search_for_repository 'jmeter-ruby'
107
+ user.view_repository '/flood-io/jmeter-ruby'
108
+ user.view_branch '/flood-io/jmeter-ruby/tree/v2.11.8'
109
+
110
+ end
111
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
112
+
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 1 do
6
+ visit name: 'Home', url: 'https://flooded.io' do
7
+ regex pattern: "content='(.+?)' name='csrf-token'", name: 'csrf-token', match_number: 1, default: '424242'
8
+ regex pattern: 'pattern', name: 'jmeter_variable_regex', variable: 'test'
9
+ regex pattern: 'pattern', name: 'jmeter_headers_regex', useHeaders: true
10
+ end
11
+ end
12
+ end.run(path: '/usr/local/share/jmeter-3.1/bin/', gui: true)
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 2 do
6
+ transaction name: 'Assertions' do
7
+ visit name: 'Altentee', url: 'http://altentee.com/' do
8
+ assert contains: 'We test, tune and secure your site'
9
+ assert 'not-contains' => 'Something in frames', scope: 'children'
10
+ assert 'substring' => 'Something in frames', variable: 'test'
11
+ assert pattern: 'pattern', test_field: 'Assertion.response_headers'
12
+ end
13
+ end
14
+ end
15
+ end.run(path: '/usr/local/share/jmeter-3.1/bin/', gui: true)
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 100 do
6
+ response_times_percentiles 'Response Times Percentiles', filename: '/path/to/output', update_at_xpath: [
7
+ { '//value/xml' => 'false' }
8
+ ]
9
+
10
+ end
11
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
data/examples/rsync.rb ADDED
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 10 do
6
+ visit name: 'Home Page', url: 'https://flooded.io'
7
+ end
8
+ end.rsync(
9
+ remote_host: 'xxx.xxx.xxx.xxx',
10
+ remote_user: 'user',
11
+ remote_path: '/path/to/remote',
12
+ rsync_bin_path: '/usr/bin/rsync',
13
+ rsync_params: '-az -e "ssh -i /path/to/key.pem"',
14
+ file: './jmx/' + File.basename(__FILE__, ".rb") + '.jmx',
15
+ debug: true
16
+ )
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 1 do
6
+ # this will let you sample 1 in every N (e.g. 100) transactions on Flood IO
7
+ get name: 'Home Page', sample: 100, url: 'http://google.com/'
8
+
9
+ post name: 'create session', url: '/api/oauth', sample: 100,
10
+ fill_in: {
11
+ username: 'Michel Rosen',
12
+ password: 4141414141
13
+ } do
14
+ extract json: '.access_token', name: 'access_token'
15
+ with_xhr
16
+ end
17
+ end
18
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 1 do
6
+ visit name: 'Home Page', url: 'https://flooded.io/'
7
+
8
+ # write errors to a simple data writer with the log alias
9
+ log filename: '/var/log/flood/custom.log', error_logging: true
10
+ end
11
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+
6
+ defaults domain: 'example.com'
7
+
8
+ with_user_agent :chrome
9
+
10
+ header [
11
+ { name: 'Accept-Encoding', value: 'gzip,deflate,sdch' },
12
+ { name: 'Accept', value: 'text/javascript, text/html, application/xml, text/xml, */*' }
13
+ ]
14
+
15
+ step name: 'stepping thread group example',
16
+ total_threads: 200,
17
+ initial_delay: 0,
18
+ start_threads: 20,
19
+ add_threads: 0,
20
+ start_every: 30,
21
+ stop_threads: 50,
22
+ stop_every: 5,
23
+ flight_time: 1800,
24
+ rampup: 5 do
25
+
26
+ random_timer 1000, 3000
27
+
28
+ get name: 'home', url: '/'
29
+ end
30
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+
6
+ test_fragment name: 'anonymous_user', enabled: false do
7
+ get name: 'Home Page', url: 'http://google.com'
8
+ end
9
+
10
+ threads count: 1 do
11
+ module_controller test_fragment: 'WorkBench/TestPlan/anonymous_user'
12
+ end
13
+
14
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 100 do
6
+
7
+ think_time 5000, 5000
8
+
9
+ transaction name: 'Google Search' do
10
+ visit name: 'Home Page', url: 'https://flooded.io/'
11
+ random_timer 3000
12
+ end
13
+
14
+ end
15
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 100, rampup: 3600, loops: 10, scheduler: false do
6
+ end
7
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 100 do
6
+
7
+ think_time 5000,5000
8
+
9
+ throughput_controller percent: 99 do
10
+ transaction name: "TC_01", parent: true, include_timers: true
11
+ end
12
+
13
+ end
14
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 100 do # threads = RPS * <max response time ms> / 1000
6
+
7
+ throughput_shaper name: 'increasing load test', steps: [
8
+ { :start_rps => 100, :end_rps => 100, :duration => 60 },
9
+ { :start_rps => 200, :end_rps => 200, :duration => 60 },
10
+ { :start_rps => 300, :end_rps => 300, :duration => 60 },
11
+ { :start_rps => 400, :end_rps => 400, :duration => 60 },
12
+ { :start_rps => 500, :end_rps => 500, :duration => 60 },
13
+ { :start_rps => 600, :end_rps => 600, :duration => 60 }
14
+ ]
15
+
16
+ transaction name: 'Google Search' do
17
+ visit name: 'Home Page', url: 'https://flooded.io/'
18
+ end
19
+ end
20
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+
6
+ defaults domain: 'example.com'
7
+
8
+ with_user_agent :chrome
9
+
10
+ header [
11
+ { name: 'Accept-Encoding', value: 'gzip,deflate,sdch' },
12
+ { name: 'Accept', value: 'text/javascript, text/html, application/xml, text/xml, */*' }
13
+ ]
14
+
15
+ ultimate name: 'ultimate thread group example',
16
+ on_sample_error: 'startnextloop',
17
+ threads: [
18
+ {
19
+ start_threads: 200,
20
+ initial_delay: 0,
21
+ start_time: 30,
22
+ hold_time: 60,
23
+ stop_time: 5
24
+ },
25
+ {
26
+ start_threads: 200,
27
+ initial_delay: 60,
28
+ start_time: 30,
29
+ hold_time: 60,
30
+ stop_time: 5
31
+ }
32
+ ] do
33
+
34
+ random_timer 1000, 3000
35
+
36
+ get name: 'home', url: '/'
37
+
38
+ end
39
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 1 do
6
+ visit 'https://flood.io/?unicode=åß∂˙∆¬¬'
7
+ end
8
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ # user defined with multiple values
6
+ variables [
7
+ { name: 'email', value: 'support@flood.io' },
8
+ { name: 'password', value: 'password' }
9
+ ]
10
+ end.run(path: '/usr/share/jmeter/bin/', gui: true)
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ # user parameters with multiple values
6
+ post name: 'oauth', url: 'https://flooded.io/api/oauth', raw_body: '${token}' do
7
+ user_parameters names: ['token'],
8
+ thread_values: {
9
+ user_1: [
10
+ '<xml>fidget widget</xml>'
11
+ ]
12
+ }
13
+
14
+ user_parameters names: ['name1', 'name2'],
15
+ thread_values: {
16
+ user_1: [
17
+ 'user1_value1',
18
+ 'user1_value2'
19
+ ],
20
+
21
+ user_2: [
22
+ 'user2_value1',
23
+ 'user2_value2'
24
+ ]
25
+ },
26
+ per_iteration: true
27
+ end
28
+ end.run(path: '/usr/local/share/jmeter-3.1/bin/', gui: true)
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'jmeter-ruby'
3
+
4
+ test do
5
+ threads count: 1, loops: 5, scheduler: false do
6
+ # Helper method to generate a single UUID per iteration
7
+ uuid_per_iteration
8
+
9
+ dummy_sampler name: '${__threadNum} - ${UUID}'
10
+ dummy_sampler name: '${__threadNum} - ${UUID}'
11
+ dummy_sampler name: '${__threadNum} - ${UUID}'
12
+
13
+ view_results
14
+ end
15
+ end.run(path: '/usr/local/share/jmeter-3.1/bin', gui: true)
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jmeter-ruby/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'jmeter-ruby'
8
+ gem.version = JmeterRuby::VERSION::STRING
9
+ gem.authors = ['Reegan Viljoen']
10
+ gem.email = ['reeganviljoen@outlook.com']
11
+ gem.description = %q{Ruby based DSL for writing JMeter test plans}
12
+ gem.summary = %q{Ruby based DSL for writing JMeter test plans}
13
+ gem.homepage = 'https://github.com/reeganviljoen/jmeter-ruby/issues'
14
+ gem.required_ruby_version = ">= 3.1.0"
15
+
16
+ gem.add_dependency 'rest-client'
17
+ gem.add_dependency 'nokogiri'
18
+ gem.add_runtime_dependency('json-jruby') if RUBY_PLATFORM == 'java'
19
+
20
+ gem.add_development_dependency "simplecov", "~> 0.22.0"
21
+ gem.add_development_dependency "simplecov-console", "~> 0.9.1"
22
+
23
+ gem.files = `git ls-files`.split($/)
24
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
25
+ gem.require_paths = ['lib']
26
+
27
+ gem.license = 'MIT'
28
+ end