fluentd 0.14.8 → 0.14.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/CONTRIBUTING.md +6 -1
  4. data/ChangeLog +38 -0
  5. data/Rakefile +21 -0
  6. data/example/out_exec_filter.conf +42 -0
  7. data/lib/fluent/agent.rb +2 -2
  8. data/lib/fluent/command/binlog_reader.rb +1 -1
  9. data/lib/fluent/command/cat.rb +5 -2
  10. data/lib/fluent/compat/output.rb +7 -8
  11. data/lib/fluent/compat/parser.rb +139 -11
  12. data/lib/fluent/config/configure_proxy.rb +2 -11
  13. data/lib/fluent/config/section.rb +7 -0
  14. data/lib/fluent/configurable.rb +1 -3
  15. data/lib/fluent/log.rb +1 -1
  16. data/lib/fluent/plugin/base.rb +17 -0
  17. data/lib/fluent/plugin/filter_parser.rb +108 -0
  18. data/lib/fluent/plugin/filter_record_transformer.rb +4 -7
  19. data/lib/fluent/plugin/filter_stdout.rb +1 -1
  20. data/lib/fluent/plugin/formatter.rb +5 -0
  21. data/lib/fluent/plugin/formatter_msgpack.rb +4 -0
  22. data/lib/fluent/plugin/formatter_stdout.rb +3 -2
  23. data/lib/fluent/plugin/formatter_tsv.rb +34 -0
  24. data/lib/fluent/plugin/in_exec.rb +48 -93
  25. data/lib/fluent/plugin/in_forward.rb +25 -105
  26. data/lib/fluent/plugin/in_http.rb +68 -65
  27. data/lib/fluent/plugin/in_syslog.rb +29 -51
  28. data/lib/fluent/plugin/multi_output.rb +1 -3
  29. data/lib/fluent/plugin/out_exec.rb +58 -71
  30. data/lib/fluent/plugin/out_exec_filter.rb +199 -279
  31. data/lib/fluent/plugin/out_file.rb +155 -80
  32. data/lib/fluent/plugin/out_forward.rb +44 -47
  33. data/lib/fluent/plugin/out_stdout.rb +6 -21
  34. data/lib/fluent/plugin/output.rb +23 -17
  35. data/lib/fluent/plugin/parser.rb +121 -61
  36. data/lib/fluent/plugin/parser_csv.rb +9 -3
  37. data/lib/fluent/plugin/parser_json.rb +37 -35
  38. data/lib/fluent/plugin/parser_ltsv.rb +11 -19
  39. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  40. data/lib/fluent/plugin/parser_regexp.rb +15 -42
  41. data/lib/fluent/plugin/parser_tsv.rb +8 -3
  42. data/lib/fluent/plugin_helper.rb +8 -1
  43. data/lib/fluent/plugin_helper/child_process.rb +139 -73
  44. data/lib/fluent/plugin_helper/compat_parameters.rb +93 -4
  45. data/lib/fluent/plugin_helper/event_emitter.rb +14 -1
  46. data/lib/fluent/plugin_helper/extract.rb +16 -4
  47. data/lib/fluent/plugin_helper/formatter.rb +9 -11
  48. data/lib/fluent/plugin_helper/inject.rb +4 -0
  49. data/lib/fluent/plugin_helper/parser.rb +3 -3
  50. data/lib/fluent/root_agent.rb +1 -1
  51. data/lib/fluent/test/driver/base.rb +51 -37
  52. data/lib/fluent/test/driver/base_owner.rb +18 -8
  53. data/lib/fluent/test/driver/multi_output.rb +2 -1
  54. data/lib/fluent/test/driver/output.rb +29 -6
  55. data/lib/fluent/test/helpers.rb +3 -1
  56. data/lib/fluent/test/log.rb +4 -0
  57. data/lib/fluent/test/startup_shutdown.rb +13 -0
  58. data/lib/fluent/time.rb +14 -8
  59. data/lib/fluent/version.rb +1 -1
  60. data/test/command/test_binlog_reader.rb +5 -1
  61. data/test/config/test_configurable.rb +173 -0
  62. data/test/config/test_configure_proxy.rb +0 -43
  63. data/test/plugin/test_base.rb +16 -0
  64. data/test/plugin/test_filter_parser.rb +665 -0
  65. data/test/plugin/test_filter_record_transformer.rb +11 -3
  66. data/test/plugin/test_filter_stdout.rb +18 -27
  67. data/test/plugin/test_in_dummy.rb +1 -1
  68. data/test/plugin/test_in_exec.rb +206 -94
  69. data/test/plugin/test_in_forward.rb +310 -327
  70. data/test/plugin/test_in_http.rb +310 -186
  71. data/test/plugin/test_out_exec.rb +223 -68
  72. data/test/plugin/test_out_exec_filter.rb +520 -169
  73. data/test/plugin/test_out_file.rb +620 -177
  74. data/test/plugin/test_out_forward.rb +110 -132
  75. data/test/plugin/test_out_null.rb +1 -1
  76. data/test/plugin/test_out_secondary_file.rb +4 -2
  77. data/test/plugin/test_out_stdout.rb +14 -35
  78. data/test/plugin/test_parser.rb +359 -0
  79. data/test/plugin/test_parser_csv.rb +1 -2
  80. data/test/plugin/test_parser_json.rb +3 -4
  81. data/test/plugin/test_parser_labeled_tsv.rb +1 -2
  82. data/test/plugin/test_parser_none.rb +1 -2
  83. data/test/plugin/test_parser_regexp.rb +8 -4
  84. data/test/plugin/test_parser_tsv.rb +4 -3
  85. data/test/plugin_helper/test_child_process.rb +184 -0
  86. data/test/plugin_helper/test_compat_parameters.rb +88 -1
  87. data/test/plugin_helper/test_extract.rb +0 -1
  88. data/test/plugin_helper/test_formatter.rb +5 -2
  89. data/test/plugin_helper/test_parser.rb +6 -5
  90. data/test/test_output.rb +24 -2
  91. data/test/test_plugin_classes.rb +20 -0
  92. data/test/test_root_agent.rb +139 -0
  93. data/test/test_test_drivers.rb +132 -0
  94. metadata +12 -4
  95. data/test/plugin/test_parser_base.rb +0 -32
