fluentd 0.14.4-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (328) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +26 -0
  4. data/.travis.yml +45 -0
  5. data/AUTHORS +2 -0
  6. data/CONTRIBUTING.md +35 -0
  7. data/COPYING +14 -0
  8. data/ChangeLog +276 -0
  9. data/Gemfile +9 -0
  10. data/README.md +51 -0
  11. data/Rakefile +53 -0
  12. data/Vagrantfile +17 -0
  13. data/appveyor.yml +41 -0
  14. data/bin/fluent-debug +5 -0
  15. data/example/copy_roundrobin.conf +39 -0
  16. data/example/filter_stdout.conf +22 -0
  17. data/example/in_forward.conf +11 -0
  18. data/example/in_http.conf +14 -0
  19. data/example/in_out_forward.conf +17 -0
  20. data/example/in_syslog.conf +15 -0
  21. data/example/in_tail.conf +14 -0
  22. data/example/in_tcp.conf +13 -0
  23. data/example/in_udp.conf +13 -0
  24. data/example/multi_filters.conf +61 -0
  25. data/example/out_buffered_null.conf +32 -0
  26. data/example/out_copy.conf +20 -0
  27. data/example/out_file.conf +13 -0
  28. data/example/out_forward.conf +35 -0
  29. data/example/out_forward_buf_file.conf +23 -0
  30. data/example/v0_12_filter.conf +78 -0
  31. data/example/v1_literal_example.conf +36 -0
  32. data/fluent.conf +139 -0
  33. data/fluentd.gemspec +51 -0
  34. data/lib/fluent/agent.rb +194 -0
  35. data/lib/fluent/command/bundler_injection.rb +45 -0
  36. data/lib/fluent/command/cat.rb +319 -0
  37. data/lib/fluent/command/debug.rb +102 -0
  38. data/lib/fluent/command/fluentd.rb +273 -0
  39. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  40. data/lib/fluent/compat/exec_util.rb +129 -0
  41. data/lib/fluent/compat/file_util.rb +54 -0
  42. data/lib/fluent/compat/filter.rb +68 -0
  43. data/lib/fluent/compat/formatter.rb +111 -0
  44. data/lib/fluent/compat/formatter_utils.rb +85 -0
  45. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  46. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  47. data/lib/fluent/compat/input.rb +49 -0
  48. data/lib/fluent/compat/output.rb +677 -0
  49. data/lib/fluent/compat/output_chain.rb +60 -0
  50. data/lib/fluent/compat/parser.rb +180 -0
  51. data/lib/fluent/compat/parser_utils.rb +40 -0
  52. data/lib/fluent/compat/propagate_default.rb +62 -0
  53. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  54. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  55. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  56. data/lib/fluent/compat/socket_util.rb +165 -0
  57. data/lib/fluent/compat/string_util.rb +34 -0
  58. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  59. data/lib/fluent/compat/type_converter.rb +90 -0
  60. data/lib/fluent/config.rb +56 -0
  61. data/lib/fluent/config/basic_parser.rb +123 -0
  62. data/lib/fluent/config/configure_proxy.rb +366 -0
  63. data/lib/fluent/config/dsl.rb +149 -0
  64. data/lib/fluent/config/element.rb +218 -0
  65. data/lib/fluent/config/error.rb +26 -0
  66. data/lib/fluent/config/literal_parser.rb +251 -0
  67. data/lib/fluent/config/parser.rb +107 -0
  68. data/lib/fluent/config/section.rb +212 -0
  69. data/lib/fluent/config/types.rb +136 -0
  70. data/lib/fluent/config/v1_parser.rb +190 -0
  71. data/lib/fluent/configurable.rb +176 -0
  72. data/lib/fluent/daemon.rb +15 -0
  73. data/lib/fluent/engine.rb +220 -0
  74. data/lib/fluent/env.rb +27 -0
  75. data/lib/fluent/event.rb +287 -0
  76. data/lib/fluent/event_router.rb +259 -0
  77. data/lib/fluent/filter.rb +21 -0
  78. data/lib/fluent/formatter.rb +23 -0
  79. data/lib/fluent/input.rb +21 -0
  80. data/lib/fluent/label.rb +38 -0
  81. data/lib/fluent/load.rb +36 -0
  82. data/lib/fluent/log.rb +445 -0
  83. data/lib/fluent/match.rb +141 -0
  84. data/lib/fluent/mixin.rb +31 -0
  85. data/lib/fluent/msgpack_factory.rb +62 -0
  86. data/lib/fluent/output.rb +26 -0
  87. data/lib/fluent/output_chain.rb +23 -0
  88. data/lib/fluent/parser.rb +23 -0
  89. data/lib/fluent/plugin.rb +161 -0
  90. data/lib/fluent/plugin/bare_output.rb +63 -0
  91. data/lib/fluent/plugin/base.rb +130 -0
  92. data/lib/fluent/plugin/buf_file.rb +154 -0
  93. data/lib/fluent/plugin/buf_memory.rb +34 -0
  94. data/lib/fluent/plugin/buffer.rb +603 -0
  95. data/lib/fluent/plugin/buffer/chunk.rb +160 -0
  96. data/lib/fluent/plugin/buffer/file_chunk.rb +323 -0
  97. data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
  98. data/lib/fluent/plugin/exec_util.rb +22 -0
  99. data/lib/fluent/plugin/file_util.rb +22 -0
  100. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  101. data/lib/fluent/plugin/filter.rb +93 -0
  102. data/lib/fluent/plugin/filter_grep.rb +75 -0
  103. data/lib/fluent/plugin/filter_record_transformer.rb +342 -0
  104. data/lib/fluent/plugin/filter_stdout.rb +53 -0
  105. data/lib/fluent/plugin/formatter.rb +45 -0
  106. data/lib/fluent/plugin/formatter_csv.rb +47 -0
  107. data/lib/fluent/plugin/formatter_hash.rb +29 -0
  108. data/lib/fluent/plugin/formatter_json.rb +44 -0
  109. data/lib/fluent/plugin/formatter_ltsv.rb +41 -0
  110. data/lib/fluent/plugin/formatter_msgpack.rb +29 -0
  111. data/lib/fluent/plugin/formatter_out_file.rb +78 -0
  112. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  113. data/lib/fluent/plugin/formatter_stdout.rb +74 -0
  114. data/lib/fluent/plugin/in_debug_agent.rb +64 -0
  115. data/lib/fluent/plugin/in_dummy.rb +135 -0
  116. data/lib/fluent/plugin/in_exec.rb +149 -0
  117. data/lib/fluent/plugin/in_forward.rb +366 -0
  118. data/lib/fluent/plugin/in_gc_stat.rb +52 -0
  119. data/lib/fluent/plugin/in_http.rb +422 -0
  120. data/lib/fluent/plugin/in_monitor_agent.rb +401 -0
  121. data/lib/fluent/plugin/in_object_space.rb +90 -0
  122. data/lib/fluent/plugin/in_syslog.rb +204 -0
  123. data/lib/fluent/plugin/in_tail.rb +838 -0
  124. data/lib/fluent/plugin/in_tcp.rb +41 -0
  125. data/lib/fluent/plugin/in_udp.rb +37 -0
  126. data/lib/fluent/plugin/in_unix.rb +201 -0
  127. data/lib/fluent/plugin/input.rb +33 -0
  128. data/lib/fluent/plugin/multi_output.rb +95 -0
  129. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  130. data/lib/fluent/plugin/out_buffered_stdout.rb +70 -0
  131. data/lib/fluent/plugin/out_copy.rb +42 -0
  132. data/lib/fluent/plugin/out_exec.rb +114 -0
  133. data/lib/fluent/plugin/out_exec_filter.rb +393 -0
  134. data/lib/fluent/plugin/out_file.rb +167 -0
  135. data/lib/fluent/plugin/out_forward.rb +646 -0
  136. data/lib/fluent/plugin/out_null.rb +27 -0
  137. data/lib/fluent/plugin/out_relabel.rb +28 -0
  138. data/lib/fluent/plugin/out_roundrobin.rb +80 -0
  139. data/lib/fluent/plugin/out_stdout.rb +48 -0
  140. data/lib/fluent/plugin/out_stream.rb +130 -0
  141. data/lib/fluent/plugin/output.rb +1020 -0
  142. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  143. data/lib/fluent/plugin/parser.rb +175 -0
  144. data/lib/fluent/plugin/parser_apache.rb +28 -0
  145. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  146. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  147. data/lib/fluent/plugin/parser_csv.rb +33 -0
  148. data/lib/fluent/plugin/parser_json.rb +79 -0
  149. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  150. data/lib/fluent/plugin/parser_multiline.rb +104 -0
  151. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  152. data/lib/fluent/plugin/parser_none.rb +36 -0
  153. data/lib/fluent/plugin/parser_regexp.rb +73 -0
  154. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  155. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  156. data/lib/fluent/plugin/socket_util.rb +22 -0
  157. data/lib/fluent/plugin/storage.rb +84 -0
  158. data/lib/fluent/plugin/storage_local.rb +132 -0
  159. data/lib/fluent/plugin/string_util.rb +22 -0
  160. data/lib/fluent/plugin_helper.rb +42 -0
  161. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  162. data/lib/fluent/plugin_helper/compat_parameters.rb +224 -0
  163. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  164. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  165. data/lib/fluent/plugin_helper/formatter.rb +149 -0
  166. data/lib/fluent/plugin_helper/inject.rb +125 -0
  167. data/lib/fluent/plugin_helper/parser.rb +147 -0
  168. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  169. data/lib/fluent/plugin_helper/storage.rb +331 -0
  170. data/lib/fluent/plugin_helper/thread.rb +147 -0
  171. data/lib/fluent/plugin_helper/timer.rb +90 -0
  172. data/lib/fluent/plugin_id.rb +63 -0
  173. data/lib/fluent/process.rb +504 -0
  174. data/lib/fluent/registry.rb +99 -0
  175. data/lib/fluent/root_agent.rb +314 -0
  176. data/lib/fluent/rpc.rb +94 -0
  177. data/lib/fluent/supervisor.rb +680 -0
  178. data/lib/fluent/system_config.rb +122 -0
  179. data/lib/fluent/test.rb +56 -0
  180. data/lib/fluent/test/base.rb +85 -0
  181. data/lib/fluent/test/driver/base.rb +179 -0
  182. data/lib/fluent/test/driver/base_owned.rb +70 -0
  183. data/lib/fluent/test/driver/base_owner.rb +125 -0
  184. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  185. data/lib/fluent/test/driver/filter.rb +57 -0
  186. data/lib/fluent/test/driver/formatter.rb +30 -0
  187. data/lib/fluent/test/driver/input.rb +31 -0
  188. data/lib/fluent/test/driver/multi_output.rb +52 -0
  189. data/lib/fluent/test/driver/output.rb +76 -0
  190. data/lib/fluent/test/driver/parser.rb +30 -0
  191. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  192. data/lib/fluent/test/filter_test.rb +77 -0
  193. data/lib/fluent/test/formatter_test.rb +65 -0
  194. data/lib/fluent/test/helpers.rb +79 -0
  195. data/lib/fluent/test/input_test.rb +172 -0
  196. data/lib/fluent/test/log.rb +73 -0
  197. data/lib/fluent/test/output_test.rb +156 -0
  198. data/lib/fluent/test/parser_test.rb +70 -0
  199. data/lib/fluent/time.rb +175 -0
  200. data/lib/fluent/timezone.rb +133 -0
  201. data/lib/fluent/unique_id.rb +39 -0
  202. data/lib/fluent/version.rb +21 -0
  203. data/lib/fluent/winsvc.rb +71 -0
  204. data/test/compat/test_calls_super.rb +166 -0
  205. data/test/compat/test_parser.rb +82 -0
  206. data/test/config/assertions.rb +42 -0
  207. data/test/config/test_config_parser.rb +507 -0
  208. data/test/config/test_configurable.rb +1194 -0
  209. data/test/config/test_configure_proxy.rb +386 -0
  210. data/test/config/test_dsl.rb +415 -0
  211. data/test/config/test_element.rb +403 -0
  212. data/test/config/test_literal_parser.rb +297 -0
  213. data/test/config/test_section.rb +184 -0
  214. data/test/config/test_system_config.rb +120 -0
  215. data/test/config/test_types.rb +171 -0
  216. data/test/helper.rb +119 -0
  217. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  218. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  219. data/test/plugin/data/2010/01/20100102.log +0 -0
  220. data/test/plugin/data/log/bar +0 -0
  221. data/test/plugin/data/log/foo/bar.log +0 -0
  222. data/test/plugin/data/log/test.log +0 -0
  223. data/test/plugin/test_bare_output.rb +118 -0
  224. data/test/plugin/test_base.rb +75 -0
  225. data/test/plugin/test_buf_file.rb +571 -0
  226. data/test/plugin/test_buf_memory.rb +42 -0
  227. data/test/plugin/test_buffer.rb +1200 -0
  228. data/test/plugin/test_buffer_chunk.rb +168 -0
  229. data/test/plugin/test_buffer_file_chunk.rb +771 -0
  230. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  231. data/test/plugin/test_file_util.rb +96 -0
  232. data/test/plugin/test_filter.rb +353 -0
  233. data/test/plugin/test_filter_grep.rb +119 -0
  234. data/test/plugin/test_filter_record_transformer.rb +600 -0
  235. data/test/plugin/test_filter_stdout.rb +211 -0
  236. data/test/plugin/test_formatter_csv.rb +94 -0
  237. data/test/plugin/test_formatter_json.rb +30 -0
  238. data/test/plugin/test_formatter_ltsv.rb +52 -0
  239. data/test/plugin/test_formatter_msgpack.rb +28 -0
  240. data/test/plugin/test_formatter_out_file.rb +95 -0
  241. data/test/plugin/test_formatter_single_value.rb +38 -0
  242. data/test/plugin/test_in_debug_agent.rb +28 -0
  243. data/test/plugin/test_in_dummy.rb +188 -0
  244. data/test/plugin/test_in_exec.rb +133 -0
  245. data/test/plugin/test_in_forward.rb +635 -0
  246. data/test/plugin/test_in_gc_stat.rb +39 -0
  247. data/test/plugin/test_in_http.rb +442 -0
  248. data/test/plugin/test_in_monitor_agent.rb +329 -0
  249. data/test/plugin/test_in_object_space.rb +64 -0
  250. data/test/plugin/test_in_syslog.rb +205 -0
  251. data/test/plugin/test_in_tail.rb +1001 -0
  252. data/test/plugin/test_in_tcp.rb +102 -0
  253. data/test/plugin/test_in_udp.rb +121 -0
  254. data/test/plugin/test_in_unix.rb +126 -0
  255. data/test/plugin/test_input.rb +122 -0
  256. data/test/plugin/test_multi_output.rb +180 -0
  257. data/test/plugin/test_out_buffered_null.rb +79 -0
  258. data/test/plugin/test_out_buffered_stdout.rb +122 -0
  259. data/test/plugin/test_out_copy.rb +160 -0
  260. data/test/plugin/test_out_exec.rb +155 -0
  261. data/test/plugin/test_out_exec_filter.rb +262 -0
  262. data/test/plugin/test_out_file.rb +383 -0
  263. data/test/plugin/test_out_forward.rb +590 -0
  264. data/test/plugin/test_out_null.rb +29 -0
  265. data/test/plugin/test_out_relabel.rb +28 -0
  266. data/test/plugin/test_out_roundrobin.rb +146 -0
  267. data/test/plugin/test_out_stdout.rb +92 -0
  268. data/test/plugin/test_out_stream.rb +93 -0
  269. data/test/plugin/test_output.rb +568 -0
  270. data/test/plugin/test_output_as_buffered.rb +1604 -0
  271. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  272. data/test/plugin/test_output_as_buffered_retries.rb +839 -0
  273. data/test/plugin/test_output_as_buffered_secondary.rb +817 -0
  274. data/test/plugin/test_output_as_standard.rb +374 -0
  275. data/test/plugin/test_owned_by.rb +35 -0
  276. data/test/plugin/test_parser_apache.rb +42 -0
  277. data/test/plugin/test_parser_apache2.rb +38 -0
  278. data/test/plugin/test_parser_apache_error.rb +45 -0
  279. data/test/plugin/test_parser_base.rb +32 -0
  280. data/test/plugin/test_parser_csv.rb +104 -0
  281. data/test/plugin/test_parser_json.rb +107 -0
  282. data/test/plugin/test_parser_labeled_tsv.rb +129 -0
  283. data/test/plugin/test_parser_multiline.rb +100 -0
  284. data/test/plugin/test_parser_nginx.rb +48 -0
  285. data/test/plugin/test_parser_none.rb +53 -0
  286. data/test/plugin/test_parser_regexp.rb +277 -0
  287. data/test/plugin/test_parser_syslog.rb +66 -0
  288. data/test/plugin/test_parser_time.rb +46 -0
  289. data/test/plugin/test_parser_tsv.rb +121 -0
  290. data/test/plugin/test_storage.rb +167 -0
  291. data/test/plugin/test_storage_local.rb +8 -0
  292. data/test/plugin/test_string_util.rb +26 -0
  293. data/test/plugin_helper/test_child_process.rb +608 -0
  294. data/test/plugin_helper/test_compat_parameters.rb +242 -0
  295. data/test/plugin_helper/test_event_emitter.rb +51 -0
  296. data/test/plugin_helper/test_event_loop.rb +52 -0
  297. data/test/plugin_helper/test_formatter.rb +252 -0
  298. data/test/plugin_helper/test_inject.rb +487 -0
  299. data/test/plugin_helper/test_parser.rb +263 -0
  300. data/test/plugin_helper/test_retry_state.rb +399 -0
  301. data/test/plugin_helper/test_storage.rb +521 -0
  302. data/test/plugin_helper/test_thread.rb +164 -0
  303. data/test/plugin_helper/test_timer.rb +131 -0
  304. data/test/scripts/exec_script.rb +32 -0
  305. data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
  306. data/test/scripts/fluent/plugin/out_test.rb +81 -0
  307. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  308. data/test/scripts/fluent/plugin/parser_known.rb +4 -0
  309. data/test/test_config.rb +179 -0
  310. data/test/test_configdsl.rb +148 -0
  311. data/test/test_event.rb +329 -0
  312. data/test/test_event_router.rb +331 -0
  313. data/test/test_event_time.rb +184 -0
  314. data/test/test_filter.rb +121 -0
  315. data/test/test_formatter.rb +319 -0
  316. data/test/test_input.rb +31 -0
  317. data/test/test_log.rb +572 -0
  318. data/test/test_match.rb +137 -0
  319. data/test/test_mixin.rb +351 -0
  320. data/test/test_output.rb +214 -0
  321. data/test/test_plugin_classes.rb +136 -0
  322. data/test/test_plugin_helper.rb +81 -0
  323. data/test/test_process.rb +48 -0
  324. data/test/test_root_agent.rb +278 -0
  325. data/test/test_supervisor.rb +339 -0
  326. data/test/test_time_formatter.rb +186 -0
  327. data/test/test_unique_id.rb +47 -0
  328. metadata +823 -0
