fluentd 1.17.0-x86-mingw32 → 1.18.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -0
  3. data/README.md +1 -0
  4. data/SECURITY.md +2 -2
  5. data/fluent.conf +14 -14
  6. data/lib/fluent/command/cap_ctl.rb +4 -4
  7. data/lib/fluent/command/fluentd.rb +7 -1
  8. data/lib/fluent/compat/call_super_mixin.rb +3 -3
  9. data/lib/fluent/compat/propagate_default.rb +4 -4
  10. data/lib/fluent/config/literal_parser.rb +9 -2
  11. data/lib/fluent/config/yaml_parser/parser.rb +4 -0
  12. data/lib/fluent/engine.rb +49 -33
  13. data/lib/fluent/env.rb +3 -0
  14. data/lib/fluent/event_router.rb +2 -2
  15. data/lib/fluent/log/console_adapter.rb +4 -2
  16. data/lib/fluent/plugin/filter_parser.rb +27 -51
  17. data/lib/fluent/plugin/in_exec.rb +14 -2
  18. data/lib/fluent/plugin/in_http.rb +6 -1
  19. data/lib/fluent/plugin/in_sample.rb +13 -7
  20. data/lib/fluent/plugin/in_syslog.rb +4 -0
  21. data/lib/fluent/plugin/in_tail.rb +65 -23
  22. data/lib/fluent/plugin/in_tcp.rb +4 -0
  23. data/lib/fluent/plugin/in_udp.rb +10 -1
  24. data/lib/fluent/plugin/input.rb +4 -0
  25. data/lib/fluent/plugin/out_buffer.rb +40 -0
  26. data/lib/fluent/plugin/out_copy.rb +1 -1
  27. data/lib/fluent/plugin/out_file.rb +8 -0
  28. data/lib/fluent/plugin/out_http.rb +12 -0
  29. data/lib/fluent/plugin/output.rb +2 -0
  30. data/lib/fluent/plugin/parser_json.rb +4 -12
  31. data/lib/fluent/plugin_helper/cert_option.rb +8 -0
  32. data/lib/fluent/plugin_helper/event_emitter.rb +12 -0
  33. data/lib/fluent/plugin_helper/http_server/server.rb +24 -8
  34. data/lib/fluent/plugin_helper/server.rb +9 -0
  35. data/lib/fluent/root_agent.rb +114 -19
  36. data/lib/fluent/source_only_buffer_agent.rb +102 -0
  37. data/lib/fluent/supervisor.rb +207 -34
  38. data/lib/fluent/system_config.rb +15 -3
  39. data/lib/fluent/version.rb +1 -1
  40. data/templates/new_gem/fluent-plugin.gemspec.erb +6 -5
  41. metadata +24 -483
  42. data/.github/DISCUSSION_TEMPLATE/q-a-japanese.yml +0 -50
  43. data/.github/DISCUSSION_TEMPLATE/q-a.yml +0 -47
  44. data/.github/ISSUE_TEMPLATE/bug_report.yml +0 -71
  45. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  46. data/.github/ISSUE_TEMPLATE/feature_request.yml +0 -39
  47. data/.github/ISSUE_TEMPLATE.md +0 -17
  48. data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
  49. data/.github/workflows/stale-actions.yml +0 -24
  50. data/.github/workflows/test-ruby-head.yml +0 -31
  51. data/.github/workflows/test.yml +0 -32
  52. data/.gitignore +0 -30
  53. data/Gemfile +0 -9
  54. data/fluentd.gemspec +0 -62
  55. data/test/command/test_binlog_reader.rb +0 -362
  56. data/test/command/test_ca_generate.rb +0 -70
  57. data/test/command/test_cap_ctl.rb +0 -100
  58. data/test/command/test_cat.rb +0 -128
  59. data/test/command/test_ctl.rb +0 -56
  60. data/test/command/test_fluentd.rb +0 -1291
  61. data/test/command/test_plugin_config_formatter.rb +0 -397
  62. data/test/command/test_plugin_generator.rb +0 -109
  63. data/test/compat/test_calls_super.rb +0 -166
  64. data/test/compat/test_parser.rb +0 -92
  65. data/test/config/assertions.rb +0 -42
  66. data/test/config/test_config_parser.rb +0 -551
  67. data/test/config/test_configurable.rb +0 -1784
  68. data/test/config/test_configure_proxy.rb +0 -604
  69. data/test/config/test_dsl.rb +0 -415
  70. data/test/config/test_element.rb +0 -518
  71. data/test/config/test_literal_parser.rb +0 -309
  72. data/test/config/test_plugin_configuration.rb +0 -56
  73. data/test/config/test_section.rb +0 -191
  74. data/test/config/test_system_config.rb +0 -195
  75. data/test/config/test_types.rb +0 -408
  76. data/test/counter/test_client.rb +0 -563
  77. data/test/counter/test_error.rb +0 -44
  78. data/test/counter/test_mutex_hash.rb +0 -179
  79. data/test/counter/test_server.rb +0 -589
  80. data/test/counter/test_store.rb +0 -258
  81. data/test/counter/test_validator.rb +0 -137
  82. data/test/helper.rb +0 -155
  83. data/test/helpers/fuzzy_assert.rb +0 -89
  84. data/test/helpers/process_extenstion.rb +0 -33
  85. data/test/log/test_console_adapter.rb +0 -117
  86. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  87. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  88. data/test/plugin/data/2010/01/20100102.log +0 -0
  89. data/test/plugin/data/log/bar +0 -0
  90. data/test/plugin/data/log/foo/bar.log +0 -0
  91. data/test/plugin/data/log/foo/bar2 +0 -0
  92. data/test/plugin/data/log/test.log +0 -0
  93. data/test/plugin/data/log_numeric/01.log +0 -0
  94. data/test/plugin/data/log_numeric/02.log +0 -0
  95. data/test/plugin/data/log_numeric/12.log +0 -0
  96. data/test/plugin/data/log_numeric/14.log +0 -0
  97. data/test/plugin/data/sd_file/config +0 -11
  98. data/test/plugin/data/sd_file/config.json +0 -17
  99. data/test/plugin/data/sd_file/config.yaml +0 -11
  100. data/test/plugin/data/sd_file/config.yml +0 -11
  101. data/test/plugin/data/sd_file/invalid_config.yml +0 -7
  102. data/test/plugin/in_tail/test_fifo.rb +0 -121
  103. data/test/plugin/in_tail/test_io_handler.rb +0 -150
  104. data/test/plugin/in_tail/test_position_file.rb +0 -346
  105. data/test/plugin/out_forward/test_ack_handler.rb +0 -140
  106. data/test/plugin/out_forward/test_connection_manager.rb +0 -145
  107. data/test/plugin/out_forward/test_handshake_protocol.rb +0 -112
  108. data/test/plugin/out_forward/test_load_balancer.rb +0 -106
  109. data/test/plugin/out_forward/test_socket_cache.rb +0 -174
  110. data/test/plugin/test_bare_output.rb +0 -131
  111. data/test/plugin/test_base.rb +0 -247
  112. data/test/plugin/test_buf_file.rb +0 -1314
  113. data/test/plugin/test_buf_file_single.rb +0 -898
  114. data/test/plugin/test_buf_memory.rb +0 -42
  115. data/test/plugin/test_buffer.rb +0 -1493
  116. data/test/plugin/test_buffer_chunk.rb +0 -209
  117. data/test/plugin/test_buffer_file_chunk.rb +0 -871
  118. data/test/plugin/test_buffer_file_single_chunk.rb +0 -611
  119. data/test/plugin/test_buffer_memory_chunk.rb +0 -339
  120. data/test/plugin/test_compressable.rb +0 -87
  121. data/test/plugin/test_file_util.rb +0 -96
  122. data/test/plugin/test_filter.rb +0 -368
  123. data/test/plugin/test_filter_grep.rb +0 -697
  124. data/test/plugin/test_filter_parser.rb +0 -731
  125. data/test/plugin/test_filter_record_transformer.rb +0 -577
  126. data/test/plugin/test_filter_stdout.rb +0 -207
  127. data/test/plugin/test_formatter_csv.rb +0 -136
  128. data/test/plugin/test_formatter_hash.rb +0 -38
  129. data/test/plugin/test_formatter_json.rb +0 -61
  130. data/test/plugin/test_formatter_ltsv.rb +0 -70
  131. data/test/plugin/test_formatter_msgpack.rb +0 -28
  132. data/test/plugin/test_formatter_out_file.rb +0 -116
  133. data/test/plugin/test_formatter_single_value.rb +0 -44
  134. data/test/plugin/test_formatter_tsv.rb +0 -76
  135. data/test/plugin/test_in_debug_agent.rb +0 -49
  136. data/test/plugin/test_in_exec.rb +0 -261
  137. data/test/plugin/test_in_forward.rb +0 -1178
  138. data/test/plugin/test_in_gc_stat.rb +0 -62
  139. data/test/plugin/test_in_http.rb +0 -1124
  140. data/test/plugin/test_in_monitor_agent.rb +0 -922
  141. data/test/plugin/test_in_object_space.rb +0 -66
  142. data/test/plugin/test_in_sample.rb +0 -190
  143. data/test/plugin/test_in_syslog.rb +0 -505
  144. data/test/plugin/test_in_tail.rb +0 -3429
  145. data/test/plugin/test_in_tcp.rb +0 -328
  146. data/test/plugin/test_in_udp.rb +0 -296
  147. data/test/plugin/test_in_unix.rb +0 -181
  148. data/test/plugin/test_input.rb +0 -137
  149. data/test/plugin/test_metadata.rb +0 -89
  150. data/test/plugin/test_metrics.rb +0 -294
  151. data/test/plugin/test_metrics_local.rb +0 -96
  152. data/test/plugin/test_multi_output.rb +0 -204
  153. data/test/plugin/test_out_copy.rb +0 -308
  154. data/test/plugin/test_out_exec.rb +0 -312
  155. data/test/plugin/test_out_exec_filter.rb +0 -606
  156. data/test/plugin/test_out_file.rb +0 -1038
  157. data/test/plugin/test_out_forward.rb +0 -1349
  158. data/test/plugin/test_out_http.rb +0 -557
  159. data/test/plugin/test_out_null.rb +0 -105
  160. data/test/plugin/test_out_relabel.rb +0 -28
  161. data/test/plugin/test_out_roundrobin.rb +0 -146
  162. data/test/plugin/test_out_secondary_file.rb +0 -458
  163. data/test/plugin/test_out_stdout.rb +0 -205
  164. data/test/plugin/test_out_stream.rb +0 -103
  165. data/test/plugin/test_output.rb +0 -1334
  166. data/test/plugin/test_output_as_buffered.rb +0 -2024
  167. data/test/plugin/test_output_as_buffered_backup.rb +0 -363
  168. data/test/plugin/test_output_as_buffered_compress.rb +0 -179
  169. data/test/plugin/test_output_as_buffered_overflow.rb +0 -250
  170. data/test/plugin/test_output_as_buffered_retries.rb +0 -966
  171. data/test/plugin/test_output_as_buffered_secondary.rb +0 -882
  172. data/test/plugin/test_output_as_standard.rb +0 -374
  173. data/test/plugin/test_owned_by.rb +0 -34
  174. data/test/plugin/test_parser.rb +0 -399
  175. data/test/plugin/test_parser_apache.rb +0 -42
  176. data/test/plugin/test_parser_apache2.rb +0 -47
  177. data/test/plugin/test_parser_apache_error.rb +0 -45
  178. data/test/plugin/test_parser_csv.rb +0 -200
  179. data/test/plugin/test_parser_json.rb +0 -244
  180. data/test/plugin/test_parser_labeled_tsv.rb +0 -160
  181. data/test/plugin/test_parser_msgpack.rb +0 -127
  182. data/test/plugin/test_parser_multiline.rb +0 -111
  183. data/test/plugin/test_parser_nginx.rb +0 -88
  184. data/test/plugin/test_parser_none.rb +0 -52
  185. data/test/plugin/test_parser_regexp.rb +0 -284
  186. data/test/plugin/test_parser_syslog.rb +0 -650
  187. data/test/plugin/test_parser_tsv.rb +0 -122
  188. data/test/plugin/test_sd_file.rb +0 -228
  189. data/test/plugin/test_sd_srv.rb +0 -230
  190. data/test/plugin/test_storage.rb +0 -166
  191. data/test/plugin/test_storage_local.rb +0 -335
  192. data/test/plugin/test_string_util.rb +0 -26
  193. data/test/plugin_helper/data/cert/cert-key.pem +0 -27
  194. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +0 -19
  195. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +0 -19
  196. data/test/plugin_helper/data/cert/cert.pem +0 -19
  197. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +0 -27
  198. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +0 -20
  199. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +0 -27
  200. data/test/plugin_helper/data/cert/cert_chains/cert.pem +0 -40
  201. data/test/plugin_helper/data/cert/empty.pem +0 -0
  202. data/test/plugin_helper/data/cert/generate_cert.rb +0 -125
  203. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +0 -30
  204. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +0 -27
  205. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +0 -20
  206. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +0 -20
  207. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +0 -30
  208. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +0 -27
  209. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +0 -21
  210. data/test/plugin_helper/data/cert/with_ca/cert.pem +0 -21
  211. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +0 -30
  212. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +0 -27
  213. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +0 -20
  214. data/test/plugin_helper/data/cert/without_ca/cert.pem +0 -20
  215. data/test/plugin_helper/http_server/test_app.rb +0 -65
  216. data/test/plugin_helper/http_server/test_route.rb +0 -32
  217. data/test/plugin_helper/service_discovery/test_manager.rb +0 -93
  218. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +0 -21
  219. data/test/plugin_helper/test_cert_option.rb +0 -25
  220. data/test/plugin_helper/test_child_process.rb +0 -862
  221. data/test/plugin_helper/test_compat_parameters.rb +0 -358
  222. data/test/plugin_helper/test_event_emitter.rb +0 -80
  223. data/test/plugin_helper/test_event_loop.rb +0 -52
  224. data/test/plugin_helper/test_extract.rb +0 -194
  225. data/test/plugin_helper/test_formatter.rb +0 -255
  226. data/test/plugin_helper/test_http_server_helper.rb +0 -372
  227. data/test/plugin_helper/test_inject.rb +0 -561
  228. data/test/plugin_helper/test_metrics.rb +0 -137
  229. data/test/plugin_helper/test_parser.rb +0 -264
  230. data/test/plugin_helper/test_record_accessor.rb +0 -238
  231. data/test/plugin_helper/test_retry_state.rb +0 -1006
  232. data/test/plugin_helper/test_server.rb +0 -1895
  233. data/test/plugin_helper/test_service_discovery.rb +0 -165
  234. data/test/plugin_helper/test_socket.rb +0 -146
  235. data/test/plugin_helper/test_storage.rb +0 -542
  236. data/test/plugin_helper/test_thread.rb +0 -164
  237. data/test/plugin_helper/test_timer.rb +0 -130
  238. data/test/scripts/exec_script.rb +0 -32
  239. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +0 -7
  240. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +0 -7
  241. data/test/scripts/fluent/plugin/formatter_known.rb +0 -8
  242. data/test/scripts/fluent/plugin/out_test.rb +0 -81
  243. data/test/scripts/fluent/plugin/out_test2.rb +0 -80
  244. data/test/scripts/fluent/plugin/parser_known.rb +0 -4
  245. data/test/test_capability.rb +0 -74
  246. data/test/test_clock.rb +0 -164
  247. data/test/test_config.rb +0 -369
  248. data/test/test_configdsl.rb +0 -148
  249. data/test/test_daemonizer.rb +0 -91
  250. data/test/test_engine.rb +0 -203
  251. data/test/test_event.rb +0 -531
  252. data/test/test_event_router.rb +0 -348
  253. data/test/test_event_time.rb +0 -199
  254. data/test/test_file_wrapper.rb +0 -53
  255. data/test/test_filter.rb +0 -121
  256. data/test/test_fluent_log_event_router.rb +0 -99
  257. data/test/test_formatter.rb +0 -369
  258. data/test/test_input.rb +0 -31
  259. data/test/test_log.rb +0 -1076
  260. data/test/test_match.rb +0 -148
  261. data/test/test_mixin.rb +0 -351
  262. data/test/test_msgpack_factory.rb +0 -50
  263. data/test/test_oj_options.rb +0 -55
  264. data/test/test_output.rb +0 -278
  265. data/test/test_plugin.rb +0 -251
  266. data/test/test_plugin_classes.rb +0 -370
  267. data/test/test_plugin_helper.rb +0 -81
  268. data/test/test_plugin_id.rb +0 -119
  269. data/test/test_process.rb +0 -14
  270. data/test/test_root_agent.rb +0 -951
  271. data/test/test_static_config_analysis.rb +0 -177
  272. data/test/test_supervisor.rb +0 -821
  273. data/test/test_test_drivers.rb +0 -136
  274. data/test/test_time_formatter.rb +0 -301
  275. data/test/test_time_parser.rb +0 -362
  276. data/test/test_tls.rb +0 -65
  277. data/test/test_unique_id.rb +0 -47
  278. data/test/test_variable_store.rb +0 -65