@@ -1,6 +1,6 @@
1
1
  require_relative '../helper'
2
2
 
3
- require 'fluent/test'
3
+ require 'fluent/test/driver/input'
4
4
  require 'fluent/test/startup_shutdown'
5
5
  require 'base64'
6
6
 
@@ -9,12 +9,19 @@ require 'fluent/event'
9
9
  require 'fluent/plugin/in_forward'
10
10
  require 'fluent/plugin/compressable'
11
11
 
12
+ require 'timecop'
13
+
12
14
  class ForwardInputTest < Test::Unit::TestCase
13
15
  include Fluent::Plugin::Compressable
14
16
 
15
17
  def setup
16
18
  Fluent::Test.setup
17
19
  @responses = [] # for testing responses after sending data
20
+ @d = nil
21
+ end
22
+
23
+ def teardown
24
+ @d.instance_shutdown if @d
18
25
  end
19
26
 
20
27
  PORT = unused_port
@@ -48,12 +55,19 @@ class ForwardInputTest < Test::Unit::TestCase
48
55
  ]
49
56
 
50
57
  def create_driver(conf=CONFIG)
51
- Fluent::Test::InputTestDriver.new(Fluent::ForwardInput).configure(conf)
58
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::ForwardInput).configure(conf)
52
59
  end
53
60
 
54
- class Configure < self
55
- def test_simple
56
- d = create_driver
61
+ sub_test_case '#configure' do
62
+ setup do
63
+ Fluent::Test::StartupShutdown.setup
64
+ end
65
+ teardown do
66
+ Fluent::Test::StartupShutdown.teardown
67
+ end
68
+
69
+ test 'simple' do
70
+ @d = d = create_driver
57
71
  assert_equal PORT, d.instance.port
58
72
  assert_equal '127.0.0.1', d.instance.bind
59
73
  assert_equal 0, d.instance.linger_timeout
@@ -61,8 +75,8 @@ class ForwardInputTest < Test::Unit::TestCase
61
75
  assert !d.instance.backlog
62
76
  end
63
77
 
64
- def test_auth
65
- d = create_driver(CONFIG_AUTH)
78
+ test 'auth' do
79
+ @d = d = create_driver(CONFIG_AUTH)
66
80
  assert_equal PORT, d.instance.port
67
81
  assert_equal '127.0.0.1', d.instance.bind
68
82
  assert_equal 0, d.instance.linger_timeout
@@ -74,148 +88,153 @@ class ForwardInputTest < Test::Unit::TestCase
74
88
  end
75
89
  end
76
90
 
77
- # TODO: Will add Loop::run arity check with stub/mock library
78
-
79
91
  def connect
80
92
  TCPSocket.new('127.0.0.1', PORT)
81
93
  end
82
94
 
83
- class Message < self
84
- extend Fluent::Test::StartupShutdown
85
-
86
- def test_time
87
- d = create_driver
88
-
89
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
90
- Fluent::Engine.now = time
91
-
92
- records = [
93
- ["tag1", time, {"a"=>1}],
94
- ["tag2", time, {"a"=>2}],
95
- ]
95
+ sub_test_case 'message' do
96
+ setup do
97
+ Fluent::Test::StartupShutdown.setup
98
+ end
99
+ teardown do
100
+ Fluent::Test::StartupShutdown.teardown
101
+ end
96
102
 
97
- d.expected_emits_length = records.length
98
- d.run_timeout = 2
99
- d.run do
100
- records.each {|tag, _time, record|
101
- send_data packer.write([tag, 0, record]).to_s
102
- }
103
+ test 'time' do
104
+ time = event_time("2011-01-02 13:14:15 UTC")
105
+ begin
106
+ Timecop.freeze(Time.at(time))
107
+ @d = d = create_driver
108
+
109
+ records = [
110
+ ["tag1", time, {"a"=>1}],
111
+ ["tag2", time, {"a"=>2}],
112
+ ]
113
+
114
+ d.run(expect_records: records.length, timeout: 5) do
115
+ records.each {|tag, _time, record|
116
+ send_data packer.write([tag, 0, record]).to_s
117
+ }
118
+ end
119
+ assert_equal(records, d.events.sort_by {|a| a[0] })
120
+ ensure
121
+ Timecop.return
103
122
  end
104
- assert_equal(records, d.emits.sort_by {|a| a[0] })
105
123
  end
106
124
 
107
- def test_plain
108
- d = create_driver
125
+ test 'plain' do
126
+ @d = d = create_driver
109
127
 
110
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
128
+ time = event_time("2011-01-02 13:14:15 UTC")
111
129
 
112
130
  records = [
113
131
  ["tag1", time, {"a"=>1}],
114
132
  ["tag2", time, {"a"=>2}],
115
133
  ]
116
134
 
117
- d.expected_emits_length = records.length
118
- d.run_timeout = 2
119
- d.run do
135
+ d.run(expect_records: records.length, timeout: 5) do
120
136
  records.each {|tag, _time, record|
121
137
  send_data packer.write([tag, _time, record]).to_s
122
138
  }
123
139
  end
124
- assert_equal(records, d.emits)
140
+ assert_equal(records, d.events)
125
141
  end
126
142
 
127
- def test_time_as_integer
128
- d = create_driver
143
+ test 'time_as_integer' do
144
+ @d = d = create_driver
129
145
 
130
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
146
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
131
147
 
132
148
  records = [
133
- ["tag1", time, {"a"=>1}],
134
- ["tag2", time, {"a"=>2}],
149
+ ["tag1", time_i, {"a"=>1}],
150
+ ["tag2", time_i, {"a"=>2}],
135
151
  ]
136
152
 
137
- d.expected_emits_length = records.length
138
- d.run_timeout = 2
139
- d.run do
153
+ d.run(expect_records: records.length, timeout: 5) do
140
154
  records.each {|tag, _time, record|
141
155
  send_data packer.write([tag, _time, record]).to_s
142
156
  }
143
157
  end
144
158
 
145
- assert_equal(records, d.emits)
159
+ assert_equal(records, d.events)
146
160
  end
147
161
 
