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
@@ -30,6 +30,7 @@ class MonitorAgentInputTest < Test::Unit::TestCase
30
30
  assert_equal(24220, d.instance.port)
31
31
  assert_equal(nil, d.instance.tag)
32
32
  assert_equal(60, d.instance.emit_interval)
33
+ assert_true d.instance.include_config
33
34
  end
34
35
 
35
36
  sub_test_case "collect plugin information" do
@@ -90,48 +91,37 @@ EOC
90
91
  assert_equal("output", d.instance.plugin_category(error_label.outputs.first))
91
92
  end
92
93
 
93
- test "get_monitor_info" do
94
+ data(:with_config_yes => true,
95
+ :with_config_no => false)
96
+ test "get_monitor_info" do |with_config|
94
97
  d = create_driver
95
98
  test_label = @ra.labels['@test']
96
99
  error_label = @ra.labels['@ERROR']
97
100
  input_info = {
98
- "config" => {
99
- "@id" => "test_in",
100
- "@type" => "test_in"
101
- },
102
101
  "output_plugin" => false,
103
102
  "plugin_category"=> "input",
104
103
  "plugin_id" => "test_in",
105
104
  "retry_count" => nil,
106
105
  "type" => "test_in"
107
106
  }
107
+ input_info.merge!("config" => {"@id" => "test_in", "@type" => "test_in"}) if with_config
108
108
  filter_info = {
109
- "config" => {
110
- "@id" => "test_filter",
111
- "@type" => "test_filter"
112
- },
113
109
  "output_plugin" => false,
114
110
  "plugin_category" => "filter",
115
111
  "plugin_id" => "test_filter",
116
112
  "retry_count" => nil,
117
113
  "type" => "test_filter"
118
114
  }
115
+ filter_info.merge!("config" => {"@id" => "test_filter", "@type" => "test_filter"}) if with_config
119
116
  output_info = {
120
- "config" => {
121
- "@id" => "test_out",
122
- "@type" => "test_out"
123
- },
124
117
  "output_plugin" => true,
125
118
  "plugin_category" => "output",
126
119
  "plugin_id" => "test_out",
127
120
  "retry_count" => 0,
128
121
  "type" => "test_out"
129
122
  }
123
+ output_info.merge!("config" => {"@id" => "test_out", "@type" => "test_out"}) if with_config
130
124
  error_label_info = {
131
- "config" => {
132
- "@id"=>"null",
133
- "@type" => "null"
134
- },
135
125
  "buffer_queue_length" => 0,
136
126
  "buffer_total_queued_size" => 0,
137
127
  "output_plugin" => true,
@@ -140,10 +130,12 @@ EOC
140
130
  "retry_count" => 0,
141
131
  "type" => "null"
142
132
  }
143
- assert_equal(input_info, d.instance.get_monitor_info(@ra.inputs.first))
144
- assert_equal(filter_info, d.instance.get_monitor_info(@ra.filters.first))
145
- assert_equal(output_info, d.instance.get_monitor_info(test_label.outputs.first))
146
- assert_equal(error_label_info, d.instance.get_monitor_info(error_label.outputs.first))
133
+ error_label_info.merge!("config" => {"@id"=>"null", "@type" => "null"}) if with_config
134
+ opts = {with_config: with_config}
135
+ assert_equal(input_info, d.instance.get_monitor_info(@ra.inputs.first, opts))
136
+ assert_equal(filter_info, d.instance.get_monitor_info(@ra.filters.first, opts))
137
+ assert_equal(output_info, d.instance.get_monitor_info(test_label.outputs.first, opts))
138
+ assert_equal(error_label_info, d.instance.get_monitor_info(error_label.outputs.first, opts))
147
139
  end
148
140
 
149
141
  test "fluentd opts" do
@@ -207,7 +199,7 @@ EOC
207
199
 
208
200
  def get(uri, header = {})
209
201
  url = URI.parse(uri)
210
- req = Net::HTTP::Get.new(url.path, header)
202
+ req = Net::HTTP::Get.new(url, header)
211
203
  unless header.has_key?('Content-Type')
212
204
  header['Content-Type'] = 'application/octet-stream'
213
205
  end
@@ -258,6 +250,8 @@ EOC
258
250
  @ra = Fluent::RootAgent.new(log: $log)
259
251
  stub(Fluent::Engine).root_agent { @ra }
