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,155 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test/driver/output'
3
+ require 'fluent/plugin/out_exec'
4
+ require 'fileutils'
5
+
6
+ class ExecOutputTest < Test::Unit::TestCase
7
+ def setup
8
+ Fluent::Test.setup
9
+ FileUtils.rm_rf(TMP_DIR, secure: true)
10
+ if File.exist?(TMP_DIR)
11
+ # ensure files are closed for Windows, on which deleted files
12
+ # are still visible from filesystem
13
+ GC.start(full_mark: true, immediate_sweep: true)
14
+ FileUtils.remove_entry_secure(TMP_DIR)
15
+ end
16
+ FileUtils.mkdir_p(TMP_DIR)
17
+ end
18
+
19
+ TMP_DIR = File.dirname(__FILE__) + "/../tmp/out_exec#{ENV['TEST_ENV_NUMBER']}"
20
+
21
+ CONFIG = %[
22
+ buffer_path #{TMP_DIR}/buffer
23
+ command cat >#{TMP_DIR}/out
24
+ localtime
25
+ ]
26
+ TSV_CONFIG = %[
27
+ keys "time,tag,k1"
28
+ tag_key "tag"
29
+ time_key "time"
30
+ time_format %Y-%m-%d %H:%M:%S
31
+ ]
32
+
33
+ def create_driver(conf = TSV_CONFIG)
34
+ config = CONFIG + conf
35
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::ExecOutput).configure(config)
36
+ end
37
+
38
+ def create_test_case
39
+ time = Time.parse("2011-01-02 13:14:15").to_i
40
+ tests = [{"k1"=>"v1","kx"=>"vx"}, {"k1"=>"v2","kx"=>"vx"}]
41
+ return time, tests
42
+ end
43
+
44
+ def test_configure
45
+ d = create_driver
46
+
47
+ assert_equal ["time","tag","k1"], d.instance.keys
48
+ assert_equal "tag", d.instance.tag_key
49
+ assert_equal "time", d.instance.time_key
50
+ assert_equal "%Y-%m-%d %H:%M:%S", d.instance.time_format
51
+ assert_equal true, d.instance.localtime
52
+ end
53
+
54
+ def test_configure_with_compat_buffer_parameters
55
+ conf = TSV_CONFIG + %[
56
+ buffer_type memory
57
+ time_slice_format %Y%m%d%H
58
+ num_threads 5
59
+ buffer_chunk_limit 50m
60
+ buffer_queue_limit 128
61
+ flush_at_shutdown yes
62
+ ]
63
+ d = create_driver(conf)
64
+ assert_equal 3600, d.instance.buffer_config.timekey
65
+ assert_equal 5, d.instance.buffer_config.flush_thread_count
66
+ assert_equal 50*1024*1024, d.instance.buffer.chunk_limit_size
67
+ assert_equal 128, d.instance.buffer.queue_length_limit
68
+ assert d.instance.buffer_config.flush_at_shutdown
69
+ end
70
+
71
+ def test_format
72
+ d = create_driver
73
+ time, tests = create_test_case
74
+
75
+ d.run(default_tag: 'test') do
76
+ d.feed(time, tests[0])
77
+ d.feed(time, tests[1])
78
+ end
79
+
80
+ assert_equal %[2011-01-02 13:14:15\ttest\tv1\n], d.formatted[0]
81
+ assert_equal %[2011-01-02 13:14:15\ttest\tv2\n], d.formatted[1]
82
+ end
83
+
84
+ def test_format_json
85
+ d = create_driver("format json")
86
+ time, tests = create_test_case
87
+
88
+ d.run(default_tag: 'test') do
89
+ d.feed(time, tests[0])
90
+ d.feed(time, tests[1])
91
+ end
92
+
93
+ assert_equal Yajl.dump(tests[0]) + "\n", d.formatted[0]
94
+ assert_equal Yajl.dump(tests[1]) + "\n", d.formatted[1]
95
+ end
96
+
97
+ def test_format_msgpack
98
+ d = create_driver("format msgpack")
99
+ time, tests = create_test_case
100
+
101
+ d.run(default_tag: 'test') do
102
+ d.feed(time, tests[0])
103
+ d.feed(time, tests[1])
104
+ end
105
+
106
+ assert_equal tests[0].to_msgpack, d.formatted[0]
107
+ assert_equal tests[1].to_msgpack, d.formatted[1]
108
+ end
109
+
110
+ def test_format_time
111
+ config = %[
112
+ keys "time,tag,k1"
113
+ tag_key "tag"
114
+ time_key "time"
115
+ time_format %Y-%m-%d %H:%M:%S.%3N
116
+ ]
117
+ d = create_driver(config)
118
+
119
+ time = event_time("2011-01-02 13:14:15.123")
120
+ tests = [{"k1"=>"v1","kx"=>"vx"}, {"k1"=>"v2","kx"=>"vx"}]
121
+
122
+ d.run(default_tag: 'test') do
123
+ d.feed(time, tests[0])
124
+ d.feed(time, tests[1])
125
+ end
126
+
127
+ assert_equal %[2011-01-02 13:14:15.123\ttest\tv1\n], d.formatted[0]
128
+ assert_equal %[2011-01-02 13:14:15.123\ttest\tv2\n], d.formatted[1]
129
+ end
130
+
131
+ def test_write
132
+ d = create_driver
133
+ time, tests = create_test_case
134
+
135
+ d.run(default_tag: 'test', flush: true) do
136
+ d.feed(time, tests[0])
137
+ d.feed(time, tests[1])
138
+ end
139
+
140
+ expect_path = "#{TMP_DIR}/out"
141
+
142
+ waiting(10, plugin: d.instance) do
143
+ sleep(0.1) until File.exist?(expect_path)
144
+ end
145
+
146
+ assert_equal true, File.exist?(expect_path)
147
+
148
+ data = File.read(expect_path)
149
+ expect_data =
150
+ %[2011-01-02 13:14:15\ttest\tv1\n] +
151
+ %[2011-01-02 13:14:15\ttest\tv2\n]
152
+ assert_equal expect_data, data
153
+ end
154
+ end
155
+
@@ -0,0 +1,262 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test'
3
+ require 'fluent/plugin/out_exec_filter'
4
+ require 'fileutils'
5
+
6
+ class ExecFilterOutputTest < Test::Unit::TestCase
7
+ def setup
8
+ Fluent::Test.setup
9
+ end
10
+
11
+ CONFIG = %[
12
+ command cat
13
+ in_keys time_in,tag,k1
14
+ out_keys time_out,tag,k2
15
+ tag_key tag
16
+ in_time_key time_in
17
+ out_time_key time_out
18
+ time_format %Y-%m-%d %H:%M:%S
19
+ localtime
20
+ num_children 3
21
+ ]
22
+
23
+ def create_driver(conf = CONFIG, tag = 'test')
24
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::ExecFilterOutput, tag).configure(conf)
25
+ end
26
+
27
+ def sed_unbuffered_support?
28
+ @sed_unbuffered_support ||= lambda {
29
+ system("echo xxx | sed --unbuffered -l -e 's/x/y/g' >#{IO::NULL} 2>&1")
30
+ $?.success?
31
+ }.call
32
+ end
33
+
34
+ def sed_unbuffered_option
35
+ sed_unbuffered_support? ? '--unbuffered' : ''
36
+ end
37
+
38
+ def test_configure
39
+ d = create_driver
40
+
41
+ assert d.instance.instance_eval{ @overrides_format_stream }
42
+
43
+ assert_equal ["time_in","tag","k1"], d.instance.in_keys
44
+ assert_equal ["time_out","tag","k2"], d.instance.out_keys
45
+ assert_equal "tag", d.instance.out_tag_key
46
+ assert_equal "tag", d.instance.in_tag_key
47
+ assert_equal "time_in", d.instance.in_time_key
48
+ assert_equal "time_out", d.instance.out_time_key
49
+ assert_equal "%Y-%m-%d %H:%M:%S", d.instance.in_time_format
50
+ assert_equal "%Y-%m-%d %H:%M:%S", d.instance.out_time_format
51
+ assert_equal true, d.instance.localtime
52
+ assert_equal 3, d.instance.num_children
53
+
54
+ d = create_driver %[
55
+ command sed -l -e s/foo/bar/
56
+ in_keys time,k1
57
+ out_keys time,k2
58
+ tag xxx
59
+ time_key time
60
+ num_children 3
61
+ ]
62
+ assert_equal "sed -l -e s/foo/bar/", d.instance.command
63
+
64
+ d = create_driver(CONFIG + %[
65
+ remove_prefix before
66
+ add_prefix after
67
+ ])
68
+ assert_equal "before", d.instance.remove_prefix
69
+ assert_equal "after" , d.instance.add_prefix
70
+ end
71
+
72
+ def test_emit_1
73
+ d = create_driver
74
+
75
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15")
76
+
77
+ d.expected_emits_length = 2
78
+ d.run do
79
+ d.emit({"k1"=>1}, time)
80
+ d.emit({"k1"=>2}, time)
81
+ end
82
+
83
+ emits = d.emits
84
+ assert_equal 2, emits.length
85
+ assert_equal ["test", time, {"k2"=>"1"}], emits[0]
86
+ assert_equal_event_time time, emits[0][1]
87
+ assert_equal ["test", time, {"k2"=>"2"}], emits[1]
88
+ assert_equal_event_time time, emits[1][1]
89
+ end
90
+
91
+ def test_emit_2
92
+ d = create_driver %[
93
+ command cat
94
+ in_keys time,k1
95
+ out_keys time,k2
96
+ tag xxx
97
+ time_key time
98
+ num_children 3
99
+ ]
100
+
101
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15")
102
+
103
+ d.expected_emits_length = 2
104
+ d.run do
105
+ d.emit({"k1"=>1}, time)
106
+ d.emit({"k1"=>2}, time)
107
+ end
108
+
109
+ emits = d.emits
110
+ assert_equal 2, emits.length
111
+ assert_equal ["xxx", time, {"k2"=>"1"}], emits[0]
112
+ assert_equal_event_time time, emits[0][1]
113
+ assert_equal ["xxx", time, {"k2"=>"2"}], emits[1]
114
+ assert_equal_event_time time, emits[1][1]
115
+ end
116
+
117
+ def test_emit_3
118
+ d = create_driver %[
119
+ command grep --line-buffered -v poo
120
+ in_keys time,val1
121
+ out_keys time,val2
122
+ tag xxx
123
+ time_key time
124
+ num_children 3
125
+ ]
126
+
127
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15")
128
+
129
+ d.expected_emits_length = 2
130
+ d.run do
131
+ d.emit({"val1"=>"sed-ed value foo"}, time)
132
+ d.emit({"val1"=>"sed-ed value poo"}, time)
133
+ end
134
+
135
+ emits = d.emits
136
+ assert_equal 1, emits.length
137
+ assert_equal ["xxx", time, {"val2"=>"sed-ed value foo"}], emits[0]
138
+ assert_equal_event_time time, emits[0][1]
139
+
140
+ d = create_driver %[
141
+ command sed #{sed_unbuffered_option} -l -e s/foo/bar/
142
+ in_keys time,val1
143
+ out_keys time,val2
144
+ tag xxx
145
+ time_key time
146
+ num_children 3
147
+ ]
148
+
149
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15")
150
+
151
+ d.expected_emits_length = 2
152
+ d.run do
153
+ d.emit({"val1"=>"sed-ed value foo"}, time)
154
+ d.emit({"val1"=>"sed-ed value poo"}, time)
155
+ end
156
+
157
+ emits = d.emits
158
+ assert_equal 2, emits.length
159
+ assert_equal ["xxx", time, {"val2"=>"sed-ed value bar"}], emits[0]
160
+ assert_equal_event_time time, emits[0][1]
161
+ assert_equal ["xxx", time, {"val2"=>"sed-ed value poo"}], emits[1]
162
+ assert_equal_event_time time, emits[1][1]
163
+ end
164
+
165
+ def test_emit_4
166
+ d = create_driver(%[
167
+ command sed #{sed_unbuffered_option} -l -e s/foo/bar/
168
+ in_keys tag,time,val1
169
+ remove_prefix input
170
+ out_keys tag,time,val2
171
+ add_prefix output
172
+ tag_key tag
173
+ time_key time
174
+ num_children 3
175
+ ], 'input.test')
176
+
177
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15")
178
+
179
+ d.expected_emits_length = 2
180
+ d.run do
181
+ d.emit({"val1"=>"sed-ed value foo"}, time)
182
+ d.emit({"val1"=>"sed-ed value poo"}, time)
183
+ end
184
+
185
+ emits = d.emits
186
+ assert_equal 2, emits.length
187
+ assert_equal ["output.test", time, {"val2"=>"sed-ed value bar"}], emits[0]
188
+ assert_equal_event_time time, emits[0][1]
189
+ assert_equal ["output.test", time, {"val2"=>"sed-ed value poo"}], emits[1]
190
+ assert_equal_event_time time, emits[1][1]
191
+ end
192
+
193
+ def test_json_1
194
+ d = create_driver(%[
195
+ command cat
196
+ in_keys message
197
+ out_format json
198
+ time_key time
199
+ tag_key tag
200
+ ], 'input.test')
201
+
202
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15")
203
+
204
+ d.expected_emits_length = 1
205
+ d.run do
206
+ d.emit({"message"=>%[{"time":#{time},"tag":"t1","k1":"v1"}]}, time+10)
207
+ end
208
+
209
+ emits = d.emits
210
+ assert_equal 1, emits.length
211
+ assert_equal ["t1", time, {"k1"=>"v1"}], emits[0]
212
+ assert_equal_event_time time, emits[0][1]
213
+ end
214
+
215
+ def test_json_with_float_time
216
+ d = create_driver(%[
217
+ command cat
218
+ in_keys message
219
+ out_format json
220
+ time_key time
221
+ tag_key tag
222
+ ], 'input.test')
223
+
224
+ float_time = Time.parse("2011-01-02 13:14:15").to_f
225
+ time = Fluent::EventTime.from_time(Time.at(float_time))
226
+
227
+ d.expected_emits_length = 1
228
+ d.run do
229
+ d.emit({"message"=>%[{"time":#{float_time},"tag":"t1","k1":"v1"}]}, time+10)
230
+ end
231
+
232
+ emits = d.emits
233
+ assert_equal 1, emits.length
234
+ assert_equal ["t1", time, {"k1"=>"v1"}], emits[0]
235
+ assert_equal_event_time time, emits[0][1]
236
+ end
237
+
238
+ def test_json_with_time_format
239
+ d = create_driver(%[
240
+ command cat
241
+ in_keys message
242
+ out_format json
243
+ time_key time
244
+ time_format %d/%b/%Y %H:%M:%S.%N %z
245
+ tag_key tag
246
+ ], 'input.test')
247
+
248
+ time_str = "28/Feb/2013 12:00:00.123456789 +0900"
249
+ time = Fluent::EventTime.from_time(Time.strptime(time_str, "%d/%b/%Y %H:%M:%S.%N %z"))
250
+
251
+ d.expected_emits_length = 1
252
+ d.run do
253
+ d.emit({"message"=>%[{"time":"#{time_str}","tag":"t1","k1":"v1"}]}, time+10)
254
+ end
255
+
256
+ emits = d.emits
257
+ assert_equal 1, emits.length
258
+ assert_equal ["t1", time, {"k1"=>"v1"}], emits[0]
259
+ assert_equal_event_time time, emits[0][1]
260
+ end
261
+ end
262
+
@@ -0,0 +1,383 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test'
3
+ require 'fluent/plugin/out_file'
4
+ require 'fileutils'
5
+ require 'time'
6
+
7
+ class FileOutputTest < Test::Unit::TestCase
8
+ def setup
9
+ Fluent::Test.setup
10
+ FileUtils.rm_rf(TMP_DIR)
11
+ FileUtils.mkdir_p(TMP_DIR)
12
+ end
13
+
14
+ TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/out_file#{ENV['TEST_ENV_NUMBER']}")
15
+ SYMLINK_PATH = File.expand_path("#{TMP_DIR}/current")
16
+
17
+ CONFIG = %[
18
+ path #{TMP_DIR}/out_file_test
19
+ compress gz
20
+ utc
21
+ ]
22
+
23
+ def create_driver(conf = CONFIG)
24
+ Fluent::Test::TimeSlicedOutputTestDriver.new(Fluent::FileOutput).configure(conf)
25
+ end
26
+
27
+ def with_timezone(timezone = 'UTC', &block)
28
+ old = ENV['TZ']
29
+ ENV['TZ'] = timezone
30
+ output = yield
31
+ ENV['TZ'] = old
32
+ output
33
+ end
34
+
35
+ def test_configure
36
+ d = create_driver %[
37
+ path test_path
38
+ compress gz
39
+ ]
40
+ assert_equal 'test_path', d.instance.path
41
+ assert_equal :gz, d.instance.compress
42
+ end
43
+
44
+ def test_path_writable
45
+ assert_nothing_raised do
46
+ create_driver %[path #{TMP_DIR}/test_path]
47
+ end
48
+
49
+ assert_nothing_raised do
50
+ FileUtils.mkdir_p("#{TMP_DIR}/test_dir")
51
+ File.chmod(0777, "#{TMP_DIR}/test_dir")
52
+ create_driver %[path #{TMP_DIR}/test_dir/foo/bar/baz]
53
+ end
54
+
55
+ assert_raise(Fluent::ConfigError) do
56
+ FileUtils.mkdir_p("#{TMP_DIR}/test_dir")
57
+ File.chmod(0555, "#{TMP_DIR}/test_dir")
58
+ create_driver %[path #{TMP_DIR}/test_dir/foo/bar/baz]
59
+ end
60
+ end
61
+
62
+ def test_default_localtime
63
+ d = create_driver(%[path #{TMP_DIR}/out_file_test])
64
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
65
+
66
+ with_timezone(Fluent.windows? ? 'NST-8' : 'Asia/Taipei') do
67
+ d.emit({"a"=>1}, time)
68
+ d.expect_format %[2011-01-02T21:14:15+08:00\ttest\t{"a":1}\n]
69
+ d.run
70
+ end
71
+ end
72
+
73
+ def test_format
74
+ d = create_driver
75
+
76
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
77
+ d.emit({"a"=>1}, time)
78
+ d.emit({"a"=>2}, time)
79
+
80
+ d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
81
+ d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
82
+
83
+ d.run
84
+ end
85
+
86
+ def test_timezone_1
87
+ d = create_driver %[
88
+ path #{TMP_DIR}/out_file_test
89
+ timezone Asia/Taipei
90
+ ]
91
+
92
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
93
+
94
+ d.emit({"a"=>1}, time)
95
+ d.expect_format %[2011-01-02T21:14:15+08:00\ttest\t{"a":1}\n]
96
+ d.run
97
+ end
98
+
99
+ def test_timezone_2
100
+ d = create_driver %[
101
+ path #{TMP_DIR}/out_file_test
102
+ timezone -03:30
103
+ ]
104
+
105
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
106
+
107
+ d.emit({"a"=>1}, time)
108
+ d.expect_format %[2011-01-02T09:44:15-03:30\ttest\t{"a":1}\n]
109
+ d.run
110
+ end
111
+
112
+ def test_timezone_invalid
113
+ assert_raise(Fluent::ConfigError) do
114
+ create_driver %[
115
+ path #{TMP_DIR}/out_file_test
116
+ timezone Invalid/Invalid
117
+ ]
118
+ end
119
+ end
120
+
121
+ def check_gzipped_result(path, expect)
122
+ # Zlib::GzipReader has a bug of concatenated file: https://bugs.ruby-lang.org/issues/9790
123
+ # Following code from https://www.ruby-forum.com/topic/971591#979520
124
+ result = ''
125
+ File.open(path, "rb") { |io|
126
+ loop do
127
+ gzr = Zlib::GzipReader.new(io)
128
+ result << gzr.read
129
+ unused = gzr.unused
130
+ gzr.finish
131
+ break if unused.nil?
132
+ io.pos -= unused.length
133
+ end
134
+ }
135
+
136
+ assert_equal expect, result
137
+ end
138
+
139
+ def test_write
140
+ d = create_driver
141
+
142
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
143
+ d.emit({"a"=>1}, time)
144
+ d.emit({"a"=>2}, time)
145
+
146
+ # FileOutput#write returns path
147
+ paths = d.run
148
+ expect_paths = ["#{TMP_DIR}/out_file_test.20110102_0.log.gz"]
149
+ assert_equal expect_paths, paths
150
+
151
+ check_gzipped_result(paths[0], %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n])
152
+ end
153
+
154
+ class TestWithSystem < self
155
+ TMP_DIR_WITH_SYSTEM = File.expand_path(File.dirname(__FILE__) + "/../tmp/out_file_system#{ENV['TEST_ENV_NUMBER']}")
156
+ # 0750 interprets as "488". "488".to_i(8) # => 4. So, it makes wrong permission. Umm....
157
+ OVERRIDE_DIR_PERMISSION = 750
158
+ OVERRIDE_FILE_PERMISSION = 0620
159
+ CONFIG_WITH_SYSTEM = %[
160
+ path #{TMP_DIR_WITH_SYSTEM}/out_file_test
161
+ compress gz
162
+ utc
163
+ <system>
164
+ file_permission #{OVERRIDE_FILE_PERMISSION}
165
+ dir_permission #{OVERRIDE_DIR_PERMISSION}
166
+ </system>
167
+ ]
168
+
169
+ def setup
170
+ omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
171
+ FileUtils.rm_rf(TMP_DIR_WITH_SYSTEM)
172
+ end
173
+
174
+ def parse_system(text)
175
+ basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
176
+ Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
177
+ end
178
+
179
+ def test_write_with_system
180
+ system_conf = parse_system(CONFIG_WITH_SYSTEM)
181
+ sc = Fluent::SystemConfig.new(system_conf)
182
+ Fluent::Engine.init(sc)
183
+ d = create_driver CONFIG_WITH_SYSTEM
184
+
185
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
186
+ d.emit({"a"=>1}, time)
187
+ d.emit({"a"=>2}, time)
188
+
189
+ # FileOutput#write returns path
190
+ paths = d.run
191
+ expect_paths = ["#{TMP_DIR_WITH_SYSTEM}/out_file_test.20110102_0.log.gz"]
192
+ assert_equal expect_paths, paths
193
+
194
+ check_gzipped_result(paths[0], %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n])
195
+ dir_mode = "%o" % File::stat(TMP_DIR_WITH_SYSTEM).mode
196
+ assert_equal(OVERRIDE_DIR_PERMISSION, dir_mode[-3, 3].to_i)
197
+ file_mode = "%o" % File::stat(paths[0]).mode
198
+ assert_equal(OVERRIDE_FILE_PERMISSION, file_mode[-3, 3].to_i)
199
+ end
200
+ end
201
+
202
+ def test_write_with_format_json
203
+ d = create_driver [CONFIG, 'format json', 'include_time_key true', 'time_as_epoch'].join("\n")
204
+
205
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
206
+ d.emit({"a"=>1}, time)
207
+ d.emit({"a"=>2}, time)
208
+
209
+ # FileOutput#write returns path
210
+ paths = d.run
211
+ check_gzipped_result(paths[0], %[#{Yajl.dump({"a" => 1, 'time' => time})}\n] + %[#{Yajl.dump({"a" => 2, 'time' => time})}\n])
212
+ end
213
+
214
+ def test_write_with_format_ltsv
215
+ d = create_driver [CONFIG, 'format ltsv', 'include_time_key true'].join("\n")
216
+
217
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
218
+ d.emit({"a"=>1}, time)
219
+ d.emit({"a"=>2}, time)
220
+
221
+ # FileOutput#write returns path
222
+ paths = d.run
223
+ check_gzipped_result(paths[0], %[a:1\ttime:2011-01-02T13:14:15Z\n] + %[a:2\ttime:2011-01-02T13:14:15Z\n])
224
+ end
225
+
226
+ def test_write_with_format_single_value
227
+ d = create_driver [CONFIG, 'format single_value', 'message_key a'].join("\n")
228
+
229
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
230
+ d.emit({"a"=>1}, time)
231
+ d.emit({"a"=>2}, time)
232
+
233
+ # FileOutput#write returns path
234
+ paths = d.run
235
+ check_gzipped_result(paths[0], %[1\n] + %[2\n])
236
+ end
237
+
238
+ def test_write_path_increment
239
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
240
+ formatted_lines = %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
241
+
242
+ write_once = ->(){
243
+ d = create_driver
244
+ d.emit({"a"=>1}, time)
245
+ d.emit({"a"=>2}, time)
246
+ d.run
247
+ }
248
+
249
+ assert !File.exist?("#{TMP_DIR}/out_file_test.20110102_0.log.gz")
250
+
251
+ # FileOutput#write returns path
252
+ paths = write_once.call
253
+ assert_equal ["#{TMP_DIR}/out_file_test.20110102_0.log.gz"], paths
254
+ check_gzipped_result(paths[0], formatted_lines)
255
+ assert_equal 1, Dir.glob("#{TMP_DIR}/out_file_test.*").size
256
+
257
+ paths = write_once.call
258
+ assert_equal ["#{TMP_DIR}/out_file_test.20110102_1.log.gz"], paths
259
+ check_gzipped_result(paths[0], formatted_lines)
260
+ assert_equal 2, Dir.glob("#{TMP_DIR}/out_file_test.*").size
261
+
262
+ paths = write_once.call
263
+ assert_equal ["#{TMP_DIR}/out_file_test.20110102_2.log.gz"], paths
264
+ check_gzipped_result(paths[0], formatted_lines)
265
+ assert_equal 3, Dir.glob("#{TMP_DIR}/out_file_test.*").size
266
+ end
267
+
268
+ def test_write_with_append
269
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
270
+ formatted_lines = %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
271
+
272
+ write_once = ->(){
273
+ d = create_driver %[
274
+ path #{TMP_DIR}/out_file_test
275
+ compress gz
276
+ utc
277
+ append true
278
+ ]
279
+ d.emit({"a"=>1}, time)
280
+ d.emit({"a"=>2}, time)
281
+ d.run
282
+ }
283
+
284
+ # FileOutput#write returns path
285
+ paths = write_once.call
286
+ assert_equal ["#{TMP_DIR}/out_file_test.20110102.log.gz"], paths
287
+ check_gzipped_result(paths[0], formatted_lines)
288
+ paths = write_once.call
289
+ assert_equal ["#{TMP_DIR}/out_file_test.20110102.log.gz"], paths
290
+ check_gzipped_result(paths[0], formatted_lines * 2)
291
+ paths = write_once.call
292
+ assert_equal ["#{TMP_DIR}/out_file_test.20110102.log.gz"], paths
293
+ check_gzipped_result(paths[0], formatted_lines * 3)
294
+ end
295
+
296
+ def test_write_with_symlink
297
+ omit "Windows doesn't support symlink" if Fluent.windows?
298
+ conf = CONFIG + %[
299
+ symlink_path #{SYMLINK_PATH}
300
+ ]
301
+ symlink_path = "#{SYMLINK_PATH}"
302
+
303
+ d = Fluent::Test::TestDriver.new(Fluent::FileOutput).configure(conf)
304
+
305
+ begin
306
+ d.instance.start
307
+ 10.times { sleep 0.05 }
308
+
309
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
310
+ es = Fluent::OneEventStream.new(time, {"a"=>1})
311
+ d.instance.emit_events('tag', es)
312
+
313
+ assert File.exist?(symlink_path)
314
+ assert File.symlink?(symlink_path)
315
+
316
+ es = Fluent::OneEventStream.new(event_time("2011-01-03 14:15:16 UTC"), {"a"=>2})
317
+ d.instance.emit_events('tag', es)
318
+
319
+ assert File.exist?(symlink_path)
320
+ assert File.symlink?(symlink_path)
321
+
322
+ meta = d.instance.metadata('tag', event_time("2011-01-03 14:15:16 UTC"), {})
323
+ assert_equal d.instance.buffer.instance_eval{ @stage[meta].path }, File.readlink(symlink_path)
324
+ ensure
325
+ d.instance.shutdown
326
+ FileUtils.rm_rf(symlink_path)
327
+ end
328
+ end
329
+
330
+ sub_test_case 'path' do
331
+ test 'normal' do
332
+ d = create_driver(%[
333
+ path #{TMP_DIR}/out_file_test
334
+ time_slice_format %Y-%m-%d-%H
335
+ utc true
336
+ ])
337
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
338
+ d.emit({"a"=>1}, time)
339
+ # FileOutput#write returns path
340
+ paths = d.run
341
+ assert_equal ["#{TMP_DIR}/out_file_test.2011-01-02-13_0.log"], paths
342
+ end
343
+
344
+ test 'normal with append' do
345
+ d = create_driver(%[
346
+ path #{TMP_DIR}/out_file_test
347
+ time_slice_format %Y-%m-%d-%H
348
+ utc true
349
+ append true
350
+ ])
351
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
352
+ d.emit({"a"=>1}, time)
353
+ paths = d.run
354
+ assert_equal ["#{TMP_DIR}/out_file_test.2011-01-02-13.log"], paths
355
+ end
356
+
357
+ test '*' do
358
+ d = create_driver(%[
359
+ path #{TMP_DIR}/out_file_test.*.txt
360
+ time_slice_format %Y-%m-%d-%H
361
+ utc true
362
+ ])
363
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
364
+ d.emit({"a"=>1}, time)
365
+ paths = d.run
366
+ assert_equal ["#{TMP_DIR}/out_file_test.2011-01-02-13_0.txt"], paths
367
+ end
368
+
369
+ test '* with append' do
370
+ d = create_driver(%[
371
+ path #{TMP_DIR}/out_file_test.*.txt
372
+ time_slice_format %Y-%m-%d-%H
373
+ utc true
374
+ append true
375
+ ])
376
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
377
+ d.emit({"a"=>1}, time)
378
+ paths = d.run
379
+ assert_equal ["#{TMP_DIR}/out_file_test.2011-01-02-13.txt"], paths
380
+ end
381
+ end
382
+ end
383
+