148
- def test_skip_invalid_event
149
- d = create_driver(CONFIG + "skip_invalid_event true")
162
+ test 'skip_invalid_event' do
163
+ @d = d = create_driver(CONFIG + "skip_invalid_event true")
150
164
 
151
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
165
+ time = event_time("2011-01-02 13:14:15 UTC")
152
166
 
153
167
  records = [
154
168
  ["tag1", time, {"a" => 1}],
155
169
  ["tag2", time, {"a" => 2}],
156
170
  ]
157
171
 
158
- d.run do
159
- entries = records.map { |tag, _time, record| [tag, _time, record] }
172
+ d.run(shutdown: false, expect_records: 2, timeout: 10) do
173
+ entries = []
160
174
  # These entries are skipped
161
175
  entries << ['tag1', true, {'a' => 3}] << ['tag2', time, 'invalid record']
176
+ entries += records.map { |tag, _time, record| [tag, _time, record] }
162
177
 
163
178
  entries.each {|tag, _time, record|
164
179
  # Without ack, logs are sometimes not saved to logs during test.
165
- send_data packer.write([tag, _time, record]).to_s, try_to_receive_response: true
180
+ send_data packer.write([tag, _time, record]).to_s #, try_to_receive_response: true
166
181
  }
167
182
  end
168
183
 
169
- assert_equal 2, d.instance.log.logs.count { |line| line =~ /got invalid event and drop it/ }
170
- assert_equal records[0], d.emits[0]
171
- assert_equal records[1], d.emits[1]
184
+ logs = d.instance.log.logs
185
+ assert_equal 2, logs.count { |line| line =~ /got invalid event and drop it/ }
186
+ assert_equal records[0], d.events[0]
187
+ assert_equal records[1], d.events[1]
188
+
189
+ d.instance_shutdown
172
190
  end
173
191
 
174
- def test_json
175
- d = create_driver
192
+ test 'json_using_integer_time' do
193
+ @d = d = create_driver
176
194
 
177
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
195
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
178
196
 
179
197
  records = [
180
- ["tag1", time, {"a"=>1}],
181
- ["tag2", time, {"a"=>2}],
198
+ ["tag1", time_i, {"a"=>1}],
199
+ ["tag2", time_i, {"a"=>2}],
182
200
  ]
183
201
 
184
- d.expected_emits_length = records.length
185
- d.run_timeout = 2
186
- d.run do
202
+ d.run(expect_records: records.length, timeout: 20) do
187
203
  records.each {|tag, _time, record|
188
204
  send_data [tag, _time, record].to_json
189
205
  }
190
206
  end
191
207
 
192
- assert_equal(records, d.emits.sort_by {|a| a[1] })
208
+ assert_equal(records, d.events.sort_by {|a| a[1] })
193
209
  end
194
210
 
195
- def test_json_with_newline
196
- d = create_driver
211
+ test 'json_with_newline' do
212
+ @d = d = create_driver
197
213
 
198
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
214
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
199
215
 
200
216
  records = [
201
- ["tag1", time, {"a"=>1}],
202
- ["tag2", time, {"a"=>2}],
217
+ ["tag1", time_i, {"a"=>1}],
218
+ ["tag2", time_i, {"a"=>2}],
203
219
  ]
204
220
 
205
- d.expected_emits_length = records.length
206
- d.run_timeout = 2
207
- d.run do
221
+ d.run(expect_records: records.length, timeout: 20) do
208
222
  records.each {|tag, _time, record|
209
223
  send_data [tag, _time, record].to_json + "\n"
210
224
  }
211
225
  end
212
226
 
213
- assert_equal(records, d.emits.sort_by {|a| a[1] })
227
+ assert_equal(records, d.events.sort_by {|a| a[1] })
214
228
  end
215
229
  end
216
230
 
217
- class Forward < self
218
- extend Fluent::Test::StartupShutdown
231
+ sub_test_case 'forward' do
232
+ setup do
233
+ Fluent::Test::StartupShutdown.setup
234
+ end
235
+ teardown do
236
+ Fluent::Test::StartupShutdown.teardown
237
+ end
219
238
 
220
239
  data(tcp: {
221
240
  config: CONFIG,
@@ -229,32 +248,26 @@ class ForwardInputTest < Test::Unit::TestCase
229
248
  auth: true
230
249
  }
231
250
  })
232
- def test_plain(data)
251
+ test 'plain' do |data|
233
252
  config = data[:config]
234
253
  options = data[:options]
235
- d = create_driver(config)
254
+ @d = d = create_driver(config)
236
255
 
237
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
256
+ time = event_time("2011-01-02 13:14:15 UTC")
238
257
 
239
258
  records = [
240
259
  ["tag1", time, {"a"=>1}],
241
260
  ["tag1", time, {"a"=>2}]
242
261
  ]
243
262
 
244
- d.expected_emits_length = records.length
245
- d.run_timeout = 2
246
- d.run do
247
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
248
-
263
+ d.run(expect_records: records.length, timeout: 20) do
249
264
  entries = []
250
265
  records.each {|tag, _time, record|
251
266
  entries << [_time, record]
252
267
  }
253
268
  send_data packer.write(["tag1", entries]).to_s, **options
254
269
  end
255
- assert_equal(records, d.emits)
256
-
257
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
270
+ assert_equal(records, d.events)
258
271
  end
259
272
 
260
273
  data(tcp: {
@@ -269,23 +282,19 @@ class ForwardInputTest < Test::Unit::TestCase
269
282
  auth: true
270
283
  }
271
284
  })
272
- def test_time_as_integer(data)
285
+ test 'time_as_integer' do |data|
273
286
  config = data[:config]
274
287
  options = data[:options]
275
- d = create_driver(config)
288
+ @d = d = create_driver(config)
276
289
 
277
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
290
+ time_i = event_time("2011-01-02 13:14:15 UTC")
278
291
 
279
292
  records = [
280
- ["tag1", time, {"a"=>1}],
281
- ["tag1", time, {"a"=>2}]
293
+ ["tag1", time_i, {"a"=>1}],
294
+ ["tag1", time_i, {"a"=>2}]
282
295
  ]
283
296
 