@@ -1,258 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/counter/store'
3
- require 'fluent/time'
4
- require 'timecop'
5
-
6
- class CounterStoreTest < ::Test::Unit::TestCase
7
- setup do
8
- @name = 'key_name'
9
- @scope = "server\tworker\tplugin"
10
-
11
- # timecop isn't compatible with EventTime
12
- t = Time.parse('2016-09-22 16:59:59 +0900')
13
- Timecop.freeze(t)
14
- @now = Fluent::EventTime.now
15
- end
16
-
17
- teardown do
18
- Timecop.return
19
- end
20
-
21
- def extract_value_from_counter(counter, key)
22
- store = counter.instance_variable_get(:@storage).instance_variable_get(:@store)
23
- store[key]
24
- end
25
-
26
- def travel(sec)
27
- # Since Timecop.travel() causes test failures on Windows/AppVeyor by inducing
28
- # rounding errors to Time.now, we need to use Timecop.freeze() instead.
29
- Timecop.freeze(Time.now + sec)
30
- end
31
-
32
- sub_test_case 'init' do
33
- setup do
34
- @reset_interval = 10
35
- @store = Fluent::Counter::Store.new
36
- @data = { 'name' => @name, 'reset_interval' => @reset_interval }
37
- @key = Fluent::Counter::Store.gen_key(@scope, @name)
38
- end
39
-
40
- test 'create new value in the counter' do
41
- v = @store.init(@key, @data)
42
-
43
- assert_equal @name, v['name']
44
- assert_equal @reset_interval, v['reset_interval']
45
-
46
- v2 = extract_value_from_counter(@store, @key)
47
- v2 = @store.send(:build_response, v2)
48
- assert_equal v, v2
49
- end
50
-
51
- test 'raise an error when a passed key already exists' do
52
- @store.init(@key, @data)
53
-
54
- assert_raise Fluent::Counter::InvalidParams do
55
- @store.init(@key, @data)
56
- end
57
- end
58
-
59
- test 'return a value when passed key already exists and a ignore option is true' do
60
- v = @store.init(@key, @data)
61
- v1 = extract_value_from_counter(@store, @key)
62
- v1 = @store.send(:build_response, v1)
63
- v2 = @store.init(@key, @data, ignore: true)
64
- assert_equal v, v2
65
- assert_equal v1, v2
66
- end
67
- end
68
-
69
- sub_test_case 'get' do
70
- setup do
71
- @store = Fluent::Counter::Store.new
72
- data = { 'name' => @name, 'reset_interval' => 10 }
73
- @key = Fluent::Counter::Store.gen_key(@scope, @name)
74
- @store.init(@key, data)
75
- end
76
-
77
- test 'return a value from the counter' do
78
- v = extract_value_from_counter(@store, @key)
79
- expected = @store.send(:build_response, v)
80
- assert_equal expected, @store.get(@key)
81
- end
82
-
83
- test 'return a raw value from the counter when raw option is true' do
84
- v = extract_value_from_counter(@store, @key)
85
- assert_equal v, @store.get(@key, raw: true)
86
- end
87
-
88
- test "return nil when a passed key doesn't exist" do
89
- assert_equal nil, @store.get('unknown_key')
90
- end
91
-
92
- test "raise a error when a passed key doesn't exist and raise_error option is true" do
93
- assert_raise Fluent::Counter::UnknownKey do
94
- @store.get('unknown_key', raise_error: true)
95
- end
96
- end
97
- end
98
-
99
- sub_test_case 'key?' do
100
- setup do
101
- @store = Fluent::Counter::Store.new
102
- data = { 'name' => @name, 'reset_interval' => 10 }
103
- @key = Fluent::Counter::Store.gen_key(@scope, @name)
104
- @store.init(@key, data)
105
- end
106
-
107
- test 'return true when passed key exists' do
108
- assert_true @store.key?(@key)
109
- end
110
-
111
- test "return false when passed key doesn't exist" do
112
- assert_true !@store.key?('unknown_key')
113
- end
114
- end
115
-
116
- sub_test_case 'delete' do
117
- setup do
118
- @store = Fluent::Counter::Store.new
119
- data = { 'name' => @name, 'reset_interval' => 10 }
120
- @key = Fluent::Counter::Store.gen_key(@scope, @name)
121
- @init_value = @store.init(@key, data)
122
- end
123
-
124
- test 'delete a value from the counter' do
125
- v = @store.delete(@key)
126
- assert_equal @init_value, v
127
- assert_nil extract_value_from_counter(@store, @key)
128
- end
129
-
130
- test "raise an error when passed key doesn't exist" do
131
- assert_raise Fluent::Counter::UnknownKey do
132
- @store.delete('unknown_key')
133
- end
134
- end
135
- end
136
-
137
- sub_test_case 'inc' do
138
- setup do
139
- @store = Fluent::Counter::Store.new
140
- @init_data = { 'name' => @name, 'reset_interval' => 10 }
141
- @travel_sec = 10
142
- end
143
-
144
- data(
145
- positive: 10,
146
- negative: -10
147
- )
148
- test 'increment or decrement a value in the counter' do |value|
149
- key = Fluent::Counter::Store.gen_key(@scope, @name)
150
- @store.init(key, @init_data)
151
- travel(@travel_sec)
152
- v = @store.inc(key, { 'value' => value })
153
-
154
- assert_equal value, v['total']
155
- assert_equal value, v['current']
156
- assert_equal @now, v['last_reset_at'] # last_reset_at doesn't change
157
-
158
- v1 = extract_value_from_counter(@store, key)
159
- v1 = @store.send(:build_response, v1)
160
- assert_equal v, v1
161
- end
162
-
163
- test "raise an error when passed key doesn't exist" do
164
- assert_raise Fluent::Counter::UnknownKey do
165
- @store.inc('unknown_key', { 'value' => 1 })
166
- end
167
- end
168
-
169
- test 'raise an error when a type of passed value is incompatible with a stored value' do
170
- key1 = Fluent::Counter::Store.gen_key(@scope, @name)
171
- key2 = Fluent::Counter::Store.gen_key(@scope, 'name2')
172
- key3 = Fluent::Counter::Store.gen_key(@scope, 'name3')
173
- v1 = @store.init(key1, @init_data.merge('type' => 'integer'))
174
- v2 = @store.init(key2, @init_data.merge('type' => 'float'))
175
- v3 = @store.init(key3, @init_data.merge('type' => 'numeric'))
176
- assert_equal 'integer', v1['type']
177
- assert_equal 'float', v2['type']
178
- assert_equal 'numeric', v3['type']
179
-
180
- assert_raise Fluent::Counter::InvalidParams do
181
- @store.inc(key1, { 'value' => 1.1 })
182
- end
183
-
184
- assert_raise Fluent::Counter::InvalidParams do
185
- @store.inc(key2, { 'value' => 1 })
186
- end
187
-
188
- assert_nothing_raised do
189
- @store.inc(key3, { 'value' => 1 })
190
- @store.inc(key3, { 'value' => 1.0 })
191
- end
192
- end
193
- end
194
-
195
- sub_test_case 'reset' do
196
- setup do
197
- @store = Fluent::Counter::Store.new
198
- @travel_sec = 10
199
-
200
- @inc_value = 10
201
- @key = Fluent::Counter::Store.gen_key(@scope, @name)
202
- @store.init(@key, { 'name' => @name, 'reset_interval' => 10 })
203
- @store.inc(@key, { 'value' => 10 })
204
- end
205
-
206
- test 'reset a value in the counter' do
207
- travel(@travel_sec)
208
-
209
- v = @store.reset(@key)
210
- assert_equal @travel_sec, v['elapsed_time']
211
- assert_true v['success']
212
- counter = v['counter_data']
213
-
214
- assert_equal @name, counter['name']
215
- assert_equal @inc_value, counter['total']
216
- assert_equal @inc_value, counter['current']
217
- assert_equal 'numeric', counter['type']
218
- assert_equal @now, counter['last_reset_at']
219
- assert_equal 10, counter['reset_interval']
220
-
221
- v1 = extract_value_from_counter(@store, @key)
222
- assert_equal 0, v1['current']
223
- assert_true v1['current'].is_a?(Integer)
224
- assert_equal @inc_value, v1['total']
225
- assert_equal (@now + @travel_sec), Fluent::EventTime.new(*v1['last_reset_at'])
226
- assert_equal (@now + @travel_sec), Fluent::EventTime.new(*v1['last_modified_at'])
227
- end
228
-
229
- test 'reset a value after `reset_interval` passed' do
230
- first_travel_sec = 5
231
- travel(first_travel_sec) # jump time less than reset_interval
232
- v = @store.reset(@key)
233
-
234
- assert_equal false, v['success']
235
- assert_equal first_travel_sec, v['elapsed_time']
236
- store = extract_value_from_counter(@store, @key)
237
- assert_equal 10, store['current']
238
- assert_equal @now, Fluent::EventTime.new(*store['last_reset_at'])
239
-
240
- # time is passed greater than reset_interval
241
- travel(@travel_sec)
242
- v = @store.reset(@key)
243
- assert_true v['success']
244
- assert_equal @travel_sec + first_travel_sec, v['elapsed_time']
245
-
246
- v1 = extract_value_from_counter(@store, @key)
247
- assert_equal 0, v1['current']
248
- assert_equal (@now + @travel_sec + first_travel_sec), Fluent::EventTime.new(*v1['last_reset_at'])
249
- assert_equal (@now + @travel_sec + first_travel_sec), Fluent::EventTime.new(*v1['last_modified_at'])
250
- end
251
-
252
- test "raise an error when passed key doesn't exist" do
253
- assert_raise Fluent::Counter::UnknownKey do
254
- @store.reset('unknown_key')
255
- end
256
- end
257
- end
258
- end
@@ -1,137 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/counter/validator'
3
-
4
- class CounterValidatorTest < ::Test::Unit::TestCase
5
- data(
6
- invalid_name1: '',
7
- invalid_name3: '_',
8
- invalid_name4: 'A',
9
- invalid_name5: 'a*',
10
- invalid_name6: "a\t",
11
- invalid_name7: "\n",
12
- )
13
- test 'invalid name' do |invalid_name|
14
- assert_nil(Fluent::Counter::Validator::VALID_NAME =~ invalid_name)
15
- end
16
-
17
- sub_test_case 'request' do
18
- test 'return an empty array' do
19
- data = { 'id' => 0, 'method' => 'init' }
20
- errors = Fluent::Counter::Validator.request(data)
21
- assert_empty errors
22
- end
23
-
24
- data(
25
- missing_id: [
26
- { 'method' => 'init' },
27
- { 'code' => 'invalid_request', 'message' => 'Request should include `id`' }
28
- ],
29
- missing_method: [
30
- { 'id' => 0 },
31
- { 'code' => 'invalid_request', 'message' => 'Request should include `method`' }
32
- ],
33
- invalid_method: [
34
- { 'id' => 0, 'method' => "A\t" },
35
- { 'code' => 'invalid_request', 'message' => '`method` is the invalid format' }
36
- ],
37
- unknown_method: [
38
- { 'id' => 0, 'method' => 'unknown_method' },
39
- { 'code' => 'method_not_found', 'message' => 'Unknown method name passed: unknown_method' }
40
- ]
41
- )
42
- test 'return an error array' do |(data, expected_error)|
43
- errors = Fluent::Counter::Validator.request(data)
44
- assert_equal [expected_error], errors
45
- end
46
- end
47
-
48
- sub_test_case 'call' do
49
- test "return an error hash when passed method doesn't exist" do
50
- v = Fluent::Counter::Validator.new(:unknown)
51
- success, errors = v.call(['key1'])
52
- assert_empty success
53
- assert_equal 'internal_server_error', errors.first.to_hash['code']
54
- end
55
- end
56
-
57
- test 'validate_empty!' do
58
- v = Fluent::Counter::Validator.new(:empty)
59
- success, errors = v.call([])
60
- assert_empty success
61
- assert_equal [Fluent::Counter::InvalidParams.new('One or more `params` are required')], errors
62
- end
63
- end
64
-
65
- class CounterArrayValidatorTest < ::Test::Unit::TestCase
66
- test 'validate_key!' do
67
- ary = ['key', 100, '_']
68
- error_expected = [
69
- { 'code' => 'invalid_params', 'message' => 'The type of `key` should be String' },
70
- { 'code' => 'invalid_params', 'message' => '`key` is the invalid format' }
71
- ]
72
- v = Fluent::Counter::ArrayValidator.new(:key)
73
- valid_params, errors = v.call(ary)
74
-
75
- assert_equal ['key'], valid_params
76
- assert_equal error_expected, errors.map(&:to_hash)
77
- end
78
- end
79
-
80
- class CounterHashValidatorTest < ::Test::Unit::TestCase
81
- test 'validate_name!' do
82
- hash = [
83
- { 'name' => 'key' },
84
- {},
85
- { 'name' => 10 },
86
- { 'name' => '_' }
87
- ]
88
- error_expected = [
89
- { 'code' => 'invalid_params', 'message' => '`name` is required' },
90
- { 'code' => 'invalid_params', 'message' => 'The type of `name` should be String' },
91
- { 'code' => 'invalid_params', 'message' => '`name` is the invalid format' },
92
- ]
93
- v = Fluent::Counter::HashValidator.new(:name)
94
- success, errors = v.call(hash)
95
-
96
- assert_equal [{ 'name' => 'key' }], success
97
- assert_equal error_expected, errors.map(&:to_hash)
98
- end
99
-
100
- test 'validate_value!' do
101
- hash = [
102
- { 'value' => 1 },
103
- { 'value' => -1 },
104
- {},
105
- { 'value' => 'str' }
106
- ]
107
- error_expected = [
108
- { 'code' => 'invalid_params', 'message' => '`value` is required' },
109
- { 'code' => 'invalid_params', 'message' => 'The type of `value` type should be Numeric' },
110
- ]
111
- v = Fluent::Counter::HashValidator.new(:value)
112
- valid_params, errors = v.call(hash)
113
-
114
- assert_equal [{ 'value' => 1 }, { 'value' => -1 }], valid_params
115
- assert_equal error_expected, errors.map(&:to_hash)
116
- end
117
-
118
- test 'validate_reset_interval!' do
119
- hash = [
120
- { 'reset_interval' => 1 },
121
- { 'reset_interval' => 1.0 },
122
- {},
123
- { 'reset_interval' => -1 },
124
- { 'reset_interval' => 'str' }
125
- ]
126
- error_expected = [
127
- { 'code' => 'invalid_params', 'message' => '`reset_interval` is required' },
128
- { 'code' => 'invalid_params', 'message' => '`reset_interval` should be a positive number' },
129
- { 'code' => 'invalid_params', 'message' => 'The type of `reset_interval` should be Numeric' },
130
- ]
131
- v = Fluent::Counter::HashValidator.new(:reset_interval)
132
- valid_params, errors = v.call(hash)
133
-
134
- assert_equal [{ 'reset_interval' => 1 }, { 'reset_interval' => 1.0 }], valid_params
135
- assert_equal error_expected.map(&:to_hash), errors.map(&:to_hash)
136
- end
137
- end
data/test/helper.rb DELETED
@@ -1,155 +0,0 @@
1
- # simplecov must be loaded before any of target code
2
- if ENV['SIMPLE_COV']
3
- require 'simplecov'
4
- if defined?(SimpleCov::SourceFile)
5
- mod = SimpleCov::SourceFile
6
- def mod.new(*args, &block)
7
- m = allocate
8
- m.instance_eval do
9
- begin
10
- initialize(*args, &block)
11
- rescue Encoding::UndefinedConversionError
12
- @src = "".force_encoding('UTF-8')
13
- end
14
- end
15
- m
16
- end
17
- end
18
- unless SimpleCov.running
19
- SimpleCov.start do
20
- add_filter '/test/'
21
- add_filter '/gems/'
22
- end
23
- end
24
- end
25
-
26
- # Some tests use Hash instead of Element for configure.
27
- # We should rewrite these tests in the future and remove this ad-hoc code
28
- class Hash
29
- def corresponding_proxies
30
- @corresponding_proxies ||= []
31
- end
32
-
33
- def to_masked_element
34
- self
35
- end
36
- end
37
-
38
- require 'rr'
39
- require 'test/unit'
40
- require 'test/unit/rr'
41
- require 'fileutils'
42
- require 'fluent/config/element'
43
- require 'fluent/log'
44
- require 'fluent/test'
45
- require 'fluent/test/helpers'
46
- require 'fluent/plugin/base'
47
- require 'fluent/plugin_id'
48
- require 'fluent/plugin_helper'
49
- require 'fluent/msgpack_factory'
50
- require 'fluent/time'
51
- require 'serverengine'
52
- require_relative 'helpers/fuzzy_assert'
53
- require_relative 'helpers/process_extenstion'
54
-
55
- module Fluent
56
- module Plugin
57
- class TestBase < Base
58
- # a base plugin class, but not input nor output
59
- # mainly for helpers and owned plugins
60
- include PluginId
61
- include PluginLoggerMixin
62
- include PluginHelper::Mixin
63
- end
64
- end
65
- end
66
-
67
- unless defined?(Test::Unit::AssertionFailedError)
68
- class Test::Unit::AssertionFailedError < StandardError
69
- end
70
- end
71
-
72
- include Fluent::Test::Helpers
73
-
74
- def unused_port(num = 1, protocol: :tcp, bind: "0.0.0.0")
75
- case protocol
76
- when :tcp
77
- unused_port_tcp(num)
78
- when :udp
79
- unused_port_udp(num, bind: bind)
80
- else
81
- raise ArgumentError, "unknown protocol: #{protocol}"
82
- end
83
- end
84
-
85
- def unused_port_tcp(num = 1)
86
- ports = []
87
- sockets = []
88
- num.times do
89
- s = TCPServer.open(0)
90
- sockets << s
91
- ports << s.addr[1]
92
- end
93
- sockets.each{|s| s.close }
94
- if num == 1
95
- return ports.first
96
- else
97
- return *ports
98
- end
99
- end
100
-
101
- PORT_RANGE_AVAILABLE = (1024...65535)
102
-
103
- def unused_port_udp(num = 1, bind: "0.0.0.0")
104
- family = IPAddr.new(IPSocket.getaddress(bind)).ipv4? ? ::Socket::AF_INET : ::Socket::AF_INET6
105
- ports = []
106
- sockets = []
107
- while ports.size < num
108
- port = rand(PORT_RANGE_AVAILABLE)
109
- u = UDPSocket.new(family)
110
- if (u.bind(bind, port) rescue nil)
111
- ports << port
112
- sockets << u
113
- else
114
- u.close
115
- end
116
- end
117
- sockets.each{|s| s.close }
118
- if num == 1
119
- return ports.first
120
- else
121
- return *ports
122
- end
123
- end
124
-
125
- def waiting(seconds, logs: nil, plugin: nil)
126
- begin
127
- Timeout.timeout(seconds) do
128
- yield
129
- end
130
- rescue Timeout::Error
131
- if logs
132
- STDERR.print(*logs)
133
- elsif plugin
134
- STDERR.print(*plugin.log.out.logs)
135
- end
136
- raise
137
- end
138
- end
139
-
140
- def ipv6_enabled?
141
- require 'socket'
142
-
143
- begin
144
- TCPServer.open("::1", 0)
145
- true
146
- rescue
147
- false
148
- end
149
- end
150
-
151
- dl_opts = {}
152
- dl_opts[:log_level] = ServerEngine::DaemonLogger::WARN
153
- logdev = Fluent::Test::DummyLogDevice.new
154
- logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
155
- $log ||= Fluent::Log.new(logger)
@@ -1,89 +0,0 @@
1
- require 'test/unit'
2
-
3
- class FuzzyIncludeAssertion
4
- include Test::Unit::Assertions
5
-
6
- def self.assert(expected, actual, message = nil)
7
- new(expected, actual, message).assert
8
- end
9
-
10
- def initialize(expected, actual, message)
11
- @expected = expected
12
- @actual = actual
13
- @message = message
14
- end
15
-
16
- def assert
17
- if collection?
18
- assert_same_collection
19
- else
20
- assert_same_value
21
- end
22
- end
23
-
24
- private
25
-
26
- def assert_same_value
27
- m = "expected(#{@expected}) !== actual(#{@actual.inspect})"
28
- if @message
29
- m = "#{@message}: #{m}"
30
- end
31
- assert_true(@expected === @actual, m)
32
- end
33
-
34
- def assert_same_class
35
- if @expected.class != @actual.class
36
- if (@expected.class.ancestors | @actual.class.ancestors).empty?
37
- assert_equal(@expected.class, @actual.class, @message)
38
- end
39
- end
40
- end
41
-
42
- def assert_same_collection
43
- assert_same_class
44
- assert_same_values
45
- end
46
-
47
- def assert_same_values
48
- if @expected.is_a?(Array)
49
- @expected.each_with_index do |val, i|
50
- self.class.assert(val, @actual[i], @message)
51
- end
52
- else
53
- @expected.each do |key, val|
54
- self.class.assert(val, @actual[key], "#{key}: ")
55
- end
56
- end
57
- end
58
-
59
- def collection?
60
- @actual.is_a?(Array) || @actual.is_a?(Hash)
61
- end
62
- end
63
-
64
- class FuzzyAssertion < FuzzyIncludeAssertion
65
- private
66
-
67
- def assert_same_collection
68
- super
69
- assert_same_keys
70
- end
71
-
72
- def assert_same_keys
73
- if @expected.is_a?(Array)
74
- assert_equal(@expected.size, @actual.size, "expected.size(#{@expected}) != actual.size(#{@expected})")
75
- else
76
- assert_equal(@expected.keys.sort, @actual.keys.sort)
77
- end
78
- end
79
- end
80
-
81
- module FuzzyAssert
82
- def assert_fuzzy_include(left, right, message = nil)
83
- FuzzyIncludeAssertion.new(left, right, message).assert
84
- end
85
-
86
- def assert_fuzzy_equal(left, right, message = nil)
87
- FuzzyAssertion.new(left, right, message).assert
88
- end
89
- end
@@ -1,33 +0,0 @@
1
- require 'timecop'
2
-
3
- module Process
4
- class << self
5
- alias_method :clock_gettime_original, :clock_gettime
6
-
7
- def clock_gettime(clock_id, unit = :float_second)
8
- # now only support CLOCK_REALTIME
9
- if Process::CLOCK_REALTIME == clock_id
10
- t = Time.now
11
-
12
- case unit
13
- when :float_second
14
- t.to_i + t.nsec / 1_000_000_000.0
15
- when :float_millisecond
16
- t.to_i * 1_000 + t.nsec / 1_000_000.0
17
- when :float_microsecond
18
- t.to_i * 1_000_000 + t.nsec / 1_000.0
19
- when :second
20
- t.to_i
21
- when :millisecond
22
- t.to_i * 1000 + t.nsec / 1_000_000
23
- when :microsecond
24
- t.to_i * 1_000_000 + t.nsec / 1_000
25
- when :nanosecond
26
- t.to_i * 1_000_000_000 + t.nsec
27
- end
28
- else
29
- Process.clock_gettime_original(clock_id, unit)
30
- end
31
- end
32
- end
33
- end