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