284
- d.expected_emits_length = records.length
285
- d.run_timeout = 2
286
- d.run do
287
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
288
-
297
+ d.run(expect_records: records.length, timeout: 20) do
289
298
  entries = []
290
299
  records.each {|tag, _time, record|
291
300
  entries << [_time, record]
@@ -293,9 +302,7 @@ class ForwardInputTest < Test::Unit::TestCase
293
302
  send_data packer.write(["tag1", entries]).to_s, **options
294
303
  end
295
304
 
296
- assert_equal(records, d.emits)
297
-
298
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
305
+ assert_equal(records, d.events)
299
306
  end
300
307
 
301
308
  data(tcp: {
@@ -310,23 +317,19 @@ class ForwardInputTest < Test::Unit::TestCase
310
317
  auth: true
311
318
  }
312
319
  })
313
- def test_skip_invalid_event(data)
320
+ test 'skip_invalid_event' do |data|
314
321
  config = data[:config]
315
322
  options = data[:options]
316
- d = create_driver(config + "skip_invalid_event true")
323
+ @d = d = create_driver(config + "skip_invalid_event true")
317
324
 
318
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
325
+ time = event_time("2011-01-02 13:14:15 UTC")
319
326
 
320
327
  records = [
321
328
  ["tag1", time, {"a" => 1}],
322
329
  ["tag1", time, {"a" => 2}],
323
330
  ]
324
331
 
325
- d.expected_emits_length = records.length
326
- d.run_timeout = 2
327
- d.run do
328
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
329
-
332
+ d.run(shutdown: false, expect_records: records.length, timeout: 20) do
330
333
  entries = records.map { |tag, _time, record| [_time, record] }
331
334
  # These entries are skipped
332
335
  entries << ['invalid time', {'a' => 3}] << [time, 'invalid record']
@@ -334,14 +337,20 @@ class ForwardInputTest < Test::Unit::TestCase
334
337
  send_data packer.write(["tag1", entries]).to_s, **options
335
338
  end
336
339
 
337
- assert_equal 2, d.instance.log.logs.count { |line| line =~ /skip invalid event/ }
340
+ logs = d.instance.log.out.logs
341
+ assert{ logs.select{|line| line =~ /skip invalid event/ }.size == 2 }
338
342
 
339
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
343
+ d.instance_shutdown
340
344
  end
341
345
  end
342
346
 
343
- class PackedForward < self
344
- extend Fluent::Test::StartupShutdown
347
+ sub_test_case 'packed forward' do
348
+ setup do
349
+ Fluent::Test::StartupShutdown.setup
350
+ end
351
+ teardown do
352
+ Fluent::Test::StartupShutdown.teardown
353
+ end
345
354
 
346
355
  data(tcp: {
347
356
  config: CONFIG,
@@ -355,32 +364,26 @@ class ForwardInputTest < Test::Unit::TestCase
355
364
  auth: true
356
365
  }
357
366
  })
358
- def test_plain(data)
367
+ test 'plain' do |data|
359
368
  config = data[:config]
360
369
  options = data[:options]
361
- d = create_driver(config)
370
+ @d = d = create_driver(config)
362
371
 
363
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
372
+ time = event_time("2011-01-02 13:14:15 UTC")
364
373
 
365
374
  records = [
366
375
  ["tag1", time, {"a"=>1}],
367
376
  ["tag1", time, {"a"=>2}],
368
377
  ]
369
378
 
370
- d.expected_emits_length = records.length
371
- d.run_timeout = 2
372
- d.run do
373
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
374
-
379
+ d.run(expect_records: records.length, timeout: 20) do
375
380
  entries = ''
376
381
  records.each {|_tag, _time, record|
377
382
  packer(entries).write([_time, record]).flush
378
383
  }
379
384
  send_data packer.write(["tag1", entries]).to_s, **options
380
385
  end
381
- assert_equal(records, d.emits)
382
-
383
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
386
+ assert_equal(records, d.events)
384
387
  end
385
388
 
386
389
  data(tcp: {
@@ -395,32 +398,26 @@ class ForwardInputTest < Test::Unit::TestCase
395
398
  auth: true
396
399
  }
397
400
  })
398
- def test_time_as_integer(data)
401
+ test 'time_as_integer' do |data|
399
402
  config = data[:config]
400
403
  options = data[:options]
401
- d = create_driver(config)
404
+ @d = d = create_driver(config)
402
405
 
403
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
406
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
404
407
 
405
408
  records = [
406
- ["tag1", time, {"a"=>1}],
407
- ["tag1", time, {"a"=>2}],
409
+ ["tag1", time_i, {"a"=>1}],
410
+ ["tag1", time_i, {"a"=>2}],
408
411
  ]
409
412
 
410
- d.expected_emits_length = records.length
411
- d.run_timeout = 2
412
- d.run do
413
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
414
-
413
+ d.run(expect_records: records.length, timeout: 20) do
415
414
  entries = ''
416
415
  records.each {|tag, _time, record|
417
416
  packer(entries).write([_time, record]).flush
418
417
  }
419
418
  send_data packer.write(["tag1", entries]).to_s, **options
420
419
  end
421
- assert_equal(records, d.emits)
422
-
423
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
420
+ assert_equal(records, d.events)
424
421
  end
425
422
 
426
423
  data(tcp: {
@@ -435,23 +432,19 @@ class ForwardInputTest < Test::Unit::TestCase
435
432
  auth: true
436
433
  }
437
434
  })
438
- def test_skip_invalid_event(data)
435
+ test 'skip_invalid_event' do |data|
439
436
  config = data[:config]
440
437
  options = data[:options]
441
- d = create_driver(config + "skip_invalid_event true")
438
+ @d = d = create_driver(config + "skip_invalid_event true")
442
439
 
443
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
440
+ time = event_time("2011-01-02 13:14:15 UTC")
444
441
 
445
442
  records = [
446
443
  ["tag1", time, {"a" => 1}],
447
444
  ["tag1", time, {"a" => 2}],
448
445
  ]
449
446
 
450
- d.expected_emits_length = records.length
451
- d.run_timeout = 2
452
- d.run do
453
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
454
-
447
+ d.run(shutdown: false, expect_records: records.length, timeout: 20) do
455
448
  entries = records.map { |tag, _time, record| [_time, record] }