260
252
  @ra = configure_ra(@ra, conf)
253
+ # store Supervisor instance to avoid collected by GC
254
+ @supervisor = Fluent::Supervisor.new(Fluent::Supervisor.default_options)
261
255
  end
262
256
 
263
257
  test "/api/plugins" do
@@ -280,36 +274,36 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
280
274
  assert_equal(expected_test_filter_response, test_filter)
281
275
  end
282
276
 
283
- test "/api/plugins.json" do
277
+ data(:include_config_yes => [true, "include_config yes"],
278
+ :include_config_no => [false, "include_config no"])
279
+ test "/api/plugins.json" do |(with_config, include_conf)|
280
+
284
281
  d = create_driver("
285
282
  @type monitor_agent
286
283
  bind '127.0.0.1'
287
284
  port #{@port}
288
285
  tag monitor
286
+ #{include_conf}
289
287
  ")
290
288
  d.instance.start
291
- expected_test_in_response =
292
- {"config" => {
293
- "@id" => "test_in",
294
- "@type" => "test_in"
295
- },
289
+ expected_test_in_response = {
296
290
  "output_plugin" => false,
297
291
  "plugin_category" => "input",
298
292
  "plugin_id" => "test_in",
299
293
  "retry_count" => nil,
300
- "type" => "test_in"}
301
- expected_null_response =
302
- {"config" => {
303
- "@id" => "null",
304
- "@type" => "null"
305
- },
294
+ "type" => "test_in"
295
+ }
296
+ expected_test_in_response.merge!("config" => {"@id" => "test_in", "@type" => "test_in"}) if with_config
297
+ expected_null_response = {
306
298
  "buffer_queue_length" => 0,
307
299
  "buffer_total_queued_size" => 0,
308
300
  "output_plugin" => true,
309
301
  "plugin_category" => "output",
310
302
  "plugin_id" => "null",
311
303
  "retry_count" => 0,
312
- "type" => "null"}
304
+ "type" => "null"
305
+ }
306
+ expected_null_response.merge!("config" => {"@id" => "null", "@type" => "null"}) if with_config
313
307
  response = JSON.parse(get("http://127.0.0.1:#{@port}/api/plugins.json"))
314
308
  test_in_response = response["plugins"][0]
315
309
  null_response = response["plugins"][5]
@@ -317,6 +311,42 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
317
311
  assert_equal(expected_null_response, null_response)
318
312
  end
319
313
 
314
+ data(:with_config_yes => [true, "?with_config=yes"],
315
+ :with_config_no => [false, "?with_config=no"])
316
+ test "/api/plugins.json with query parameter. query parameter is preferred than include_config" do |(with_config, query_param)|
317
+
318
+ d = create_driver("
319
+ @type monitor_agent
320
+ bind '127.0.0.1'
321
+ port #{@port}
322
+ tag monitor
323
+ ")
324
+ d.instance.start
325
+ expected_test_in_response = {
326
+ "output_plugin" => false,
327
+ "plugin_category" => "input",
328
+ "plugin_id" => "test_in",
329
+ "retry_count" => nil,
330
+ "type" => "test_in"
331
+ }
332
+ expected_test_in_response.merge!("config" => {"@id" => "test_in", "@type" => "test_in"}) if with_config
333
+ expected_null_response = {
334
+ "buffer_queue_length" => 0,
335
+ "buffer_total_queued_size" => 0,
336
+ "output_plugin" => true,
337
+ "plugin_category" => "output",
338
+ "plugin_id" => "null",
339
+ "retry_count" => 0,
340
+ "type" => "null"
341
+ }
342
+ expected_null_response.merge!("config" => {"@id" => "null", "@type" => "null"}) if with_config
343
+ response = JSON.parse(get("http://127.0.0.1:#{@port}/api/plugins.json#{query_param}"))
344
+ test_in_response = response["plugins"][0]
345
+ null_response = response["plugins"][5]
346
+ assert_equal(expected_test_in_response, test_in_response)
347
+ assert_equal(expected_null_response, null_response)
348
+ end
349
+
320
350
  test "/api/config" do
321
351
  d = create_driver("
322
352
  @type monitor_agent
@@ -176,7 +176,41 @@ class SyslogInputTest < Test::Unit::TestCase
176
176
  end
177
177
 
178
178
  assert(d.events.size > 0)
179
- compare_test_result(d.events, tests, host)
179
+ compare_test_result(d.events, tests, {host: host})
180
+ end
181
+
182
+ def test_msg_size_with_include_priority
183
+ d = create_driver([CONFIG, 'priority_key priority'].join("\n"))
184
+ tests = create_test_case
185
+
186
+ priority = 'info'
187
+ d.run(expect_emits: 2) do
188
+ u = UDPSocket.new
189
+ u.connect('127.0.0.1', PORT)
190
+ tests.each {|test|
191
+ u.send(test['msg'], 0)
192
+ }
193
+ end
194
+
195
+ assert(d.events.size > 0)
196
+ compare_test_result(d.events, tests, {priority: priority})
197
+ end
198
+
199
+ def test_msg_size_with_include_facility
200
+ d = create_driver([CONFIG, 'facility_key facility'].join("\n"))
201
+ tests = create_test_case
202
+
203
+ facility = 'kern'
204
+ d.run(expect_emits: 2) do
205
+ u = UDPSocket.new
206
+ u.connect('127.0.0.1', PORT)
207
+ tests.each {|test|
208
+ u.send(test['msg'], 0)
209
+ }
210
+ end
211
+
212
+ assert(d.events.size > 0)
213
+ compare_test_result(d.events, tests, {facility: facility})
180
214
  end
181
215
 
182
216
  def create_test_case(large_message: false)
@@ -195,11 +229,13 @@ class SyslogInputTest < Test::Unit::TestCase
195
229
  end
196
230
  end
197
231
 
198
- def compare_test_result(events, tests, host = nil)
232
+ def compare_test_result(events, tests, options = {})
199
233
  events.each_index { |i|
200
234
  assert_equal('syslog.kern.info', events[i][0]) # <6> means kern.info
201
235
  assert_equal(tests[i]['expected'], events[i][2]['message'])
202
- assert_equal(host, events[i][2]['source_host']) if host
236
+ assert_equal(options[:host], events[i][2]['source_host']) if options[:host]
237
+ assert_equal(options[:priority], events[i][2]['priority']) if options[:priority]
238
+ assert_equal(options[:facility], events[i][2]['facility']) if options[:facility]
203
239
  }
204
240
  end
205
241
  end
@@ -1,20 +1,8 @@
1
1
  require_relative '../helper'
2
- require 'fluent/test'
2
+ require 'fluent/test/driver/input'
3
3
  require 'fluent/plugin/in_tcp'
4
4
 
5
5
  class TcpInputTest < Test::Unit::TestCase
6
- class << self
7
- def startup
8
- socket_manager_path = ServerEngine::SocketManager::Server.generate_path
9
- @server = ServerEngine::SocketManager::Server.open(socket_manager_path)
10
- ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
11
- end
12
-
13
- def shutdown
14
- @server.close
15
- end
16
- end
17
-
18
6
  def setup
19
7
  Fluent::Test.setup
20
8
  end
@@ -34,69 +22,97 @@ class TcpInputTest < Test::Unit::TestCase
34
22
  ]
35
23
 
36
24
  def create_driver(conf)
37
- Fluent::Test::InputTestDriver.new(Fluent::TcpInput).configure(conf)
25
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::TcpInput).configure(conf)
38
26
  end
39
27
 
40
- def test_configure
41
- configs = {'127.0.0.1' => CONFIG}
42
- configs.merge!('::1' => IPv6_CONFIG) if ipv6_enabled?
28
+ def create_tcp_socket(host, port, &block)
29
+ if block_given?
30
+ TCPSocket.open(host, port, &block)
31
+ else
32
+ TCPSocket.open(host, port)
33
+ end
34
+ end
35
+
36
+
37
+ data(
38
+ 'ipv4' => [CONFIG, '127.0.0.1', :ipv4],
39
+ 'ipv6' => [IPv6_CONFIG, '::1', :ipv6],
40
+ )
41
+ test 'configure' do |data|
42
+ conf, bind, protocol = data
43
+ omit "IPv6 is not supported on this environment" if protocol == :ipv6 && !ipv6_enabled?
43
44
 
44
- configs.each_pair { |k, v|
45
- d = create_driver(v)
46
- assert_equal PORT, d.instance.port
47
- assert_equal k, d.instance.bind
48
- assert_equal "\n", d.instance.delimiter
49
- }
45
+ d = create_driver(conf)
46
+ assert_equal PORT, d.instance.port
47
+ assert_equal bind, d.instance.bind
48
+ assert_equal "\n", d.instance.delimiter
50
49
  end
51
50
 
52
- {
53
- 'none' => [
54
- {'msg' => "tcptest1\n", 'expected' => 'tcptest1'},
55
- {'msg' => "tcptest2\n", 'expected' => 'tcptest2'},
56
- ],
57
- 'json' => [
58
- {'msg' => {'k' => 123, 'message' => 'tcptest1'}.to_json + "\n", 'expected' => 'tcptest1'},
59
- {'msg' => {'k' => 'tcptest2', 'message' => 456}.to_json + "\n", 'expected' => 456},
60
- ]
61
- }.each { |format, test_cases|
62
- define_method("test_msg_size_#{format}") do
63
- d = create_driver(BASE_CONFIG + "format #{format}")
64
- tests = test_cases
51
+ test_case_data = {
52
+ 'none' => {
53
+ 'format' => 'none',
54
+ 'payloads' => [ "tcptest1\n", "tcptest2\n" ],
55
+ 'expecteds' => [
56
+ {'message' => 'tcptest1'},
57
+ {'message' => 'tcptest2'},
58
+ ],
59
+ },
60
+ 'json' => {
61
+ 'format' => 'json',
62
+ 'payloads' => [
63
+ {'k' => 123, 'message' => 'tcptest1'}.to_json + "\n",
64
+ {'k' => 'tcptest2', 'message' => 456}.to_json + "\n",
65
+ ],
66
+ 'expecteds' => [
67
+ {'k' => 123, 'message' => 'tcptest1'},
68
+ {'k' => 'tcptest2', 'message' => 456}
69
+ ],
70
+ },
71
+ }
72
+
73
+ data(test_case_data)
74
+ test 'test_msg_size' do |data|
75
+ format = data['format']
76
+ payloads = data['payloads']
77
+ expecteds = data['expecteds']
65
78
 
66
- d.run do
67
- tests.each {|test|
68
- TCPSocket.open('127.0.0.1', PORT) do |s|
69
- s.send(test['msg'], 0)
70
- end
71
- }
72
- sleep 1
79
+ d = create_driver(BASE_CONFIG + "format #{format}")
80
+ d.run(expect_records: 2) do
81
+ payloads.each do |payload|
82
+ create_tcp_socket('127.0.0.1', PORT) do |sock|
83
+ sock.send(payload, 0)
84
+ end
73
85
  end
86
+ end
74
87
 
75
- compare_test_result(d.emits, tests)
88
+ assert_equal 2, d.events.size
89
+ expecteds.each_with_index do |expected_record, i|
90
+ assert_equal "tcp", d.events[i][0]
91
+ assert d.events[i][1].is_a?(Fluent::EventTime)
92
+ assert_equal expected_record, d.events[i][2]
76
93
  end
94
+ end
77
95
 
78
- define_method("test_msg_size_with_same_connection_#{format}") do
79
- d = create_driver(BASE_CONFIG + "format #{format}")
80
- tests = test_cases
96
+ data(test_case_data)
97
+ test 'test data in a connection' do |data|
98
+ format = data['format']
99
+ payloads = data['payloads']
100
+ expecteds = data['expecteds']
81
101
 
82
- d.run do
83
- TCPSocket.open('127.0.0.1', PORT) do |s|
84
- tests.each {|test|
85
- s.send(test['msg'], 0)
86
- }
102
+ d = create_driver(BASE_CONFIG + "format #{format}")
103
+ d.run(expect_records: 2) do
104
+ create_tcp_socket('127.0.0.1', PORT) do |sock|
105
+ payloads.each do |payload|
106
+ sock.send(payload, 0)
87
107
  end
88
- sleep 1
89
108
  end
90
-
91
- compare_test_result(d.emits, tests)
92
109
  end
93
- }
94
110
 
95
- def compare_test_result(emits, tests)
96
- assert_equal(2, emits.size)
97
- emits.each_index {|i|
98
- assert_equal(tests[i]['expected'], emits[i][2]['message'])
99
- assert(emits[i][1].is_a?(Fluent::EventTime))
100
- }
111
+ assert_equal 2, d.events.size
112
+ expecteds.each_with_index do |expected_record, i|
113
+ assert_equal "tcp", d.events[i][0]
114
+ assert d.events[i][1].is_a?(Fluent::EventTime)
115
+ assert_equal expected_record, d.events[i][2]
116
+ end
101
117
  end
102
118
  end
@@ -1,20 +1,8 @@
1
1
  require_relative '../helper'
2
- require 'fluent/test'
2
+ require 'fluent/test/driver/input'
3
3
  require 'fluent/plugin/in_udp'
4
4
 
5
5
  class UdpInputTest < Test::Unit::TestCase
6
- class << self
7
- def startup
8
- socket_manager_path = ServerEngine::SocketManager::Server.generate_path
9
- @server = ServerEngine::SocketManager::Server.open(socket_manager_path)
10
- ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
11
- end
12
-
13
- def shutdown
14
- @server.close
15
- end
16
- end
17
-
18
6
  def setup
19
7
  Fluent::Test.setup
20
8
  end
@@ -34,88 +22,121 @@ class UdpInputTest < Test::Unit::TestCase
34
22
  !
35
23
 
36
24
  def create_driver(conf)
37
- Fluent::Test::InputTestDriver.new(Fluent::UdpInput).configure(conf)
25
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::UdpInput).configure(conf)
38
26
  end
