fluentd222 1.16.2-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (562) hide show
  1. checksums.yaml +7 -0
  2. data/.deepsource.toml +13 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.yaml +71 -0
  4. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.yaml +39 -0
  6. data/.github/ISSUE_TEMPLATE.md +17 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
  8. data/.github/workflows/stale-actions.yml +24 -0
  9. data/.github/workflows/test-ruby-head.yaml +31 -0
  10. data/.github/workflows/test.yaml +32 -0
  11. data/.gitignore +30 -0
  12. data/ADOPTERS.md +5 -0
  13. data/AUTHORS +2 -0
  14. data/CHANGELOG.md +2720 -0
  15. data/CONTRIBUTING.md +45 -0
  16. data/GOVERNANCE.md +55 -0
  17. data/Gemfile +9 -0
  18. data/GithubWorkflow.md +78 -0
  19. data/LICENSE +202 -0
  20. data/MAINTAINERS.md +13 -0
  21. data/README.md +75 -0
  22. data/Rakefile +79 -0
  23. data/SECURITY.md +14 -0
  24. data/bin/fluent-binlog-reader +7 -0
  25. data/bin/fluent-ca-generate +6 -0
  26. data/bin/fluent-cap-ctl +7 -0
  27. data/bin/fluent-cat +5 -0
  28. data/bin/fluent-ctl +7 -0
  29. data/bin/fluent-debug +5 -0
  30. data/bin/fluent-gem +9 -0
  31. data/bin/fluent-plugin-config-format +5 -0
  32. data/bin/fluent-plugin-generate +5 -0
  33. data/bin/fluentd +15 -0
  34. data/code-of-conduct.md +3 -0
  35. data/docs/SECURITY_AUDIT.pdf +0 -0
  36. data/example/copy_roundrobin.conf +39 -0
  37. data/example/counter.conf +18 -0
  38. data/example/filter_stdout.conf +22 -0
  39. data/example/in_forward.conf +14 -0
  40. data/example/in_forward_client.conf +37 -0
  41. data/example/in_forward_shared_key.conf +15 -0
  42. data/example/in_forward_tls.conf +14 -0
  43. data/example/in_forward_users.conf +24 -0
  44. data/example/in_forward_workers.conf +21 -0
  45. data/example/in_http.conf +16 -0
  46. data/example/in_out_forward.conf +17 -0
  47. data/example/in_sample_blocks.conf +17 -0
  48. data/example/in_sample_with_compression.conf +23 -0
  49. data/example/in_syslog.conf +15 -0
  50. data/example/in_tail.conf +14 -0
  51. data/example/in_tcp.conf +13 -0
  52. data/example/in_udp.conf +13 -0
  53. data/example/logevents.conf +25 -0
  54. data/example/multi_filters.conf +61 -0
  55. data/example/out_copy.conf +20 -0
  56. data/example/out_exec_filter.conf +42 -0
  57. data/example/out_file.conf +13 -0
  58. data/example/out_forward.conf +35 -0
  59. data/example/out_forward_buf_file.conf +23 -0
  60. data/example/out_forward_client.conf +109 -0
  61. data/example/out_forward_heartbeat_none.conf +16 -0
  62. data/example/out_forward_sd.conf +17 -0
  63. data/example/out_forward_shared_key.conf +36 -0
  64. data/example/out_forward_tls.conf +18 -0
  65. data/example/out_forward_users.conf +65 -0
  66. data/example/out_null.conf +36 -0
  67. data/example/sd.yaml +8 -0
  68. data/example/secondary_file.conf +42 -0
  69. data/example/suppress_config_dump.conf +7 -0
  70. data/example/v0_12_filter.conf +78 -0
  71. data/example/v1_literal_example.conf +36 -0
  72. data/example/worker_section.conf +36 -0
  73. data/fluent.conf +139 -0
  74. data/fluentd.gemspec +54 -0
  75. data/lib/fluent/agent.rb +168 -0
  76. data/lib/fluent/capability.rb +87 -0
  77. data/lib/fluent/clock.rb +66 -0
  78. data/lib/fluent/command/binlog_reader.rb +244 -0
  79. data/lib/fluent/command/bundler_injection.rb +45 -0
  80. data/lib/fluent/command/ca_generate.rb +184 -0
  81. data/lib/fluent/command/cap_ctl.rb +174 -0
  82. data/lib/fluent/command/cat.rb +365 -0
  83. data/lib/fluent/command/ctl.rb +180 -0
  84. data/lib/fluent/command/debug.rb +103 -0
  85. data/lib/fluent/command/fluentd.rb +374 -0
  86. data/lib/fluent/command/plugin_config_formatter.rb +308 -0
  87. data/lib/fluent/command/plugin_generator.rb +365 -0
  88. data/lib/fluent/compat/call_super_mixin.rb +76 -0
  89. data/lib/fluent/compat/detach_process_mixin.rb +33 -0
  90. data/lib/fluent/compat/exec_util.rb +129 -0
  91. data/lib/fluent/compat/file_util.rb +54 -0
  92. data/lib/fluent/compat/filter.rb +68 -0
  93. data/lib/fluent/compat/formatter.rb +111 -0
  94. data/lib/fluent/compat/formatter_utils.rb +85 -0
  95. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  96. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  97. data/lib/fluent/compat/input.rb +49 -0
  98. data/lib/fluent/compat/output.rb +721 -0
  99. data/lib/fluent/compat/output_chain.rb +60 -0
  100. data/lib/fluent/compat/parser.rb +310 -0
  101. data/lib/fluent/compat/parser_utils.rb +40 -0
  102. data/lib/fluent/compat/propagate_default.rb +62 -0
  103. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  104. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  105. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  106. data/lib/fluent/compat/socket_util.rb +165 -0
  107. data/lib/fluent/compat/string_util.rb +34 -0
  108. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  109. data/lib/fluent/compat/type_converter.rb +90 -0
  110. data/lib/fluent/config/basic_parser.rb +123 -0
  111. data/lib/fluent/config/configure_proxy.rb +424 -0
  112. data/lib/fluent/config/dsl.rb +152 -0
  113. data/lib/fluent/config/element.rb +265 -0
  114. data/lib/fluent/config/error.rb +44 -0
  115. data/lib/fluent/config/literal_parser.rb +286 -0
  116. data/lib/fluent/config/parser.rb +107 -0
  117. data/lib/fluent/config/section.rb +272 -0
  118. data/lib/fluent/config/types.rb +249 -0
  119. data/lib/fluent/config/v1_parser.rb +192 -0
  120. data/lib/fluent/config/yaml_parser/fluent_value.rb +47 -0
  121. data/lib/fluent/config/yaml_parser/loader.rb +108 -0
  122. data/lib/fluent/config/yaml_parser/parser.rb +166 -0
  123. data/lib/fluent/config/yaml_parser/section_builder.rb +107 -0
  124. data/lib/fluent/config/yaml_parser.rb +56 -0
  125. data/lib/fluent/config.rb +89 -0
  126. data/lib/fluent/configurable.rb +201 -0
  127. data/lib/fluent/counter/base_socket.rb +44 -0
  128. data/lib/fluent/counter/client.rb +297 -0
  129. data/lib/fluent/counter/error.rb +86 -0
  130. data/lib/fluent/counter/mutex_hash.rb +163 -0
  131. data/lib/fluent/counter/server.rb +273 -0
  132. data/lib/fluent/counter/store.rb +205 -0
  133. data/lib/fluent/counter/validator.rb +145 -0
  134. data/lib/fluent/counter.rb +23 -0
  135. data/lib/fluent/daemon.rb +13 -0
  136. data/lib/fluent/daemonizer.rb +88 -0
  137. data/lib/fluent/engine.rb +253 -0
  138. data/lib/fluent/env.rb +40 -0
  139. data/lib/fluent/error.rb +37 -0
  140. data/lib/fluent/event.rb +330 -0
  141. data/lib/fluent/event_router.rb +315 -0
  142. data/lib/fluent/ext_monitor_require.rb +28 -0
  143. data/lib/fluent/file_wrapper.rb +137 -0
  144. data/lib/fluent/filter.rb +21 -0
  145. data/lib/fluent/fluent_log_event_router.rb +139 -0
  146. data/lib/fluent/formatter.rb +23 -0
  147. data/lib/fluent/input.rb +21 -0
  148. data/lib/fluent/label.rb +46 -0
  149. data/lib/fluent/load.rb +34 -0
  150. data/lib/fluent/log/console_adapter.rb +66 -0
  151. data/lib/fluent/log.rb +752 -0
  152. data/lib/fluent/match.rb +187 -0
  153. data/lib/fluent/mixin.rb +31 -0
  154. data/lib/fluent/msgpack_factory.rb +111 -0
  155. data/lib/fluent/oj_options.rb +61 -0
  156. data/lib/fluent/output.rb +29 -0
  157. data/lib/fluent/output_chain.rb +23 -0
  158. data/lib/fluent/parser.rb +23 -0
  159. data/lib/fluent/plugin/bare_output.rb +104 -0
  160. data/lib/fluent/plugin/base.rb +214 -0
  161. data/lib/fluent/plugin/buf_file.rb +242 -0
  162. data/lib/fluent/plugin/buf_file_single.rb +254 -0
  163. data/lib/fluent/plugin/buf_memory.rb +34 -0
  164. data/lib/fluent/plugin/buffer/chunk.rb +240 -0
  165. data/lib/fluent/plugin/buffer/file_chunk.rb +413 -0
  166. data/lib/fluent/plugin/buffer/file_single_chunk.rb +310 -0
  167. data/lib/fluent/plugin/buffer/memory_chunk.rb +91 -0
  168. data/lib/fluent/plugin/buffer.rb +941 -0
  169. data/lib/fluent/plugin/compressable.rb +96 -0
  170. data/lib/fluent/plugin/exec_util.rb +22 -0
  171. data/lib/fluent/plugin/file_util.rb +22 -0
  172. data/lib/fluent/plugin/filter.rb +127 -0
  173. data/lib/fluent/plugin/filter_grep.rb +189 -0
  174. data/lib/fluent/plugin/filter_parser.rb +130 -0
  175. data/lib/fluent/plugin/filter_record_transformer.rb +324 -0
  176. data/lib/fluent/plugin/filter_stdout.rb +53 -0
  177. data/lib/fluent/plugin/formatter.rb +75 -0
  178. data/lib/fluent/plugin/formatter_csv.rb +78 -0
  179. data/lib/fluent/plugin/formatter_hash.rb +35 -0
  180. data/lib/fluent/plugin/formatter_json.rb +59 -0
  181. data/lib/fluent/plugin/formatter_ltsv.rb +44 -0
  182. data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
  183. data/lib/fluent/plugin/formatter_out_file.rb +53 -0
  184. data/lib/fluent/plugin/formatter_single_value.rb +36 -0
  185. data/lib/fluent/plugin/formatter_stdout.rb +76 -0
  186. data/lib/fluent/plugin/formatter_tsv.rb +40 -0
  187. data/lib/fluent/plugin/in_debug_agent.rb +71 -0
  188. data/lib/fluent/plugin/in_dummy.rb +18 -0
  189. data/lib/fluent/plugin/in_exec.rb +110 -0
  190. data/lib/fluent/plugin/in_forward.rb +473 -0
  191. data/lib/fluent/plugin/in_gc_stat.rb +72 -0
  192. data/lib/fluent/plugin/in_http.rb +677 -0
  193. data/lib/fluent/plugin/in_monitor_agent.rb +412 -0
  194. data/lib/fluent/plugin/in_object_space.rb +93 -0
  195. data/lib/fluent/plugin/in_sample.rb +141 -0
  196. data/lib/fluent/plugin/in_syslog.rb +276 -0
  197. data/lib/fluent/plugin/in_tail/group_watch.rb +204 -0
  198. data/lib/fluent/plugin/in_tail/position_file.rb +269 -0
  199. data/lib/fluent/plugin/in_tail.rb +1299 -0
  200. data/lib/fluent/plugin/in_tcp.rb +226 -0
  201. data/lib/fluent/plugin/in_udp.rb +92 -0
  202. data/lib/fluent/plugin/in_unix.rb +195 -0
  203. data/lib/fluent/plugin/input.rb +75 -0
  204. data/lib/fluent/plugin/metrics.rb +119 -0
  205. data/lib/fluent/plugin/metrics_local.rb +96 -0
  206. data/lib/fluent/plugin/multi_output.rb +195 -0
  207. data/lib/fluent/plugin/out_copy.rb +120 -0
  208. data/lib/fluent/plugin/out_exec.rb +105 -0
  209. data/lib/fluent/plugin/out_exec_filter.rb +319 -0
  210. data/lib/fluent/plugin/out_file.rb +340 -0
  211. data/lib/fluent/plugin/out_forward/ack_handler.rb +176 -0
  212. data/lib/fluent/plugin/out_forward/connection_manager.rb +113 -0
  213. data/lib/fluent/plugin/out_forward/error.rb +28 -0
  214. data/lib/fluent/plugin/out_forward/failure_detector.rb +84 -0
  215. data/lib/fluent/plugin/out_forward/handshake_protocol.rb +125 -0
  216. data/lib/fluent/plugin/out_forward/load_balancer.rb +114 -0
  217. data/lib/fluent/plugin/out_forward/socket_cache.rb +142 -0
  218. data/lib/fluent/plugin/out_forward.rb +826 -0
  219. data/lib/fluent/plugin/out_http.rb +275 -0
  220. data/lib/fluent/plugin/out_null.rb +74 -0
  221. data/lib/fluent/plugin/out_relabel.rb +32 -0
  222. data/lib/fluent/plugin/out_roundrobin.rb +84 -0
  223. data/lib/fluent/plugin/out_secondary_file.rb +148 -0
  224. data/lib/fluent/plugin/out_stdout.rb +74 -0
  225. data/lib/fluent/plugin/out_stream.rb +130 -0
  226. data/lib/fluent/plugin/output.rb +1603 -0
  227. data/lib/fluent/plugin/owned_by_mixin.rb +41 -0
  228. data/lib/fluent/plugin/parser.rb +274 -0
  229. data/lib/fluent/plugin/parser_apache.rb +28 -0
  230. data/lib/fluent/plugin/parser_apache2.rb +88 -0
  231. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  232. data/lib/fluent/plugin/parser_csv.rb +114 -0
  233. data/lib/fluent/plugin/parser_json.rb +96 -0
  234. data/lib/fluent/plugin/parser_ltsv.rb +51 -0
  235. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  236. data/lib/fluent/plugin/parser_multiline.rb +152 -0
  237. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  238. data/lib/fluent/plugin/parser_none.rb +36 -0
  239. data/lib/fluent/plugin/parser_regexp.rb +68 -0
  240. data/lib/fluent/plugin/parser_syslog.rb +496 -0
  241. data/lib/fluent/plugin/parser_tsv.rb +42 -0
  242. data/lib/fluent/plugin/sd_file.rb +156 -0
  243. data/lib/fluent/plugin/sd_srv.rb +135 -0
  244. data/lib/fluent/plugin/sd_static.rb +58 -0
  245. data/lib/fluent/plugin/service_discovery.rb +65 -0
  246. data/lib/fluent/plugin/socket_util.rb +22 -0
  247. data/lib/fluent/plugin/storage.rb +84 -0
  248. data/lib/fluent/plugin/storage_local.rb +162 -0
  249. data/lib/fluent/plugin/string_util.rb +22 -0
  250. data/lib/fluent/plugin.rb +206 -0
  251. data/lib/fluent/plugin_helper/cert_option.rb +191 -0
  252. data/lib/fluent/plugin_helper/child_process.rb +369 -0
  253. data/lib/fluent/plugin_helper/compat_parameters.rb +343 -0
  254. data/lib/fluent/plugin_helper/counter.rb +51 -0
  255. data/lib/fluent/plugin_helper/event_emitter.rb +100 -0
  256. data/lib/fluent/plugin_helper/event_loop.rb +170 -0
  257. data/lib/fluent/plugin_helper/extract.rb +104 -0
  258. data/lib/fluent/plugin_helper/formatter.rb +147 -0
  259. data/lib/fluent/plugin_helper/http_server/app.rb +79 -0
  260. data/lib/fluent/plugin_helper/http_server/compat/server.rb +92 -0
  261. data/lib/fluent/plugin_helper/http_server/compat/ssl_context_extractor.rb +52 -0
  262. data/lib/fluent/plugin_helper/http_server/compat/webrick_handler.rb +58 -0
  263. data/lib/fluent/plugin_helper/http_server/methods.rb +35 -0
  264. data/lib/fluent/plugin_helper/http_server/request.rb +42 -0
  265. data/lib/fluent/plugin_helper/http_server/router.rb +54 -0
  266. data/lib/fluent/plugin_helper/http_server/server.rb +94 -0
  267. data/lib/fluent/plugin_helper/http_server/ssl_context_builder.rb +41 -0
  268. data/lib/fluent/plugin_helper/http_server.rb +135 -0
  269. data/lib/fluent/plugin_helper/inject.rb +154 -0
  270. data/lib/fluent/plugin_helper/metrics.rb +129 -0
  271. data/lib/fluent/plugin_helper/parser.rb +147 -0
  272. data/lib/fluent/plugin_helper/record_accessor.rb +207 -0
  273. data/lib/fluent/plugin_helper/retry_state.rb +219 -0
  274. data/lib/fluent/plugin_helper/server.rb +828 -0
  275. data/lib/fluent/plugin_helper/service_discovery/manager.rb +146 -0
  276. data/lib/fluent/plugin_helper/service_discovery/round_robin_balancer.rb +43 -0
  277. data/lib/fluent/plugin_helper/service_discovery.rb +125 -0
  278. data/lib/fluent/plugin_helper/socket.rb +288 -0
  279. data/lib/fluent/plugin_helper/socket_option.rb +98 -0
  280. data/lib/fluent/plugin_helper/storage.rb +349 -0
  281. data/lib/fluent/plugin_helper/thread.rb +180 -0
  282. data/lib/fluent/plugin_helper/timer.rb +92 -0
  283. data/lib/fluent/plugin_helper.rb +75 -0
  284. data/lib/fluent/plugin_id.rb +93 -0
  285. data/lib/fluent/process.rb +22 -0
  286. data/lib/fluent/registry.rb +117 -0
  287. data/lib/fluent/root_agent.rb +372 -0
  288. data/lib/fluent/rpc.rb +95 -0
  289. data/lib/fluent/static_config_analysis.rb +194 -0
  290. data/lib/fluent/supervisor.rb +1076 -0
  291. data/lib/fluent/system_config.rb +189 -0
  292. data/lib/fluent/test/base.rb +78 -0
  293. data/lib/fluent/test/driver/base.rb +231 -0
  294. data/lib/fluent/test/driver/base_owned.rb +83 -0
  295. data/lib/fluent/test/driver/base_owner.rb +135 -0
  296. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  297. data/lib/fluent/test/driver/filter.rb +61 -0
  298. data/lib/fluent/test/driver/formatter.rb +30 -0
  299. data/lib/fluent/test/driver/input.rb +31 -0
  300. data/lib/fluent/test/driver/multi_output.rb +53 -0
  301. data/lib/fluent/test/driver/output.rb +102 -0
  302. data/lib/fluent/test/driver/parser.rb +30 -0
  303. data/lib/fluent/test/driver/storage.rb +30 -0
  304. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  305. data/lib/fluent/test/filter_test.rb +77 -0
  306. data/lib/fluent/test/formatter_test.rb +65 -0
  307. data/lib/fluent/test/helpers.rb +134 -0
  308. data/lib/fluent/test/input_test.rb +174 -0
  309. data/lib/fluent/test/log.rb +79 -0
  310. data/lib/fluent/test/output_test.rb +156 -0
  311. data/lib/fluent/test/parser_test.rb +70 -0
  312. data/lib/fluent/test/startup_shutdown.rb +44 -0
  313. data/lib/fluent/test.rb +58 -0
  314. data/lib/fluent/time.rb +512 -0
  315. data/lib/fluent/timezone.rb +171 -0
  316. data/lib/fluent/tls.rb +81 -0
  317. data/lib/fluent/unique_id.rb +39 -0
  318. data/lib/fluent/variable_store.rb +40 -0
  319. data/lib/fluent/version.rb +21 -0
  320. data/lib/fluent/win32api.rb +38 -0
  321. data/lib/fluent/winsvc.rb +100 -0
  322. data/templates/new_gem/Gemfile +3 -0
  323. data/templates/new_gem/README.md.erb +43 -0
  324. data/templates/new_gem/Rakefile +13 -0
  325. data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
  326. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
  327. data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
  328. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
  329. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
  330. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
  331. data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
  332. data/templates/new_gem/test/helper.rb.erb +7 -0
  333. data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
  334. data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
  335. data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
  336. data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
  337. data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
  338. data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
  339. data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
  340. data/templates/plugin_config_formatter/param.md-table.erb +10 -0
  341. data/templates/plugin_config_formatter/param.md.erb +34 -0
  342. data/templates/plugin_config_formatter/section.md.erb +12 -0
  343. data/test/command/test_binlog_reader.rb +362 -0
  344. data/test/command/test_ca_generate.rb +70 -0
  345. data/test/command/test_cap_ctl.rb +100 -0
  346. data/test/command/test_cat.rb +128 -0
  347. data/test/command/test_ctl.rb +56 -0
  348. data/test/command/test_fluentd.rb +1291 -0
  349. data/test/command/test_plugin_config_formatter.rb +397 -0
  350. data/test/command/test_plugin_generator.rb +109 -0
  351. data/test/compat/test_calls_super.rb +166 -0
  352. data/test/compat/test_parser.rb +92 -0
  353. data/test/config/assertions.rb +42 -0
  354. data/test/config/test_config_parser.rb +551 -0
  355. data/test/config/test_configurable.rb +1784 -0
  356. data/test/config/test_configure_proxy.rb +604 -0
  357. data/test/config/test_dsl.rb +415 -0
  358. data/test/config/test_element.rb +518 -0
  359. data/test/config/test_literal_parser.rb +309 -0
  360. data/test/config/test_plugin_configuration.rb +56 -0
  361. data/test/config/test_section.rb +191 -0
  362. data/test/config/test_system_config.rb +195 -0
  363. data/test/config/test_types.rb +408 -0
  364. data/test/counter/test_client.rb +563 -0
  365. data/test/counter/test_error.rb +44 -0
  366. data/test/counter/test_mutex_hash.rb +179 -0
  367. data/test/counter/test_server.rb +589 -0
  368. data/test/counter/test_store.rb +258 -0
  369. data/test/counter/test_validator.rb +137 -0
  370. data/test/helper.rb +155 -0
  371. data/test/helpers/fuzzy_assert.rb +89 -0
  372. data/test/helpers/process_extenstion.rb +33 -0
  373. data/test/log/test_console_adapter.rb +110 -0
  374. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  375. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  376. data/test/plugin/data/2010/01/20100102.log +0 -0
  377. data/test/plugin/data/log/bar +0 -0
  378. data/test/plugin/data/log/foo/bar.log +0 -0
  379. data/test/plugin/data/log/foo/bar2 +0 -0
  380. data/test/plugin/data/log/test.log +0 -0
  381. data/test/plugin/data/sd_file/config +11 -0
  382. data/test/plugin/data/sd_file/config.json +17 -0
  383. data/test/plugin/data/sd_file/config.yaml +11 -0
  384. data/test/plugin/data/sd_file/config.yml +11 -0
  385. data/test/plugin/data/sd_file/invalid_config.yml +7 -0
  386. data/test/plugin/in_tail/test_fifo.rb +121 -0
  387. data/test/plugin/in_tail/test_io_handler.rb +150 -0
  388. data/test/plugin/in_tail/test_position_file.rb +346 -0
  389. data/test/plugin/out_forward/test_ack_handler.rb +140 -0
  390. data/test/plugin/out_forward/test_connection_manager.rb +145 -0
  391. data/test/plugin/out_forward/test_handshake_protocol.rb +112 -0
  392. data/test/plugin/out_forward/test_load_balancer.rb +106 -0
  393. data/test/plugin/out_forward/test_socket_cache.rb +174 -0
  394. data/test/plugin/test_bare_output.rb +131 -0
  395. data/test/plugin/test_base.rb +247 -0
  396. data/test/plugin/test_buf_file.rb +1314 -0
  397. data/test/plugin/test_buf_file_single.rb +898 -0
  398. data/test/plugin/test_buf_memory.rb +42 -0
  399. data/test/plugin/test_buffer.rb +1434 -0
  400. data/test/plugin/test_buffer_chunk.rb +209 -0
  401. data/test/plugin/test_buffer_file_chunk.rb +871 -0
  402. data/test/plugin/test_buffer_file_single_chunk.rb +611 -0
  403. data/test/plugin/test_buffer_memory_chunk.rb +339 -0
  404. data/test/plugin/test_compressable.rb +87 -0
  405. data/test/plugin/test_file_util.rb +96 -0
  406. data/test/plugin/test_filter.rb +368 -0
  407. data/test/plugin/test_filter_grep.rb +697 -0
  408. data/test/plugin/test_filter_parser.rb +731 -0
  409. data/test/plugin/test_filter_record_transformer.rb +577 -0
  410. data/test/plugin/test_filter_stdout.rb +207 -0
  411. data/test/plugin/test_formatter_csv.rb +136 -0
  412. data/test/plugin/test_formatter_hash.rb +38 -0
  413. data/test/plugin/test_formatter_json.rb +61 -0
  414. data/test/plugin/test_formatter_ltsv.rb +70 -0
  415. data/test/plugin/test_formatter_msgpack.rb +28 -0
  416. data/test/plugin/test_formatter_out_file.rb +116 -0
  417. data/test/plugin/test_formatter_single_value.rb +44 -0
  418. data/test/plugin/test_formatter_tsv.rb +76 -0
  419. data/test/plugin/test_in_debug_agent.rb +49 -0
  420. data/test/plugin/test_in_exec.rb +261 -0
  421. data/test/plugin/test_in_forward.rb +1178 -0
  422. data/test/plugin/test_in_gc_stat.rb +62 -0
  423. data/test/plugin/test_in_http.rb +1102 -0
  424. data/test/plugin/test_in_monitor_agent.rb +922 -0
  425. data/test/plugin/test_in_object_space.rb +66 -0
  426. data/test/plugin/test_in_sample.rb +190 -0
  427. data/test/plugin/test_in_syslog.rb +505 -0
  428. data/test/plugin/test_in_tail.rb +3125 -0
  429. data/test/plugin/test_in_tcp.rb +328 -0
  430. data/test/plugin/test_in_udp.rb +296 -0
  431. data/test/plugin/test_in_unix.rb +181 -0
  432. data/test/plugin/test_input.rb +137 -0
  433. data/test/plugin/test_metadata.rb +89 -0
  434. data/test/plugin/test_metrics.rb +294 -0
  435. data/test/plugin/test_metrics_local.rb +96 -0
  436. data/test/plugin/test_multi_output.rb +204 -0
  437. data/test/plugin/test_out_copy.rb +308 -0
  438. data/test/plugin/test_out_exec.rb +312 -0
  439. data/test/plugin/test_out_exec_filter.rb +606 -0
  440. data/test/plugin/test_out_file.rb +1038 -0
  441. data/test/plugin/test_out_forward.rb +1361 -0
  442. data/test/plugin/test_out_http.rb +429 -0
  443. data/test/plugin/test_out_null.rb +105 -0
  444. data/test/plugin/test_out_relabel.rb +28 -0
  445. data/test/plugin/test_out_roundrobin.rb +146 -0
  446. data/test/plugin/test_out_secondary_file.rb +458 -0
  447. data/test/plugin/test_out_stdout.rb +205 -0
  448. data/test/plugin/test_out_stream.rb +103 -0
  449. data/test/plugin/test_output.rb +1334 -0
  450. data/test/plugin/test_output_as_buffered.rb +2024 -0
  451. data/test/plugin/test_output_as_buffered_backup.rb +363 -0
  452. data/test/plugin/test_output_as_buffered_compress.rb +179 -0
  453. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  454. data/test/plugin/test_output_as_buffered_retries.rb +966 -0
  455. data/test/plugin/test_output_as_buffered_secondary.rb +882 -0
  456. data/test/plugin/test_output_as_standard.rb +374 -0
  457. data/test/plugin/test_owned_by.rb +34 -0
  458. data/test/plugin/test_parser.rb +399 -0
  459. data/test/plugin/test_parser_apache.rb +42 -0
  460. data/test/plugin/test_parser_apache2.rb +47 -0
  461. data/test/plugin/test_parser_apache_error.rb +45 -0
  462. data/test/plugin/test_parser_csv.rb +200 -0
  463. data/test/plugin/test_parser_json.rb +138 -0
  464. data/test/plugin/test_parser_labeled_tsv.rb +160 -0
  465. data/test/plugin/test_parser_multiline.rb +111 -0
  466. data/test/plugin/test_parser_nginx.rb +88 -0
  467. data/test/plugin/test_parser_none.rb +52 -0
  468. data/test/plugin/test_parser_regexp.rb +284 -0
  469. data/test/plugin/test_parser_syslog.rb +650 -0
  470. data/test/plugin/test_parser_tsv.rb +122 -0
  471. data/test/plugin/test_sd_file.rb +228 -0
  472. data/test/plugin/test_sd_srv.rb +230 -0
  473. data/test/plugin/test_storage.rb +166 -0
  474. data/test/plugin/test_storage_local.rb +335 -0
  475. data/test/plugin/test_string_util.rb +26 -0
  476. data/test/plugin_helper/data/cert/cert-key.pem +27 -0
  477. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +19 -0
  478. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +19 -0
  479. data/test/plugin_helper/data/cert/cert.pem +19 -0
  480. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +27 -0
  481. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +20 -0
  482. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +27 -0
  483. data/test/plugin_helper/data/cert/cert_chains/cert.pem +40 -0
  484. data/test/plugin_helper/data/cert/empty.pem +0 -0
  485. data/test/plugin_helper/data/cert/generate_cert.rb +125 -0
  486. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +30 -0
  487. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +27 -0
  488. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +20 -0
  489. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +20 -0
  490. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +30 -0
  491. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +27 -0
  492. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +21 -0
  493. data/test/plugin_helper/data/cert/with_ca/cert.pem +21 -0
  494. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +30 -0
  495. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +27 -0
  496. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +20 -0
  497. data/test/plugin_helper/data/cert/without_ca/cert.pem +20 -0
  498. data/test/plugin_helper/http_server/test_app.rb +65 -0
  499. data/test/plugin_helper/http_server/test_route.rb +32 -0
  500. data/test/plugin_helper/service_discovery/test_manager.rb +93 -0
  501. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +21 -0
  502. data/test/plugin_helper/test_cert_option.rb +25 -0
  503. data/test/plugin_helper/test_child_process.rb +862 -0
  504. data/test/plugin_helper/test_compat_parameters.rb +358 -0
  505. data/test/plugin_helper/test_event_emitter.rb +80 -0
  506. data/test/plugin_helper/test_event_loop.rb +52 -0
  507. data/test/plugin_helper/test_extract.rb +194 -0
  508. data/test/plugin_helper/test_formatter.rb +255 -0
  509. data/test/plugin_helper/test_http_server_helper.rb +372 -0
  510. data/test/plugin_helper/test_inject.rb +561 -0
  511. data/test/plugin_helper/test_metrics.rb +137 -0
  512. data/test/plugin_helper/test_parser.rb +264 -0
  513. data/test/plugin_helper/test_record_accessor.rb +238 -0
  514. data/test/plugin_helper/test_retry_state.rb +1006 -0
  515. data/test/plugin_helper/test_server.rb +1895 -0
  516. data/test/plugin_helper/test_service_discovery.rb +165 -0
  517. data/test/plugin_helper/test_socket.rb +146 -0
  518. data/test/plugin_helper/test_storage.rb +542 -0
  519. data/test/plugin_helper/test_thread.rb +164 -0
  520. data/test/plugin_helper/test_timer.rb +130 -0
  521. data/test/scripts/exec_script.rb +32 -0
  522. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
  523. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
  524. data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
  525. data/test/scripts/fluent/plugin/out_test.rb +81 -0
  526. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  527. data/test/scripts/fluent/plugin/parser_known.rb +4 -0
  528. data/test/test_capability.rb +74 -0
  529. data/test/test_clock.rb +164 -0
  530. data/test/test_config.rb +369 -0
  531. data/test/test_configdsl.rb +148 -0
  532. data/test/test_daemonizer.rb +91 -0
  533. data/test/test_engine.rb +203 -0
  534. data/test/test_event.rb +531 -0
  535. data/test/test_event_router.rb +348 -0
  536. data/test/test_event_time.rb +199 -0
  537. data/test/test_file_wrapper.rb +53 -0
  538. data/test/test_filter.rb +121 -0
  539. data/test/test_fluent_log_event_router.rb +99 -0
  540. data/test/test_formatter.rb +369 -0
  541. data/test/test_input.rb +31 -0
  542. data/test/test_log.rb +1076 -0
  543. data/test/test_match.rb +148 -0
  544. data/test/test_mixin.rb +351 -0
  545. data/test/test_msgpack_factory.rb +50 -0
  546. data/test/test_oj_options.rb +55 -0
  547. data/test/test_output.rb +278 -0
  548. data/test/test_plugin.rb +251 -0
  549. data/test/test_plugin_classes.rb +370 -0
  550. data/test/test_plugin_helper.rb +81 -0
  551. data/test/test_plugin_id.rb +119 -0
  552. data/test/test_process.rb +14 -0
  553. data/test/test_root_agent.rb +951 -0
  554. data/test/test_static_config_analysis.rb +177 -0
  555. data/test/test_supervisor.rb +821 -0
  556. data/test/test_test_drivers.rb +136 -0
  557. data/test/test_time_formatter.rb +301 -0
  558. data/test/test_time_parser.rb +362 -0
  559. data/test/test_tls.rb +65 -0
  560. data/test/test_unique_id.rb +47 -0
  561. data/test/test_variable_store.rb +65 -0
  562. metadata +1183 -0