456
449
  # These entries are skipped
457
450
  entries << ['invalid time', {'a' => 3}] << [time, 'invalid record']
@@ -463,22 +456,28 @@ class ForwardInputTest < Test::Unit::TestCase
463
456
  send_data packer.write(["tag1", packed_entries]).to_s, **options
464
457
  end
465
458
 
466
- assert_equal 2, d.instance.log.logs.count { |line| line =~ /skip invalid event/ }
459
+ logs = d.instance.log.logs
460
+ assert_equal 2, logs.count { |line| line =~ /skip invalid event/ }
467
461
 
468
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
462
+ d.instance_shutdown
469
463
  end
470
464
  end
471
465
 
472
- class CompressedPackedForward < self
473
- extend Fluent::Test::StartupShutdown
466
+ sub_test_case 'compressed packed forward' do
467
+ setup do
468
+ Fluent::Test::StartupShutdown.setup
469
+ end
470
+ teardown do
471
+ Fluent::Test::StartupShutdown.teardown
472
+ end
474
473
 
475
- def test_set_compress_to_option
476
- d = create_driver
474
+ test 'set_compress_to_option' do
475
+ @d = d = create_driver
477
476
 
478
- time = event_time("2011-01-02 13:14:15 UTC").to_i
477
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
479
478
  events = [
480
- ["tag1", time, {"a"=>1}],
481
- ["tag1", time, {"a"=>2}]
479
+ ["tag1", time_i, {"a"=>1}],
480
+ ["tag1", time_i, {"a"=>2}]
482
481
  ]
483
482
 
484
483
  # create compressed entries
@@ -496,16 +495,16 @@ class ForwardInputTest < Test::Unit::TestCase
496
495
  end
497
496
  end
498
497
 
499
- assert_equal events, d.emits
498
+ assert_equal events, d.events
500
499
  end
501
500
 
502
- def test_create_CompressedMessagePackEventStream_with_gzip_compress_option
503
- d = create_driver
501
+ test 'create_CompressedMessagePackEventStream_with_gzip_compress_option' do
502
+ @d = d = create_driver
504
503
 
505
- time = event_time("2011-01-02 13:14:15 UTC").to_i
504
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
506
505
  events = [
507
- ["tag1", time, {"a"=>1}],
508
- ["tag1", time, {"a"=>2}]
506
+ ["tag1", time_i, {"a"=>1}],
507
+ ["tag1", time_i, {"a"=>2}]
509
508
  ]
510
509
 
511
510
  # create compressed entries
@@ -525,20 +524,24 @@ class ForwardInputTest < Test::Unit::TestCase
525
524
  assert_equal 'gzip', option['compressed']
526
525
  end
527
526
  end
528
- d.emits
529
527
  end
530
528
  end
531
529
 
532
- class Warning < self
533
- extend Fluent::Test::StartupShutdown
530
+ sub_test_case 'warning' do
531
+ setup do
532
+ Fluent::Test::StartupShutdown.setup
533
+ end
534
+ teardown do
535
+ Fluent::Test::StartupShutdown.teardown
536
+ end
534
537
 
535
- def test_send_large_chunk_warning
536
- d = create_driver(CONFIG + %[
537
- chunk_size_warn_limit 16M
538
- chunk_size_limit 32M
539
- ])
538
+ test 'send_large_chunk_warning' do
539
+ @d = d = create_driver(CONFIG + %[
540
+ chunk_size_warn_limit 16M
541
+ chunk_size_limit 32M
542
+ ])
540
543
 
541
- time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
544
+ time = event_time("2014-04-25 13:14:15 UTC")
542
545
 
543
546
  # generate over 16M chunk
544
547
  str = "X" * 1024 * 1024
@@ -546,59 +549,61 @@ class ForwardInputTest < Test::Unit::TestCase
546
549
  assert chunk.size > (16 * 1024 * 1024)
547
550
  assert chunk.size < (32 * 1024 * 1024)
548
551
 
549
- d.run do
550
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
551
-
552
+ d.run(shutdown: false) do
552
553
  Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
553
554
  d.instance.send(:on_message, obj, chunk.size, PEERADDR)
554
555
  end
555
556
  end
556
557
 
557
558
  # check emitted data
558
- emits = d.emits
559
+ emits = d.events
559
560
  assert_equal 16, emits.size
560
561
  assert emits.map(&:first).all?{|t| t == "test.tag" }
561
562
  assert_equal (0...16).to_a, emits.map{|_tag, t, _record| t - time }
562
563
 
563
564
  # check log
564
- assert d.instance.log.logs.select{|line|
565
+ logs = d.instance.log.logs
566
+ assert_equal 1, logs.select{|line|
565
567
  line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_warn_limit':/ &&
566
568
  line =~ / tag="test.tag" source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" limit=16777216 size=16777501/
567
- }.size == 1, "large chunk warning is not logged"
569
+ }.size, "large chunk warning is not logged"
570
+
571
+ d.instance_shutdown
568
572
  end
569
573
 
570
- def test_send_large_chunk_only_warning
571
- d = create_driver(CONFIG + %[
572
- chunk_size_warn_limit 16M
573
- ])
574
- time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
574
+ test 'send_large_chunk_only_warning' do
575
+ @d = d = create_driver(CONFIG + %[
576
+ chunk_size_warn_limit 16M
577
+ ])
578
+ time = event_time("2014-04-25 13:14:15 UTC")
575
579
 
576
580
  # generate over 16M chunk
577
581
  str = "X" * 1024 * 1024
578
582
  chunk = [ "test.tag", (0...16).map{|i| [time + i, {"data" => str}] } ].to_msgpack
579
583
 
580
- d.run do
581
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
582
-
584
+ d.run(shutdown: false) do
583
585
  Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
584
586
  d.instance.send(:on_message, obj, chunk.size, PEERADDR)
585
587
  end
586
588
  end
587
589
 
588
590
  # check log
589
- assert d.instance.log.logs.select{ |line|
591
+ logs = d.instance.log.logs
592
+ assert_equal 1, logs.select{ |line|
590
593
  line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_warn_limit':/ &&
591
594
  line =~ / tag="test.tag" source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" limit=16777216 size=16777501/
592
- }.size == 1, "large chunk warning is not logged"
595
+ }.size, "large chunk warning is not logged"
596
+
597
+ d.instance_shutdown
593
598
  end