39
27
 
40
- def test_configure
41
- configs = {'127.0.0.1' => CONFIG}
42
- configs.merge!('::1' => IPv6_CONFIG) if ipv6_enabled?
28
+ def create_udp_socket(host, port)
29
+ u = if IPAddr.new(IPSocket.getaddress(host)).ipv4?
30
+ UDPSocket.new(Socket::AF_INET)
31
+ else
32
+ UDPSocket.new(Socket::AF_INET6)
33
+ end
34
+ u.connect(host, port)
35
+ if block_given?
36
+ begin
37
+ yield u
38
+ ensure
39
+ u.close rescue nil
40
+ end
41
+ else
42
+ u
43
+ end
44
+ end
43
45
 
44
- configs.each_pair { |k, v|
45
- d = create_driver(v)
46
- assert_equal PORT, d.instance.port
47
- assert_equal k, d.instance.bind
48
- assert_equal 4096, d.instance.body_size_limit
49
- }
46
+ data(
47
+ 'ipv4' => [CONFIG, '127.0.0.1', :ipv4],
48
+ 'ipv6' => [IPv6_CONFIG, '::1', :ipv6],
49
+ )
50
+ test 'configure' do |data|
51
+ conf, bind, protocol = data
52
+ omit "IPv6 is not supported on this environment" if protocol == :ipv6 && !ipv6_enabled?
53
+
54
+ d = create_driver(conf)
55
+ assert_equal PORT, d.instance.port
56
+ assert_equal bind, d.instance.bind
57
+ assert_equal 4096, d.instance.body_size_limit
50
58
  end