@@ -0,0 +1,1006 @@
1
+ require_relative '../helper'
2
+ require 'fluent/plugin_helper/retry_state'
3
+ require 'fluent/plugin/base'
4
+
5
+ require 'time'
6
+
7
+ class RetryStateHelperTest < Test::Unit::TestCase
8
+ def override_current_time(state, time)
9
+ mojule = Module.new do
10
+ define_method(:current_time){ time }
11
+ end
12
+ state.singleton_class.module_eval do
13
+ prepend mojule
14
+ end
15
+ end
16
+
17
+ class Dummy < Fluent::Plugin::TestBase
18
+ helpers :retry_state
19
+ end
20
+
21
+ class RetryRecord
22
+ attr_reader :retry_count, :elapsed_sec, :is_secondary
23
+ def initialize(retry_count, elapsed_sec, is_secondary)
24
+ @retry_count = retry_count # This is Nth retryment
25
+ @elapsed_sec = elapsed_sec
26
+ @is_secondary = is_secondary
27
+ end
28
+
29
+ def ==(obj)
30
+ @retry_count == obj.retry_count &&
31
+ @elapsed_sec == obj.elapsed_sec &&
32
+ @is_secondary == obj.is_secondary
33
+ end
34
+ end
35
+
36
+ setup do
37
+ @d = Dummy.new
38
+ end
39
+
40
+ test 'randomize can generate value within specified +/- range' do
41
+ s = @d.retry_state_create(:t1, :exponential_backoff, 0.1, 30) # default enabled w/ 0.125
42
+ 500.times do
43
+ r = s.randomize(1000)
44
+ assert{ r >= 875 && r < 1125 }
45
+ end
46
+
47
+ s = @d.retry_state_create(:t1, :exponential_backoff, 0.1, 30, randomize_width: 0.25)
48
+ 500.times do
49
+ r = s.randomize(1000)
50
+ assert{ r >= 750 && r < 1250 }
51
+ end
52
+ end
53
+
54
+ test 'plugin can create retry_state machine' do
55
+ s = @d.retry_state_create(:t1, :exponential_backoff, 0.1, 30)
56
+ # attr_reader :title, :start, :steps, :next_time, :timeout_at, :current, :secondary_transition_at, :secondary_transition_times
57
+
58
+ assert_equal :t1, s.title
59
+ start_time = s.start
60
+
61
+ assert_equal 0, s.steps
62
+ assert_equal (start_time + 0.1).to_i, s.next_time.to_i
63
+ assert_equal (start_time + 0.1).nsec, s.next_time.nsec
64
+ assert_equal (start_time + 30), s.timeout_at
65
+
66
+ assert_equal :primary, s.current
67
+ assert{ s.is_a? Fluent::PluginHelper::RetryState::ExponentialBackOffRetry }
68
+ end
69
+
70
+ test 'periodic retries' do
71
+ s = @d.retry_state_create(:t2, :periodic, 3, 29, randomize: false)
72
+ dummy_current_time = s.start
73
+ override_current_time(s, dummy_current_time)
74
+
75
+ assert_equal dummy_current_time, s.current_time
76
+ assert_equal (dummy_current_time + 29), s.timeout_at
77
+ assert_equal (dummy_current_time + 3), s.next_time
78
+
79
+ i = 1
80
+ while i < 9
81
+ override_current_time(s, s.next_time)
82
+ s.step
83
+ assert_equal i, s.steps
84
+ assert_equal (s.current_time + 3), s.next_time
85
+ assert !s.limit?
86
+ i += 1
87
+ end
88
+
89
+ assert_equal 9, i
90
+ override_current_time(s, s.next_time)
91
+ s.step
92
+ assert_equal s.timeout_at, s.next_time
93
+ s.step
94
+ assert s.limit?
95
+ end
96
+
97
+ test 'periodic retries with max_steps' do
98
+ s = @d.retry_state_create(:t2, :periodic, 3, 29, randomize: false, max_steps: 5)
99
+ dummy_current_time = s.start
100
+ override_current_time(s, dummy_current_time)
101
+
102
+ assert_equal dummy_current_time, s.current_time
103
+ assert_equal (dummy_current_time + 29), s.timeout_at
104
+ assert_equal (dummy_current_time + 3), s.next_time
105
+
106
+ i = 1
107
+ while i < 5
108
+ override_current_time(s, s.next_time)
109
+ s.step
110
+ assert_equal i, s.steps
111
+ assert_equal (s.current_time + 3), s.next_time
112
+ assert !s.limit?
113
+ i += 1
114
+ end
115
+
116
+ assert_equal 5, i
117
+ override_current_time(s, s.next_time)
118
+ s.step
119
+ assert s.limit?
120
+ end
121
+
122
+ test 'periodic retries with secondary' do
123
+ s = @d.retry_state_create(:t3, :periodic, 3, 100, randomize: false, secondary: true) # threshold 0.8
124
+ dummy_current_time = s.start
125
+ override_current_time(s, dummy_current_time)
126
+
127
+ assert_equal dummy_current_time, s.current_time
128
+ assert_equal (dummy_current_time + 100), s.timeout_at
129
+ assert_equal (dummy_current_time + 100 * 0.8), s.secondary_transition_at
130
+
131
+ assert_equal (dummy_current_time + 3), s.next_time
132
+ assert !s.secondary?
133
+
134
+ i = 1
135
+ while i < 26
136
+ override_current_time(s, s.next_time)
137
+ assert !s.secondary?
138
+
139
+ s.step
140
+ assert_equal i, s.steps
141
+ assert_equal (s.current_time + 3), s.next_time
142
+ assert !s.limit?
143
+ i += 1
144
+ end
145
+
146
+ assert_equal 26, i
147
+ override_current_time(s, s.next_time) # 78
148
+ assert !s.secondary?
149
+
150
+ s.step
151
+ assert_equal 26, s.steps
152
+ assert_equal s.secondary_transition_at, s.next_time
153
+ assert !s.limit?
154
+
155
+ i += 1
156
+ assert_equal 27, i
157
+ override_current_time(s, s.next_time) # 80
158
+ assert s.secondary?
159
+
160
+ s.step
161
+ assert_equal (s.current_time + 3), s.next_time
162
+ assert_equal s.steps, s.secondary_transition_steps
163
+ assert !s.limit?
164
+
165
+ i += 1
166
+
167
+ while i < 33
168
+ override_current_time(s, s.next_time)
169
+ assert s.secondary?
170
+
171
+ s.step
172
+ assert_equal (s.current_time + 3), s.next_time
173
+ assert !s.limit?
174
+ i += 1
175
+ end
176
+
177
+ assert_equal 33, i
178
+ override_current_time(s, s.next_time) # 98
179
+ assert s.secondary?
180
+
181
+ s.step
182
+ assert_equal s.timeout_at, s.next_time # 100
183
+
184
+ s.step
185
+ assert s.limit?
186
+ end
187
+
188
+ test 'periodic retries with secondary and specified threshold' do
189
+ s = @d.retry_state_create(:t3, :periodic, 3, 100, randomize: false, secondary: true, secondary_threshold: 0.75)
190
+ dummy_current_time = s.start
191
+ override_current_time(s, dummy_current_time)
192
+
193
+ assert_equal dummy_current_time, s.current_time
194
+ assert_equal (dummy_current_time + 100), s.timeout_at
195
+ assert_equal (dummy_current_time + 100 * 0.75), s.secondary_transition_at
196
+ end
197
+
198
+ test 'periodic retries with secondary and max_steps' do
199
+ s = @d.retry_state_create(:t3, :periodic, 3, 100, max_steps: 5, randomize: false, secondary: true)
200
+ dummy_current_time = s.start
201
+ override_current_time(s, dummy_current_time)
202
+
203
+ assert_equal dummy_current_time, s.current_time
204
+ assert_equal (dummy_current_time + 100), s.timeout_at
205
+ assert_equal (dummy_current_time + 3 * 5 * 0.8), s.secondary_transition_at
206
+ end
207
+
208
+ test 'exponential backoff forever without randomization' do
209
+ s = @d.retry_state_create(:t11, :exponential_backoff, 0.1, 300, randomize: false, forever: true, backoff_base: 2)
210
+ dummy_current_time = s.start
211
+ override_current_time(s, dummy_current_time)
212
+
213
+ assert_equal dummy_current_time, s.current_time
214
+
215
+ assert_equal 0, s.steps
216
+ assert_equal (dummy_current_time + 0.1), s.next_time
217
+
218
+ i = 1
219
+ while i < 300
220
+ s.step
221
+ assert_equal i, s.steps
222
+ assert_equal (dummy_current_time + 0.1 * (2 ** i)), s.next_time
223
+ assert !s.limit?
224
+ i += 1
225
+ end
226
+ end
227
+
228
+ test 'exponential backoff with max_interval' do
229
+ s = @d.retry_state_create(:t12, :exponential_backoff, 0.1, 300, randomize: false, forever: true, backoff_base: 2, max_interval: 100)
230
+ dummy_current_time = s.start
231
+ override_current_time(s, dummy_current_time)
232
+
233
+ assert_equal dummy_current_time, s.current_time
234
+
235
+ assert_equal 0, s.steps
236
+ assert_equal (dummy_current_time + 0.1), s.next_time
237
+
238
+ # 0.1 * 2 ** 9 == 51.2
239
+ # 0.1 * 2 ** 10 == 102.4
240
+ i = 1
241
+ while i < 10
242
+ s.step
243
+ assert_equal i, s.steps
244
+ assert_equal (dummy_current_time + 0.1 * (2 ** i)), s.next_time, "start:#{dummy_current_time}, i:#{i}"
245
+ i += 1
246
+ end
247
+
248
+ s.step
249
+ assert_equal 10, s.steps
250
+ assert_equal (dummy_current_time + 100), s.next_time
251
+
252
+ s.step
253
+ assert_equal 11, s.steps
254
+ assert_equal (dummy_current_time + 100), s.next_time
255
+ end
256
+
257
+ test 'exponential backoff with shorter timeout' do
258
+ s = @d.retry_state_create(:t13, :exponential_backoff, 1, 12, randomize: false, backoff_base: 2, max_interval: 10)
259
+ dummy_current_time = s.start
260
+ override_current_time(s, dummy_current_time)
261
+
262
+ assert_equal dummy_current_time, s.current_time
263
+
264
+ assert_equal (dummy_current_time + 12), s.timeout_at
265
+
266
+ assert_equal 0, s.steps
267
+ assert_equal (dummy_current_time + 1), s.next_time
268
+
269
+ # 1 + 2 + 4 (=7)
270
+
271
+ override_current_time(s, s.next_time)
272
+ s.step
273
+ assert_equal 1, s.steps
274
+ assert_equal (s.current_time + 2), s.next_time
275
+
276
+ override_current_time(s, s.next_time)
277
+ s.step
278
+ assert_equal 2, s.steps
279
+ assert_equal (s.current_time + 4), s.next_time
280
+
281
+ assert !s.limit?
282
+
283
+ # + 8 (=15) > 12
284
+
285
+ override_current_time(s, s.next_time)
286
+ s.step
287
+ assert_equal 3, s.steps
288
+ assert_equal s.timeout_at, s.next_time
289
+
290
+ s.step
291
+ assert s.limit?
292
+ end
293
+
294
+ test 'exponential backoff with max_steps' do
295
+ s = @d.retry_state_create(:t14, :exponential_backoff, 1, 120, randomize: false, backoff_base: 2, max_interval: 10, max_steps: 6)
296
+ dummy_current_time = s.start
297
+ override_current_time(s, dummy_current_time)
298
+
299
+ assert_equal dummy_current_time, s.current_time
300
+
301
+ assert_equal (dummy_current_time + 120), s.timeout_at
302
+
303
+ assert_equal 0, s.steps
304
+ assert_equal (dummy_current_time + 1), s.next_time
305
+
306
+ override_current_time(s, s.next_time)
307
+ s.step
308
+ assert_equal 1, s.steps
309
+ assert_equal (s.current_time + 2), s.next_time
310
+
311
+ override_current_time(s, s.next_time)
312
+ s.step
313
+ assert_equal 2, s.steps
314
+ assert_equal (s.current_time + 4), s.next_time
315
+
316
+ override_current_time(s, s.next_time)
317
+ s.step
318
+ assert_equal 3, s.steps
319
+ assert_equal (s.current_time + 8), s.next_time
320
+
321
+ assert !s.limit?
322
+
323
+ override_current_time(s, s.next_time)
324
+ s.step
325
+ assert_equal 4, s.steps
326
+ assert_equal (s.current_time + 10), s.next_time
327
+
328
+ assert !s.limit?
329
+
330
+ override_current_time(s, s.next_time)
331
+ s.step
332
+ assert_equal 5, s.steps
333
+ assert_equal (s.current_time + 10), s.next_time
334
+
335
+ assert !s.limit?
336
+
337
+ override_current_time(s, s.next_time)
338
+ s.step
339
+ assert_equal 6, s.steps
340
+ assert s.limit?
341
+ end
342
+
343
+ test 'exponential backoff retries with secondary' do
344
+ s = @d.retry_state_create(:t15, :exponential_backoff, 1, 100, randomize: false, backoff_base: 2, secondary: true) # threshold 0.8
345
+ dummy_current_time = s.start
346
+ override_current_time(s, dummy_current_time)
347
+
348
+ assert_equal dummy_current_time, s.current_time
349
+ assert_equal (dummy_current_time + 100), s.timeout_at
350
+ assert_equal (dummy_current_time + 100 * 0.8), s.secondary_transition_at
351
+
352
+ assert_equal (dummy_current_time + 1), s.next_time
353
+ assert !s.secondary?
354
+
355
+ # primary: 3, 7, 15, 31, 63, 80 (timeout * threashold)
356
+ # secondary: 81, 83, 87, 95, 100
357
+ i = 1
358
+ while i < 6
359
+ override_current_time(s, s.next_time)
360
+ assert !s.secondary?
361
+
362
+ s.step
363
+ assert_equal i, s.steps
364
+ assert_equal (s.current_time + 1 * (2 ** i)), s.next_time
365
+ assert !s.limit?
366
+ i += 1
367
+ end
368
+
369
+ assert_equal 6, i
370
+ override_current_time(s, s.next_time) # 63
371
+ assert !s.secondary?
372
+
373
+ s.step
374
+ assert_equal 6, s.steps
375
+ assert_equal s.secondary_transition_at, s.next_time
376
+ assert !s.limit?
377
+
378
+ i += 1
379
+ assert_equal 7, i
380
+ override_current_time(s, s.next_time) # 80
381
+ assert s.secondary?
382
+
383
+ s.step
384
+ assert_equal 7, s.steps
385
+ assert_equal s.steps, s.secondary_transition_steps
386
+ assert_equal (s.secondary_transition_at + 1.0), s.next_time # 81
387
+ assert !s.limit?
388
+ assert_equal :secondary, s.current
389
+
390
+ # 83, 87, 95, 100
391
+ j = 1
392
+ while j < 4
393
+ override_current_time(s, s.next_time)
394
+ assert s.secondary?
395
+ assert_equal :secondary, s.current
396
+
397
+ s.step
398
+ assert_equal (7 + j), s.steps
399
+ assert_equal (s.current_time + (1 * (2 ** j))), s.next_time
400
+ assert !s.limit?, "j:#{j}"
401
+ j += 1
402
+ end
403
+
404
+ assert_equal 4, j
405
+ override_current_time(s, s.next_time) # 95
406
+ assert s.secondary?
407
+
408
+ s.step
409
+ assert_equal s.timeout_at, s.next_time # 100
410
+
411
+ s.step
412
+ assert s.limit?
413
+ end
414
+
415
+ test 'exponential backoff retries with secondary and specified threshold' do
416
+ s = @d.retry_state_create(:t16, :exponential_backoff, 1, 100, randomize: false, secondary: true, backoff_base: 2, secondary_threshold: 0.75)
417
+ dummy_current_time = s.start
418
+ override_current_time(s, dummy_current_time)
419
+
420
+ assert_equal dummy_current_time, s.current_time
421
+ assert_equal (dummy_current_time + 100), s.timeout_at
422
+ assert_equal (dummy_current_time + 100 * 0.75), s.secondary_transition_at
423
+ end
424
+
425
+ test 'exponential backoff retries with secondary and max_steps' do
426
+ s = @d.retry_state_create(:t15, :exponential_backoff, 1, 100, randomize: false, max_steps: 5, backoff_base: 2, secondary: true) # threshold 0.8
427
+ dummy_current_time = s.start
428
+ override_current_time(s, dummy_current_time)
429
+
430
+ timeout = 0
431
+ 5.times { |i| timeout += 1.0 * (2 ** i) }
432
+
433
+ assert_equal dummy_current_time, s.current_time
434
+ assert_equal (dummy_current_time + 100), s.timeout_at
435
+ assert_equal (dummy_current_time + timeout * 0.8), s.secondary_transition_at
436
+ end
437
+
438
+ sub_test_case 'exponential backoff' do
439
+ test 'too big steps(check inf handling)' do
440
+ s = @d.retry_state_create(:t11, :exponential_backoff, 1, 300, randomize: false, forever: true, backoff_base: 2)
441
+ dummy_current_time = s.start
442
+ override_current_time(s, dummy_current_time)
443
+
444
+ i = 1
445
+ while i < 1027
446
+ if i >= 1025
447
+ # With this setting, 1025+ number causes inf in `calc_interval`, so 1024 value is used for next_time
448
+ assert_nothing_raised(FloatDomainError) { s.step }
449
+ assert_equal (dummy_current_time + (2 ** (1024 - 1))), s.next_time
450
+ else
451
+ s.step
452
+ end
453
+ i += 1
454
+ end
455
+ end
456
+ end
457
+
458
+ sub_test_case "ExponentialBackOff_ScenarioTests" do
459
+ data("Simple timeout", {
460
+ timeout: 100, max_steps: nil, max_interval: nil, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
461
+ expected: [
462
+ RetryRecord.new(1, 1, false),
463
+ RetryRecord.new(2, 3, false),
464
+ RetryRecord.new(3, 7, false),
465
+ RetryRecord.new(4, 15, false),
466
+ RetryRecord.new(5, 31, false),
467
+ RetryRecord.new(6, 63, false),
468
+ RetryRecord.new(7, 100, false),
469
+ ],
470
+ })
471
+ data("Simple timeout with secondary", {
472
+ timeout: 100, max_steps: nil, max_interval: nil, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
473
+ expected: [
474
+ RetryRecord.new(1, 1, false),
475
+ RetryRecord.new(2, 3, false),
476
+ RetryRecord.new(3, 7, false),
477
+ RetryRecord.new(4, 15, false),
478
+ RetryRecord.new(5, 31, false),
479
+ RetryRecord.new(6, 63, false),
480
+ RetryRecord.new(7, 80, true),
481
+ RetryRecord.new(8, 81, true),
482
+ RetryRecord.new(9, 83, true),
483
+ RetryRecord.new(10, 87, true),
484
+ RetryRecord.new(11, 95, true),
485
+ RetryRecord.new(12, 100, true),
486
+ ],
487
+ })
488
+ data("Simple timeout with custom wait and backoff_base", {
489
+ timeout: 1000, max_steps: nil, max_interval: nil, use_sec: false, sec_thres: 0.8, wait: 2, backoff_base: 3,
490
+ expected: [
491
+ RetryRecord.new(1, 2, false),
492
+ RetryRecord.new(2, 8, false),
493
+ RetryRecord.new(3, 26, false),
494
+ RetryRecord.new(4, 80, false),
495
+ RetryRecord.new(5, 242, false),
496
+ RetryRecord.new(6, 728, false),
497
+ RetryRecord.new(7, 1000, false),
498
+ ],
499
+ })
500
+ data("Simple timeout with custom wait and backoff_base and secondary", {
501
+ timeout: 1000, max_steps: nil, max_interval: nil, use_sec: true, sec_thres: 0.8, wait: 2, backoff_base: 3,
502
+ expected: [
503
+ RetryRecord.new(1, 2, false),
504
+ RetryRecord.new(2, 8, false),
505
+ RetryRecord.new(3, 26, false),
506
+ RetryRecord.new(4, 80, false),
507
+ RetryRecord.new(5, 242, false),
508
+ RetryRecord.new(6, 728, false),
509
+ RetryRecord.new(7, 800, true),
510
+ RetryRecord.new(8, 802, true),
511
+ RetryRecord.new(9, 808, true),
512
+ RetryRecord.new(10, 826, true),
513
+ RetryRecord.new(11, 880, true),
514
+ RetryRecord.new(12, 1000, true),
515
+ ],
516
+ })
517
+ data("Default timeout", {
518
+ timeout: 72*3600, max_steps: nil, max_interval: nil, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
519
+ expected: [
520
+ RetryRecord.new(1, 1, false),
521
+ RetryRecord.new(2, 3, false),
522
+ RetryRecord.new(3, 7, false),
523
+ RetryRecord.new(4, 15, false),
524
+ RetryRecord.new(5, 31, false),
525
+ RetryRecord.new(6, 63, false),
526
+ RetryRecord.new(7, 127, false),
527
+ RetryRecord.new(8, 255, false),
528
+ RetryRecord.new(9, 511, false),
529
+ RetryRecord.new(10, 1023, false),
530
+ RetryRecord.new(11, 2047, false),
531
+ RetryRecord.new(12, 4095, false),
532
+ RetryRecord.new(13, 8191, false),
533
+ RetryRecord.new(14, 16383, false),
534
+ RetryRecord.new(15, 32767, false),
535
+ RetryRecord.new(16, 65535, false),
536
+ RetryRecord.new(17, 131071, false),
537
+ RetryRecord.new(18, 259200, false),
538
+ ],
539
+ })
540
+ data("Default timeout with secondary", {
541
+ timeout: 72*3600, max_steps: nil, max_interval: nil, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
542
+ expected: [
543
+ RetryRecord.new(1, 1, false),
544
+ RetryRecord.new(2, 3, false),
545
+ RetryRecord.new(3, 7, false),
546
+ RetryRecord.new(4, 15, false),
547
+ RetryRecord.new(5, 31, false),
548
+ RetryRecord.new(6, 63, false),
549
+ RetryRecord.new(7, 127, false),
550
+ RetryRecord.new(8, 255, false),
551
+ RetryRecord.new(9, 511, false),
552
+ RetryRecord.new(10, 1023, false),
553
+ RetryRecord.new(11, 2047, false),
554
+ RetryRecord.new(12, 4095, false),
555
+ RetryRecord.new(13, 8191, false),
556
+ RetryRecord.new(14, 16383, false),
557
+ RetryRecord.new(15, 32767, false),
558
+ RetryRecord.new(16, 65535, false),
559
+ RetryRecord.new(17, 131071, false),
560
+ RetryRecord.new(18, 207360, true),
561
+ RetryRecord.new(19, 207361, true),
562
+ RetryRecord.new(20, 207363, true),
563
+ RetryRecord.new(21, 207367, true),
564
+ RetryRecord.new(22, 207375, true),
565
+ RetryRecord.new(23, 207391, true),
566
+ RetryRecord.new(24, 207423, true),
567
+ RetryRecord.new(25, 207487, true),
568
+ RetryRecord.new(26, 207615, true),
569
+ RetryRecord.new(27, 207871, true),
570
+ RetryRecord.new(28, 208383, true),
571
+ RetryRecord.new(29, 209407, true),
572
+ RetryRecord.new(30, 211455, true),
573
+ RetryRecord.new(31, 215551, true),
574
+ RetryRecord.new(32, 223743, true),
575
+ RetryRecord.new(33, 240127, true),
576
+ RetryRecord.new(34, 259200, true),
577
+ ],
578
+ })
579
+ data("Default timeout with secondary and custom threshold", {
580
+ timeout: 72*3600, max_steps: nil, max_interval: nil, use_sec: true, sec_thres: 0.5, wait: 1, backoff_base: 2,
581
+ expected: [
582
+ RetryRecord.new(1, 1, false),
583
+ RetryRecord.new(2, 3, false),
584
+ RetryRecord.new(3, 7, false),
585
+ RetryRecord.new(4, 15, false),
586
+ RetryRecord.new(5, 31, false),
587
+ RetryRecord.new(6, 63, false),
588
+ RetryRecord.new(7, 127, false),
589
+ RetryRecord.new(8, 255, false),
590
+ RetryRecord.new(9, 511, false),
591
+ RetryRecord.new(10, 1023, false),
592
+ RetryRecord.new(11, 2047, false),
593
+ RetryRecord.new(12, 4095, false),
594
+ RetryRecord.new(13, 8191, false),
595
+ RetryRecord.new(14, 16383, false),
596
+ RetryRecord.new(15, 32767, false),
597
+ RetryRecord.new(16, 65535, false),
598
+ RetryRecord.new(17, 129600, true),
599
+ RetryRecord.new(18, 129601, true),
600
+ RetryRecord.new(19, 129603, true),
601
+ RetryRecord.new(20, 129607, true),
602
+ RetryRecord.new(21, 129615, true),
603
+ RetryRecord.new(22, 129631, true),
604
+ RetryRecord.new(23, 129663, true),
605
+ RetryRecord.new(24, 129727, true),
606
+ RetryRecord.new(25, 129855, true),
607
+ RetryRecord.new(26, 130111, true),
608
+ RetryRecord.new(27, 130623, true),
609
+ RetryRecord.new(28, 131647, true),
610
+ RetryRecord.new(29, 133695, true),
611
+ RetryRecord.new(30, 137791, true),
612
+ RetryRecord.new(31, 145983, true),
613
+ RetryRecord.new(32, 162367, true),
614
+ RetryRecord.new(33, 195135, true),
615
+ RetryRecord.new(34, 259200, true),
616
+ ],
617
+ })
618
+ data("Simple max_steps", {
619
+ timeout: 72*3600, max_steps: 10, max_interval: nil, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
620
+ expected: [
621
+ RetryRecord.new(1, 1, false),
622
+ RetryRecord.new(2, 3, false),
623
+ RetryRecord.new(3, 7, false),
624
+ RetryRecord.new(4, 15, false),
625
+ RetryRecord.new(5, 31, false),
626
+ RetryRecord.new(6, 63, false),
627
+ RetryRecord.new(7, 127, false),
628
+ RetryRecord.new(8, 255, false),
629
+ RetryRecord.new(9, 511, false),
630
+ RetryRecord.new(10, 1023, false),
631
+ ],
632
+ })
633
+ data("Simple max_steps with secondary", {
634
+ timeout: 72*3600, max_steps: 10, max_interval: nil, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
635
+ expected: [
636
+ RetryRecord.new(1, 1, false),
637
+ RetryRecord.new(2, 3, false),
638
+ RetryRecord.new(3, 7, false),
639
+ RetryRecord.new(4, 15, false),
640
+ RetryRecord.new(5, 31, false),
641
+ RetryRecord.new(6, 63, false),
642
+ RetryRecord.new(7, 127, false),
643
+ RetryRecord.new(8, 255, false),
644
+ RetryRecord.new(9, 511, false),
645
+ RetryRecord.new(10, 818, true),
646
+ ],
647
+ })
648
+ data("Simple interval", {
649
+ timeout: 72*3600, max_steps: nil, max_interval: 3600, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
650
+ expected: [
651
+ RetryRecord.new(1, 1, false),
652
+ RetryRecord.new(2, 3, false),
653
+ RetryRecord.new(3, 7, false),
654
+ RetryRecord.new(4, 15, false),
655
+ RetryRecord.new(5, 31, false),
656
+ RetryRecord.new(6, 63, false),
657
+ RetryRecord.new(7, 127, false),
658
+ RetryRecord.new(8, 255, false),
659
+ RetryRecord.new(9, 511, false),
660
+ RetryRecord.new(10, 1023, false),
661
+ RetryRecord.new(11, 2047, false),
662
+ RetryRecord.new(12, 4095, false),
663
+ RetryRecord.new(13, 7695, false),
664
+ RetryRecord.new(14, 11295, false),
665
+ RetryRecord.new(15, 14895, false),
666
+ RetryRecord.new(16, 18495, false),
667
+ RetryRecord.new(17, 22095, false),
668
+ RetryRecord.new(18, 25695, false),
669
+ RetryRecord.new(19, 29295, false),
670
+ RetryRecord.new(20, 32895, false),
671
+ RetryRecord.new(21, 36495, false),
672
+ RetryRecord.new(22, 40095, false),
673
+ RetryRecord.new(23, 43695, false),
674
+ RetryRecord.new(24, 47295, false),
675
+ RetryRecord.new(25, 50895, false),
676
+ RetryRecord.new(26, 54495, false),
677
+ RetryRecord.new(27, 58095, false),
678
+ RetryRecord.new(28, 61695, false),
679
+ RetryRecord.new(29, 65295, false),
680
+ RetryRecord.new(30, 68895, false),
681
+ RetryRecord.new(31, 72495, false),
682
+ RetryRecord.new(32, 76095, false),
683
+ RetryRecord.new(33, 79695, false),
684
+ RetryRecord.new(34, 83295, false),
685
+ RetryRecord.new(35, 86895, false),
686
+ RetryRecord.new(36, 90495, false),
687
+ RetryRecord.new(37, 94095, false),
688
+ RetryRecord.new(38, 97695, false),
689
+ RetryRecord.new(39, 101295, false),
690
+ RetryRecord.new(40, 104895, false),
691
+ RetryRecord.new(41, 108495, false),
692
+ RetryRecord.new(42, 112095, false),
693
+ RetryRecord.new(43, 115695, false),
694
+ RetryRecord.new(44, 119295, false),
695
+ RetryRecord.new(45, 122895, false),
696
+ RetryRecord.new(46, 126495, false),
697
+ RetryRecord.new(47, 130095, false),
698
+ RetryRecord.new(48, 133695, false),
699
+ RetryRecord.new(49, 137295, false),
700
+ RetryRecord.new(50, 140895, false),
701
+ RetryRecord.new(51, 144495, false),
702
+ RetryRecord.new(52, 148095, false),
703
+ RetryRecord.new(53, 151695, false),
704
+ RetryRecord.new(54, 155295, false),
705
+ RetryRecord.new(55, 158895, false),
706
+ RetryRecord.new(56, 162495, false),
707
+ RetryRecord.new(57, 166095, false),
708
+ RetryRecord.new(58, 169695, false),
709
+ RetryRecord.new(59, 173295, false),
710
+ RetryRecord.new(60, 176895, false),
711
+ RetryRecord.new(61, 180495, false),
712
+ RetryRecord.new(62, 184095, false),
713
+ RetryRecord.new(63, 187695, false),
714
+ RetryRecord.new(64, 191295, false),
715
+ RetryRecord.new(65, 194895, false),
716
+ RetryRecord.new(66, 198495, false),
717
+ RetryRecord.new(67, 202095, false),
718
+ RetryRecord.new(68, 205695, false),
719
+ RetryRecord.new(69, 209295, false),
720
+ RetryRecord.new(70, 212895, false),
721
+ RetryRecord.new(71, 216495, false),
722
+ RetryRecord.new(72, 220095, false),
723
+ RetryRecord.new(73, 223695, false),
724
+ RetryRecord.new(74, 227295, false),
725
+ RetryRecord.new(75, 230895, false),
726
+ RetryRecord.new(76, 234495, false),
727
+ RetryRecord.new(77, 238095, false),
728
+ RetryRecord.new(78, 241695, false),
729
+ RetryRecord.new(79, 245295, false),
730
+ RetryRecord.new(80, 248895, false),
731
+ RetryRecord.new(81, 252495, false),
732
+ RetryRecord.new(82, 256095, false),
733
+ RetryRecord.new(83, 259200, false),
734
+ ],
735
+ })
736
+ data("Simple interval with secondary", {
737
+ timeout: 72*3600, max_steps: nil, max_interval: 3600, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
738
+ expected: [
739
+ RetryRecord.new(1, 1, false),
740
+ RetryRecord.new(2, 3, false),
741
+ RetryRecord.new(3, 7, false),
742
+ RetryRecord.new(4, 15, false),
743
+ RetryRecord.new(5, 31, false),
744
+ RetryRecord.new(6, 63, false),
745
+ RetryRecord.new(7, 127, false),
746
+ RetryRecord.new(8, 255, false),
747
+ RetryRecord.new(9, 511, false),
748
+ RetryRecord.new(10, 1023, false),
749
+ RetryRecord.new(11, 2047, false),
750
+ RetryRecord.new(12, 4095, false),
751
+ RetryRecord.new(13, 7695, false),
752
+ RetryRecord.new(14, 11295, false),
753
+ RetryRecord.new(15, 14895, false),
754
+ RetryRecord.new(16, 18495, false),
755
+ RetryRecord.new(17, 22095, false),
756
+ RetryRecord.new(18, 25695, false),
757
+ RetryRecord.new(19, 29295, false),
758
+ RetryRecord.new(20, 32895, false),
759
+ RetryRecord.new(21, 36495, false),
760
+ RetryRecord.new(22, 40095, false),
761
+ RetryRecord.new(23, 43695, false),
762
+ RetryRecord.new(24, 47295, false),
763
+ RetryRecord.new(25, 50895, false),
764
+ RetryRecord.new(26, 54495, false),
765
+ RetryRecord.new(27, 58095, false),
766
+ RetryRecord.new(28, 61695, false),
767
+ RetryRecord.new(29, 65295, false),
768
+ RetryRecord.new(30, 68895, false),
769
+ RetryRecord.new(31, 72495, false),
770
+ RetryRecord.new(32, 76095, false),
771
+ RetryRecord.new(33, 79695, false),
772
+ RetryRecord.new(34, 83295, false),
773
+ RetryRecord.new(35, 86895, false),
774
+ RetryRecord.new(36, 90495, false),
775
+ RetryRecord.new(37, 94095, false),
776
+ RetryRecord.new(38, 97695, false),
777
+ RetryRecord.new(39, 101295, false),
778
+ RetryRecord.new(40, 104895, false),
779
+ RetryRecord.new(41, 108495, false),
780
+ RetryRecord.new(42, 112095, false),
781
+ RetryRecord.new(43, 115695, false),
782
+ RetryRecord.new(44, 119295, false),
783
+ RetryRecord.new(45, 122895, false),
784
+ RetryRecord.new(46, 126495, false),
785
+ RetryRecord.new(47, 130095, false),
786
+ RetryRecord.new(48, 133695, false),
787
+ RetryRecord.new(49, 137295, false),
788
+ RetryRecord.new(50, 140895, false),
789
+ RetryRecord.new(51, 144495, false),
790
+ RetryRecord.new(52, 148095, false),
791
+ RetryRecord.new(53, 151695, false),
792
+ RetryRecord.new(54, 155295, false),
793
+ RetryRecord.new(55, 158895, false),
794
+ RetryRecord.new(56, 162495, false),
795
+ RetryRecord.new(57, 166095, false),
796
+ RetryRecord.new(58, 169695, false),
797
+ RetryRecord.new(59, 173295, false),
798
+ RetryRecord.new(60, 176895, false),
799
+ RetryRecord.new(61, 180495, false),
800
+ RetryRecord.new(62, 184095, false),
801
+ RetryRecord.new(63, 187695, false),
802
+ RetryRecord.new(64, 191295, false),
803
+ RetryRecord.new(65, 194895, false),
804
+ RetryRecord.new(66, 198495, false),
805
+ RetryRecord.new(67, 202095, false),
806
+ RetryRecord.new(68, 205695, false),
807
+ RetryRecord.new(69, 207360, true),
808
+ RetryRecord.new(70, 207361, true),
809
+ RetryRecord.new(71, 207363, true),
810
+ RetryRecord.new(72, 207367, true),
811
+ RetryRecord.new(73, 207375, true),
812
+ RetryRecord.new(74, 207391, true),
813
+ RetryRecord.new(75, 207423, true),
814
+ RetryRecord.new(76, 207487, true),
815
+ RetryRecord.new(77, 207615, true),
816
+ RetryRecord.new(78, 207871, true),
817
+ RetryRecord.new(79, 208383, true),
818
+ RetryRecord.new(80, 209407, true),
819
+ RetryRecord.new(81, 211455, true),
820
+ RetryRecord.new(82, 215055, true),
821
+ RetryRecord.new(83, 218655, true),
822
+ RetryRecord.new(84, 222255, true),
823
+ RetryRecord.new(85, 225855, true),
824
+ RetryRecord.new(86, 229455, true),
825
+ RetryRecord.new(87, 233055, true),
826
+ RetryRecord.new(88, 236655, true),
827
+ RetryRecord.new(89, 240255, true),
828
+ RetryRecord.new(90, 243855, true),
829
+ RetryRecord.new(91, 247455, true),
830
+ RetryRecord.new(92, 251055, true),
831
+ RetryRecord.new(93, 254655, true),
832
+ RetryRecord.new(94, 258255, true),
833
+ RetryRecord.new(95, 259200, true),
834
+ ],
835
+ })
836
+ data("Max_steps and max_interval", {
837
+ timeout: 72*3600, max_steps: 30, max_interval: 3600, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
838
+ expected: [
839
+ RetryRecord.new(1, 1, false),
840
+ RetryRecord.new(2, 3, false),
841
+ RetryRecord.new(3, 7, false),
842
+ RetryRecord.new(4, 15, false),
843
+ RetryRecord.new(5, 31, false),
844
+ RetryRecord.new(6, 63, false),
845
+ RetryRecord.new(7, 127, false),
846
+ RetryRecord.new(8, 255, false),
847
+ RetryRecord.new(9, 511, false),
848
+ RetryRecord.new(10, 1023, false),
849
+ RetryRecord.new(11, 2047, false),
850
+ RetryRecord.new(12, 4095, false),
851
+ RetryRecord.new(13, 7695, false),
852
+ RetryRecord.new(14, 11295, false),
853
+ RetryRecord.new(15, 14895, false),
854
+ RetryRecord.new(16, 18495, false),
855
+ RetryRecord.new(17, 22095, false),
856
+ RetryRecord.new(18, 25695, false),
857
+ RetryRecord.new(19, 29295, false),
858
+ RetryRecord.new(20, 32895, false),
859
+ RetryRecord.new(21, 36495, false),
860
+ RetryRecord.new(22, 40095, false),
861
+ RetryRecord.new(23, 43695, false),
862
+ RetryRecord.new(24, 47295, false),
863
+ RetryRecord.new(25, 50895, false),
864
+ RetryRecord.new(26, 54495, false),
865
+ RetryRecord.new(27, 58095, false),
866
+ RetryRecord.new(28, 61695, false),
867
+ RetryRecord.new(29, 65295, false),
868
+ RetryRecord.new(30, 68895, false),
869
+ ],
870
+ })
871
+ data("Max_steps and max_interval with secondary", {
872
+ timeout: 72*3600, max_steps: 30, max_interval: 3600, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
873
+ expected: [
874
+ RetryRecord.new(1, 1, false),
875
+ RetryRecord.new(2, 3, false),
876
+ RetryRecord.new(3, 7, false),
877
+ RetryRecord.new(4, 15, false),
878
+ RetryRecord.new(5, 31, false),
879
+ RetryRecord.new(6, 63, false),
880
+ RetryRecord.new(7, 127, false),
881
+ RetryRecord.new(8, 255, false),
882
+ RetryRecord.new(9, 511, false),
883
+ RetryRecord.new(10, 1023, false),
884
+ RetryRecord.new(11, 2047, false),
885
+ RetryRecord.new(12, 4095, false),
886
+ RetryRecord.new(13, 7695, false),
887
+ RetryRecord.new(14, 11295, false),
888
+ RetryRecord.new(15, 14895, false),
889
+ RetryRecord.new(16, 18495, false),
890
+ RetryRecord.new(17, 22095, false),
891
+ RetryRecord.new(18, 25695, false),
892
+ RetryRecord.new(19, 29295, false),
893
+ RetryRecord.new(20, 32895, false),
894
+ RetryRecord.new(21, 36495, false),
895
+ RetryRecord.new(22, 40095, false),
896
+ RetryRecord.new(23, 43695, false),
897
+ RetryRecord.new(24, 47295, false),
898
+ RetryRecord.new(25, 50895, false),
899
+ RetryRecord.new(26, 54495, false),
900
+ RetryRecord.new(27, 55116, true),
901
+ RetryRecord.new(28, 55117, true),
902
+ RetryRecord.new(29, 55119, true),
903
+ RetryRecord.new(30, 55123, true),
904
+ ],
905
+ })
906
+ data("Max_steps and max_interval with timeout", {
907
+ timeout: 10000, max_steps: 30, max_interval: 1000, use_sec: false, sec_thres: 0.8, wait: 1, backoff_base: 2,
908
+ expected: [
909
+ RetryRecord.new(1, 1, false),
910
+ RetryRecord.new(2, 3, false),
911
+ RetryRecord.new(3, 7, false),
912
+ RetryRecord.new(4, 15, false),
913
+ RetryRecord.new(5, 31, false),
914
+ RetryRecord.new(6, 63, false),
915
+ RetryRecord.new(7, 127, false),
916
+ RetryRecord.new(8, 255, false),
917
+ RetryRecord.new(9, 511, false),
918
+ RetryRecord.new(10, 1023, false),
919
+ RetryRecord.new(11, 2023, false),
920
+ RetryRecord.new(12, 3023, false),
921
+ RetryRecord.new(13, 4023, false),
922
+ RetryRecord.new(14, 5023, false),
923
+ RetryRecord.new(15, 6023, false),
924
+ RetryRecord.new(16, 7023, false),
925
+ RetryRecord.new(17, 8023, false),
926
+ RetryRecord.new(18, 9023, false),
927
+ RetryRecord.new(19, 10000, false),
928
+ ],
929
+ })
930
+ data("Max_steps and max_interval with timeout and secondary", {
931
+ timeout: 10000, max_steps: 30, max_interval: 1000, use_sec: true, sec_thres: 0.8, wait: 1, backoff_base: 2,
932
+ expected: [
933
+ RetryRecord.new(1, 1, false),
934
+ RetryRecord.new(2, 3, false),
935
+ RetryRecord.new(3, 7, false),
936
+ RetryRecord.new(4, 15, false),
937
+ RetryRecord.new(5, 31, false),
938
+ RetryRecord.new(6, 63, false),
939
+ RetryRecord.new(7, 127, false),
940
+ RetryRecord.new(8, 255, false),
941
+ RetryRecord.new(9, 511, false),
942
+ RetryRecord.new(10, 1023, false),
943
+ RetryRecord.new(11, 2023, false),
944
+ RetryRecord.new(12, 3023, false),
945
+ RetryRecord.new(13, 4023, false),
946
+ RetryRecord.new(14, 5023, false),
947
+ RetryRecord.new(15, 6023, false),
948
+ RetryRecord.new(16, 7023, false),
949
+ RetryRecord.new(17, 8000, true),
950
+ RetryRecord.new(18, 8001, true),
951
+ RetryRecord.new(19, 8003, true),
952
+ RetryRecord.new(20, 8007, true),
953
+ RetryRecord.new(21, 8015, true),
954
+ RetryRecord.new(22, 8031, true),
955
+ RetryRecord.new(23, 8063, true),
956
+ RetryRecord.new(24, 8127, true),
957
+ RetryRecord.new(25, 8255, true),
958
+ RetryRecord.new(26, 8511, true),
959
+ RetryRecord.new(27, 9023, true),
960
+ RetryRecord.new(28, 10000, true),
961
+ ],
962
+ })
963
+ test "exponential backoff with senario" do |data|
964
+ print_for_debug = false # change this value true if need to see msg always.
965
+ trying_count = 1000 # just for avoiding infinite loop
966
+
967
+ retry_records = []
968
+ msg = ""
969
+
970
+ s = @d.retry_state_create(
971
+ :t15, :exponential_backoff, data[:wait], data[:timeout],
972
+ max_steps: data[:max_steps], max_interval: data[:max_interval],
973
+ secondary: data[:use_sec], secondary_threshold: data[:sec_thres],
974
+ backoff_base: data[:backoff_base], randomize: false
975
+ )
976
+ override_current_time(s, s.start)
977
+
978
+ retry_count = 0
979
+ trying_count.times do
980
+ next_elapsed = (s.next_time - s.start).to_i
981
+
982
+ msg << "step: #{s.steps}, next: #{next_elapsed}s (#{next_elapsed / 3600}h)\n"
983
+
984
+ # Wait until next time to trigger the next retry
985
+ override_current_time(s, s.next_time)
986
+
987
+ # Retry will be triggered at this point.
988
+ retry_count += 1
989
+ rec = RetryRecord.new(retry_count, next_elapsed, s.secondary?)
990
+ retry_records.append(rec)
991
+ msg << "[#{next_elapsed}s elapsed point] #{retry_count}th-Retry(#{s.secondary? ? "SEC" : "PRI"}) is triggered.\n"
992
+
993
+ # Update retry statement
994
+ s.step
995
+ if s.limit?
996
+ msg << "--- Reach limit. ---\n"
997
+ break
998
+ end
999
+ end
1000
+
1001
+ assert_equal(data[:expected], retry_records, msg)
1002
+
1003
+ print(msg) if print_for_debug
1004
+ end
1005
+ end
1006
+ end