@@ -0,0 +1,38 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test/driver/formatter'
3
+ require 'fluent/plugin/formatter_single_value'
4
+
5
+ class SingleValueFormatterTest < ::Test::Unit::TestCase
6
+ def create_driver(conf = "")
7
+ Fluent::Test::Driver::Formatter.new(Fluent::Plugin::SingleValueFormatter).configure(conf)
8
+ end
9
+
10
+ def test_config_params
11
+ d = create_driver
12
+ assert_equal "message", d.instance.message_key
13
+ end
14
+
15
+ def test_config_params_message_key
16
+ d = create_driver('message_key' => 'foobar')
17
+ assert_equal "foobar", d.instance.message_key
18
+ end
19
+
20
+ def test_format
21
+ d = create_driver
22
+ formatted = d.instance.format('tag', event_time, {'message' => 'awesome'})
23
+ assert_equal("awesome\n", formatted)
24
+ end
25
+
26
+ def test_format_without_newline
27
+ d = create_driver('add_newline' => 'false')
28
+ formatted = d.instance.format('tag', event_time, {'message' => 'awesome'})
29
+ assert_equal("awesome", formatted)
30
+ end
31
+
32
+ def test_format_with_message_key
33
+ d = create_driver('message_key' => 'foobar')
34
+ formatted = d.instance.format('tag', event_time, {'foobar' => 'foo'})
35
+
36
+ assert_equal("foo\n", formatted)
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test/driver/input'
3
+ require 'fluent/plugin/in_debug_agent'
4
+ require 'fileutils'
5
+
6
+ class DebugAgentInputTest < Test::Unit::TestCase
7
+ def setup
8
+ Fluent::Test.setup
9
+ FileUtils.rm_rf(TMP_DIR)
10
+ FileUtils.mkdir_p(TMP_DIR)
11
+ end
12
+
13
+ TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/in_debug_agent")
14
+
15
+ def create_driver(conf = '')
16
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::DebugAgentInput).configure(conf)
17
+ end
18
+
19
+ def test_unix_path_writable
20
+ assert_nothing_raised do
21
+ create_driver %[unix_path #{TMP_DIR}/test_path]
22
+ end
23
+
24
+ assert_raise(Fluent::ConfigError) do
25
+ create_driver %[unix_path #{TMP_DIR}/does_not_exist/test_path]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,188 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test/driver/input'
3
+ require 'fluent/plugin/in_dummy'
4
+ require 'fileutils'
5
+
6
+ class DummyTest < Test::Unit::TestCase
7
+ def setup
8
+ Fluent::Test.setup
9
+ end
10
+
11
+ def create_driver(conf)
12
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::DummyInput).configure(conf)
13
+ end
14
+
15
+ sub_test_case 'configure' do
16
+ test 'required parameters' do
17
+ assert_raise_message("'tag' parameter is required") do
18
+ create_driver('')
19
+ end
20
+ end
21
+
22
+ test 'tag' do
23
+ d = create_driver(%[
24
+ tag dummy
25
+ ])
26
+ assert_equal "dummy", d.instance.tag
27
+ end
28
+
29
+ config = %[
30
+ tag dummy
31
+ ]
32
+
33
+ test 'auto_increment_key' do
34
+ d = create_driver(config + %[
35
+ auto_increment_key id
36
+ ])
37
+ assert_equal "id", d.instance.auto_increment_key
38
+ end
39
+
40
+ test 'rate' do
41
+ d = create_driver(config + %[
42
+ rate 10
43
+ ])
44
+ assert_equal 10, d.instance.rate
45
+ end
46
+
47
+ test 'dummy' do
48
+ # hash is okay
49
+ d = create_driver(config + %[dummy {"foo":"bar"}])
50
+ assert_equal [{"foo"=>"bar"}], d.instance.dummy
51
+
52
+ # array of hash is okay
53
+ d = create_driver(config + %[dummy [{"foo":"bar"}]])
54
+ assert_equal [{"foo"=>"bar"}], d.instance.dummy
55
+
56
+ assert_raise_message(/JSON::ParserError|got incomplete JSON/) do
57
+ create_driver(config + %[dummy "foo"])
58
+ end
59
+
60
+ assert_raise_message(/is not a hash/) do
61
+ create_driver(config + %[dummy ["foo"]])
62
+ end
63
+ end
64
+ end
65
+
66
+ sub_test_case "emit" do
67
+ config = %[
68
+ tag dummy
69
+ rate 10
70
+ dummy {"foo":"bar"}
71
+ ]
72
+
73
+ test 'simple' do
74
+ d = create_driver(config)
75
+ d.run(timeout: 0.5)
76
+
77
+ d.events.each do |tag, time, record|
78
+ assert_equal("dummy", tag)
79
+ assert_equal({"foo"=>"bar"}, record)
80
+ assert(time.is_a?(Fluent::EventTime))
81
+ end
82
+ end
83
+
84
+ test 'with auto_increment_key' do
85
+ d = create_driver(config + %[auto_increment_key id])
86
+ d.run(timeout: 0.5)
87
+
88
+ d.events.each_with_index do |(tag, _time, record), i|
89
+ assert_equal("dummy", tag)
90
+ assert_equal({"foo"=>"bar", "id"=>i}, record)
91
+ end
92
+ end
93
+ end
94
+
95
+ TEST_PLUGIN_STORAGE_PATH = File.join( File.dirname(File.dirname(__FILE__)), 'tmp', 'in_dummy', 'store' )
96
+ FileUtils.mkdir_p TEST_PLUGIN_STORAGE_PATH
97
+
98
+ sub_test_case "doesn't suspend internal counters in default" do
99
+ config1 = {
100
+ 'tag' => 'dummy',
101
+ 'rate' => '2',
102
+ 'dummy' => '[{"x": 1, "y": "1"}, {"x": 2, "y": "2"}, {"x": 3, "y": "3"}]',
103
+ 'auto_increment_key' => 'id',
104
+ 'suspend' => false,
105
+ }
106
+ conf1 = config_element('ROOT', '', config1, [])
107
+ test "value of auto increment key is not suspended after stop-and-start" do
108
+ assert !File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-01.json'))
109
+
110
+ d1 = create_driver(conf1)
111
+ d1.run(timeout: 0.5) do
112
+ d1.instance.emit(4)
113
+ end
114
+
115
+ first_id1 = d1.events.first[2]['id']
116
+ assert_equal 0, first_id1
117
+
118
+ last_id1 = d1.events.last[2]['id']
119
+ assert { last_id1 > 0 }
120
+
121
+ assert !File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-01.json'))
122
+
123
+ d2 = create_driver(conf1)
124
+ d2.run(timeout: 0.5) do
125
+ d2.instance.emit(4)
126
+ end
127
+
128
+ first_id2 = d2.events.first[2]['id']
129
+ assert_equal 0, first_id2
130
+
131
+ assert !File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-01.json'))
132
+ end
133
+ end
134
+
135
+ sub_test_case "suspend internal counters if suspend is true" do
136
+ setup do
137
+ FileUtils.rm_rf(TEST_PLUGIN_STORAGE_PATH)
138
+ FileUtils.mkdir_p(File.join(TEST_PLUGIN_STORAGE_PATH, 'json'))
139
+ FileUtils.chmod_R(0755, File.join(TEST_PLUGIN_STORAGE_PATH, 'json'))
140
+ end
141
+
142
+ config2 = {
143
+ '@id' => 'test-02',
144
+ 'tag' => 'dummy',
145
+ 'rate' => '2',
146
+ 'dummy' => '[{"x": 1, "y": "1"}, {"x": 2, "y": "2"}, {"x": 3, "y": "3"}]',
147
+ 'auto_increment_key' => 'id',
148
+ 'suspend' => true,
149
+ }
150
+ conf2 = config_element('ROOT', '', config2, [
151
+ config_element(
152
+ 'storage', '',
153
+ {'@type' => 'local',
154
+ '@id' => 'test-02',
155
+ 'path' => File.join(TEST_PLUGIN_STORAGE_PATH,
156
+ 'json', 'test-02.json'),
157
+ 'persistent' => true,
158
+ })
159
+ ])
160
+ test "value of auto increment key is suspended after stop-and-start" do
161
+ assert !File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-02.json'))
162
+
163
+ d1 = create_driver(conf2)
164
+ d1.run(timeout: 0.5) do
165
+ d1.instance.emit(4)
166
+ end
167
+
168
+ first_id1 = d1.events.first[2]['id']
169
+ assert_equal 0, first_id1
170
+
171
+ last_id1 = d1.events.last[2]['id']
172
+ assert { last_id1 > 0 }
173
+
174
+ assert File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-02.json'))
175
+
176
+ d2 = create_driver(conf2)
177
+ d2.run(timeout: 0.5) do
178
+ d2.instance.emit(4)
179
+ end
180
+ d2.events
181
+
182
+ first_id2 = d2.events.first[2]['id']
183
+ assert_equal last_id1 + 1, first_id2
184
+
185
+ assert File.exist?(File.join(TEST_PLUGIN_STORAGE_PATH, 'json', 'test-02.json'))
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,133 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test/driver/input'
3
+ require 'fluent/plugin/in_exec'
4
+ require 'net/http'
5
+
6
+ class ExecInputTest < Test::Unit::TestCase
7
+ def setup
8
+ Fluent::Test.setup
9
+ @test_time = event_time("2011-01-02 13:14:15")
10
+ @script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb'))
11
+ end
12
+
13
+ def create_driver(conf = tsv_config)
14
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::ExecInput).configure(conf)
15
+ end
16
+
17
+ def tsv_config
18
+ %[
19
+ command ruby #{@script} "2011-01-02 13:14:15" 0
20
+ keys time,tag,k1
21
+ time_key time
22
+ tag_key tag
23
+ time_format %Y-%m-%d %H:%M:%S
24
+ run_interval 1s
25
+ ]
26
+ end
27
+
28
+ def json_config
29
+ %[
30
+ command ruby #{@script} #{@test_time} 1
31
+ format json
32
+ tag_key tag
33
+ time_key time
34
+ run_interval 1s
35
+ ]
36
+ end
37
+
38
+ def msgpack_config
39
+ %[
40
+ command ruby #{@script} #{@test_time} 2
41
+ format msgpack
42
+ tag_key tagger
43
+ time_key datetime
44
+ run_interval 1s
45
+ ]
46
+ end
47
+
48
+ def regexp_config
49
+ %[
50
+ command ruby #{@script} "2011-01-02 13:14:15" 3
51
+ format /(?<time>[^\\\]]*) (?<message>[^ ]*)/
52
+ tag regex_tag
53
+ run_interval 1s
54
+ ]
55
+ end
56
+
57
+ def test_configure
58
+ d = create_driver
59
+ assert_equal 'tsv', d.instance.format
60
+ assert_equal ["time","tag","k1"], d.instance.keys
61
+ assert_equal "tag", d.instance.tag_key
62
+ assert_equal "time", d.instance.time_key
63
+ assert_equal "%Y-%m-%d %H:%M:%S", d.instance.time_format
64
+ end
65
+
66
+ def test_configure_with_json
67
+ d = create_driver json_config
68
+ assert_equal 'json', d.instance.format
69
+ assert_equal [], d.instance.keys
70
+ end
71
+
72
+ def test_configure_with_msgpack
73
+ d = create_driver msgpack_config
74
+ assert_equal 'msgpack', d.instance.format
75
+ assert_equal [], d.instance.keys
76
+ end
77
+
78
+ def test_configure_with_regexp
79
+ d = create_driver regexp_config
80
+ assert_equal '/(?<time>[^\]]*) (?<message>[^ ]*)/', d.instance.format
81
+ assert_equal 'regex_tag', d.instance.tag
82
+ end
83
+
84
+ # TODO: Merge following tests into one case with parameters
85
+
86
+ def test_emit
87
+ d = create_driver
88
+
89
+ d.run(expect_emits: 2)
90
+
91
+ assert_equal true, d.events.length > 0
92
+ d.events.each_with_index {|event, i|
93
+ assert_equal ["tag1", @test_time, {"k1"=>"ok"}], event
94
+ assert_equal_event_time(@test_time, event[1])
95
+ }
96
+ end
97
+
98
+ def test_emit_json
99
+ d = create_driver json_config
100
+
101
+ d.run(expect_emits: 2)
102
+
103
+ assert_equal true, d.events.length > 0
104
+ d.events.each_with_index {|event, i|
105
+ assert_equal ["tag1", @test_time, {"k1"=>"ok"}], event
106
+ assert_equal_event_time(@test_time, event[1])
107
+ }
108
+ end
109
+
110
+ def test_emit_msgpack
111
+ d = create_driver msgpack_config
112
+
113
+ d.run(expect_emits: 2)
114
+
115
+ assert_equal true, d.events.length > 0
116
+ d.events.each_with_index {|event, i|
117
+ assert_equal ["tag1", @test_time, {"k1"=>"ok"}], event
118
+ assert_equal_event_time(@test_time, event[1])
119
+ }
120
+ end
121
+
122
+ def test_emit_regexp
123
+ d = create_driver regexp_config
124
+
125
+ d.run(expect_emits: 2)
126
+
127
+ assert_equal true, d.events.length > 0
128
+ d.events.each_with_index {|event, i|
129
+ assert_equal ["regex_tag", @test_time, {"message"=>"hello"}], event
130
+ assert_equal_event_time(@test_time, event[1])
131
+ }
132
+ end
133
+ end
@@ -0,0 +1,635 @@
1
+ require_relative '../helper'
2
+
3
+ require 'fluent/test'
4
+ require 'base64'
5
+
6
+ require 'fluent/env'
7
+ require 'fluent/plugin/in_forward'
8
+
9
+ class ForwardInputTest < Test::Unit::TestCase
10
+ class << self
11
+ def startup
12
+ socket_manager_path = ServerEngine::SocketManager::Server.generate_path
13
+ @server = ServerEngine::SocketManager::Server.open(socket_manager_path)
14
+ ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
15
+ end
16
+
17
+ def shutdown
18
+ @server.close
19
+ end
20
+ end
21
+
22
+ def setup
23
+ Fluent::Test.setup
24
+ @responses = [] # for testing responses after sending data
25
+ end
26
+
27
+ PORT = unused_port
28
+ CONFIG = %[
29
+ port #{PORT}
30
+ bind 127.0.0.1
31
+ ]
32
+ PEERADDR = ['?', '0000', '127.0.0.1', '127.0.0.1']
33
+
34
+ def create_driver(conf=CONFIG)
35
+ Fluent::Test::InputTestDriver.new(Fluent::ForwardInput).configure(conf)
36
+ end
37
+
38
+ def test_configure
39
+ d = create_driver
40
+ assert_equal PORT, d.instance.port
41
+ assert_equal '127.0.0.1', d.instance.bind
42
+ assert_equal 0, d.instance.linger_timeout
43
+ assert_equal 0.5, d.instance.blocking_timeout
44
+ assert !d.instance.backlog
45
+ end
46
+
47
+ # TODO: Will add Loop::run arity check with stub/mock library
48
+
49
+ def connect
50
+ TCPSocket.new('127.0.0.1', PORT)
51
+ end
52
+
53
+ def test_time
54
+ d = create_driver
55
+
56
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
57
+ Fluent::Engine.now = time
58
+
59
+ d.expect_emit "tag1", time, {"a"=>1}
60
+ d.expect_emit "tag2", time, {"a"=>2}
61
+
62
+ d.run do
63
+ d.expected_emits.each {|tag, _time, record|
64
+ send_data Fluent::Engine.msgpack_factory.packer.write([tag, 0, record]).to_s
65
+ }
66
+ end
67
+ end
68
+
69
+ def test_message
70
+ d = create_driver
71
+
72
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
73
+
74
+ d.expect_emit "tag1", time, {"a"=>1}
75
+ d.expect_emit "tag2", time, {"a"=>2}
76
+
77
+ d.run do
78
+ d.expected_emits.each {|tag, _time, record|
79
+ send_data Fluent::Engine.msgpack_factory.packer.write([tag, _time, record]).to_s
80
+ }
81
+ end
82
+ end
83
+
84
+ def test_message_with_time_as_integer
85
+ d = create_driver
86
+
87
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
88
+
89
+ d.expect_emit "tag1", time, {"a"=>1}
90
+ d.expect_emit "tag2", time, {"a"=>2}
91
+
92
+ d.run do
93
+ d.expected_emits.each {|tag, _time, record|
94
+ send_data Fluent::Engine.msgpack_factory.packer.write([tag, _time, record]).to_s
95
+ }
96
+ end
97
+ end
98
+
99
+ def test_message_with_skip_invalid_event
100
+ d = create_driver(CONFIG + "skip_invalid_event true")
101
+
102
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
103
+
104
+ d.expect_emit "tag1", time, {"a" => 1}
105
+ d.expect_emit "tag2", time, {"a" => 2}
106
+
107
+ d.run do
108
+ entries = d.expected_emits.map {|tag, _time, record| [tag, _time, record] }
109
+ # These entries are skipped
110
+ entries << ['tag1', true, {'a' => 3}] << ['tag2', time, 'invalid record']
111
+
112
+ entries.each {|tag, _time, record|
113
+ # Without ack, logs are sometimes not saved to logs during test.
114
+ send_data Fluent::Engine.msgpack_factory.packer.write([tag, _time, record]).to_s, true
115
+ }
116
+ end
117
+
118
+ assert_equal 2, d.instance.log.logs.count { |line| line =~ /got invalid event and drop it/ }
119
+ end
120
+
121
+ def test_forward
122
+ d = create_driver
123
+
124
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
125
+
126
+ d.expect_emit "tag1", time, {"a"=>1}
127
+ d.expect_emit "tag1", time, {"a"=>2}
128
+
129
+ d.run do
130
+ entries = []
131
+ d.expected_emits.each {|tag, _time,record|
132
+ entries << [time, record]
133
+ }
134
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
135
+ end
136
+ end
137
+
138
+ def test_forward_with_time_as_integer
139
+ d = create_driver
140
+
141
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
142
+
143
+ d.expect_emit "tag1", time, {"a"=>1}
144
+ d.expect_emit "tag1", time, {"a"=>2}
145
+
146
+ d.run do
147
+ entries = []
148
+ d.expected_emits.each {|_tag, _time, record|
149
+ entries << [_time, record]
150
+ }
151
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
152
+ end
153
+ end
154
+
155
+ def test_forward_with_skip_invalid_event
156
+ d = create_driver(CONFIG + "skip_invalid_event true")
157
+
158
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
159
+
160
+ d.expect_emit "tag1", time, {"a" => 1}
161
+ d.expect_emit "tag1", time, {"a" => 2}
162
+
163
+ d.run do
164
+ entries = d.expected_emits.map {|_tag, _time, record| [_time, record] }
165
+ # These entries are skipped
166
+ entries << ['invalid time', {'a' => 3}] << [time, 'invalid record']
167
+
168
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
169
+ end
170
+
171
+ assert_equal 2, d.instance.log.logs.count { |line| line =~ /skip invalid event/ }
172
+ end
173
+
174
+ def test_packed_forward
175
+ d = create_driver
176
+
177
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
178
+
179
+ d.expect_emit "tag1", time, {"a"=>1}
180
+ d.expect_emit "tag1", time, {"a"=>2}
181
+
182
+ d.run do
183
+ entries = ''
184
+ d.expected_emits.each {|_tag, _time, record|
185
+ Fluent::Engine.msgpack_factory.packer(entries).write([_time, record]).flush
186
+ }
187
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
188
+ end
189
+ end
190
+
191
+ def test_packed_forward_with_time_as_integer
192
+ d = create_driver
193
+
194
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
195
+
196
+ d.expect_emit "tag1", time, {"a"=>1}
197
+ d.expect_emit "tag1", time, {"a"=>2}
198
+
199
+ d.run do
200
+ entries = ''
201
+ d.expected_emits.each {|_tag, _time, record|
202
+ Fluent::Engine.msgpack_factory.packer(entries).write([_time, record]).flush
203
+ }
204
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
205
+ end
206
+ end
207
+
208
+ def test_packed_forward_with_skip_invalid_event
209
+ d = create_driver(CONFIG + "skip_invalid_event true")
210
+
211
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
212
+
213
+ d.expect_emit "tag1", time, {"a" => 1}
214
+ d.expect_emit "tag1", time, {"a" => 2}
215
+
216
+ d.run do
217
+ entries = d.expected_emits.map {|_tag , _time, record| [_time, record] }
218
+ # These entries are skipped
219
+ entries << ['invalid time', {'a' => 3}] << [time, 'invalid record']
220
+
221
+ packed_entries = ''
222
+ entries.each {|_time, record|
223
+ Fluent::Engine.msgpack_factory.packer(packed_entries).write([_time, record]).flush
224
+ }
225
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", packed_entries]).to_s
226
+ end
227
+
228
+ assert_equal 2, d.instance.log.logs.count { |line| line =~ /skip invalid event/ }
229
+ end
230
+
231
+ def test_message_json
232
+ d = create_driver
233
+
234
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
235
+
236
+ d.expect_emit "tag1", time, {"a"=>1}
237
+ d.expect_emit "tag2", time, {"a"=>2}
238
+
239
+ d.run do
240
+ d.expected_emits.each {|tag, _time, record|
241
+ send_data [tag, _time, record].to_json
242
+ }
243
+ end
244
+ end
245
+
246
+ def test_set_size_to_option
247
+ d = create_driver
248
+
249
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
250
+ events = [
251
+ ["tag1", time, {"a"=>1}],
252
+ ["tag1", time, {"a"=>2}]
253
+ ]
254
+
255
+ entries = ''
256
+ events.each {|_tag, _time, record|
257
+ [_time, record].to_msgpack(entries)
258
+ }
259
+
260
+ chunk = ["tag1", entries, { 'size' => events.length }].to_msgpack
261
+
262
+ d.run do
263
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
264
+ option = d.instance.send(:on_message, obj, chunk.size, PEERADDR)
265
+ assert_equal option['size'], events.length
266
+ end
267
+ end
268
+ end
269
+
270
+ def test_send_large_chunk_warning
271
+ d = create_driver(CONFIG + %[
272
+ chunk_size_warn_limit 16M
273
+ chunk_size_limit 32M
274
+ ])
275
+
276
+ time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
277
+
278
+ # generate over 16M chunk
279
+ str = "X" * 1024 * 1024
280
+ chunk = [ "test.tag", (0...16).map{|i| [time + i, {"data" => str}] } ].to_msgpack
281
+ assert chunk.size > (16 * 1024 * 1024)
282
+ assert chunk.size < (32 * 1024 * 1024)
283
+
284
+ d.run do
285
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
286
+ d.instance.send(:on_message, obj, chunk.size, PEERADDR)
287
+ end
288
+ end
289
+
290
+ # check emitted data
291
+ emits = d.emits
292
+ assert_equal 16, emits.size
293
+ assert emits.map(&:first).all?{|t| t == "test.tag" }
294
+ assert_equal (0...16).to_a, emits.map{|_tag, t, _record| t - time }
295
+
296
+ # check log
297
+ assert d.instance.log.logs.select{|line|
298
+ line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_warn_limit':/ &&
299
+ line =~ / tag="test.tag" source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" limit=16777216 size=16777501/
300
+ }.size == 1, "large chunk warning is not logged"
301
+ end
302
+
303
+ def test_send_large_chunk_only_warning
304
+ d = create_driver(CONFIG + %[
305
+ chunk_size_warn_limit 16M
306
+ ])
307
+ time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
308
+
309
+ # generate over 16M chunk
310
+ str = "X" * 1024 * 1024
311
+ chunk = [ "test.tag", (0...16).map{|i| [time + i, {"data" => str}] } ].to_msgpack
312
+
313
+ d.run do
314
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
315
+ d.instance.send(:on_message, obj, chunk.size, PEERADDR)
316
+ end
317
+ end
318
+
319
+ # check log
320
+ assert d.instance.log.logs.select{ |line|
321
+ line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_warn_limit':/ &&
322
+ line =~ / tag="test.tag" source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" limit=16777216 size=16777501/
323
+ }.size == 1, "large chunk warning is not logged"
324
+ end
325
+
326
+ def test_send_large_chunk_limit
327
+ d = create_driver(CONFIG + %[
328
+ chunk_size_warn_limit 16M
329
+ chunk_size_limit 32M
330
+ ])
331
+
332
+ time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
333
+
334
+ # generate over 32M chunk
335
+ str = "X" * 1024 * 1024
336
+ chunk = [ "test.tag", (0...32).map{|i| [time + i, {"data" => str}] } ].to_msgpack
337
+ assert chunk.size > (32 * 1024 * 1024)
338
+
339
+ # d.run => send_data
340
+ d.run do
341
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
342
+ d.instance.send(:on_message, obj, chunk.size, PEERADDR)
343
+ end
344
+ end
345
+
346
+ # check emitted data
347
+ emits = d.emits
348
+ assert_equal 0, emits.size
349
+
350
+ # check log
351
+ assert d.instance.log.logs.select{|line|
352
+ line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_limit', dropped:/ &&
353
+ line =~ / tag="test.tag" source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" limit=33554432 size=33554989/
354
+ }.size == 1, "large chunk warning is not logged"
355
+ end
356
+
357
+ data('string chunk' => 'broken string',
358
+ 'integer chunk' => 10)
359
+ def test_send_broken_chunk(data)
360
+ d = create_driver
361
+
362
+ # d.run => send_data
363
+ d.run do
364
+ d.instance.send(:on_message, data, 1000000000, PEERADDR)
365
+ end
366
+
367
+ # check emitted data
368
+ emits = d.emits
369
+ assert_equal 0, emits.size
370
+
371
+ # check log
372
+ assert d.instance.log.logs.select{|line|
373
+ line =~ / \[warn\]: incoming chunk is broken: source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" msg=#{data.inspect}/
374
+ }.size == 1, "should not accept broken chunk"
375
+ end
376
+
377
+ def test_respond_to_message_requiring_ack
378
+ d = create_driver
379
+
380
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
381
+
382
+ events = [
383
+ ["tag1", time, {"a"=>1}],
384
+ ["tag2", time, {"a"=>2}]
385
+ ]
386
+ d.expected_emits_length = events.length
387
+
388
+ expected_acks = []
389
+
390
+ d.run do
391
+ events.each {|tag, _time, record|
392
+ op = { 'chunk' => Base64.encode64(record.object_id.to_s) }
393
+ expected_acks << op['chunk']
394
+ send_data [tag, _time, record, op].to_msgpack, true
395
+ }
396
+ end
397
+
398
+ assert_equal events, d.emits
399
+ assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
400
+ end
401
+
402
+ # FIX: response is not pushed into @responses because IO.select has been blocked until InputForward shutdowns
403
+ def test_respond_to_forward_requiring_ack
404
+ d = create_driver
405
+
406
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
407
+
408
+ events = [
409
+ ["tag1", time, {"a"=>1}],
410
+ ["tag1", time, {"a"=>2}]
411
+ ]
412
+ d.expected_emits_length = events.length
413
+
414
+ expected_acks = []
415
+
416
+ d.run do
417
+ entries = []
418
+ events.each {|_tag, _time, record|
419
+ entries << [time, record]
420
+ }
421
+ op = { 'chunk' => Base64.encode64(entries.object_id.to_s) }
422
+ expected_acks << op['chunk']
423
+ send_data ["tag1", entries, op].to_msgpack, true
424
+ end
425
+
426
+ assert_equal events, d.emits
427
+ assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
428
+ end
429
+
430
+ def test_respond_to_packed_forward_requiring_ack
431
+ d = create_driver
432
+
433
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
434
+
435
+ events = [
436
+ ["tag1", time, {"a"=>1}],
437
+ ["tag1", time, {"a"=>2}]
438
+ ]
439
+ d.expected_emits_length = events.length
440
+
441
+ expected_acks = []
442
+
443
+ d.run do
444
+ entries = ''
445
+ events.each {|_tag, _time, record|
446
+ [_time, record].to_msgpack(entries)
447
+ }
448
+ op = { 'chunk' => Base64.encode64(entries.object_id.to_s) }
449
+ expected_acks << op['chunk']
450
+ send_data ["tag1", entries, op].to_msgpack, true
451
+ end
452
+
453
+ assert_equal events, d.emits
454
+ assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
455
+ end
456
+
457
+ def test_respond_to_message_json_requiring_ack
458
+ d = create_driver
459
+
460
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
461
+
462
+ events = [
463
+ ["tag1", time, {"a"=>1}],
464
+ ["tag2", time, {"a"=>2}]
465
+ ]
466
+ d.expected_emits_length = events.length
467
+
468
+ expected_acks = []
469
+
470
+ d.run do
471
+ events.each {|tag, _time, record|
472
+ op = { 'chunk' => Base64.encode64(record.object_id.to_s) }
473
+ expected_acks << op['chunk']
474
+ send_data [tag, _time, record, op].to_json, true
475
+ }
476
+ end
477
+
478
+ assert_equal events, d.emits
479
+ assert_equal expected_acks, @responses.map { |res| JSON.parse(res)['ack'] }
480
+ end
481
+
482
+ def test_not_respond_to_message_not_requiring_ack
483
+ d = create_driver
484
+
485
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
486
+
487
+ events = [
488
+ ["tag1", time, {"a"=>1}],
489
+ ["tag2", time, {"a"=>2}]
490
+ ]
491
+ d.expected_emits_length = events.length
492
+
493
+ d.run do
494
+ events.each {|tag, _time, record|
495
+ send_data [tag, _time, record].to_msgpack, true
496
+ }
497
+ end
498
+
499
+ assert_equal events, d.emits
500
+ assert_equal [nil, nil], @responses
501
+ end
502
+
503
+ def test_not_respond_to_forward_not_requiring_ack
504
+ d = create_driver
505
+
506
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
507
+
508
+ events = [
509
+ ["tag1", time, {"a"=>1}],
510
+ ["tag1", time, {"a"=>2}]
511
+ ]
512
+ d.expected_emits_length = events.length
513
+
514
+ d.run do
515
+ entries = []
516
+ events.each {|_tag, _time, record|
517
+ entries << [_time, record]
518
+ }
519
+ send_data ["tag1", entries].to_msgpack, true
520
+ end
521
+
522
+ assert_equal events, d.emits
523
+ assert_equal [nil], @responses
524
+ end
525
+
526
+ def test_not_respond_to_packed_forward_not_requiring_ack
527
+ d = create_driver
528
+
529
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
530
+
531
+ events = [
532
+ ["tag1", time, {"a"=>1}],
533
+ ["tag1", time, {"a"=>2}]
534
+ ]
535
+ d.expected_emits_length = events.length
536
+
537
+ d.run do
538
+ entries = ''
539
+ events.each {|_tag, _time, record|
540
+ [_time, record].to_msgpack(entries)
541
+ }
542
+ send_data ["tag1", entries].to_msgpack, true
543
+ end
544
+
545
+ assert_equal events, d.emits
546
+ assert_equal [nil], @responses
547
+ end
548
+
549
+ def test_not_respond_to_message_json_not_requiring_ack
550
+ d = create_driver
551
+
552
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
553
+
554
+ events = [
555
+ ["tag1", time, {"a"=>1}],
556
+ ["tag2", time, {"a"=>2}]
557
+ ]
558
+ d.expected_emits_length = events.length
559
+
560
+ d.run do
561
+ events.each {|tag, _time, record|
562
+ send_data [tag, _time, record].to_json, true
563
+ }
564
+ end
565
+
566
+ assert_equal events, d.emits
567
+ assert_equal [nil, nil], @responses
568
+ end
569
+
570
+ def send_data(data, try_to_receive_response=false, response_timeout=1)
571
+ io = connect
572
+ begin
573
+ io.write data
574
+ if try_to_receive_response
575
+ if IO.select([io], nil, nil, response_timeout)
576
+ res = io.recv(1024)
577
+ end
578
+ # timeout means no response, so push nil to @responses
579
+ end
580
+ ensure
581
+ io.close
582
+ end
583
+ @responses << res if try_to_receive_response
584
+ end
585
+
586
+ # TODO: Use sub_test_case. Currently Errno::EADDRINUSE happens inside sub_test_case
587
+ test 'message protocol with source_hostname_key' do
588
+ execute_test { |events|
589
+ events.each { |tag, time, record|
590
+ send_data [tag, time, record].to_msgpack
591
+ }
592
+ }
593
+ end
594
+
595
+ test 'forward protocol with source_hostname_key' do
596
+ execute_test { |events|
597
+ entries = []
598
+ events.each {|tag,time,record|
599
+ entries << [time, record]
600
+ }
601
+ send_data ['tag1', entries].to_msgpack
602
+ }
603
+ end
604
+
605
+ test 'packed forward protocol with source_hostname_key' do
606
+ execute_test { |events|
607
+ entries = ''
608
+ events.each { |tag, time, record|
609
+ Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush
610
+ }
611
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
612
+ }
613
+ end
614
+
615
+ def execute_test(&block)
616
+ d = create_driver(CONFIG + 'source_hostname_key source')
617
+
618
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
619
+ events = [
620
+ ["tag1", time, {"a"=>1}],
621
+ ["tag1", time, {"a"=>2}]
622
+ ]
623
+ d.expected_emits_length = events.length
624
+
625
+ d.run do
626
+ block.call(events)
627
+ end
628
+
629
+ d.emits.each { |tag, _time, record|
630
+ assert_true record.has_key?('source')
631
+ }
632
+ end
633
+
634
+ # TODO heartbeat
635
+ end