fluentd 0.14.7-x64-mingw32 → 0.14.10-x64-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,7 +1,8 @@
1
1
  require_relative '../helper'
2
- require 'fluent/test'
2
+ require 'fluent/test/driver/input'
3
3
  require 'fluent/plugin/in_http'
4
4
  require 'net/http'
5
+ require 'timecop'
5
6
 
6
7
  class HttpInputTest < Test::Unit::TestCase
7
8
  class << self
@@ -20,6 +21,10 @@ class HttpInputTest < Test::Unit::TestCase
20
21
  Fluent::Test.setup
21
22
  end
22
23
 
24
+ def teardown
25
+ Timecop.return
26
+ end
27
+
23
28
  PORT = unused_port
24
29
  CONFIG = %[
25
30
  port #{PORT}
@@ -30,7 +35,7 @@ class HttpInputTest < Test::Unit::TestCase
30
35
  ]
31
36
 
32
37
  def create_driver(conf=CONFIG)
33
- Fluent::Test::InputTestDriver.new(Fluent::HttpInput).configure(conf, true)
38
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpInput).configure(conf)
34
39
  end
35
40
 
36
41
  def test_configure
@@ -44,228 +49,314 @@ class HttpInputTest < Test::Unit::TestCase
44
49
 
45
50
  def test_time
46
51
  d = create_driver
52
+ time = event_time("2011-01-02 13:14:15.123 UTC")
53
+ Timecop.freeze(Time.at(time))
47
54
 
48
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
49
- Fluent::Engine.now = time
50
-
51
- d.expect_emit "tag1", time, {"a"=>1}
52
- d.expect_emit "tag2", time, {"a"=>2}
55
+ events = [
56
+ ["tag1", time, {"a" => 1}],
57
+ ["tag2", time, {"a" => 2}],
58
+ ]
59
+ res_codes = []
53
60
 
54
- d.run do
55
- d.expected_emits.each {|tag,_time,record|
61
+ d.run(expect_records: 2) do
62
+ events.each do |tag, _time, record|
56
63
  res = post("/#{tag}", {"json"=>record.to_json})
57
- assert_equal "200", res.code
58
- }
64
+ res_codes << res.code
65
+ end
59
66
  end
67
+
68
+ assert_equal ["200", "200"], res_codes
69
+ assert_equal events, d.events
70
+ assert_equal_event_time time, d.events[0][1]
71
+ assert_equal_event_time time, d.events[1][1]
60
72
  end
61
73
 
62
74
  def test_time_as_float
63
75
  d = create_driver
76
+ time = event_time("2011-01-02 13:14:15.123 UTC")
77
+ float_time = time.to_f
64
78
 
65
- float_time = Time.parse("2011-01-02 13:14:15.123 UTC").to_f
66
- time = Fluent::EventTime.from_time(Time.at(float_time))
67
-
68
- d.expect_emit "tag1", time, {"a"=>1}
79
+ events = [
80
+ ["tag1", time, {"a"=>1}],
81
+ ]
82
+ res_codes = []
69
83
 
70
- d.run do
71
- d.expected_emits.each {|tag,_time,record|
84
+ d.run(expect_records: 1) do
85
+ events.each do |tag, t, record|
72
86
  res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s})
73
- assert_equal "200", res.code
74
- }
87
+ res_codes << res.code
88
+ end
75
89
  end
90
+ assert_equal ["200"], res_codes
91
+ assert_equal events, d.events
92
+ assert_equal_event_time time, d.events[0][1]
76
93
  end
77
94
 
78
95
  def test_json
79
96
  d = create_driver
80
-
81
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
82
-
83
- d.expect_emit "tag1", time, {"a"=>1}
84
- d.expect_emit "tag2", time, {"a"=>2}
85
-
86
- d.run do
87
- d.expected_emits.each {|tag,_time,record|
88
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
89
- assert_equal "200", res.code
90
- }
97
+ time = event_time("2011-01-02 13:14:15 UTC")
98
+ time_i = time.to_i
99
+
100
+ events = [
101
+ ["tag1", time_i, {"a"=>1}],
102
+ ["tag2", time_i, {"a"=>2}],
103
+ ]
104
+ res_codes = []
105
+
106
+ d.run(expect_records: 2) do
107
+ events.each do |tag, t, record|
108
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>t.to_s})
109
+ res_codes << res.code
110
+ end
91
111
  end
