fluentd 0.10.62 → 0.12.0.pre.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.

Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.travis.yml +0 -4
  4. data/ChangeLog +0 -72
  5. data/Gemfile +0 -6
  6. data/Rakefile +12 -3
  7. data/example/in_http.conf +14 -0
  8. data/example/in_syslog.conf +15 -0
  9. data/example/in_tail.conf +14 -0
  10. data/example/in_tcp.conf +13 -0
  11. data/example/in_udp.conf +13 -0
  12. data/example/out_copy.conf +20 -0
  13. data/example/out_file.conf +13 -0
  14. data/example/out_forward.conf +30 -0
  15. data/fluent.conf +2 -12
  16. data/fluentd.gemspec +8 -11
  17. data/lib/fluent/agent.rb +180 -0
  18. data/lib/fluent/buffer.rb +6 -12
  19. data/lib/fluent/command/cat.rb +1 -3
  20. data/lib/fluent/command/debug.rb +1 -3
  21. data/lib/fluent/command/fluentd.rb +0 -10
  22. data/lib/fluent/config.rb +9 -3
  23. data/lib/fluent/config/basic_parser.rb +1 -6
  24. data/lib/fluent/config/configure_proxy.rb +25 -61
  25. data/lib/fluent/config/dsl.rb +16 -0
  26. data/lib/fluent/config/element.rb +21 -2
  27. data/lib/fluent/config/error.rb +16 -0
  28. data/lib/fluent/config/literal_parser.rb +9 -27
  29. data/lib/fluent/config/parser.rb +16 -0
  30. data/lib/fluent/config/section.rb +16 -2
  31. data/lib/fluent/config/types.rb +16 -1
  32. data/lib/fluent/config/v1_parser.rb +4 -12
  33. data/lib/fluent/configurable.rb +16 -0
  34. data/lib/fluent/engine.rb +43 -163
  35. data/lib/fluent/env.rb +16 -1
  36. data/lib/fluent/event.rb +20 -48
  37. data/lib/fluent/event_router.rb +187 -0
  38. data/lib/fluent/filter.rb +32 -0
  39. data/lib/fluent/formatter.rb +29 -101
  40. data/lib/fluent/input.rb +6 -4
  41. data/lib/fluent/label.rb +18 -0
  42. data/lib/fluent/load.rb +1 -3
  43. data/lib/fluent/log.rb +1 -3
  44. data/lib/fluent/match.rb +12 -19
  45. data/lib/fluent/mixin.rb +9 -25
  46. data/lib/fluent/output.rb +27 -45
  47. data/lib/fluent/parser.rb +93 -99
  48. data/lib/fluent/plugin.rb +22 -48
  49. data/lib/fluent/plugin/buf_file.rb +10 -7
  50. data/lib/fluent/plugin/buf_memory.rb +2 -3
  51. data/lib/fluent/plugin/buf_zfile.rb +75 -0
  52. data/lib/fluent/plugin/exec_util.rb +16 -0
  53. data/lib/fluent/plugin/in_debug_agent.rb +2 -3
  54. data/lib/fluent/plugin/in_exec.rb +2 -9
  55. data/lib/fluent/plugin/in_forward.rb +4 -22
  56. data/lib/fluent/plugin/in_gc_stat.rb +2 -3
  57. data/lib/fluent/plugin/in_http.rb +19 -59
  58. data/lib/fluent/plugin/in_monitor_agent.rb +21 -47
  59. data/lib/fluent/plugin/in_object_space.rb +2 -3
  60. data/lib/fluent/plugin/in_status.rb +2 -3
  61. data/lib/fluent/plugin/in_stream.rb +6 -16
  62. data/lib/fluent/plugin/in_syslog.rb +8 -17
  63. data/lib/fluent/plugin/in_tail.rb +17 -24
  64. data/lib/fluent/plugin/in_tcp.rb +16 -0
  65. data/lib/fluent/plugin/in_udp.rb +16 -0
  66. data/lib/fluent/plugin/out_copy.rb +3 -4
  67. data/lib/fluent/plugin/out_exec.rb +2 -4
  68. data/lib/fluent/plugin/out_exec_filter.rb +2 -13
  69. data/lib/fluent/plugin/out_file.rb +5 -6
  70. data/lib/fluent/plugin/out_forward.rb +4 -5
  71. data/lib/fluent/plugin/out_null.rb +2 -3
  72. data/lib/fluent/plugin/out_relabel.rb +26 -0
  73. data/lib/fluent/plugin/out_roundrobin.rb +3 -4
  74. data/lib/fluent/plugin/out_stdout.rb +2 -3
  75. data/lib/fluent/plugin/out_stream.rb +2 -3
  76. data/{test/scripts → lib}/fluent/plugin/out_test.rb +2 -3
  77. data/lib/fluent/plugin/socket_util.rb +19 -10
  78. data/lib/fluent/process.rb +4 -6
  79. data/lib/fluent/registry.rb +16 -0
  80. data/lib/fluent/root_agent.rb +212 -0
  81. data/lib/fluent/status.rb +2 -3
  82. data/lib/fluent/supervisor.rb +33 -54
  83. data/lib/fluent/test.rb +16 -0
  84. data/lib/fluent/test/base.rb +3 -17
  85. data/lib/fluent/test/input_test.rb +52 -7
  86. data/lib/fluent/test/output_test.rb +4 -20
  87. data/lib/fluent/version.rb +17 -1
  88. data/spec/config/config_parser_spec.rb +314 -0
  89. data/spec/config/configurable_spec.rb +524 -0
  90. data/spec/config/configure_proxy_spec.rb +96 -0
  91. data/spec/config/dsl_spec.rb +239 -0
  92. data/spec/config/helper.rb +49 -0
  93. data/spec/config/literal_parser_spec.rb +222 -0
  94. data/spec/config/section_spec.rb +97 -0
  95. data/spec/config/system_config_spec.rb +49 -0
  96. data/test/helper.rb +0 -25
  97. data/test/plugin/test_in_exec.rb +1 -1
  98. data/test/plugin/test_in_forward.rb +2 -1
  99. data/test/plugin/test_in_gc_stat.rb +1 -1
  100. data/test/plugin/test_in_http.rb +3 -78
  101. data/test/plugin/test_in_object_space.rb +1 -1
  102. data/test/plugin/test_in_status.rb +1 -1
  103. data/test/plugin/test_in_stream.rb +2 -1
  104. data/test/plugin/test_in_syslog.rb +2 -1
  105. data/test/plugin/test_in_tail.rb +6 -11
  106. data/test/plugin/test_in_tcp.rb +2 -1
  107. data/test/plugin/test_in_udp.rb +2 -1
  108. data/test/plugin/test_out_copy.rb +1 -12
  109. data/test/plugin/test_out_exec.rb +1 -1
  110. data/test/plugin/test_out_exec_filter.rb +1 -1
  111. data/test/plugin/test_out_file.rb +7 -96
  112. data/test/plugin/test_out_forward.rb +2 -1
  113. data/test/plugin/test_out_roundrobin.rb +1 -12
  114. data/test/plugin/test_out_stdout.rb +1 -1
  115. data/test/plugin/test_out_stream.rb +2 -1
  116. data/test/scripts/fluent/plugin/formatter_known.rb +1 -4
  117. data/test/scripts/fluent/plugin/parser_known.rb +1 -2
  118. data/test/test_config.rb +1 -1
  119. data/test/test_configdsl.rb +2 -1
  120. data/test/test_formatter.rb +3 -395
  121. data/test/test_match.rb +2 -1
  122. data/test/test_mixin.rb +3 -75
  123. data/test/test_output.rb +1 -112
  124. data/test/test_parser.rb +85 -152
  125. metadata +58 -167
  126. data/example/v1_literal_example.conf +0 -36
  127. data/lib/fluent/plugin/in_dummy.rb +0 -103
  128. data/lib/fluent/timezone.rb +0 -131
  129. data/test/config/assertions.rb +0 -42
  130. data/test/config/test_config_parser.rb +0 -389
  131. data/test/config/test_configurable.rb +0 -652
  132. data/test/config/test_configure_proxy.rb +0 -99
  133. data/test/config/test_dsl.rb +0 -237
  134. data/test/config/test_literal_parser.rb +0 -295
  135. data/test/config/test_section.rb +0 -112
  136. data/test/config/test_system_config.rb +0 -99
  137. data/test/config/test_types.rb +0 -63
  138. data/test/plugin/test_in_dummy.rb +0 -95
  139. data/test/test_event.rb +0 -168
  140. data/test/test_input.rb +0 -21