51
59
 
52
- def test_time_format
53
- configs = {'127.0.0.1' => CONFIG}
54
- configs.merge!('::1' => IPv6_CONFIG) if ipv6_enabled?
60
+ data(
61
+ 'ipv4' => [CONFIG, '127.0.0.1', :ipv4],
62
+ 'ipv6' => [IPv6_CONFIG, '::1', :ipv6],
63
+ )
64
+ test 'time_format' do |data|
65
+ conf, bind, protocol = data
66
+ omit "IPv6 is not supported on this environment" if protocol == :ipv6 && !ipv6_enabled?
55
67
 
56
- configs.each_pair { |k, v|
57
- d = create_driver(v)
68
+ d = create_driver(conf)
58
69
 
59
- tests = [
60
- {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => Fluent::EventTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))},
61
- {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => Fluent::EventTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))},
62
- ]
70
+ tests = [
71
+ {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => event_time('Sep 11 00:00:00', format: '%b %d %H:%M:%S')},
72
+ {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => event_time('Sep 1 00:00:00', format: '%b %d %H:%M:%S')},
73
+ ]
63
74
 
64
- d.run do
65
- u = Fluent::SocketUtil.create_udp_socket(k)
66
- u.connect(k, PORT)
67
- tests.each {|test|
75
+ d.run(expect_records: 2) do
76
+ create_udp_socket(bind, PORT) do |u|
77
+ tests.each do |test|
68
78
  u.send(test['msg'], 0)
69
- }
70
- u.close
71
- sleep 1
79
+ end
72
80
  end