92
-
93
- d.emit_streams.each { |tag, es|
94
- assert !include_http_header?(es.first[1])
95
- }
112
+ assert_equal ["200", "200"], res_codes
113
+ assert_equal events, d.events
114
+ assert_equal_event_time time, d.events[0][1]
115
+ assert_equal_event_time time, d.events[1][1]
96
116
  end
97
117
 
98
118
  def test_multi_json
99
119
  d = create_driver
100
-
101
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
102
-
103
- events = [{"a"=>1},{"a"=>2}]
120
+ time = event_time("2011-01-02 13:14:15 UTC")
121
+ time_i = time.to_i
122
+
123
+ records = [{"a"=>1},{"a"=>2}]
124
+ events = [
125
+ ["tag1", time_i, records[0]],
126
+ ["tag1", time_i, records[1]],
127
+ ]
104
128
  tag = "tag1"
105
-
106
- events.each { |ev|
107
- d.expect_emit tag, time, ev
108
- }
109
-
110
- d.run do
111
- res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
112
- assert_equal "200", res.code
129
+ res_codes = []
130
+ d.run(expect_records: 2, timeout: 5) do
131
+ res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
132
+ res_codes << res.code
113
133
  end
114
-
134
+ assert_equal ["200"], res_codes
135
+ assert_equal events, d.events
136
+ assert_equal_event_time time, d.events[0][1]
137
+ assert_equal_event_time time, d.events[1][1]
115
138
  end
116
139
 
117
140
  def test_json_with_add_remote_addr
118
141
  d = create_driver(CONFIG + "add_remote_addr true")
119
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
120
-
121
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}
122
- d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}
123
-
124
- d.run do
125
- d.expected_emits.each {|tag,_time,record|
126
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
127
- assert_equal "200", res.code
128
- }
142
+ time = event_time("2011-01-02 13:14:15 UTC")
143
+ time_i = time.to_i
144
+
145
+ events = [
146
+ ["tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}],
147
+ ["tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}],
148
+ ]
149
+ res_codes = []
150
+ d.run(expect_records: 2) do
151
+ events.each do |tag, _t, record|
152
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
153
+ res_codes << res.code
154
+ end
129
155
  end
130
-
156
+ assert_equal ["200", "200"], res_codes
157
+ assert_equal events, d.events
158
+ assert_equal_event_time time, d.events[0][1]
159
+ assert_equal_event_time time, d.events[1][1]
131
160
  end
132
161
 
133
162
  def test_multi_json_with_add_remote_addr
134
163
  d = create_driver(CONFIG + "add_remote_addr true")
164
+ time = event_time("2011-01-02 13:14:15 UTC")
165
+ time_i = time.to_i
135
166
 
136
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
137
- events = [{"a"=>1},{"a"=>2}]
167
+ records = [{"a"=>1},{"a"=>2}]
138
168
  tag = "tag1"
169
+ res_codes = []
139
170
 
140
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}
141
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}
142
-
143
- d.run do
144
- res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
145
- assert_equal "200", res.code
171
+ d.run(expect_records: 2, timeout: 5) do
172
+ res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
173
+ res_codes << res.code
146
174
  end
175
+ assert_equal ["200"], res_codes
147
176
 
177
+ assert_equal "tag1", d.events[0][0]
178
+ assert_equal_event_time time, d.events[0][1]
179
+ assert_equal 1, d.events[0][2]["a"]
180
+ assert{ d.events[0][2].has_key?("REMOTE_ADDR") && d.events[0][2]["REMOTE_ADDR"] =~ /^\d{1,4}(\.\d{1,4}){3}$/ }
181
+
182
+ assert_equal "tag1", d.events[1][0]
183
+ assert_equal_event_time time, d.events[1][1]
184
+ assert_equal 2, d.events[1][2]["a"]
148
185
  end
