fluentd 0.12.40 → 0.14.0

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 (252) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +33 -21
  5. data/CONTRIBUTING.md +1 -0
  6. data/ChangeLog +810 -237
  7. data/README.md +0 -25
  8. data/Rakefile +2 -1
  9. data/Vagrantfile +17 -0
  10. data/appveyor.yml +35 -0
  11. data/example/filter_stdout.conf +5 -5
  12. data/example/in_forward.conf +2 -2
  13. data/example/in_http.conf +2 -2
  14. data/example/in_out_forward.conf +17 -0
  15. data/example/in_syslog.conf +2 -2
  16. data/example/in_tail.conf +2 -2
  17. data/example/in_tcp.conf +2 -2
  18. data/example/in_udp.conf +2 -2
  19. data/example/out_copy.conf +4 -4
  20. data/example/out_file.conf +2 -2
  21. data/example/out_forward.conf +2 -2
  22. data/example/out_forward_buf_file.conf +23 -0
  23. data/example/v0_12_filter.conf +8 -8
  24. data/fluent.conf +29 -0
  25. data/fluentd.gemspec +18 -11
  26. data/lib/fluent/agent.rb +60 -58
  27. data/lib/fluent/command/cat.rb +1 -1
  28. data/lib/fluent/command/debug.rb +7 -5
  29. data/lib/fluent/command/fluentd.rb +97 -2
  30. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  31. data/lib/fluent/compat/filter.rb +50 -0
  32. data/lib/fluent/compat/formatter.rb +109 -0
  33. data/lib/fluent/compat/input.rb +50 -0
  34. data/lib/fluent/compat/output.rb +617 -0
  35. data/lib/fluent/compat/output_chain.rb +60 -0
  36. data/lib/fluent/compat/parser.rb +163 -0
  37. data/lib/fluent/compat/propagate_default.rb +62 -0
  38. data/lib/fluent/config.rb +23 -20
  39. data/lib/fluent/config/configure_proxy.rb +119 -70
  40. data/lib/fluent/config/dsl.rb +5 -18
  41. data/lib/fluent/config/element.rb +72 -8
  42. data/lib/fluent/config/error.rb +0 -3
  43. data/lib/fluent/config/literal_parser.rb +0 -2
  44. data/lib/fluent/config/parser.rb +4 -4
  45. data/lib/fluent/config/section.rb +39 -28
  46. data/lib/fluent/config/types.rb +2 -13
  47. data/lib/fluent/config/v1_parser.rb +1 -3
  48. data/lib/fluent/configurable.rb +48 -16
  49. data/lib/fluent/daemon.rb +15 -0
  50. data/lib/fluent/engine.rb +26 -52
  51. data/lib/fluent/env.rb +6 -4
  52. data/lib/fluent/event.rb +58 -11
  53. data/lib/fluent/event_router.rb +5 -5
  54. data/lib/fluent/filter.rb +2 -50
  55. data/lib/fluent/formatter.rb +4 -293
  56. data/lib/fluent/input.rb +2 -32
  57. data/lib/fluent/label.rb +2 -2
  58. data/lib/fluent/load.rb +3 -2
  59. data/lib/fluent/log.rb +107 -38
  60. data/lib/fluent/match.rb +0 -36
  61. data/lib/fluent/mixin.rb +117 -7
  62. data/lib/fluent/msgpack_factory.rb +62 -0
  63. data/lib/fluent/output.rb +7 -612
  64. data/lib/fluent/output_chain.rb +23 -0
  65. data/lib/fluent/parser.rb +4 -800
  66. data/lib/fluent/plugin.rb +100 -121
  67. data/lib/fluent/plugin/bare_output.rb +63 -0
  68. data/lib/fluent/plugin/base.rb +121 -0
  69. data/lib/fluent/plugin/buf_file.rb +101 -182
  70. data/lib/fluent/plugin/buf_memory.rb +9 -92
  71. data/lib/fluent/plugin/buffer.rb +473 -0
  72. data/lib/fluent/plugin/buffer/chunk.rb +135 -0
  73. data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
  74. data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
  75. data/lib/fluent/plugin/exec_util.rb +80 -75
  76. data/lib/fluent/plugin/file_util.rb +33 -28
  77. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  78. data/lib/fluent/plugin/filter.rb +51 -0
  79. data/lib/fluent/plugin/filter_grep.rb +13 -40
  80. data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
  81. data/lib/fluent/plugin/formatter.rb +93 -0
  82. data/lib/fluent/plugin/formatter_csv.rb +48 -0
  83. data/lib/fluent/plugin/formatter_hash.rb +32 -0
  84. data/lib/fluent/plugin/formatter_json.rb +47 -0
  85. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  86. data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
  87. data/lib/fluent/plugin/formatter_out_file.rb +45 -0
  88. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  89. data/lib/fluent/plugin/formatter_stdout.rb +39 -0
  90. data/lib/fluent/plugin/in_debug_agent.rb +4 -0
  91. data/lib/fluent/plugin/in_dummy.rb +22 -18
  92. data/lib/fluent/plugin/in_exec.rb +18 -8
  93. data/lib/fluent/plugin/in_forward.rb +36 -79
  94. data/lib/fluent/plugin/in_gc_stat.rb +4 -0
  95. data/lib/fluent/plugin/in_http.rb +21 -18
  96. data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
  97. data/lib/fluent/plugin/in_object_space.rb +6 -1
  98. data/lib/fluent/plugin/in_stream.rb +7 -3
  99. data/lib/fluent/plugin/in_syslog.rb +46 -95
  100. data/lib/fluent/plugin/in_tail.rb +51 -595
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -14
  103. data/lib/fluent/plugin/input.rb +33 -0
  104. data/lib/fluent/plugin/multi_output.rb +95 -0
  105. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  106. data/lib/fluent/plugin/out_copy.rb +11 -7
  107. data/lib/fluent/plugin/out_exec.rb +15 -11
  108. data/lib/fluent/plugin/out_exec_filter.rb +18 -10
  109. data/lib/fluent/plugin/out_file.rb +34 -5
  110. data/lib/fluent/plugin/out_forward.rb +19 -9
  111. data/lib/fluent/plugin/out_null.rb +0 -14
  112. data/lib/fluent/plugin/out_roundrobin.rb +11 -7
  113. data/lib/fluent/plugin/out_stdout.rb +5 -7
  114. data/lib/fluent/plugin/out_stream.rb +3 -1
  115. data/lib/fluent/plugin/output.rb +979 -0
  116. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  117. data/lib/fluent/plugin/parser.rb +244 -0
  118. data/lib/fluent/plugin/parser_apache.rb +24 -0
  119. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  120. data/lib/fluent/plugin/parser_apache_error.rb +21 -0
  121. data/lib/fluent/plugin/parser_csv.rb +31 -0
  122. data/lib/fluent/plugin/parser_json.rb +79 -0
  123. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  124. data/lib/fluent/plugin/parser_multiline.rb +102 -0
  125. data/lib/fluent/plugin/parser_nginx.rb +24 -0
  126. data/lib/fluent/plugin/parser_none.rb +36 -0
  127. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  128. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  129. data/lib/fluent/plugin/socket_util.rb +120 -114
  130. data/lib/fluent/plugin/storage.rb +84 -0
  131. data/lib/fluent/plugin/storage_local.rb +116 -0
  132. data/lib/fluent/plugin/string_util.rb +16 -13
  133. data/lib/fluent/plugin_helper.rb +39 -0
  134. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  135. data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
  136. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  137. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  138. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  139. data/lib/fluent/plugin_helper/storage.rb +308 -0
  140. data/lib/fluent/plugin_helper/thread.rb +147 -0
  141. data/lib/fluent/plugin_helper/timer.rb +85 -0
  142. data/lib/fluent/plugin_id.rb +63 -0
  143. data/lib/fluent/process.rb +21 -30
  144. data/lib/fluent/registry.rb +21 -9
  145. data/lib/fluent/root_agent.rb +115 -40
  146. data/lib/fluent/supervisor.rb +330 -320
  147. data/lib/fluent/system_config.rb +42 -18
  148. data/lib/fluent/test.rb +6 -1
  149. data/lib/fluent/test/base.rb +23 -3
  150. data/lib/fluent/test/driver/base.rb +247 -0
  151. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  152. data/lib/fluent/test/driver/filter.rb +35 -0
  153. data/lib/fluent/test/driver/input.rb +31 -0
  154. data/lib/fluent/test/driver/output.rb +78 -0
  155. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  156. data/lib/fluent/test/filter_test.rb +0 -1
  157. data/lib/fluent/test/formatter_test.rb +2 -1
  158. data/lib/fluent/test/input_test.rb +23 -17
  159. data/lib/fluent/test/output_test.rb +28 -39
  160. data/lib/fluent/test/parser_test.rb +1 -1
  161. data/lib/fluent/time.rb +104 -1
  162. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  163. data/lib/fluent/version.rb +1 -1
  164. data/lib/fluent/winsvc.rb +72 -0
  165. data/test/compat/test_calls_super.rb +164 -0
  166. data/test/config/test_config_parser.rb +83 -0
  167. data/test/config/test_configurable.rb +547 -274
  168. data/test/config/test_configure_proxy.rb +146 -29
  169. data/test/config/test_dsl.rb +3 -181
  170. data/test/config/test_element.rb +274 -0
  171. data/test/config/test_literal_parser.rb +1 -1
  172. data/test/config/test_section.rb +79 -7
  173. data/test/config/test_system_config.rb +21 -0
  174. data/test/config/test_types.rb +3 -26
  175. data/test/helper.rb +78 -8
  176. data/test/plugin/test_bare_output.rb +118 -0
  177. data/test/plugin/test_base.rb +75 -0
  178. data/test/plugin/test_buf_file.rb +420 -521
  179. data/test/plugin/test_buf_memory.rb +32 -194
  180. data/test/plugin/test_buffer.rb +981 -0
  181. data/test/plugin/test_buffer_chunk.rb +110 -0
  182. data/test/plugin/test_buffer_file_chunk.rb +770 -0
  183. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  184. data/test/plugin/test_filter.rb +255 -0
  185. data/test/plugin/test_filter_grep.rb +2 -73
  186. data/test/plugin/test_filter_record_transformer.rb +24 -68
  187. data/test/plugin/test_filter_stdout.rb +6 -6
  188. data/test/plugin/test_in_debug_agent.rb +2 -0
  189. data/test/plugin/test_in_dummy.rb +11 -17
  190. data/test/plugin/test_in_exec.rb +6 -25
  191. data/test/plugin/test_in_forward.rb +112 -151
  192. data/test/plugin/test_in_gc_stat.rb +2 -0
  193. data/test/plugin/test_in_http.rb +106 -157
  194. data/test/plugin/test_in_object_space.rb +21 -5
  195. data/test/plugin/test_in_stream.rb +14 -13
  196. data/test/plugin/test_in_syslog.rb +30 -275
  197. data/test/plugin/test_in_tail.rb +95 -234
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -13
  200. data/test/plugin/test_input.rb +122 -0
  201. data/test/plugin/test_multi_output.rb +180 -0
  202. data/test/plugin/test_out_buffered_null.rb +79 -0
  203. data/test/plugin/test_out_copy.rb +15 -2
  204. data/test/plugin/test_out_exec.rb +75 -25
  205. data/test/plugin/test_out_exec_filter.rb +74 -8
  206. data/test/plugin/test_out_file.rb +61 -7
  207. data/test/plugin/test_out_forward.rb +92 -15
  208. data/test/plugin/test_out_roundrobin.rb +1 -0
  209. data/test/plugin/test_out_stdout.rb +22 -13
  210. data/test/plugin/test_out_stream.rb +18 -0
  211. data/test/plugin/test_output.rb +515 -0
  212. data/test/plugin/test_output_as_buffered.rb +1540 -0
  213. data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
  214. data/test/plugin/test_output_as_buffered_retries.rb +808 -0
  215. data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
  216. data/test/plugin/test_output_as_standard.rb +362 -0
  217. data/test/plugin/test_owned_by.rb +35 -0
  218. data/test/plugin/test_storage.rb +167 -0
  219. data/test/plugin/test_storage_local.rb +8 -0
  220. data/test/plugin_helper/test_child_process.rb +599 -0
  221. data/test/plugin_helper/test_compat_parameters.rb +175 -0
  222. data/test/plugin_helper/test_event_emitter.rb +51 -0
  223. data/test/plugin_helper/test_event_loop.rb +52 -0
  224. data/test/plugin_helper/test_retry_state.rb +399 -0
  225. data/test/plugin_helper/test_storage.rb +411 -0
  226. data/test/plugin_helper/test_thread.rb +164 -0
  227. data/test/plugin_helper/test_timer.rb +100 -0
  228. data/test/scripts/exec_script.rb +0 -6
  229. data/test/scripts/fluent/plugin/out_test.rb +3 -0
  230. data/test/test_config.rb +13 -4
  231. data/test/test_event.rb +24 -13
  232. data/test/test_event_router.rb +8 -7
  233. data/test/test_event_time.rb +187 -0
  234. data/test/test_formatter.rb +13 -51
  235. data/test/test_input.rb +1 -1
  236. data/test/test_log.rb +239 -16
  237. data/test/test_mixin.rb +1 -1
  238. data/test/test_output.rb +53 -66
  239. data/test/test_parser.rb +105 -323
  240. data/test/test_plugin_helper.rb +81 -0
  241. data/test/test_root_agent.rb +4 -52
  242. data/test/test_supervisor.rb +272 -0
  243. data/test/test_unique_id.rb +47 -0
  244. metadata +180 -54
  245. data/lib/fluent/buffer.rb +0 -365
  246. data/lib/fluent/plugin/filter_parser.rb +0 -107
  247. data/lib/fluent/plugin/in_status.rb +0 -76
  248. data/lib/fluent/test/helpers.rb +0 -86
  249. data/test/plugin/data/log/foo/bar2 +0 -0
  250. data/test/plugin/test_filter_parser.rb +0 -744
  251. data/test/plugin/test_in_status.rb +0 -38
  252. data/test/test_buffer.rb +0 -624
