fluentd 0.14.0 → 0.14.1
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.
- checksums.yaml +4 -4
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +5 -5
- data/example/in_forward.conf +2 -2
- data/example/in_http.conf +2 -2
- data/example/in_syslog.conf +2 -2
- data/example/in_tail.conf +2 -2
- data/example/in_tcp.conf +2 -2
- data/example/in_udp.conf +2 -2
- data/example/out_buffered_null.conf +32 -0
- data/example/out_copy.conf +4 -4
- data/example/out_file.conf +2 -2
- data/example/out_forward.conf +2 -2
- data/example/v0_12_filter.conf +8 -8
- data/fluentd.gemspec +1 -1
- data/lib/fluent/command/fluentd.rb +6 -1
- data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
- data/lib/fluent/compat/input.rb +1 -0
- data/lib/fluent/compat/output.rb +1 -0
- data/lib/fluent/compat/record_filter_mixin.rb +34 -0
- data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
- data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
- data/lib/fluent/compat/type_converter.rb +90 -0
- data/lib/fluent/config/configure_proxy.rb +24 -4
- data/lib/fluent/config/dsl.rb +18 -1
- data/lib/fluent/config/v1_parser.rb +3 -2
- data/lib/fluent/configurable.rb +1 -1
- data/lib/fluent/event.rb +37 -9
- data/lib/fluent/mixin.rb +12 -286
- data/lib/fluent/plugin/buffer.rb +2 -2
- data/lib/fluent/plugin/in_dummy.rb +5 -1
- data/lib/fluent/plugin/in_gc_stat.rb +7 -37
- data/lib/fluent/plugin/in_http.rb +2 -0
- data/lib/fluent/plugin/{in_stream.rb → in_unix.rb} +0 -0
- data/lib/fluent/plugin/out_buffered_stdout.rb +60 -0
- data/lib/fluent/plugin/out_copy.rb +8 -51
- data/lib/fluent/plugin/out_null.rb +5 -5
- data/lib/fluent/plugin/out_relabel.rb +5 -5
- data/lib/fluent/plugin/out_roundrobin.rb +13 -40
- data/lib/fluent/plugin/output.rb +9 -0
- data/lib/fluent/plugin_helper.rb +2 -0
- data/lib/fluent/plugin_helper/formatter.rb +138 -0
- data/lib/fluent/plugin_helper/inject.rb +112 -0
- data/lib/fluent/plugin_helper/parser.rb +138 -0
- data/lib/fluent/plugin_helper/storage.rb +64 -50
- data/lib/fluent/process.rb +6 -1
- data/lib/fluent/registry.rb +1 -1
- data/lib/fluent/supervisor.rb +20 -2
- data/lib/fluent/test.rb +30 -5
- data/lib/fluent/test/base.rb +2 -66
- data/lib/fluent/test/driver/base.rb +3 -0
- data/lib/fluent/test/driver/base_owned.rb +106 -0
- data/lib/fluent/test/driver/formatter.rb +30 -0
- data/lib/fluent/test/driver/multi_output.rb +52 -0
- data/lib/fluent/test/driver/owner.rb +32 -0
- data/lib/fluent/test/driver/parser.rb +30 -0
- data/lib/fluent/test/helpers.rb +54 -0
- data/lib/fluent/test/log.rb +73 -0
- data/lib/fluent/time.rb +71 -0
- data/lib/fluent/version.rb +1 -1
- data/test/compat/test_parser.rb +82 -0
- data/test/config/test_configure_proxy.rb +15 -0
- data/test/config/test_dsl.rb +180 -2
- data/test/helper.rb +2 -24
- data/test/plugin/test_in_gc_stat.rb +6 -6
- data/test/plugin/test_in_http.rb +49 -32
- data/test/plugin/{test_in_stream.rb → test_in_unix.rb} +1 -1
- data/test/plugin/test_out_buffered_stdout.rb +108 -0
- data/test/plugin/test_out_copy.rb +88 -127
- data/test/plugin/test_out_null.rb +29 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +35 -29
- data/test/plugin/test_out_stdout.rb +4 -4
- data/test/plugin/test_output_as_buffered.rb +51 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +13 -0
- data/test/plugin/test_parser_apache.rb +38 -0
- data/test/plugin/test_parser_apache2.rb +38 -0
- data/test/plugin/test_parser_apache_error.rb +40 -0
- data/test/plugin/test_parser_base.rb +32 -0
- data/test/plugin/test_parser_csv.rb +94 -0
- data/test/plugin/test_parser_json.rb +107 -0
- data/test/plugin/test_parser_labeled_tsv.rb +129 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +42 -0
- data/test/plugin/test_parser_none.rb +53 -0
- data/test/plugin/test_parser_regexp.rb +110 -0
- data/test/plugin/test_parser_syslog.rb +66 -0
- data/test/plugin/test_parser_time.rb +46 -0
- data/test/plugin/test_parser_tsv.rb +125 -0
- data/test/plugin_helper/test_child_process.rb +11 -2
- data/test/plugin_helper/test_formatter.rb +212 -0
- data/test/plugin_helper/test_inject.rb +388 -0
- data/test/plugin_helper/test_parser.rb +223 -0
- data/test/plugin_helper/test_retry_state.rb +40 -40
- data/test/plugin_helper/test_storage.rb +77 -10
- data/test/scripts/fluent/plugin/out_test.rb +22 -17
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/test_event.rb +57 -0
- data/test/test_formatter.rb +0 -178
- data/test/test_output.rb +2 -152
- data/test/test_root_agent.rb +3 -2
- data/test/test_supervisor.rb +93 -26
- data/test/test_time_formatter.rb +186 -0
- metadata +69 -7
- data/test/test_parser.rb +0 -1087
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Fluent::Plugin
|
18
|
+
class Test2Output < Output
|
19
|
+
Fluent::Plugin.register_output('test2', self)
|
20
|
+
|
21
|
+
helpers :event_emitter
|
22
|
+
|
23
|
+
config_param :name, :string
|
24
|
+
|
25
|
+
config_section :buffer do
|
26
|
+
config_set_default :chunk_keys, ['tag']
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
super
|
31
|
+
@emit_streams = []
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :emit_streams
|
35
|
+
|
36
|
+
def emits
|
37
|
+
all = []
|
38
|
+
@emit_streams.each {|tag,events|
|
39
|
+
events.each {|time,record|
|
40
|
+
all << [tag, time, record]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
all
|
44
|
+
end
|
45
|
+
|
46
|
+
def events
|
47
|
+
all = []
|
48
|
+
@emit_streams.each {|tag,events|
|
49
|
+
all.concat events
|
50
|
+
}
|
51
|
+
all
|
52
|
+
end
|
53
|
+
|
54
|
+
def records
|
55
|
+
all = []
|
56
|
+
@emit_streams.each {|tag,events|
|
57
|
+
events.each {|time,record|
|
58
|
+
all << record
|
59
|
+
}
|
60
|
+
}
|
61
|
+
all
|
62
|
+
end
|
63
|
+
|
64
|
+
def prefer_buffered_processing
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
def process(tag, es)
|
69
|
+
@emit_streams << [tag, es.to_a]
|
70
|
+
end
|
71
|
+
|
72
|
+
def write(chunk)
|
73
|
+
es = Fluent::ArrayEventStream.new
|
74
|
+
chunk.each do |time, record|
|
75
|
+
es.add(time, record)
|
76
|
+
end
|
77
|
+
@emit_streams << [tag, es]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/test/test_event.rb
CHANGED
@@ -3,8 +3,26 @@ require 'fluent/test'
|
|
3
3
|
require 'fluent/event'
|
4
4
|
|
5
5
|
module EventTest
|
6
|
+
module DeepCopyAssertion
|
7
|
+
def assert_duplicated_records(es1, es2)
|
8
|
+
ary1 = []
|
9
|
+
es1.each do |_, record|
|
10
|
+
ary1 << record
|
11
|
+
end
|
12
|
+
ary2 = []
|
13
|
+
es2.each do |_, record|
|
14
|
+
ary2 << record
|
15
|
+
end
|
16
|
+
assert_equal ary1.size, ary2.size
|
17
|
+
ary1.each_with_index do |r, i|
|
18
|
+
assert_not_equal r.object_id, ary2[i].object_id
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
6
23
|
class OneEventStreamTest < ::Test::Unit::TestCase
|
7
24
|
include Fluent
|
25
|
+
include DeepCopyAssertion
|
8
26
|
|
9
27
|
def setup
|
10
28
|
@time = event_time()
|
@@ -12,6 +30,14 @@ module EventTest
|
|
12
30
|
@es = OneEventStream.new(@time, @record)
|
13
31
|
end
|
14
32
|
|
33
|
+
test 'empty?' do
|
34
|
+
assert_false @es.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'size' do
|
38
|
+
assert_equal 1, @es.size
|
39
|
+
end
|
40
|
+
|
15
41
|
test 'repeatable?' do
|
16
42
|
assert_true @es.repeatable?
|
17
43
|
end
|
@@ -20,6 +46,21 @@ module EventTest
|
|
20
46
|
dupped = @es.dup
|
21
47
|
assert_kind_of OneEventStream, dupped
|
22
48
|
assert_not_equal @es.object_id, dupped.object_id
|
49
|
+
assert_duplicated_records @es, dupped
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'slice' do
|
53
|
+
assert_equal 0, @es.slice(1, 1).size
|
54
|
+
assert_equal 0, @es.slice(0, 0).size
|
55
|
+
|
56
|
+
sliced = @es.slice(0, 1)
|
57
|
+
assert_kind_of EventStream, sliced
|
58
|
+
assert_equal 1, sliced.size
|
59
|
+
|
60
|
+
sliced.each do |time, record|
|
61
|
+
assert_equal @time, time
|
62
|
+
assert_equal @record, record
|
63
|
+
end
|
23
64
|
end
|
24
65
|
|
25
66
|
test 'each' do
|
@@ -48,6 +89,7 @@ module EventTest
|
|
48
89
|
|
49
90
|
class ArrayEventStreamTest < ::Test::Unit::TestCase
|
50
91
|
include Fluent
|
92
|
+
include DeepCopyAssertion
|
51
93
|
|
52
94
|
def setup
|
53
95
|
time = Engine.now
|
@@ -64,6 +106,7 @@ module EventTest
|
|
64
106
|
dupped = @es.dup
|
65
107
|
assert_kind_of ArrayEventStream, dupped
|
66
108
|
assert_not_equal @es.object_id, dupped.object_id
|
109
|
+
assert_duplicated_records @es, dupped
|
67
110
|
end
|
68
111
|
|
69
112
|
test 'empty?' do
|
@@ -93,6 +136,7 @@ module EventTest
|
|
93
136
|
|
94
137
|
class MultiEventStreamTest < ::Test::Unit::TestCase
|
95
138
|
include Fluent
|
139
|
+
include DeepCopyAssertion
|
96
140
|
|
97
141
|
def setup
|
98
142
|
time = Engine.now
|
@@ -112,6 +156,7 @@ module EventTest
|
|
112
156
|
dupped = @es.dup
|
113
157
|
assert_kind_of MultiEventStream, dupped
|
114
158
|
assert_not_equal @es.object_id, dupped.object_id
|
159
|
+
assert_duplicated_records @es, dupped
|
115
160
|
end
|
116
161
|
|
117
162
|
test 'empty?' do
|
@@ -141,6 +186,7 @@ module EventTest
|
|
141
186
|
|
142
187
|
class MessagePackEventStreamTest < ::Test::Unit::TestCase
|
143
188
|
include Fluent
|
189
|
+
include DeepCopyAssertion
|
144
190
|
|
145
191
|
def setup
|
146
192
|
pk = Fluent::Engine.msgpack_factory.packer
|
@@ -153,6 +199,17 @@ module EventTest
|
|
153
199
|
@es = MessagePackEventStream.new(pk.to_s)
|
154
200
|
end
|
155
201
|
|
202
|
+
test 'dup' do
|
203
|
+
dupped = @es.dup
|
204
|
+
assert_kind_of MessagePackEventStream, dupped
|
205
|
+
assert_not_equal @es.object_id, dupped.object_id
|
206
|
+
assert_duplicated_records @es, dupped
|
207
|
+
end
|
208
|
+
|
209
|
+
test 'empty?' do
|
210
|
+
assert_false @es.empty?
|
211
|
+
end
|
212
|
+
|
156
213
|
test 'repeatable?' do
|
157
214
|
assert_true @es.repeatable?
|
158
215
|
end
|
data/test/test_formatter.rb
CHANGED
@@ -430,184 +430,6 @@ module FormatterTest
|
|
430
430
|
end
|
431
431
|
end
|
432
432
|
|
433
|
-
class TimeFormatterTest < ::Test::Unit::TestCase
|
434
|
-
include FormatterTest
|
435
|
-
|
436
|
-
def setup
|
437
|
-
@time = Time.new(2014, 9, 27, 0, 0, 0, 0).to_i
|
438
|
-
@fmt = "%Y%m%d %H%M%z" # YYYYMMDD HHMM[+-]HHMM
|
439
|
-
end
|
440
|
-
|
441
|
-
def format(format, localtime, timezone)
|
442
|
-
formatter = Fluent::TimeFormatter.new(format, localtime, timezone)
|
443
|
-
formatter.format(@time)
|
444
|
-
end
|
445
|
-
|
446
|
-
def test_default_utc_nil
|
447
|
-
assert_equal("2014-09-27T00:00:00Z", format(nil, false, nil))
|
448
|
-
end
|
449
|
-
|
450
|
-
def test_default_utc_pHH_MM
|
451
|
-
assert_equal("2014-09-27T01:30:00+01:30", format(nil, false, "+01:30"))
|
452
|
-
end
|
453
|
-
|
454
|
-
def test_default_utc_nHH_MM
|
455
|
-
assert_equal("2014-09-26T22:30:00-01:30", format(nil, false, "-01:30"))
|
456
|
-
end
|
457
|
-
|
458
|
-
def test_default_utc_pHHMM
|
459
|
-
assert_equal("2014-09-27T02:30:00+02:30", format(nil, false, "+0230"))
|
460
|
-
end
|
461
|
-
|
462
|
-
def test_default_utc_nHHMM
|
463
|
-
assert_equal("2014-09-26T21:30:00-02:30", format(nil, false, "-0230"))
|
464
|
-
end
|
465
|
-
|
466
|
-
def test_default_utc_pHH
|
467
|
-
assert_equal("2014-09-27T03:00:00+03:00", format(nil, false, "+03"))
|
468
|
-
end
|
469
|
-
|
470
|
-
def test_default_utc_nHH
|
471
|
-
assert_equal("2014-09-26T21:00:00-03:00", format(nil, false, "-03"))
|
472
|
-
end
|
473
|
-
|
474
|
-
def test_default_utc_timezone_1
|
475
|
-
# Asia/Tokyo (+09:00) does not have daylight saving time.
|
476
|
-
assert_equal("2014-09-27T09:00:00+09:00", format(nil, false, "Asia/Tokyo"))
|
477
|
-
end
|
478
|
-
|
479
|
-
def test_default_utc_timezone_2
|
480
|
-
# Pacific/Honolulu (-10:00) does not have daylight saving time.
|
481
|
-
assert_equal("2014-09-26T14:00:00-10:00", format(nil, false, "Pacific/Honolulu"))
|
482
|
-
end
|
483
|
-
|
484
|
-
def test_default_utc_timezone_3
|
485
|
-
# America/Argentina/Buenos_Aires (-03:00) does not have daylight saving time.
|
486
|
-
assert_equal("2014-09-26T21:00:00-03:00", format(nil, false, "America/Argentina/Buenos_Aires"))
|
487
|
-
end
|
488
|
-
|
489
|
-
def test_default_utc_timezone_4
|
490
|
-
# Europe/Paris has daylight saving time. Its UTC offset is +01:00 and its
|
491
|
-
# UTC offset in DST is +02:00. In September, Europe/Paris is in DST.
|
492
|
-
assert_equal("2014-09-27T02:00:00+02:00", format(nil, false, "Europe/Paris"))
|
493
|
-
end
|
494
|
-
|
495
|
-
def test_default_utc_timezone_5
|
496
|
-
# Europe/Paris has daylight saving time. Its UTC offset is +01:00 and its
|
497
|
-
# UTC offset in DST is +02:00. In January, Europe/Paris is not in DST.
|
498
|
-
@time = Time.new(2014, 1, 24, 0, 0, 0, 0).to_i
|
499
|
-
assert_equal("2014-01-24T01:00:00+01:00", format(nil, false, "Europe/Paris"))
|
500
|
-
end
|
501
|
-
|
502
|
-
def test_default_utc_invalid
|
503
|
-
assert_equal("2014-09-27T00:00:00Z", format(nil, false, "Invalid"))
|
504
|
-
end
|
505
|
-
|
506
|
-
def test_default_localtime_nil_1
|
507
|
-
with_timezone("UTC-04") do
|
508
|
-
assert_equal("2014-09-27T04:00:00+04:00", format(nil, true, nil))
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
|
-
def test_default_localtime_nil_2
|
513
|
-
with_timezone("UTC+05") do
|
514
|
-
assert_equal("2014-09-26T19:00:00-05:00", format(nil, true, nil))
|
515
|
-
end
|
516
|
-
end
|
517
|
-
|
518
|
-
def test_default_localtime_timezone
|
519
|
-
# 'timezone' takes precedence over 'localtime'.
|
520
|
-
with_timezone("UTC-06") do
|
521
|
-
assert_equal("2014-09-27T07:00:00+07:00", format(nil, true, "+07"))
|
522
|
-
end
|
523
|
-
end
|
524
|
-
|
525
|
-
def test_specific_utc_nil
|
526
|
-
assert_equal("20140927 0000+0000", format(@fmt, false, nil))
|
527
|
-
end
|
528
|
-
|
529
|
-
def test_specific_utc_pHH_MM
|
530
|
-
assert_equal("20140927 0830+0830", format(@fmt, false, "+08:30"))
|
531
|
-
end
|
532
|
-
|
533
|
-
def test_specific_utc_nHH_MM
|
534
|
-
assert_equal("20140926 1430-0930", format(@fmt, false, "-09:30"))
|
535
|
-
end
|
536
|
-
|
537
|
-
def test_specific_utc_pHHMM
|
538
|
-
assert_equal("20140927 1030+1030", format(@fmt, false, "+1030"))
|
539
|
-
end
|
540
|
-
|
541
|
-
def test_specific_utc_nHHMM
|
542
|
-
assert_equal("20140926 1230-1130", format(@fmt, false, "-1130"))
|
543
|
-
end
|
544
|
-
|
545
|
-
def test_specific_utc_pHH
|
546
|
-
assert_equal("20140927 1200+1200", format(@fmt, false, "+12"))
|
547
|
-
end
|
548
|
-
|
549
|
-
def test_specific_utc_nHH
|
550
|
-
assert_equal("20140926 1100-1300", format(@fmt, false, "-13"))
|
551
|
-
end
|
552
|
-
|
553
|
-
def test_specific_utc_timezone_1
|
554
|
-
# Europe/Moscow (+04:00) does not have daylight saving time.
|
555
|
-
assert_equal("20140927 0400+0400", format(@fmt, false, "Europe/Moscow"))
|
556
|
-
end
|
557
|
-
|
558
|
-
def test_specific_utc_timezone_2
|
559
|
-
# Pacific/Galapagos (-06:00) does not have daylight saving time.
|
560
|
-
assert_equal("20140926 1800-0600", format(@fmt, false, "Pacific/Galapagos"))
|
561
|
-
end
|
562
|
-
|
563
|
-
def test_specific_utc_timezone_3
|
564
|
-
# America/Argentina/Buenos_Aires (-03:00) does not have daylight saving time.
|
565
|
-
assert_equal("20140926 2100-0300", format(@fmt, false, "America/Argentina/Buenos_Aires"))
|
566
|
-
end
|
567
|
-
|
568
|
-
def test_specific_utc_timezone_4
|
569
|
-
# America/Los_Angeles has daylight saving time. Its UTC offset is -08:00 and its
|
570
|
-
# UTC offset in DST is -07:00. In September, America/Los_Angeles is in DST.
|
571
|
-
assert_equal("20140926 1700-0700", format(@fmt, false, "America/Los_Angeles"))
|
572
|
-
end
|
573
|
-
|
574
|
-
def test_specific_utc_timezone_5
|
575
|
-
# America/Los_Angeles has daylight saving time. Its UTC offset is -08:00 and its
|
576
|
-
# UTC offset in DST is -07:00. In January, America/Los_Angeles is not in DST.
|
577
|
-
@time = Time.new(2014, 1, 24, 0, 0, 0, 0).to_i
|
578
|
-
assert_equal("20140123 1600-0800", format(@fmt, false, "America/Los_Angeles"))
|
579
|
-
end
|
580
|
-
|
581
|
-
def test_specific_utc_invalid
|
582
|
-
assert_equal("20140927 0000+0000", format(@fmt, false, "Invalid"))
|
583
|
-
end
|
584
|
-
|
585
|
-
def test_specific_localtime_nil_1
|
586
|
-
with_timezone("UTC-07") do
|
587
|
-
assert_equal("20140927 0700+0700", format(@fmt, true, nil))
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
def test_specific_localtime_nil_2
|
592
|
-
with_timezone("UTC+08") do
|
593
|
-
assert_equal("20140926 1600-0800", format(@fmt, true, nil))
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
def test_specific_localtime_timezone
|
598
|
-
# 'timezone' takes precedence over 'localtime'.
|
599
|
-
with_timezone("UTC-09") do
|
600
|
-
assert_equal("20140926 1400-1000", format(@fmt, true, "-10"))
|
601
|
-
end
|
602
|
-
end
|
603
|
-
|
604
|
-
def test_format_with_subsec
|
605
|
-
time = Fluent::EventTime.new(@time)
|
606
|
-
formatter = Fluent::TimeFormatter.new("%Y%m%d %H%M.%N", false, nil)
|
607
|
-
assert_equal("20140927 0000.000000000", formatter.format(time))
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
433
|
class TimeConfigTest < ::Test::Unit::TestCase
|
612
434
|
include FormatterTest
|
613
435
|
|
data/test/test_output.rb
CHANGED
@@ -16,6 +16,7 @@ module FluentOutputTest
|
|
16
16
|
def startup
|
17
17
|
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), 'scripts'))
|
18
18
|
require 'fluent/plugin/out_test'
|
19
|
+
require 'fluent/plugin/out_test2'
|
19
20
|
end
|
20
21
|
|
21
22
|
def shutdown
|
@@ -64,54 +65,6 @@ module FluentOutputTest
|
|
64
65
|
# assert_equal Float, d.instance.retry_wait.class
|
65
66
|
end
|
66
67
|
|
67
|
-
def test_calc_retry_wait
|
68
|
-
omit "too internal test"
|
69
|
-
|
70
|
-
# default
|
71
|
-
d = create_driver
|
72
|
-
d.instance.retry_limit.times {
|
73
|
-
# "d.instance.instance_variable_get(:@num_errors) += 1" causes SyntaxError
|
74
|
-
d.instance.instance_eval { @num_errors += 1 }
|
75
|
-
}
|
76
|
-
wait = d.instance.retry_wait * (2 ** (d.instance.retry_limit - 1))
|
77
|
-
assert( d.instance.calc_retry_wait > wait - wait / 8.0 )
|
78
|
-
|
79
|
-
# max_retry_wait
|
80
|
-
d = create_driver(CONFIG + %[max_retry_wait 4])
|
81
|
-
d.instance.retry_limit.times {
|
82
|
-
d.instance.instance_eval { @num_errors += 1 }
|
83
|
-
}
|
84
|
-
assert_equal 4, d.instance.calc_retry_wait
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_calc_retry_wait_with_integer_retry_wait
|
88
|
-
omit "too internal test"
|
89
|
-
|
90
|
-
d = create_driver(CONFIG + %[retry_wait 2s])
|
91
|
-
d.instance.retry_limit.times {
|
92
|
-
d.instance.instance_eval { @num_errors += 1 }
|
93
|
-
}
|
94
|
-
assert_equal true, d.instance.calc_retry_wait.finite?
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_large_num_retries
|
98
|
-
omit "too internal test"
|
99
|
-
|
100
|
-
# Test that everything works properly after a very large number of
|
101
|
-
# retries and we hit the expected max_retry_wait.
|
102
|
-
exp_max_retry_wait = 300
|
103
|
-
d = create_driver(CONFIG + %[
|
104
|
-
disable_retry_limit true
|
105
|
-
max_retry_wait #{exp_max_retry_wait}
|
106
|
-
])
|
107
|
-
d.instance.instance_eval { @num_errors += 1000 }
|
108
|
-
assert_equal exp_max_retry_wait, d.instance.calc_retry_wait
|
109
|
-
d.instance.instance_eval { @num_errors += 1000 }
|
110
|
-
assert_equal exp_max_retry_wait, d.instance.calc_retry_wait
|
111
|
-
d.instance.instance_eval { @num_errors += 1000 }
|
112
|
-
assert_equal exp_max_retry_wait, d.instance.calc_retry_wait
|
113
|
-
end
|
114
|
-
|
115
68
|
def create_mock_driver(conf=CONFIG)
|
116
69
|
Fluent::Test::BufferedOutputTestDriver.new(Fluent::BufferedOutput) do
|
117
70
|
attr_accessor :submit_flush_threads
|
@@ -141,78 +94,15 @@ module FluentOutputTest
|
|
141
94
|
end.configure(conf)
|
142
95
|
end
|
143
96
|
|
144
|
-
def test_submit_flush_target
|
145
|
-
omit "too internal test"
|
146
|
-
|
147
|
-
# default
|
148
|
-
d = create_mock_driver
|
149
|
-
d.instance.start_mock
|
150
|
-
assert_equal 0, d.instance.instance_variable_get('@writer_current_position')
|
151
|
-
d.instance.submit_flush
|
152
|
-
assert_equal 0, d.instance.instance_variable_get('@writer_current_position')
|
153
|
-
d.instance.submit_flush
|
154
|
-
assert_equal 0, d.instance.instance_variable_get('@writer_current_position')
|
155
|
-
d.instance.submit_flush
|
156
|
-
assert_equal 0, d.instance.instance_variable_get('@writer_current_position')
|
157
|
-
d.instance.submit_flush
|
158
|
-
assert_equal 0, d.instance.instance_variable_get('@writer_current_position')
|
159
|
-
d.instance.shutdown
|
160
|
-
assert_equal 1, d.instance.submit_flush_threads.size
|
161
|
-
|
162
|
-
# num_threads 4
|
163
|
-
d = create_mock_driver(CONFIG + %[num_threads 4])
|
164
|
-
d.instance.start
|
165
|
-
assert_equal 0, d.instance.instance_variable_get('@writer_current_position')
|
166
|
-
d.instance.submit_flush
|
167
|
-
assert_equal 1, d.instance.instance_variable_get('@writer_current_position')
|
168
|
-
d.instance.submit_flush
|
169
|
-
assert_equal 2, d.instance.instance_variable_get('@writer_current_position')
|
170
|
-
d.instance.submit_flush
|
171
|
-
assert_equal 3, d.instance.instance_variable_get('@writer_current_position')
|
172
|
-
d.instance.submit_flush
|
173
|
-
assert_equal 0, d.instance.instance_variable_get('@writer_current_position')
|
174
|
-
d.instance.shutdown
|
175
|
-
assert (d.instance.submit_flush_threads.size > 1), "fails if only one thread works to submit flush"
|
176
|
-
end
|
177
|
-
|
178
97
|
def test_secondary
|
179
98
|
d = create_driver(CONFIG + %[
|
180
99
|
<secondary>
|
181
|
-
type
|
100
|
+
type test2
|
182
101
|
name c0
|
183
102
|
</secondary>
|
184
103
|
])
|
185
104
|
assert_not_nil d.instance.instance_variable_get(:@secondary).router
|
186
105
|
end
|
187
|
-
|
188
|
-
sub_test_case "test_force_flush" do
|
189
|
-
setup do
|
190
|
-
time = Time.parse("2011-01-02 13:14:15 UTC")
|
191
|
-
Timecop.freeze(time)
|
192
|
-
@time = time.to_i
|
193
|
-
end
|
194
|
-
|
195
|
-
teardown do
|
196
|
-
Timecop.return
|
197
|
-
end
|
198
|
-
|
199
|
-
test "force_flush works on retrying" do
|
200
|
-
omit "too internal test"
|
201
|
-
|
202
|
-
d = create_driver(CONFIG)
|
203
|
-
d.instance.start
|
204
|
-
buffer = d.instance.instance_variable_get(:@buffer)
|
205
|
-
# imitate 10 failures
|
206
|
-
d.instance.instance_variable_set(:@num_errors, 10)
|
207
|
-
d.instance.instance_variable_set(:@next_retry_time, @time + d.instance.calc_retry_wait)
|
208
|
-
# buffer should be popped (flushed) immediately
|
209
|
-
flexmock(buffer).should_receive(:pop).once
|
210
|
-
# force_flush
|
211
|
-
buffer.emit("test", 'test', NullOutputChain.instance)
|
212
|
-
d.instance.force_flush
|
213
|
-
10.times { sleep 0.05 }
|
214
|
-
end
|
215
|
-
end
|
216
106
|
end
|
217
107
|
|
218
108
|
class ObjectBufferedOutputTest < ::Test::Unit::TestCase
|
@@ -262,33 +152,6 @@ module FluentOutputTest
|
|
262
152
|
Fluent::Test::TimeSlicedOutputTestDriver.new(TimeSlicedOutputTestPlugin).configure(conf, true)
|
263
153
|
end
|
264
154
|
|
265
|
-
sub_test_case "force_flush test" do
|
266
|
-
setup do
|
267
|
-
time = Time.parse("2011-01-02 13:14:15 UTC")
|
268
|
-
Timecop.freeze(time)
|
269
|
-
@es = OneEventStream.new(time.to_i, {"message" => "foo"})
|
270
|
-
end
|
271
|
-
|
272
|
-
teardown do
|
273
|
-
Timecop.return
|
274
|
-
end
|
275
|
-
|
276
|
-
test "force_flush immediately flushes" do
|
277
|
-
omit "too internal test"
|
278
|
-
|
279
|
-
d = create_driver(CONFIG + %[
|
280
|
-
time_format %Y%m%d%H%M%S
|
281
|
-
])
|
282
|
-
d.instance.start
|
283
|
-
# buffer should be popped (flushed) immediately
|
284
|
-
flexmock(d.instance.instance_variable_get(:@buffer)).should_receive(:pop).once
|
285
|
-
# force_flush
|
286
|
-
d.instance.emit('test', @es, NullOutputChain.instance)
|
287
|
-
d.instance.force_flush
|
288
|
-
10.times { sleep 0.05 }
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
155
|
sub_test_case "test emit" do
|
293
156
|
setup do
|
294
157
|
@time = Time.parse("2011-01-02 13:14:15 UTC")
|
@@ -299,19 +162,6 @@ module FluentOutputTest
|
|
299
162
|
Timecop.return
|
300
163
|
end
|
301
164
|
|
302
|
-
test "emit with valid event" do
|
303
|
-
omit "there's no #emit method anymore in output plugins"
|
304
|
-
|
305
|
-
d = create_driver
|
306
|
-
d.instance.start
|
307
|
-
if d.instance.method(:emit).arity == 3
|
308
|
-
d.instance.emit('test', OneEventStream.new(@time.to_i, {"message" => "foo"}), NullOutputChain.instance)
|
309
|
-
else
|
310
|
-
d.instance.emit('test', OneEventStream.new(@time.to_i, {"message" => "foo"}))
|
311
|
-
end
|
312
|
-
assert_equal 0, d.instance.log.logs.size
|
313
|
-
end
|
314
|
-
|
315
165
|
test "emit with invalid event" do
|
316
166
|
d = create_driver
|
317
167
|
d.instance.start
|