@@ -1,112 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/config/section'
3
-
4
- module Fluent::Config
5
- class TestSection < ::Test::Unit::TestCase
6
- sub_test_case Fluent::Config::Section do
7
- sub_test_case 'class' do
8
- sub_test_case '.name' do
9
- test 'returns its full module name as String' do
10
- assert_equal('Fluent::Config::Section', Fluent::Config::Section.name)
11
- end
12
- end
13
- end
14
-
15
- sub_test_case 'instance object' do
16
- sub_test_case '#initialize' do
17
- test 'creates blank object without argument' do
18
- s = Fluent::Config::Section.new
19
- assert_equal({}, s.instance_eval{ @params })
20
- end
21
-
22
- test 'creates object which contains specified hash object itself' do
23
- hash = {
24
- name: 'tagomoris',
25
- age: 34,
26
- send: 'email',
27
- class: 'normal',
28
- keys: 5,
29
- }
30
- s1 = Fluent::Config::Section.new(hash)
31
- assert_equal(hash, s1.instance_eval { @params })
32
- assert_equal("tagomoris", s1[:name])
33
- assert_equal(34, s1[:age])
34
- assert_equal("email", s1[:send])
35
- assert_equal("normal", s1[:class])
36
- assert_equal(5, s1[:keys])
37
-
38
- assert_equal("tagomoris", s1.name)
39
- assert_equal(34, s1.age)
40
- assert_equal("email", s1.send)
41
- assert_equal("normal", s1.class)
42
- assert_equal(5, s1.keys)
43
-
44
- assert_raise(NoMethodError) { s1.dup }
45
- end
46
- end
47
-
48
- sub_test_case '#object_id' do
49
- test 'returns its object id' do
50
- s1 = Fluent::Config::Section.new({})
51
- assert s1.object_id
52
- s2 = Fluent::Config::Section.new({})
53
- assert s2.object_id
54
- assert_not_equal s1.object_id, s2.object_id
55
- end
56
- end
57
-
58
- sub_test_case '#to_h' do
59
- test 'returns internal hash itself' do
60
- hash = {
61
- name: 'tagomoris',
62
- age: 34,
63
- send: 'email',
64
- class: 'normal',
65
- keys: 5,
66
- }
67
- s = Fluent::Config::Section.new(hash)
68
- assert_equal(hash, s.to_h)
69
- assert_instance_of(Hash, s.to_h)
70
- end
71
- end
72
-
73
- sub_test_case '#instance_of?' do
74
- test 'can judge whether it is a Section object or not' do
75
- s = Fluent::Config::Section.new
76
- assert_true(s.instance_of?(Fluent::Config::Section))
77
- assert_false(s.instance_of?(BasicObject))
78
- end
79
- end
80
-
81
- sub_test_case '#is_a?' do
82
- test 'can judge whether it belongs to or not' do
83
- s = Fluent::Config::Section.new
84
- assert_true(s.is_a?(Fluent::Config::Section))
85
- assert_true(s.kind_of?(Fluent::Config::Section))
86
- assert_true(s.is_a?(BasicObject))
87
- end
88
- end
89
-
90
- sub_test_case '#+' do
91
- test 'can merge 2 sections: argument side is primary, internal hash is newly created' do
92
- h1 = {name: "s1", num: 10, class: "A"}
93
- s1 = Fluent::Config::Section.new(h1)
94
-
95
- h2 = {name: "s2", class: "A", num2: "5", num3: "8"}
96
- s2 = Fluent::Config::Section.new(h2)
97
- s = s1 + s2
98
-
99
- assert_not_equal(h1.object_id, s.to_h.object_id)
100
- assert_not_equal(h2.object_id, s.to_h.object_id)
101
-
102
- assert_equal("s2", s.name)
103
- assert_equal(10, s.num)
104
- assert_equal("A", s.class)
105
- assert_equal("5", s.num2)
106
- assert_equal("8", s.num3)
107
- end
108
- end
109
- end
110
- end
111
- end
112
- end
@@ -1,99 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/configurable'
3
- require 'fluent/config/element'
4
- require 'fluent/config/section'
5
- require 'fluent/supervisor'
6
-
7
- module Fluent::Config
8
- class FakeLoggerInitializer
9
- attr_accessor :level
10
- def initalize
11
- @level = nil
12
- end
13
- end
14
-
15
- class FakeSupervisor
16
- def initialize
17
- @log = FakeLoggerInitializer.new
18
- @log_level = nil
19
- @suppress_interval = nil
20
- @suppress_config_dump = nil
21
- @suppress_repeated_stacktrace = nil
22
- @without_source = nil
23
- end
24
- end
25
-
26
- class TestSystemConfig < ::Test::Unit::TestCase
27
-
28
- def parse_text(text)
29
- basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
30
- Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
31
- end
32
-
33
- test 'should not override default configurations when no parameters' do
34
- conf = parse_text(<<-EOS)
35
- <system>
36
- </system>
37
- EOS
38
- s = FakeSupervisor.new
39
- sc = Fluent::Supervisor::SystemConfig.new(conf)
40
- sc.apply(s)
41
- assert_nil(sc.log_level)
42
- assert_nil(sc.suppress_repeated_stacktrace)
43
- assert_nil(sc.emit_error_log_interval)
44
- assert_nil(sc.suppress_config_dump)
45
- assert_nil(sc.without_source)
46
- assert_nil(s.instance_variable_get(:@log_level))
47
- assert_nil(s.instance_variable_get(:@suppress_repeated_stacktrace))
48
- assert_nil(s.instance_variable_get(:@emit_error_log_interval))
49
- assert_nil(s.instance_variable_get(:@suppress_config_dump))
50
- assert_nil(s.instance_variable_get(:@without_source))
51
- end
52
-
53
- {'log_level' => 'error',
54
- 'suppress_repeated_stacktrace' => true,
55
- 'emit_error_log_interval' => 60,
56
- 'suppress_config_dump' => true,
57
- 'without_source' => true,
58
- }.each { |k, v|
59
- test "accepts #{k} parameter" do
60
- conf = parse_text(<<-EOS)
61
- <system>
62
- #{k} #{v}
63
- </system>
64
- EOS
65
- s = FakeSupervisor.new
66
- sc = Fluent::Supervisor::SystemConfig.new(conf)
67
- sc.apply(s)
68
- assert_not_nil(sc.instance_variable_get("@#{k}"))
69
- key = (k == 'emit_error_log_interval' ? 'suppress_interval' : k)
70
- assert_not_nil(s.instance_variable_get("@#{key}"))
71
- end
72
- }
73
-
74
- {'foo' => 'bar', 'hoge' => 'fuga'}.each { |k, v|
75
- test "should not affect settable parameters with unknown #{k} parameter" do
76
- s = FakeSupervisor.new
77
- sc = Fluent::Supervisor::SystemConfig.new({k => v})
78
- sc.apply(s)
79
- assert_nil(s.instance_variable_get(:@log_level))
80
- assert_nil(s.instance_variable_get(:@suppress_repeated_stacktrace))
81
- assert_nil(s.instance_variable_get(:@emit_error_log_interval))
82
- assert_nil(s.instance_variable_get(:@suppress_config_dump))
83
- assert_nil(s.instance_variable_get(:@without_source))
84
- end
85
- }
86
-
87
- test 'log_level' do
88
- conf = parse_text(<<-EOS)
89
- <system>
90
- log_level warn
91
- </system>
92
- EOS
93
- s = FakeSupervisor.new
94
- sc = Fluent::Supervisor::SystemConfig.new(conf)
95
- sc.apply(s)
96
- assert_equal(Fluent::Log::LEVEL_WARN, s.instance_variable_get("@log").level)
97
- end
98
- end
99
- end
@@ -1,63 +0,0 @@
1
- require 'helper'
2
- require 'fluent/config/types'
3
-
4
- class TestConfigTypes < ::Test::Unit::TestCase
5
- include Fluent
6
-
7
- sub_test_case 'Config.size_value' do
8
- test 'normal case' do
9
- assert_equal(2048, Config.size_value("2k"))
10
- assert_equal(2048, Config.size_value("2K"))
11
- assert_equal(3145728, Config.size_value("3m"))
12
- assert_equal(3145728, Config.size_value("3M"))
13
- assert_equal(4294967296, Config.size_value("4g"))
14
- assert_equal(4294967296, Config.size_value("4G"))
15
- assert_equal(5497558138880, Config.size_value("5t"))
16
- assert_equal(5497558138880, Config.size_value("5T"))
17
- assert_equal(6, Config.size_value("6"))
18
- end
19
-
20
- test 'not assumed case' do
21
- assert_equal(6, Config.size_value(6))
22
- assert_equal(0, Config.size_value("hoge"))
23
- assert_equal(0, Config.size_value(""))
24
- assert_equal(0, Config.size_value(nil))
25
- end
26
- end
27
-
28
- sub_test_case 'Config.time_value' do
29
- test 'normal case' do
30
- assert_equal(10, Config.time_value("10s"))
31
- assert_equal(10, Config.time_value("10sec"))
32
- assert_equal(120, Config.time_value("2m"))
33
- assert_equal(10800, Config.time_value("3h"))
34
- assert_equal(345600, Config.time_value("4d"))
35
- end
36
-
37
- test 'not assumed case' do
38
- assert_equal(4.0, Config.time_value(4))
39
- assert_equal(0.4, Config.time_value(0.4))
40
- assert_equal(0.0, Config.time_value("hoge"))
41
- assert_equal(0.0, Config.time_value(""))
42
- assert_equal(0.0, Config.time_value(nil))
43
- end
44
- end
45
-
46
- sub_test_case 'Config.bool_value' do
47
- test 'normal case' do
48
- assert_true Config.bool_value("true")
49
- assert_true Config.bool_value("yes")
50
- assert_true Config.bool_value("")
51
- assert_false Config.bool_value("false")
52
- assert_false Config.bool_value("no")
53
- end
54
-
55
- test 'not assumed case' do
56
- assert_true Config.bool_value(true)
57
- assert_false Config.bool_value(false)
58
- assert_nil Config.bool_value("hoge")
59
- assert_nil Config.bool_value(nil)
60
- assert_nil Config.bool_value(10)
61
- end
62
- end
63
- end
@@ -1,95 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/test'
3
-
4
- class DummyTest < Test::Unit::TestCase
5
- def setup
6
- Fluent::Test.setup
7
- end
8
-
9
- def create_driver(conf)
10
- Fluent::Test::InputTestDriver.new(Fluent::DummyInput).configure(conf)
11
- end
12
-
13
- sub_test_case 'configure' do
14
- test 'required parameters' do
15
- assert_raise_message("'tag' parameter is required") do
16
- create_driver('')
17
- end
18
- end
19
-
20
- test 'tag' do
21
- d = create_driver(%[
22
- tag dummy
23
- ])
24
- assert_equal "dummy", d.instance.tag
25
- end
26
-
27
- config = %[
28
- tag dummy
29
- ]
30
-
31
- test 'auto_increment_key' do
32
- d = create_driver(config + %[
33
- auto_increment_key id
34
- ])
35
- assert_equal "id", d.instance.auto_increment_key
36
- end
37
-
38
- test 'rate' do
39
- d = create_driver(config + %[
40
- rate 10
41
- ])
42
- assert_equal 10, d.instance.rate
43
- end
44
-
45
- test 'dummy' do
46
- # hash is okay
47
- d = create_driver(config + %[dummy {"foo":"bar"}])
48
- assert_equal [{"foo"=>"bar"}], d.instance.dummy
49
-
50
- # array of hash is okay
51
- d = create_driver(config + %[dummy [{"foo":"bar"}]])
52
- assert_equal [{"foo"=>"bar"}], d.instance.dummy
53
-
54
- assert_raise_message(/JSON::ParserError|got incomplete JSON/) do
55
- create_driver(config + %[dummy "foo"])
56
- end
57
-
58
- assert_raise_message(/is not a hash/) do
59
- create_driver(config + %[dummy ["foo"]])
60
- end
61
- end
62
- end
63
-
64
- sub_test_case "emit" do
65
- config = %[
66
- tag dummy
67
- rate 10
68
- dummy {"foo":"bar"}
69
- ]
70
-
71
- test 'simple' do
72
- d = create_driver(config)
73
- d.run {
74
- # d.run sleeps 0.5 sec
75
- }
76
- emits = d.emits
77
- emits.each do |tag, time, record|
78
- assert_equal("dummy", tag)
79
- assert_equal({"foo"=>"bar"}, record)
80
- end
81
- end
82
-
83
- test 'with auto_increment_key' do
84
- d = create_driver(config + %[auto_increment_key id])
85
- d.run {
86
- # d.run sleeps 0.5 sec
87
- }
88
- emits = d.emits
89
- emits.each_with_index do |(tag, time, record), i|
90
- assert_equal("dummy", tag)
91
- assert_equal({"foo"=>"bar", "id"=>i}, record)
92
- end
93
- end
94
- end
95
- end
data/test/test_event.rb DELETED
@@ -1,168 +0,0 @@
1
- require_relative 'helper'
2
- require 'fluent/test'
3
- require 'fluent/event'
4
-
5
- module EventTest
6
- class OneEventStreamTest < ::Test::Unit::TestCase
7
- include Fluent
8
-
9
- def setup
10
- @time = Engine.now
11
- @record = {'k' => 'v', 'n' => 1}
12
- @es = OneEventStream.new(@time, @record)
13
- end
14
-
15
- test 'repeatable?' do
16
- assert_true @es.repeatable?
17
- end
18
-
19
- test 'dup' do
20
- dupped = @es.dup
21
- assert_kind_of OneEventStream, dupped
22
- assert_not_equal @es.object_id, dupped.object_id
23
- end
24
-
25
- test 'each' do
26
- @es.each { |time, record|
27
- assert_equal @time, time
28
- assert_equal @record, record
29
- }
30
- end
31
-
32
- test 'to_msgpack_stream' do
33
- stream = @es.to_msgpack_stream
34
- MessagePack::Unpacker.new.feed_each(stream) { |time, record|
35
- assert_equal @time, time
36
- assert_equal @record, record
37
- }
38
- end
39
- end
40
-
41
- class ArrayEventStreamTest < ::Test::Unit::TestCase
42
- include Fluent
43
-
44
- def setup
45
- @times = [Engine.now, Engine.now + 1]
46
- @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
47
- @es = ArrayEventStream.new(@times.zip(@records))
48
- end
49
-
50
- test 'repeatable?' do
51
- assert_true @es.repeatable?
52
- end
53
-
54
- test 'dup' do
55
- dupped = @es.dup
56
- assert_kind_of ArrayEventStream, dupped
57
- assert_not_equal @es.object_id, dupped.object_id
58
- end
59
-
60
- test 'empty?' do
61
- assert_not_empty @es
62
- assert_true ArrayEventStream.new([]).empty?
63
- end
64
-
65
- test 'each' do
66
- i = 0
67
- @es.each { |time, record|
68
- assert_equal @times[i], time
69
- assert_equal @records[i], record
70
- i += 1
71
- }
72
- end
73
-
74
- test 'to_msgpack_stream' do
75
- i = 0
76
- stream = @es.to_msgpack_stream
77
- MessagePack::Unpacker.new.feed_each(stream) { |time, record|
78
- assert_equal @times[i], time
79
- assert_equal @records[i], record
80
- i += 1
81
- }
82
- end
83
- end
84
-
85
- class MultiEventStreamTest < ::Test::Unit::TestCase
86
- include Fluent
87
-
88
- def setup
89
- @times = [Engine.now, Engine.now + 1]
90
- @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
91
- @es = MultiEventStream.new
92
- @times.zip(@records).each { |time, record|
93
- @es.add(time, record)
94
- }
95
- end
96
-
97
- test 'repeatable?' do
98
- assert_true @es.repeatable?
99
- end
100
-
101
- test 'dup' do
102
- dupped = @es.dup
103
- assert_kind_of MultiEventStream, dupped
104
- assert_not_equal @es.object_id, dupped.object_id
105
- end
106
-
107
- test 'empty?' do
108
- assert_not_empty @es
109
- assert_true MultiEventStream.new.empty?
110
- end
111
-
112
- test 'each' do
113
- i = 0
114
- @es.each { |time, record|
115
- assert_equal @times[i], time
116
- assert_equal @records[i], record
117
- i += 1
118
- }
119
- end
120
-
121
- test 'to_msgpack_stream' do
122
- i = 0
123
- stream = @es.to_msgpack_stream
124
- MessagePack::Unpacker.new.feed_each(stream) { |time, record|
125
- assert_equal @times[i], time
126
- assert_equal @records[i], record
127
- i += 1
128
- }
129
- end
130
- end
131
-
132
- class MessagePackEventStreamTest < ::Test::Unit::TestCase
133
- include Fluent
134
-
135
- def setup
136
- out = ''.force_encoding('ASCII-8BIT')
137
- @times = [Engine.now, Engine.now + 1]
138
- @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
139
- @times.zip(@records).each { |time, record|
140
- out << MessagePack.pack([time, record])
141
- }
142
- @es = MessagePackEventStream.new(out)
143
- end
144
-
145
- test 'repeatable?' do
146
- assert_true @es.repeatable?
147
- end
148
-
149
- test 'each' do
150
- i = 0
151
- @es.each { |time, record|
152
- assert_equal @times[i], time
153
- assert_equal @records[i], record
154
- i += 1
155
- }
156
- end
157
-
158
- test 'to_msgpack_stream' do
159
- i = 0
160
- stream = @es.to_msgpack_stream
161
- MessagePack::Unpacker.new.feed_each(stream) { |time, record|
162
- assert_equal @times[i], time
163
- assert_equal @records[i], record
164
- i += 1
165
- }
166
- end
167
- end
168
- end