594
599
 
595
- def test_send_large_chunk_limit
596
- d = create_driver(CONFIG + %[
597
- chunk_size_warn_limit 16M
598
- chunk_size_limit 32M
599
- ])
600
+ test 'send_large_chunk_limit' do
601
+ @d = d = create_driver(CONFIG + %[
602
+ chunk_size_warn_limit 16M
603
+ chunk_size_limit 32M
604
+ ])
600
605
 
601
- time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
606
+ time = event_time("2014-04-25 13:14:15 UTC")
602
607
 
603
608
  # generate over 32M chunk
604
609
  str = "X" * 1024 * 1024
@@ -606,50 +611,56 @@ class ForwardInputTest < Test::Unit::TestCase
606
611
  assert chunk.size > (32 * 1024 * 1024)
607
612
 
608
613
  # d.run => send_data
609
- d.run do
610
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
611
-
614
+ d.run(shutdown: false) do
612
615
  Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
613
616
  d.instance.send(:on_message, obj, chunk.size, PEERADDR)
614
617
  end
615
618
  end
616
619
 
617
620
  # check emitted data
618
- emits = d.emits
621
+ emits = d.events
619
622
  assert_equal 0, emits.size
620
623
 
621
624
  # check log
622
- assert d.instance.log.logs.select{|line|
625
+ logs = d.instance.log.logs
626
+ assert_equal 1, logs.select{|line|
623
627
  line =~ / \[warn\]: Input chunk size is larger than 'chunk_size_limit', dropped:/ &&
624
628
  line =~ / tag="test.tag" source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" limit=33554432 size=33554989/
625
- }.size == 1, "large chunk warning is not logged"
629
+ }.size, "large chunk warning is not logged"
630
+
631
+ d.instance_shutdown
626
632
  end
627
633
 
628
634
  data('string chunk' => 'broken string',
629
635
  'integer chunk' => 10)
630
- def test_send_broken_chunk(data)
631
- d = create_driver
636
+ test 'send_broken_chunk' do |data|
637
+ @d = d = create_driver
632
638
 
633
639
  # d.run => send_data
634
- d.run do
635
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
636
-
640
+ d.run(shutdown: false) do
637
641
  d.instance.send(:on_message, data, 1000000000, PEERADDR)
638
642
  end
639
643
 
640
644
  # check emitted data
641
- emits = d.emits
642
- assert_equal 0, emits.size
645
+ assert_equal 0, d.events.size
643
646
 
644
647
  # check log
645
- assert d.instance.log.logs.select{|line|
648
+ logs = d.instance.log.logs
649
+ assert_equal 1, logs.select{|line|
646
650
  line =~ / \[warn\]: incoming chunk is broken: source="host: 127.0.0.1, addr: 127.0.0.1, port: \d+" msg=#{data.inspect}/
647
- }.size == 1, "should not accept broken chunk"
651
+ }.size, "should not accept broken chunk"
652
+
653
+ d.instance_shutdown
648
654
  end
649
655
  end
650
656
 
651
- class RespondToRequiringAck < self
652
- extend Fluent::Test::StartupShutdown
657
+ sub_test_case 'respond to required ack' do
658
+ setup do
659
+ Fluent::Test::StartupShutdown.setup
660
+ end
661
+ teardown do
662
+ Fluent::Test::StartupShutdown.teardown
663
+ end
653
664
 
654
665
  data(tcp: {
655
666
  config: CONFIG,
@@ -663,24 +674,21 @@ class ForwardInputTest < Test::Unit::TestCase
663
674
  auth: true
664
675
  }
665
676
  })
666
- def test_message(data)
677
+ test 'message' do |data|
667
678
  config = data[:config]
668
679
  options = data[:options]
669
- d = create_driver(config)
680
+ @d = d = create_driver(config)
670
681
 
671
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
682
+ time = event_time("2011-01-02 13:14:15 UTC")
672
683
 
673
684
  events = [
674
685
  ["tag1", time, {"a"=>1}],
675
686
  ["tag2", time, {"a"=>2}]
676
687
  ]
677
- d.expected_emits_length = events.length
678
688
 
679
689
  expected_acks = []
680
690
 
681
- d.run do
682
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
683
-
691
+ d.run(expect_records: events.size) do
684
692
  events.each {|tag, _time, record|
685
693
  op = { 'chunk' => Base64.encode64(record.object_id.to_s) }
686
694
  expected_acks << op['chunk']
@@ -688,10 +696,8 @@ class ForwardInputTest < Test::Unit::TestCase
688
696
  }
689
697
  end
690
698
 
691
- assert_equal events, d.emits
699
+ assert_equal events, d.events
692
700
  assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
693
-
694
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
695
701
  end
696
702
 
697
703
  # FIX: response is not pushed into @responses because IO.select has been blocked until InputForward shutdowns
@@ -707,24 +713,21 @@ class ForwardInputTest < Test::Unit::TestCase
707
713
  auth: true
708
714
  }
709
715
  })
710
- def test_forward(data)
716
+ test 'forward' do |data|
711
717
  config = data[:config]
712
718
  options = data[:options]
713
- d = create_driver(config)
719
+ @d = d = create_driver(config)
714
720
 
715
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
721
+ time = event_time("2011-01-02 13:14:15 UTC")
716
722
 
717
723
  events = [
718
724
  ["tag1", time, {"a"=>1}],
719
725
  ["tag1", time, {"a"=>2}]
720
726
  ]
721
- d.expected_emits_length = events.length
722
727
 
723
728
  expected_acks = []
724
729
 
725
- d.run do
726
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
727
-
730
+ d.run(expect_records: events.size) do
728
731
  entries = []
729
732
  events.each {|_tag, _time, record|
730
733
  entries << [_time, record]
@@ -734,10 +737,8 @@ class ForwardInputTest < Test::Unit::TestCase
734
737
  send_data ["tag1", entries, op].to_msgpack, try_to_receive_response: true, **options
735
738
  end
736
739
 
737
- assert_equal events, d.emits
740
+ assert_equal events, d.events
738
741
  assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
739
-
740
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
741
742
  end
742
743
 
743
744
  data(tcp: {
@@ -752,24 +753,21 @@ class ForwardInputTest < Test::Unit::TestCase
752
753
  auth: true
753
754
  }
754
755
  })