@@ -0,0 +1,100 @@
1
+ require_relative '../helper'
2
+ require 'fluent/plugin_helper/timer'
3
+ require 'fluent/plugin/base'
4
+
5
+ class TimerTest < Test::Unit::TestCase
6
+ class Dummy < Fluent::Plugin::TestBase
7
+ helpers :timer
8
+ end
9
+
10
+ test 'can be instantiated under state that timer is not running' do
11
+ d1 = Dummy.new
12
+ assert d1.respond_to?(:timer_running?)
13
+ assert !d1.timer_running?
14
+ end
15
+
16
+ test 'can be configured' do
17
+ d1 = Dummy.new
18
+ assert_nothing_raised do
19
+ d1.configure(config_element())
20
+ end
21
+ assert d1.plugin_id
22
+ assert d1.log
23
+ end
24
+
25
+ test 'can start timers by start' do
26
+ d1 = Dummy.new
27
+ d1.configure(config_element())
28
+ assert !d1.timer_running?
29
+ d1.start
30
+ assert d1.timer_running?
31
+
32
+ counter = 0
33
+ d1.timer_execute(:test, 1) do
34
+ counter += 1
35
+ end
36
+
37
+ sleep 5
38
+
39
+ d1.stop
40
+ assert !d1.timer_running?
41
+
42
+ assert{ counter >= 3 && counter <= 6 }
43
+
44
+ d1.shutdown; d1.close; d1.terminate
45
+ end
46
+
47
+ test 'can run many timers' do
48
+ d1 = Dummy.new
49
+ d1.configure(config_element())
50
+ d1.start
51
+
52
+ counter1 = 0
53
+ counter2 = 0
54
+
55
+ d1.timer_execute(:t1, 1) do
56
+ counter1 += 1
57
+ end
58
+ d1.timer_execute(:t2, 2) do
59
+ counter2 += 1
60
+ end
61
+
62
+ sleep 6
63
+
64
+ d1.stop
65
+
66
+ assert{ counter1 >= 4 && counter1 <= 7 }
67
+ assert{ counter2 >= 2 && counter2 <= 4 }
68
+
69
+ d1.shutdown; d1.close; d1.terminate
70
+ end
71
+
72
+ test 'aborts timer which raises exceptions' do
73
+ d1 = Dummy.new
74
+ d1.configure(config_element())
75
+ d1.start
76
+
77
+ counter1 = 0
78
+ counter2 = 0
79
+
80
+ d1.timer_execute(:t1, 1) do
81
+ counter1 += 1
82
+ end
83
+ d1.timer_execute(:t2, 1) do
84
+ raise "abort!!!!!!" if counter2 > 1
85
+ counter2 += 1
86
+ end
87
+
88
+ sleep 5
89
+
90
+ d1.stop
91
+
92
+ assert{ counter1 >= 3 && counter1 <= 6 }
93
+ assert{ counter2 == 2 }
94
+ msg = "Unexpected error raised. Stopping the timer. title=:t2"
95
+ assert{ d1.log.out.logs.any?{|line| line.include?("[error]:") && line.include?(msg) && line.include?("abort!!!!!!") } }
96
+ assert{ d1.log.out.logs.any?{|line| line.include?("[error]:") && line.include?("Timer detached. title=:t2") } }
97
+
98
+ d1.shutdown; d1.close; d1.terminate
99
+ end
100
+ end
@@ -17,10 +17,6 @@ def gen_raw_string(time)
17
17
  "#{time} hello"