149
186
 
150
187
  def test_json_with_add_remote_addr_given_x_forwarded_for
151
188
  d = create_driver(CONFIG + "add_remote_addr true")
152
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
153
-
154
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
155
- d.expect_emit "tag2", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
156
-
157
- d.run do
158
- d.expected_emits.each {|tag,_time,record|
159
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
160
- assert_equal "200", res.code
161
- }
189
+ time = event_time("2011-01-02 13:14:15 UTC")
190
+ time_i = time.to_i
191
+
192
+ events = [
193
+ ["tag1", time, {"a"=>1}],
194
+ ["tag2", time, {"a"=>2}],
195
+ ]
196
+ res_codes = []
197
+
198
+ d.run(expect_records: 2) do
199
+ events.each do |tag, _t, record|
200
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
201
+ res_codes << res.code
202
+ end
162
203
  end
204
+ assert_equal ["200", "200"], res_codes
163
205
 
206
+ assert_equal "tag1", d.events[0][0]
207
+ assert_equal_event_time time, d.events[0][1]
208
+ assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}, d.events[0][2])
209
+
210
+ assert_equal "tag2", d.events[1][0]
211
+ assert_equal_event_time time, d.events[1][1]
212
+ assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}, d.events[1][2])
164
213
  end
165
214
 
166
215
  def test_multi_json_with_add_remote_addr_given_x_forwarded_for
167
216
  d = create_driver(CONFIG + "add_remote_addr true")
168
217
 
169
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
170
- events = [{"a"=>1},{"a"=>2}]
218
+ time = event_time("2011-01-02 13:14:15 UTC")
219
+ time_i = time.to_i
220
+ records = [{"a"=>1},{"a"=>2}]
221
+ events = [
222
+ ["tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}],
223
+ ["tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}],
224
+ ]
171
225
  tag = "tag1"
226
+ res_codes = []
172
227
 
173
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}
174
- d.expect_emit "tag1", time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}
175
-
176
- d.run do
177
- res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
178
- assert_equal "200", res.code
228
+ d.run(expect_records: 2, timeout: 5) do
229
+ res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
230
+ res_codes << res.code
179
231
  end
180
-
232
+ assert_equal ["200"], res_codes
233
+ assert_equal events, d.events
234
+ assert_equal_event_time time, d.events[0][1]
235
+ assert_equal_event_time time, d.events[1][1]
181
236
  end
182
237
 
183
238
  def test_multi_json_with_add_http_headers
184
239
  d = create_driver(CONFIG + "add_http_headers true")
185
-
186
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
187
- events = [{"a"=>1},{"a"=>2}]
240
+ time = event_time("2011-01-02 13:14:15 UTC")
241
+ time_i = time.to_i
242
+ records = [{"a"=>1},{"a"=>2}]
188
243
  tag = "tag1"
244
+ res_codes = []
189
245
 
190
- d.run do
191
- res = post("/#{tag}", {"json"=>events.to_json, "time"=>time.to_s})
192
- assert_equal "200", res.code
246
+ d.run(expect_records: 2, timeout: 5) do
247
+ res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
248
+ res_codes << res.code
193
249
  end
250
+ assert_equal ["200"], res_codes
251
+
252
+ assert_equal "tag1", d.events[0][0]
253
+ assert_equal_event_time time, d.events[0][1]
254
+ assert_equal 1, d.events[0][2]["a"]
194
255
 
195
- d.emit_streams.each { |_tag, es|
196
- assert include_http_header?(es.first[1])
197
- }
256
+ assert_equal "tag1", d.events[1][0]
257
+ assert_equal_event_time time, d.events[1][1]
258
+ assert_equal 2, d.events[1][2]["a"]
259
+
260
+ assert include_http_header?(d.events[0][2])
261
+ assert include_http_header?(d.events[1][2])
198
262
  end
199
263
 
200
264
  def test_json_with_add_http_headers