755
- def test_packed_forward(data)
756
+ test 'packed_forward' do |data|
756
757
  config = data[:config]
757
758
  options = data[:options]
758
- d = create_driver(config)
759
+ @d = d = create_driver(config)
759
760
 
760
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
761
+ time = event_time("2011-01-02 13:14:15 UTC")
761
762
 
762
763
  events = [
763
764
  ["tag1", time, {"a"=>1}],
764
765
  ["tag1", time, {"a"=>2}]
765
766
  ]
766
- d.expected_emits_length = events.length
767
767
 
768
768
  expected_acks = []
769
769
 
770
- d.run do
771
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
772
-
770
+ d.run(expect_records: events.size) do
773
771
  entries = ''
774
772
  events.each {|_tag, _time,record|
775
773
  [time, record].to_msgpack(entries)
@@ -779,45 +777,40 @@ class ForwardInputTest < Test::Unit::TestCase
779
777
  send_data ["tag1", entries, op].to_msgpack, try_to_receive_response: true, **options
780
778
  end
781
779
 
782
- assert_equal events, d.emits
780
+ assert_equal events, d.events
783
781
  assert_equal expected_acks, @responses.map { |res| MessagePack.unpack(res)['ack'] }
784
-
785
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
786
782
  end
787
783
 
788
- data(tcp: {
789
- config: CONFIG,
790
- options: {
791
- auth: false
792
- }
793
- },
794
- auth: {
795
- config: CONFIG_AUTH,
796
- options: {
797
- auth: true
798
- }
799
- })
800
- def test_message_json(data)
784
+ data(
785
+ tcp: {
786
+ config: CONFIG,
787
+ options: {
788
+ auth: false
789
+ }
790
+ },
791
+ ### Auth is not supported with json
792
+ # auth: {
793
+ # config: CONFIG_AUTH,
794
+ # options: {
795
+ # auth: true
796
+ # }
797
+ # },
798
+ )
799
+ test 'message_json' do |data|
801
800
  config = data[:config]
802
801
  options = data[:options]
803
- omit "with json, auth doen NOT work" if options[:auth]
804
- d = create_driver(config)
802
+ @d = d = create_driver(config)
805
803
 
806
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
804
+ time_i = event_time("2011-01-02 13:14:15 UTC")
807
805
 
808
806
  events = [
809
- ["tag1", time, {"a"=>1}],
810
- ["tag2", time, {"a"=>2}]
807
+ ["tag1", time_i, {"a"=>1}],
808
+ ["tag2", time_i, {"a"=>2}]
811
809
  ]
812
- d.expected_emits_length = events.length
813
810
 
814
811
  expected_acks = []
815
812
 
816
- d.expected_emits_length = events.length
817
- d.run_timeout = 2
818
- d.run do
819
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
820
-
813
+ d.run(expect_records: events.size, timeout: 20) do
821
814
  events.each {|tag, _time, record|
822
815
  op = { 'chunk' => Base64.encode64(record.object_id.to_s) }
823
816
  expected_acks << op['chunk']
@@ -825,15 +818,18 @@ class ForwardInputTest < Test::Unit::TestCase
825
818
  }
826
819
  end
827
820
 
828
- assert_equal events, d.emits
821
+ assert_equal events, d.events
829
822
  assert_equal expected_acks, @responses.map { |res| JSON.parse(res)['ack'] }
830
-
831
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
832
823
  end
833
824
  end
834
825
 
835
- class NotRespondToNotRequiringAck < self
836
- extend Fluent::Test::StartupShutdown
826
+ sub_test_case 'not respond without required ack' do
827
+ setup do
828
+ Fluent::Test::StartupShutdown.setup
829
+ end
830
+ teardown do
831
+ Fluent::Test::StartupShutdown.teardown
832
+ end
837
833
 
838
834
  data(tcp: {
839
835
  config: CONFIG,
@@ -847,31 +843,26 @@ class ForwardInputTest < Test::Unit::TestCase
847
843
  auth: true
848
844
  }
849
845
  })
850
- def test_message(data)
846
+ test 'message' do |data|
851
847
  config = data[:config]
852
848
  options = data[:options]
853
- d = create_driver(config)
849
+ @d = d = create_driver(config)
854
850
 
855
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
851
+ time = event_time("2011-01-02 13:14:15 UTC")
856
852
 
857
853
  events = [
858
854
  ["tag1", time, {"a"=>1}],
859
855
  ["tag2", time, {"a"=>2}]
860
856
  ]
861
- d.expected_emits_length = events.length
862
-
863
- d.run do
864
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
865
857
 
858
+ d.run(expect_records: events.size, timeout: 20) do
866
859
  events.each {|tag, _time, record|
867
860
  send_data [tag, _time, record].to_msgpack, try_to_receive_response: true, **options
868
861
  }
869
862
  end
870
863
 
871
- assert_equal events, d.emits
864
+ assert_equal events, d.events
872
865
  assert_equal [nil, nil], @responses
873
-
874
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
875
866
  end
876
867
 
877
868
  data(tcp: {
@@ -886,22 +877,19 @@ class ForwardInputTest < Test::Unit::TestCase
886
877
  auth: true
887
878
  }
888
879
  })
889
- def test_forward(data)
880
+ test 'forward' do |data|
890
881
  config = data[:config]
891
882
  options = data[:options]
892
- d = create_driver(config)
883
+ @d = d = create_driver(config)
893
884
 
894
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
885
+ time = event_time("2011-01-02 13:14:15 UTC")
895
886
 
896
887
  events = [
897
888
  ["tag1", time, {"a"=>1}],
898
889
  ["tag1", time, {"a"=>2}]
899
890
  ]
900
- d.expected_emits_length = events.length
901
-
902
- d.run do
903
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
904
891
 
892
+ d.run(expect_records: events.size, timeout: 20) do
905
893
  entries = []