18
18
  end
19
19
 
20
- def gen_invalid_json(time)
21
- %({"tag": "tag1", "time": #{time}, "k1": "ok", })
22
- end
23
-
24
20
  time = ARGV.first
25
21
  time = Integer(time) rescue time
26
22
 
@@ -33,6 +29,4 @@ when 2
33
29
  print gen_msgpack(time)
34
30
  when 3
35
31
  print gen_raw_string(time)
36
- when 4
37
- print gen_invalid_json(time)
38
32
  end
@@ -19,6 +19,7 @@ module Fluent
19
19
  Plugin.register_output('test', self)
20
20
 
21
21
  def initialize
22
+ super
22
23
  @emit_streams = []
23
24
  @name = nil
24
25
  end
@@ -60,9 +61,11 @@ module Fluent
60
61
  end
61
62
 
62
63
  def start
64
+ super
63
65
  end
64
66
 
65
67
  def shutdown
68
+ super
66
69
  end
67
70
 
68
71
  def emit(tag, es, chain)
@@ -157,14 +157,23 @@ class ConfigTest < Test::Unit::TestCase
157
157
  end
158
158
 
159
159
  def test_inline
160
- prepare_config
160
+ prepare_config
161
161
  opts = {
162
- config_path: "#{TMP_DIR}/config_test_1.conf",
163
- inline_config: "<source>\n type http\n port 2222\n </source>"
162
+ :config_path => "#{TMP_DIR}/config_test_1.conf",
163
+ :inline_config => "<source>\n type http\n port 2222\n </source>"
164
164
  }
165
165
  assert_nothing_raised do
166
166
  Fluent::Supervisor.new(opts)
167
- end
167
+ end
168
+ create_warn_dummy_logger
169
+ end
170
+
171
+ def create_warn_dummy_logger
172
+ dl_opts = {}
173
+ dl_opts[:log_level] = ServerEngine::DaemonLogger::WARN
174
+ logdev = Fluent::Test::DummyLogDevice.new
175
+ logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
176
+ $log = Fluent::Log.new(logger)
168
177
  end
169
178
  end
170
179
 
@@ -7,7 +7,7 @@ module EventTest
7
7
  include Fluent
8
8
 
9
9
  def setup
10
- @time = Engine.now
10
+ @time = event_time()
11
11
  @record = {'k' => 'v', 'n' => 1}
12
12
  @es = OneEventStream.new(@time, @record)
13
13
  end
@@ -31,18 +31,27 @@ module EventTest
31
31
 
32
32
  test 'to_msgpack_stream' do
33
33
  stream = @es.to_msgpack_stream
34
- MessagePack::Unpacker.new.feed_each(stream) { |time, record|
34
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
35
35
  assert_equal @time, time
36
36
  assert_equal @record, record
37
37
  }
38
38
  end
39
+
40
+ test 'to_msgpack_stream with time_int argument' do
41
+ stream = @es.to_msgpack_stream(time_int: true)
42
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
43
+ assert_equal @time.to_i, time
44
+ assert_equal @record, record
45
+ }
46
+ end
39
47
  end
40
48
 
41
49
  class ArrayEventStreamTest < ::Test::Unit::TestCase
42
50
  include Fluent
43
51
 
44
52
  def setup
45
- @times = [Engine.now, Engine.now + 1]
53
+ time = Engine.now
54
+ @times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)]
46
55
  @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