201
265
  d = create_driver(CONFIG + "add_http_headers true")
266
+ time = event_time("2011-01-02 13:14:15 UTC")
267
+ time_i = time.to_i
268
+ events = [
269
+ ["tag1", time, {"a"=>1}],
270
+ ["tag2", time, {"a"=>2}],
271
+ ]
272
+ res_codes = []
273
+
274
+ d.run(expect_records: 2) do
275
+ events.each do |tag, t, record|
276
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
277
+ res_codes << res.code
278
+ end
279
+ end
280
+ assert_equal ["200", "200"], res_codes
202
281
 
203
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
204
-
205
- records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]]
282
+ assert_equal "tag1", d.events[0][0]
283
+ assert_equal_event_time time, d.events[0][1]
284
+ assert_equal 1, d.events[0][2]["a"]
206
285
 
207
- d.run do
208
- records.each {|tag,_time,record|
209
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
210
- assert_equal "200", res.code
211
-
212
- }
213
- end
286
+ assert_equal "tag2", d.events[1][0]
287
+ assert_equal_event_time time, d.events[1][1]
288
+ assert_equal 2, d.events[1][2]["a"]
214
289
 
215
- d.emit_streams.each { |tag, es|
216
- assert include_http_header?(es.first[1])
217
- }
290
+ assert include_http_header?(d.events[0][2])
291
+ assert include_http_header?(d.events[1][2])
218
292
  end
219
293
 
220
294
  def test_application_json
221
295
  d = create_driver
222
-
223
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
224
-
225
- d.expect_emit "tag1", time, {"a"=>1}
226
- d.expect_emit "tag2", time, {"a"=>2}
227
-
228
- d.run do
229
- d.expected_emits.each {|tag,_time,record|
230
- res = post("/#{tag}?time=#{_time.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
231
- assert_equal "200", res.code
232
- }
296
+ time = event_time("2011-01-02 13:14:15 UTC")
297
+ time_i = time.to_i
298
+ events = [
299
+ ["tag1", time, {"a"=>1}],
300
+ ["tag2", time, {"a"=>2}],
301
+ ]
302
+ res_codes = []
303
+
304
+ d.run(expect_records: 2) do
305
+ events.each do |tag, t, record|
306
+ res = post("/#{tag}?time=#{time_i.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
307
+ res_codes << res.code
308
+ end
233
309
  end
310
+ assert_equal ["200", "200"], res_codes
311
+ assert_equal events, d.events
312
+ assert_equal_event_time time, d.events[0][1]
313
+ assert_equal_event_time time, d.events[1][1]
234
314
  end
235
315
 
236
316
  def test_msgpack
237
317
  d = create_driver
238
-
239
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
240
-
241
- d.expect_emit "tag1", time, {"a"=>1}
242
- d.expect_emit "tag2", time, {"a"=>2}
243
-
244
- d.run do
245
- d.expected_emits.each {|tag,_time,record|
246
- res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>_time.to_s})
247
- assert_equal "200", res.code
248
- }
318
+ time = event_time("2011-01-02 13:14:15 UTC")
319
+ time_i = time.to_i
320
+
321
+ events = [
322
+ ["tag1", time, {"a"=>1}],
323
+ ["tag2", time, {"a"=>2}],
324
+ ]
325
+ res_codes = []
326
+
327
+ d.run(expect_records: 2) do
328
+ events.each do |tag, t, record|
329
+ res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time_i.to_s})
330
+ res_codes << res.code
331
+ end
249
332
  end
333
+ assert_equal ["200", "200"], res_codes
334
+ assert_equal events, d.events
335
+ assert_equal_event_time time, d.events[0][1]
336
+ assert_equal_event_time time, d.events[1][1]
250
337
  end
251
338
 
252
339
  def test_multi_msgpack
253
340
  d = create_driver
254
341
 
255
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
342
+ time = event_time("2011-01-02 13:14:15 UTC")
343
+ time_i = time.to_i
256
344
 