906
894
  events.each {|tag, _time, record|
907
895
  entries << [_time, record]
@@ -909,10 +897,8 @@ class ForwardInputTest < Test::Unit::TestCase
909
897
  send_data ["tag1", entries].to_msgpack, try_to_receive_response: true, **options
910
898
  end
911
899
 
912
- assert_equal events, d.emits
900
+ assert_equal events, d.events
913
901
  assert_equal [nil], @responses
914
-
915
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
916
902
  end
917
903
 
918
904
  data(tcp: {
@@ -927,22 +913,19 @@ class ForwardInputTest < Test::Unit::TestCase
927
913
  auth: true
928
914
  }
929
915
  })
930
- def test_packed_forward(data)
916
+ test 'packed_forward' do |data|
931
917
  config = data[:config]
932
918
  options = data[:options]
933
- d = create_driver(config)
919
+ @d = d = create_driver(config)
934
920
 
935
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
921
+ time = event_time("2011-01-02 13:14:15 UTC")
936
922
 
937
923
  events = [
938
924
  ["tag1", time, {"a"=>1}],
939
925
  ["tag1", time, {"a"=>2}]
940
926
  ]
941
- d.expected_emits_length = events.length
942
-
943
- d.run do
944
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
945
927
 
928
+ d.run(expect_records: events.size, timeout: 20) do
946
929
  entries = ''
947
930
  events.each {|tag, _time, record|
948
931
  [_time, record].to_msgpack(entries)
@@ -950,50 +933,45 @@ class ForwardInputTest < Test::Unit::TestCase
950
933
  send_data ["tag1", entries].to_msgpack, try_to_receive_response: true, **options
951
934
  end
952
935
 
953
- assert_equal events, d.emits
936
+ assert_equal events, d.events
954
937
  assert_equal [nil], @responses
955
-
956
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
957
938
  end
958
939
 
959
- data(tcp: {
960
- config: CONFIG,
961
- options: {
962
- auth: false
963
- }
964
- },
965
- auth: {
966
- config: CONFIG_AUTH,
967
- options: {
968
- auth: true
969
- }
970
- })
971
- def test_message_json(data)
940
+ data(
941
+ tcp: {
942
+ config: CONFIG,
943
+ options: {
944
+ auth: false
945
+ }
946
+ },
947
+ ### Auth is not supported with json
948
+ # auth: {
949
+ # config: CONFIG_AUTH,
950
+ # options: {
951
+ # auth: true
952
+ # }
953
+ # },
954
+ )
955
+ test 'message_json' do |data|
972
956
  config = data[:config]
973
957
  options = data[:options]
974
- omit "with json, auth doen NOT work" if options[:auth]
975
- d = create_driver(config)
958
+ @d = d = create_driver(config)
976
959
 
977
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
960
+ time_i = event_time("2011-01-02 13:14:15 UTC").to_i
978
961
 
979
962
  events = [
980
- ["tag1", time, {"a"=>1}],
981
- ["tag2", time, {"a"=>2}]
963
+ ["tag1", time_i, {"a"=>1}],
964
+ ["tag2", time_i, {"a"=>2}]
982
965
  ]
983
- d.expected_emits_length = events.length
984
-
985
- d.run do
986
- sleep 0.1 until d.instance.instance_eval{ @thread } && d.instance.instance_eval{ @thread }.status
987
966
 
967
+ d.run(expect_records: events.size, timeout: 20) do
988
968
  events.each {|tag, _time, record|
989
969
  send_data [tag, _time, record].to_json, try_to_receive_response: true, **options
990
970
  }
991
971
  end
992
972
 
993
- assert_equal events, d.emits
973
+ assert_equal events, d.events
994
974
  assert_equal [nil, nil], @responses
995
-
996
- sleep 0.1 while d.instance.instance_eval{ @thread }.status # to confirm that plugin stopped completely
997
975
  end
998
976
  end
999
977
 
@@ -1011,11 +989,12 @@ class ForwardInputTest < Test::Unit::TestCase
1011
989
  def read_data(io, timeout, &block)
1012
990
  res = ''
1013
991
  select_timeout = 2
1014
- timeout_at = Time.now + timeout
992
+ clock_id = Process::CLOCK_MONOTONIC_RAW rescue Process::CLOCK_MONOTONIC
993
+ timeout_at = Process.clock_gettime(clock_id) + timeout
1015
994
  begin
1016
995
  buf = ''
1017
996
  io_activated = false
1018
- while Time.now < timeout_at
997
+ while Process.clock_gettime(clock_id) < timeout_at
1019
998
  if IO.select([io], nil, nil, select_timeout)
1020
999
  io_activated = true
1021
1000
  buf = io.readpartial(2048)
@@ -1110,7 +1089,12 @@ class ForwardInputTest < Test::Unit::TestCase
1110
1089
  end
1111
1090
 
1112
1091
  sub_test_case 'source_hostname_key feature' do
1113
- extend Fluent::Test::StartupShutdown
1092
+ setup do
1093
+ Fluent::Test::StartupShutdown.setup
1094
+ end
1095
+ teardown do
1096
+ Fluent::Test::StartupShutdown.teardown
1097
+ end
1114
1098
 
1115
1099
  test 'message protocol with source_hostname_key' do
1116
1100
  execute_test { |events|
@@ -1142,20 +1126,19 @@ class ForwardInputTest < Test::Unit::TestCase
1142
1126
  end
1143
1127
 
1144
1128
  def execute_test(&block)
1145
- d = create_driver(CONFIG + 'source_hostname_key source')
1129
+ @d = d = create_driver(CONFIG + 'source_hostname_key source')
1146
1130
 
1147
- time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
1131
+ time = event_time("2011-01-02 13:14:15 UTC")
1148
1132
  events = [
1149
1133
  ["tag1", time, {"a"=>1}],
1150
1134
  ["tag1", time, {"a"=>2}]
1151
1135
  ]
1152
- d.expected_emits_length = events.length
1153
1136
 
1154
- d.run do
1137
+ d.run(expect_records: events.size) do
1155
1138
  block.call(events)
1156
1139
  end
1157
1140
 
1158
- d.emits.each { |tag, _time, record|
1141
+ d.events.each { |tag, _time, record|
1159
1142
  assert_true record.has_key?('source')
1160
1143
  }
1161
1144
  end