47
56
  @es = ArrayEventStream.new(@times.zip(@records))
48
57
  end
@@ -74,7 +83,7 @@ module EventTest
74
83
  test 'to_msgpack_stream' do
75
84
  i = 0
76
85
  stream = @es.to_msgpack_stream
77
- MessagePack::Unpacker.new.feed_each(stream) { |time, record|
86
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
78
87
  assert_equal @times[i], time
79
88
  assert_equal @records[i], record
80
89
  i += 1
@@ -86,11 +95,12 @@ module EventTest
86
95
  include Fluent
87
96
 
88
97
  def setup
89
- @times = [Engine.now, Engine.now + 1]
98
+ time = Engine.now
99
+ @times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)]
90
100
  @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
91
101
  @es = MultiEventStream.new
92
- @times.zip(@records).each { |time, record|
93
- @es.add(time, record)
102
+ @times.zip(@records).each { |_time, record|
103
+ @es.add(_time, record)
94
104
  }
95
105
  end
96
106
 
@@ -121,7 +131,7 @@ module EventTest
121
131
  test 'to_msgpack_stream' do
122
132
  i = 0
123
133
  stream = @es.to_msgpack_stream
124
- MessagePack::Unpacker.new.feed_each(stream) { |time, record|
134
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
125
135
  assert_equal @times[i], time
126
136
  assert_equal @records[i], record
127
137
  i += 1
@@ -133,11 +143,12 @@ module EventTest
133
143
  include Fluent
134
144
 
135
145
  def setup
136
- pk = MessagePack::Packer.new
137
- @times = [Engine.now, Engine.now + 1]
146
+ pk = Fluent::Engine.msgpack_factory.packer
147
+ time = Engine.now
148
+ @times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)]
138
149
  @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