257
- events = [{"a"=>1},{"a"=>2}]
345
+ records = [{"a"=>1},{"a"=>2}]
346
+ events = [
347
+ ["tag1", time, records[0]],
348
+ ["tag1", time, records[1]],
349
+ ]
258
350
  tag = "tag1"
259
-
260
- events.each { |ev|
261
- d.expect_emit tag, time, ev
262
- }
263
-
264
- d.run do
265
- res = post("/#{tag}", {"msgpack"=>events.to_msgpack, "time"=>time.to_s})
266
- assert_equal "200", res.code
351
+ res_codes = []
352
+ d.run(expect_records: 2) do
353
+ res = post("/#{tag}", {"msgpack"=>records.to_msgpack, "time"=>time_i.to_s})
354
+ res_codes << res.code
267
355
  end
268
-
356
+ assert_equal ["200"], res_codes
357
+ assert_equal events, d.events
358
+ assert_equal_event_time time, d.events[0][1]
359
+ assert_equal_event_time time, d.events[1][1]
269
360
  end
270
361
 
271
362
  def test_with_regexp
@@ -274,20 +365,27 @@ class HttpInputTest < Test::Unit::TestCase
274
365
  types field_1:integer
275
366
  ])
276
367
 
277
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
368
+ time = event_time("2011-01-02 13:14:15 UTC")
369
+ time_i = time.to_i
370
+ events = [
371
+ ["tag1", time, {"field_1" => 1, "field_2" => 'str'}],
372
+ ["tag2", time, {"field_1" => 2, "field_2" => 'str'}],
373
+ ]
374
+ res_codes = []
278
375
 
279
- d.expect_emit "tag1", time, {"field_1" => 1, "field_2" => 'str'}
280
- d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'}
281
-
282
- d.run do
283
- d.expected_emits.each { |tag, _time, record|
376
+ d.run(expect_records: 2) do
377
+ events.each do |tag, t, record|
284
378
  body = record.map { |k, v|
285
379
  v.to_s
286
380
  }.join(':')
287
- res = post("/#{tag}?time=#{_time.to_s}", body, {'Content-Type' => 'application/octet-stream'})
288
- assert_equal "200", res.code
289
- }
381
+ res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'application/octet-stream'})
382
+ res_codes << res.code
383
+ end
290
384
  end
385
+ assert_equal ["200", "200"], res_codes
386
+ assert_equal events, d.events
387
+ assert_equal_event_time time, d.events[0][1]
388
+ assert_equal_event_time time, d.events[1][1]
291
389
  end
292
390
 
293
391
  def test_with_csv
@@ -297,72 +395,98 @@ class HttpInputTest < Test::Unit::TestCase
297
395
  format csv
298
396
  keys foo,bar
299
397
  ])
300
-
301
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
302
-
303
- d.expect_emit "tag1", time, {"foo" => "1", "bar" => 'st"r'}
304
- d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'}
305
-
306
- d.run do
307
- d.expected_emits.each { |tag, _time, record|
398
+ time = event_time("2011-01-02 13:14:15 UTC")
399
+ time_i = time.to_i
400
+ events = [
401
+ ["tag1", time, {"foo" => "1", "bar" => 'st"r'}],
402
+ ["tag2", time, {"foo" => "2", "bar" => 'str'}],
403
+ ]
404
+ res_codes = []
405
+
406
+ d.run(expect_records: 2) do
407
+ events.each do |tag, t, record|
308
408
  body = record.map { |k, v| v }.to_csv
309
- res = post("/#{tag}?time=#{_time.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
310
- assert_equal "200", res.code
311
- }
409
+ res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
410
+ res_codes << res.code
411
+ end
312
412
  end
413
+ assert_equal ["200", "200"], res_codes
414
+ assert_equal events, d.events
415
+ assert_equal_event_time time, d.events[0][1]
416
+ assert_equal_event_time time, d.events[1][1]
313
417
  end
314
418
 
315
419
  def test_resonse_with_empty_img
316
420
  d = create_driver(CONFIG + "respond_with_empty_img true")
317
421
  assert_equal true, d.instance.respond_with_empty_img
318
422
 
319
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
320
-
321
- d.expect_emit "tag1", time, {"a"=>1}
322
- d.expect_emit "tag2", time, {"a"=>2}
423
+ time = event_time("2011-01-02 13:14:15 UTC")
424
+ time_i = time.to_i
425
+ events = [
426
+ ["tag1", time, {"a"=>1}],
427
+ ["tag2", time, {"a"=>2}],
428
+ ]
429
+ res_codes = []
430
+ res_bodies = []
323
431
 
324
432
  d.run do
325
- d.expected_emits.each {|tag,_time,record|
326
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s})
327
- assert_equal "200", res.code
433
+ events.each do |tag, _t, record|
434
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
435
+ res_codes << res.code
328
436
  # Ruby returns ASCII-8 encoded string for GIF.