81
+ end
73
82
 
74
- emits = d.emits
75
- emits.each_index {|i|
76
- assert_equal_event_time(tests[i]['expected'], emits[i][1])
77
- }
78
- }
79
-
83
+ events = d.events
84
+ tests.each_with_index do |t, i|
85
+ assert_equal_event_time(t['expected'], events[i][1])
86
+ end
80
87
  end
81
88
 
82
- {
83
- 'none' => [
84
- {'msg' => "tcptest1\n", 'expected' => 'tcptest1'},
85
- {'msg' => "tcptest2\n", 'expected' => 'tcptest2'},
86
- ],
87
- 'json' => [
88
- {'msg' => {'k' => 123, 'message' => 'tcptest1'}.to_json + "\n", 'expected' => 'tcptest1'},
89
- {'msg' => {'k' => 'tcptest2', 'message' => 456}.to_json + "\n", 'expected' => 456},
90
- ],
91
- '/^\\[(?<time>[^\\]]*)\\] (?<message>.*)/' => [
92
- {'msg' => '[Sep 10 00:00:00] localhost: ' + 'x' * 100 + "\n", 'expected' => 'localhost: ' + 'x' * 100},
93
- {'msg' => '[Sep 10 00:00:00] localhost: ' + 'x' * 1024 + "\n", 'expected' => 'localhost: ' + 'x' * 1024},
94
- ]
95
- }.each { |format, test_cases|
96
- define_method("test_msg_size_#{format[0] == '/' ? 'regexp' : format}") do
97
- d = create_driver(BASE_CONFIG + "format #{format}")
98
- tests = test_cases
99
-
100
- d.run do
101
- u = UDPSocket.new
102
- u.connect('127.0.0.1', PORT)
103
- tests.each { |test|
104
- u.send(test['msg'], 0)
105
- }
106
- u.close
107
- sleep 1
89
+ data(
90
+ 'none' => {
91
+ 'format' => 'none',
92
+ 'payloads' => ["tcptest1\n", "tcptest2\n"],
93
+ 'expecteds' => [
94
+ {"message" => "tcptest1"},
95
+ {"message" => "tcptest2"},
96
+ ],
97
+ },
98
+ 'json' => {
99
+ 'format' => 'json',
100
+ 'payloads' => [
101
+ {'k' => 123, 'message' => 'tcptest1'}.to_json + "\n",
102
+ {'k' => 'tcptest2', 'message' => 456}.to_json + "\n",
103
+ ],
104
+ 'expecteds' => [
105
+ {'k' => 123, 'message' => 'tcptest1'},
106
+ {'k' => 'tcptest2', 'message' => 456},
107
+ ],
108
+ },
109
+ 'regexp' => {
110
+ 'format' => '/^\\[(?<time>[^\\]]*)\\] (?<message>.*)/',
111
+ 'payloads' => [
112
+ '[Sep 10 00:00:00] localhost: ' + 'x' * 100 + "\n",
113
+ '[Sep 10 00:00:00] localhost: ' + 'x' * 1024 + "\n"
114
+ ],
115
+ 'expecteds' => [
116
+ {"message" => 'localhost: ' + 'x' * 100},
117
+ {"message" => 'localhost: ' + 'x' * 1024},
118
+ ],
119
+ },
120
+ )
121
+ test 'message size with format' do |data|
122
+ format = data['format']
123
+ payloads = data['payloads']
124
+ expecteds = data['expecteds']
125
+
126
+ d = create_driver(BASE_CONFIG + "format #{format}")
127
+ d.run(expect_records: 2) do
128
+ create_udp_socket('127.0.0.1', PORT) do |u|
129
+ payloads.each do |payload|
130
+ u.send(payload, 0)
131
+ end
108
132
  end
109
-
110
- compare_test_result(d.emits, tests)
111
133
  end
112
- }
113
134
 
114
- def compare_test_result(emits, tests)
115
- assert_equal(2, emits.size)
116
- emits.each_index {|i|
117
- assert_equal(tests[i]['expected'], emits[i][2]['message'])
118
- assert(emits[i][1].is_a?(Fluent::EventTime))
119
- }
135
+ assert_equal 2, d.events.size
136
+ expecteds.each_with_index do |expected_record, i|
137
+ assert_equal "udp", d.events[i][0]
138
+ assert d.events[i][1].is_a?(Fluent::EventTime)
139
+ assert_equal expected_record, d.events[i][2]
140
+ end
120
141
  end
121
142
  end