139
- @times.zip(@records).each { |time, record|
140
- pk.write([time, record])
150
+ @times.zip(@records).each { |_time, record|
151
+ pk.write([_time, record])
141
152
  }
142
153
  @es = MessagePackEventStream.new(pk.to_s)
143
154
  end
@@ -158,7 +169,7 @@ module EventTest
158
169
  test 'to_msgpack_stream' do
159
170
  i = 0
160
171
  stream = @es.to_msgpack_stream
161
- MessagePack::Unpacker.new.feed_each(stream) { |time, record|
172
+ Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
162
173
  assert_equal @times[i], time
163
174
  assert_equal @records[i], record
164
175
  i += 1
@@ -97,7 +97,7 @@ class EventRouterTest < ::Test::Unit::TestCase
97
97
 
98
98
  test 'set one output' do
99
99
  @pipeline.set_output(output)
100
- @pipeline.emit('test', @es, nil)
100
+ @pipeline.emit_events('test', @es)
101
101
  assert_equal 1, output.events.size
102
102
  assert_equal 'value', output.events['test'].first['key']
103
103
  end
@@ -109,7 +109,7 @@ class EventRouterTest < ::Test::Unit::TestCase
109
109
 
110
110
  test 'set one filer' do
111
111
  @pipeline.add_filter(filter)
112
- @pipeline.emit('test', @es, nil)
112
+ @pipeline.emit_events('test', @es)
113
113
  assert_equal 1, output.events.size
114
114
  assert_equal 'value', output.events['test'].first['key']
115
115
  assert_equal 0, output.events['test'].first['__test__']
@@ -117,7 +117,7 @@ class EventRouterTest < ::Test::Unit::TestCase
117
117
 
118
118
  test 'set one filer with multi events' do
119
119
  @pipeline.add_filter(filter)
120
- @pipeline.emit('test', events, nil)
120
+ @pipeline.emit_events('test', events)
121
121
  assert_equal 1, output.events.size
122
122
  assert_equal 5, output.events['test'].size
123
123
  DEFAULT_EVENT_NUM.times { |i|
@@ -140,7 +140,7 @@ class EventRouterTest < ::Test::Unit::TestCase
140
140
  sub_test_case 'default collector' do
141
141
  test 'call default collector when no output' do
142
142
  assert_rr do
143
- mock(default_collector).emit('test', is_a(OneEventStream), NullOutputChain.instance)
143
+ mock(default_collector).emit_events('test', is_a(OneEventStream))
144
144
  event_router.emit('test', Engine.now, 'k' => 'v')
145
145
  end
146
146
  end
@@ -149,7 +149,7 @@ class EventRouterTest < ::Test::Unit::TestCase
149
149
  event_router.add_rule('test', filter)
150
150
  assert_rr do
151
151
  # After apply Filter, EventStream becomes MultiEventStream by default
152
- mock(default_collector).emit('test', is_a(MultiEventStream), NullOutputChain.instance)
152
+ mock(default_collector).emit_events('test', is_a(MultiEventStream))
153
153
  event_router.emit('test', Engine.now, 'k' => 'v')
154
154
  end
155
155
  assert_equal 1, filter.num
@@ -158,7 +158,7 @@ class EventRouterTest < ::Test::Unit::TestCase
158
158
  test "call default collector when no matched with output" do
159
159
  event_router.add_rule('test', output)
160
160
  assert_rr do
161
- mock(default_collector).emit('dummy', is_a(OneEventStream), NullOutputChain.instance)
161
+ mock(default_collector).emit_events('dummy', is_a(OneEventStream))
162
162
  event_router.emit('dummy', Engine.now, 'k' => 'v')
163
163
  end
164
164
  end
@@ -166,7 +166,7 @@ class EventRouterTest < ::Test::Unit::TestCase
166
166
  test "don't call default collector when tag matched" do
167
167
  event_router.add_rule('test', output)
168
168
  assert_rr do
169
- dont_allow(default_collector).emit('test', is_a(OneEventStream), NullOutputChain.instance)
169
+ dont_allow(default_collector).emit_events('test', is_a(OneEventStream))
170
170
  event_router.emit('test', Engine.now, 'k' => 'v')
171
171
  end
172
172
  # check emit handler doesn't catch rr error
@@ -224,6 +224,7 @@ class EventRouterTest < ::Test::Unit::TestCase
224
224
  test 'call handle_emits_error when emit failed' do
225
225
  event_router.add_rule('test', error_output)
226
226
 
227
+ event_router.emit('test', Engine.now, 'k' => 'v')
227
228
  assert_rr do
228
229
  mock(emit_handler).handle_emits_error('test', is_a(OneEventStream), is_a(RuntimeError))
229
230
  event_router.emit('test', Engine.now, 'k' => 'v')
@@ -0,0 +1,187 @@
1
+ require_relative 'helper'
2
+ require 'timecop'
3
+ require 'oj'
4
+ require 'yajl'
5
+
6
+ class EventTimeTest < Test::Unit::TestCase
7
+ setup do
8
+ @now = Time.now
9
+ Timecop.freeze(@now)
10
+ end
11
+
12
+ teardown do
13
+ Timecop.return
14
+ end
15
+
16
+ test '#sec' do
17
+ assert_equal(1, Fluent::EventTime.new(1, 2).sec)
18
+ end
19
+
20
+ test '#nsec' do
21
+ assert_equal(2, Fluent::EventTime.new(1, 2).nsec)
22
+ assert_equal(0, Fluent::EventTime.new(1).nsec)
23
+ end
24
+
25
+ test '#to_int' do
26
+ assert_equal(1, Fluent::EventTime.new(1, 2).to_int)
27
+ end
28
+
29
+ test '#to_r' do
30
+ assert_equal(Rational(1_000_000_002, 1_000_000_000), Fluent::EventTime.new(1, 2).to_r)
31
+ end
32
+
33
+ test '#to_s' do
34
+ time = Fluent::EventTime.new(100)
35
+ assert_equal('100', time.to_s)
36
+ assert_equal('100', "#{time}")
37
+ end
38
+
39
+ test '#to_json' do
40
+ time = Fluent::EventTime.new(100)
41
+ assert_equal('100', time.to_json)
42
+ assert_equal('{"time":100}', {'time' => time}.to_json)
43
+ assert_equal('["tag",100,{"key":"value"}]', ["tag", time, {"key" => "value"}].to_json)
44
+ end
45
+
46
+ test 'JSON.dump' do
47
+ time = Fluent::EventTime.new(100)
48
+ assert_equal('100', JSON.dump(time))
49
+ assert_equal('{"time":100}', JSON.dump({'time' => time}))
50
+ assert_equal('["tag",100,{"key":"value"}]', JSON.dump(["tag", time, {"key" => "value"}]))
51
+ end
52
+
53
+ test 'Oj.dump' do
54
+ time = Fluent::EventTime.new(100)
55
+ assert_equal('100', Oj.dump(time, mode: :compat))
56
+ assert_equal('{"time":100}', Oj.dump({'time' => time}, mode: :compat))
57
+ assert_equal('["tag",100,{"key":"value"}]', Oj.dump(["tag", time, {"key" => "value"}], mode: :compat))
58
+ end
59
+
60
+ test 'Yajl.dump' do
61
+ time = Fluent::EventTime.new(100)
62
+ assert_equal('100', Yajl.dump(time))
63
+ assert_equal('{"time":100}', Yajl.dump({'time' => time}))
64
+ assert_equal('["tag",100,{"key":"value"}]', Yajl.dump(["tag", time, {"key" => "value"}]))
65
+ end
66
+
67
+ test '.from_time' do
68
+ sec = 1000
69
+ usec = 2
70
+ time = Fluent::EventTime.from_time(Time.at(sec, usec))
71
+ assert_equal(time.sec, sec)
72
+ assert_equal(time.nsec, usec * 1000)
73
+ end
74
+
75
+ test 'now' do
76
+ assert_equal(@now.to_i, Fluent::EventTime.now.sec)
77
+ assert_equal(@now.nsec, Fluent::EventTime.now.nsec)
78
+ end
79
+
80
+ test 'parse' do
81
+ assert_equal(Time.parse("2011-01-02 13:14:15").to_i, Fluent::EventTime.parse("2011-01-02 13:14:15").sec)
82
+ assert_equal(Time.parse("2011-01-02 13:14:15").nsec, Fluent::EventTime.parse("2011-01-02 13:14:15").nsec)
83
+ end
84
+
85
+ test 'eq?' do
86
+ assert(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(1, 2)))
87
+ refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(1, 3)))
88
+ refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(3, 2)))
89
+ refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(3, 4)))
90
+
91
+ assert(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), 1))
92
+ refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), 2))
93
+
94
+ assert(Fluent::EventTime.eq?(1, Fluent::EventTime.new(1, 2)))
95
+ refute(Fluent::EventTime.eq?(2, Fluent::EventTime.new(1, 2)))
96
+ end
97
+
98
+ test '==' do
99
+ assert(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(1, 2))
100
+ assert(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(1, 3))
101
+ refute(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(3, 2))
102
+ refute(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(3, 4))
103
+
104
+ assert(Fluent::EventTime.new(1, 2) == 1)
105
+ refute(Fluent::EventTime.new(1, 2) == 2)
106
+
107
+ assert(1 == Fluent::EventTime.new(1, 2))
108
+ refute(2 == Fluent::EventTime.new(1, 2))
109
+ end
110
+
111
+ test '+' do
112
+ assert_equal(4, Fluent::EventTime.new(1, 2) + Fluent::EventTime.new(3, 4))
113
+ assert_equal(6, Fluent::EventTime.new(1, 2) + 5)
114
+ assert_equal(6, 5 + Fluent::EventTime.new(1, 2))
115
+ end
116
+
117
+ test '-' do
118
+ assert_equal(-2, Fluent::EventTime.new(1, 2) - Fluent::EventTime.new(3, 4))
119
+ assert_equal(-4, Fluent::EventTime.new(1, 2) - 5)
120
+ assert_equal(4, 5 - Fluent::EventTime.new(1, 2))
121
+ end
122
+
123
+ test '>' do
124
+ assert(Fluent::EventTime.new(2) > Fluent::EventTime.new(1))
125
+ refute(Fluent::EventTime.new(1) > Fluent::EventTime.new(1))
126
+ refute(Fluent::EventTime.new(1) > Fluent::EventTime.new(2))
127
+
128
+ assert(Fluent::EventTime.new(2) > 1)
129
+ refute(Fluent::EventTime.new(1) > 1)
130
+ refute(Fluent::EventTime.new(1) > 2)
131
+
132
+ assert(2 > Fluent::EventTime.new(1))
133
+ refute(1 > Fluent::EventTime.new(1))
134
+ refute(1 > Fluent::EventTime.new(2))
135
+ end
136
+
137
+ test '>=' do
138
+ assert(Fluent::EventTime.new(2) >= Fluent::EventTime.new(1))
139
+ assert(Fluent::EventTime.new(1) >= Fluent::EventTime.new(1))
140
+ refute(Fluent::EventTime.new(1) >= Fluent::EventTime.new(2))
141
+
142
+ assert(Fluent::EventTime.new(2) >= 1)
143
+ assert(Fluent::EventTime.new(1) >= 1)
144
+ refute(Fluent::EventTime.new(1) >= 2)
145
+
146
+ assert(2 >= Fluent::EventTime.new(1))
147
+ assert(1 >= Fluent::EventTime.new(1))
148
+ refute(1 >= Fluent::EventTime.new(2))
149
+ end
150
+
151
+ test '<' do
152
+ assert(Fluent::EventTime.new(1) < Fluent::EventTime.new(2))
153
+ refute(Fluent::EventTime.new(1) < Fluent::EventTime.new(1))
154
+ refute(Fluent::EventTime.new(2) < Fluent::EventTime.new(1))
155
+
156
+ assert(Fluent::EventTime.new(1) < 2)
157
+ refute(Fluent::EventTime.new(1) < 1)
158
+ refute(Fluent::EventTime.new(2) < 1)
159
+
160
+ assert(1 < Fluent::EventTime.new(2))
161
+ refute(1 < Fluent::EventTime.new(1))
162
+ refute(2 < Fluent::EventTime.new(1))
163
+ end
164
+
165
+ test '=<' do
166
+ assert(Fluent::EventTime.new(1) <= Fluent::EventTime.new(2))
167
+ assert(Fluent::EventTime.new(1) <= Fluent::EventTime.new(1))
168
+ refute(Fluent::EventTime.new(2) <= Fluent::EventTime.new(1))
169
+
170
+ assert(Fluent::EventTime.new(1) <= 2)
171
+ assert(Fluent::EventTime.new(1) <= 1)
172
+ refute(Fluent::EventTime.new(2) <= 1)
173
+
174
+ assert(1 <= Fluent::EventTime.new(2))
175
+ assert(1 <= Fluent::EventTime.new(1))
176
+ refute(2 <= Fluent::EventTime.new(1))
177
+ end
178
+
179
+ test 'Time.at' do
180
+ sec = 1000
181
+ nsec = 2000
182
+ ntime = Fluent::EventTime.new(sec, nsec)
183
+ time = Time.at(ntime)
184
+ assert_equal(sec, time.to_i)
185
+ assert_equal(nsec, time.nsec)
186
+ end
187
+ end