329
- assert_equal Fluent::HttpInput::EMPTY_GIF_IMAGE, res.body.force_encoding("UTF-8")
330
- }
437
+ res_bodies << res.body.force_encoding("UTF-8")
438
+ end
331
439
  end
440
+ assert_equal ["200", "200"], res_codes
441
+ assert_equal [Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE, Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE], res_bodies
442
+ assert_equal events, d.events
443
+ assert_equal_event_time time, d.events[0][1]
444
+ assert_equal_event_time time, d.events[1][1]
332
445
  end
333
446
 
334
447
  def test_cors_allowed
335
448
  d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
336
449
  assert_equal ["http://foo.com"], d.instance.cors_allow_origins
337
450
 
338
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
339
-
340
- d.expect_emit "tag1", time, {"a"=>1}
341
- d.expect_emit "tag2", time, {"a"=>1}
451
+ time = event_time("2011-01-02 13:14:15 UTC")
452
+ time_i = time.to_i
453
+ events = [
454
+ ["tag1", time, {"a"=>1}],
455
+ ["tag2", time, {"a"=>2}],
456
+ ]
457
+ res_codes = []
458
+ res_headers = []
342
459
 
343
460
  d.run do
344
- d.expected_emits.each {|tag,_time,record|
345
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>_time.to_s}, {"Origin"=>"http://foo.com"})
346
- assert_equal "200", res.code
347
- assert_equal "http://foo.com", res["Access-Control-Allow-Origin"]
348
- }
461
+ events.each do |tag, _t, record|
462
+ res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://foo.com"})
463
+ res_codes << res.code
464
+ res_headers << res["Access-Control-Allow-Origin"]
465
+ end
349
466
  end
467
+ assert_equal ["200", "200"], res_codes
468
+ assert_equal ["http://foo.com", "http://foo.com"], res_headers
469
+ assert_equal events, d.events
470
+ assert_equal_event_time time, d.events[0][1]
471
+ assert_equal_event_time time, d.events[1][1]
350
472
  end
351
473
 
352
474
  def test_cors_disallowed
353
475
  d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
354
476
  assert_equal ["http://foo.com"], d.instance.cors_allow_origins
355
477
 
356
- time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i)
478
+ time = event_time("2011-01-02 13:14:15 UTC")
479
+ time_i = time.to_i
480
+ res_codes = []
357
481
 
358
- d.expected_emits_length = 0
482
+ d.end_if{ res_codes.size == 2 }
359
483
  d.run do
360
- res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time.to_s}, {"Origin"=>"http://bar.com"})
361
- assert_equal "403", res.code
362
-
363
- res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time.to_s}, {"Origin"=>"http://bar.com"})
364
- assert_equal "403", res.code
484
+ res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
485
+ res_codes << res.code
486
+ res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
487
+ res_codes << res.code
365
488
  end
489
+ assert_equal ["403", "403"], res_codes
366
490
  end
367
491
 
368
492
  $test_in_http_connection_object_ids = []
@@ -388,7 +512,7 @@ class HttpInputTest < Test::Unit::TestCase
388
512
  end
389
513
  end
390
514
 
391
- class Fluent::HttpInput::Handler
515
+ class Fluent::Plugin::HttpInput::Handler
392
516
  prepend ContentTypeHook
393
517
  end
394
518