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,652 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/configurable'
3
- require 'fluent/config/element'
4
- require 'fluent/config/section'
5
-
6
- module ConfigurableSpec
7
- class Base1
8
- include Fluent::Configurable
9
-
10
- config_param :node, :string, :default => "node"
11
- config_param :flag1, :bool, :default => false
12
- config_param :flag2, :bool, :default => true
13
-
14
- config_param :name1, :string
15
- config_param :name2, :string
16
- config_param :name3, :string, :default => "base1"
17
- config_param :name4, :string, :default => "base1"
18
-
19
- def get_all
20
- [@node, @flag1, @flag2, @name1, @name2, @name3, @name4]
21
- end
22
- end
23
-
24
- class Base2 < Base1
25
- config_set_default :name2, "base2"
26
- config_set_default :name4, "base2"
27
- config_param :name5, :string
28
- config_param :name6, :string, :default => "base2"
29
-
30
- def get_all
31
- ary = super
32
- ary + [@name5, @name6]
33
- end
34
- end
35
-
36
- class Base3 < Base2
37
- config_section :node do
38
- config_param :name, :string, :default => "node"
39
- config_param :type, :string
40
- end
41
- config_section :branch, required: true, multi: true do
42
- config_argument :name, :string
43
- config_param :size, :integer, default: 10
44
- config_section :leaf, required: false, multi: true do
45
- config_param :weight, :integer
46
- config_section :worm, param_name: 'worms', multi: true do
47
- config_param :type, :string, default: 'ladybird'
48
- end
49
- end
50
- end
51
-
52
- def get_all
53
- ary = super
54
- ary + [@branch]
55
- end
56
- end
57
-
58
- class Base4 < Base2
59
- config_section :node, param_name: :nodes do
60
- config_argument :num, :integer
61
- config_param :name, :string, :default => "node"
62
- config_param :type, :string, :default => "b4"
63
- end
64
- config_section :description1, required: false, multi: false do
65
- config_argument :note, :string, default: "desc1"
66
- config_param :text, :string
67
- end
68
- config_section :description2, required: true, multi: false do
69
- config_argument :note, :string, default: "desc2"
70
- config_param :text, :string
71
- end
72
- config_section :description3, required: true, multi: true do
73
- config_argument :note, default: "desc3" do |val|
74
- "desc3: #{val}"
75
- end
76
- config_param :text, :string
77
- end
78
-
79
- def get_all
80
- ary = super
81
- ary + [@nodes, @description1, @description2, @description3]
82
- end
83
- end
84
-
85
- class Example0
86
- include Fluent::Configurable
87
-
88
- config_param :stringvalue, :string
89
- config_param :boolvalue, :bool
90
- config_param :integervalue, :integer
91
- config_param :sizevalue, :size
92
- config_param :timevalue, :time
93
- config_param :floatvalue, :float
94
- config_param :hashvalue, :hash
95
- config_param :arrayvalue, :array
96
- end
97
-
98
- class Example1
99
- include Fluent::Configurable
100
-
101
- config_param :name, :string, alias: :fullname
102
- config_param :bool, :bool, alias: :flag
103
- config_section :detail, required: false, multi: false, alias: "information" do
104
- config_param :address, :string, default: "x"
105
- end
106
-
107
- def get_all
108
- [@name, @detail]
109
- end
110
- end
111
-
112
- class Example2 < Example1
113
- config_section :detail, required: true, multi: false, alias: "information2" do
114
- config_param :address, :string, default: "y"
115
- config_param :phone_no, :string
116
- end
117
- end
118
-
119
- class Example3
120
- include Fluent::Configurable
121
-
122
- config_param :age, :integer, default: 10
123
-
124
- config_section :appendix, required: true, multi: false, final: true do
125
- config_param :type, :string
126
- config_param :name, :string, default: "x"
127
- end
128
-
129
- def get_all
130
- [@name, @detail]
131
- end
132
- end
133
-
134
- class Example4 < Example3
135
- config_param :age, :integer, default: 20
136
-
137
- config_section :appendix, required: false, multi: false, final: false do
138
- config_param :name, :string, default: "y"
139
- config_param :age, :integer, default: 10
140
- end
141
- end
142
- end
143
-
144
- module Fluent::Config
145
- class TestConfigurable < ::Test::Unit::TestCase
146
- sub_test_case 'class defined without config_section' do
147
- sub_test_case '#initialize' do
148
- test 'create instance methods and default values by config_param and config_set_default' do
149
- obj1 = ConfigurableSpec::Base1.new
150
- assert_equal("node", obj1.node)
151
- assert_false(obj1.flag1)
152
- assert_true(obj1.flag2)
153
- assert_nil(obj1.name1)
154
- assert_nil(obj1.name2)
155
- assert_equal("base1", obj1.name3)
156
- assert_equal("base1", obj1.name4)
157
- end
158
-
159
- test 'create instance methods and default values overwritten by sub class definition' do
160
- obj2 = ConfigurableSpec::Base2.new
161
- assert_equal("node", obj2.node)
162
- assert_false(obj2.flag1)
163
- assert_true(obj2.flag2)
164
- assert_nil(obj2.name1)
165
- assert_equal("base2", obj2.name2)
166
- assert_equal("base1", obj2.name3)
167
- assert_equal("base2", obj2.name4)
168
- assert_nil(obj2.name5)
169
- assert_equal("base2", obj2.name6)
170
- end
171
- end
172
-
173
- sub_test_case '#configure' do
174
- test 'returns configurable object itself' do
175
- b2 = ConfigurableSpec::Base2.new
176
- assert_instance_of(ConfigurableSpec::Base2, b2.configure({"name1" => "t1", "name5" => "t5"}))
177
- end
178
-
179
- test 'raise errors without any specifications for param without defaults' do
180
- b2 = ConfigurableSpec::Base2.new
181
- assert_raise(Fluent::ConfigError) { b2.configure({}) }
182
- assert_raise(Fluent::ConfigError) { b2.configure({"name1" => "t1"}) }
183
- assert_raise(Fluent::ConfigError) { b2.configure({"name5" => "t5"}) }
184
- assert_nothing_raised { b2.configure({"name1" => "t1", "name5" => "t5"}) }
185
-
186
- assert_equal(["node", false, true, "t1", "base2", "base1", "base2", "t5", "base2"], b2.get_all)
187
- end
188
-
189
- test 'can configure bool values' do
190
- b2a = ConfigurableSpec::Base2.new
191
- assert_nothing_raised { b2a.configure({"flag1" => "true", "flag2" => "yes", "name1" => "t1", "name5" => "t5"}) }
192
- assert_true(b2a.flag1)
193
- assert_true(b2a.flag2)
194
-
195
- b2b = ConfigurableSpec::Base2.new
196
- assert_nothing_raised { b2b.configure({"flag1" => false, "flag2" => "no", "name1" => "t1", "name5" => "t5"}) }
197
- assert_false(b2b.flag1)
198
- assert_false(b2b.flag2)
199
- end
200
-
201
- test 'overwrites values of defaults' do
202
- b2 = ConfigurableSpec::Base2.new
203
- b2.configure({"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5"})
204
- assert_equal("t1", b2.name1)
205
- assert_equal("t2", b2.name2)
206
- assert_equal("t3", b2.name3)
207
- assert_equal("t4", b2.name4)
208
- assert_equal("t5", b2.name5)
209
- assert_equal("base2", b2.name6)
210
-
211
- assert_equal(["node", false, true, "t1", "t2", "t3", "t4", "t5", "base2"], b2.get_all)
212
- end
213
- end
214
- end
215
-
216
- sub_test_case 'class defined with config_section' do
217
- sub_test_case '#initialize' do
218
- test 'create instance methods and default values as nil for params from config_section specified as non-multi' do
219
- b4 = ConfigurableSpec::Base4.new
220
- assert_nil(b4.description1)
221
- assert_nil(b4.description2)
222
- end
223
-
224
- test 'create instance methods and default values as [] for params from config_section specified as multi' do
225
- b4 = ConfigurableSpec::Base4.new
226
- assert_equal([], b4.description3)
227
- end
228
-
229
- test 'overwrite base class definition by config_section of sub class definition' do
230
- b3 = ConfigurableSpec::Base3.new
231
- assert_equal([], b3.node)
232
- end
233
-
234
- test 'create instance methods and default values by param_name' do
235
- b4 = ConfigurableSpec::Base4.new
236
- assert_equal([], b4.nodes)
237
- assert_equal("node", b4.node)
238
- end
239
-
240
- test 'create non-required and multi without any specifications' do
241
- b3 = ConfigurableSpec::Base3.new
242
- assert_false(b3.class.merged_configure_proxy.sections[:node].required?)
243
- assert_true(b3.class.merged_configure_proxy.sections[:node].multi?)
244
- end
245
- end
246
-
247
- sub_test_case '#configure' do
248
- def e(name, arg = '', attrs = {}, elements = [])
249
- attrs_str_keys = {}
250
- attrs.each{|key, value| attrs_str_keys[key.to_s] = value }
251
- Fluent::Config::Element.new(name, arg, attrs_str_keys, elements)
252
- end
253
-
254
- BASE_ATTRS = {
255
- "name1" => "1", "name2" => "2", "name3" => "3",
256
- "name4" => "4", "name5" => "5", "name6" => "6",
257
- }
258
- test 'checks required subsections' do
259
- b3 = ConfigurableSpec::Base3.new
260
- # branch sections required
261
- assert_raise(Fluent::ConfigError) { b3.configure(e('ROOT', '', BASE_ATTRS, [])) }
262
-
263
- # branch argument required
264
- msg = "'<branch ARG>' section requires argument, in section branch"
265
- #expect{ b3.configure(e('ROOT', '', BASE_ATTRS, [e('branch', '')])) }.to raise_error(Fluent::ConfigError, msg)
266
- assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(e('ROOT', '', BASE_ATTRS, [e('branch', '')])) }
267
-
268
- # leaf is not required
269
- assert_nothing_raised { b3.configure(e('ROOT', '', BASE_ATTRS, [e('branch', 'branch_name')])) }
270
-
271
- # leaf weight required
272
- msg = "'weight' parameter is required, in section branch > leaf"
273
- branch1 = e('branch', 'branch_name', {size: 1}, [e('leaf', '10', {weight: 1})])
274
- assert_nothing_raised { b3.configure(e('ROOT', '', BASE_ATTRS, [branch1])) }
275
- branch2 = e('branch', 'branch_name', {size: 1}, [e('leaf', '20')])
276
- assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(e('ROOT', '', BASE_ATTRS, [branch1, branch2])) }
277
- branch3 = e('branch', 'branch_name', {size: 1}, [e('leaf', '10', {weight: 3}), e('leaf', '20')])
278
- assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(e('ROOT', '', BASE_ATTRS, [branch3])) }
279
-
280
- ### worm not required
281
-
282
- b4 = ConfigurableSpec::Base4.new
283
-
284
- d1 = e('description1', '', {text:"d1"})
285
- d2 = e('description2', '', {text:"d2"})
286
- d3 = e('description3', '', {text:"d3"})
287
- assert_nothing_raised { b4.configure(e('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup])) }
288
-
289
- # description1 cannot be specified 2 or more
290
- msg = "'<description1>' section cannot be written twice or more"
291
- assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(e('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d1.dup, d3.dup])) }
292
-
293
- # description2 cannot be specified 2 or more
294
- msg = "'<description2>' section cannot be written twice or more"
295
- assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(e('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d2.dup])) }
296
-
297
- # description3 can be specified 2 or more
298
- assert_nothing_raised { b4.configure(e('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d3.dup])) }
299
- end
300
-
301
- test 'constructs confuguration object tree for Base3' do
302
- conf = e(
303
- 'ROOT',
304
- '',
305
- BASE_ATTRS,
306
- [
307
- e('node', '', {type:"1"}), e('node', '', {name:"node2",type:"2"}),
308
- e('branch', 'b1.*', {}, []),
309
- e('branch',
310
- 'b2.*',
311
- {size: 5},
312
- [
313
- e('leaf', 'THIS IS IGNORED', {weight: 55}, []),
314
- e('leaf', 'THIS IS IGNORED', {weight: 50}, [ e('worm', '', {}) ]),
315
- e('leaf', 'THIS IS IGNORED', {weight: 50}, [ e('worm', '', {type:"w1"}), e('worm', '', {type:"w2"}) ]),
316
- ]
317
- ),
318
- e('branch',
319
- 'b3.*',
320
- {size: "503"},
321
- [
322
- e('leaf', 'THIS IS IGNORED', {weight: 55}, []),
323
- ]
324
- )
325
- ],
326
- )
327
- b3 = ConfigurableSpec::Base3.new.configure(conf)
328
-
329
- assert_not_equal("node", b3.node) # overwritten
330
-
331
- assert_equal("1", b3.name1)
332
- assert_equal("2", b3.name2)
333
- assert_equal("3", b3.name3)
334
- assert_equal("4", b3.name4)
335
- assert_equal("5", b3.name5)
336
- assert_equal("6", b3.name6)
337
-
338
- assert_instance_of(Array, b3.node)
339
- assert_equal(2, b3.node.size)
340
-
341
- assert_equal("node", b3.node[0].name)
342
- assert_equal("1", b3.node[0].type)
343
- assert_equal(b3.node[0].type, b3.node[0][:type])
344
- assert_equal("node2", b3.node[1].name)
345
- assert_equal("2", b3.node[1].type)
346
- assert_equal(b3.node[1].type, b3.node[1][:type])
347
-
348
- assert_instance_of(Array, b3.branch)
349
- assert_equal(3, b3.branch.size)
350
-
351
- assert_equal('b1.*', b3.branch[0].name)
352
- assert_equal(10, b3.branch[0].size)
353
- assert_equal([], b3.branch[0].leaf)
354
-
355
- assert_equal('b2.*', b3.branch[1].name)
356
- assert_equal(5, b3.branch[1].size)
357
- assert_equal(3, b3.branch[1].leaf.size)
358
- assert_equal(b3.branch[1].leaf, b3.branch[1][:leaf])
359
-
360
- assert_equal(55, b3.branch[1].leaf[0].weight)
361
- assert_equal(0, b3.branch[1].leaf[0].worms.size)
362
-
363
- assert_equal(50, b3.branch[1].leaf[1].weight)
364
- assert_equal(1, b3.branch[1].leaf[1].worms.size)
365
- assert_equal("ladybird", b3.branch[1].leaf[1].worms[0].type)
366
-
367
- assert_equal(50, b3.branch[1].leaf[2].weight)
368
- assert_equal(2, b3.branch[1].leaf[2].worms.size)
369
- assert_equal("w1", b3.branch[1].leaf[2].worms[0].type)
370
- assert_equal("w2", b3.branch[1].leaf[2].worms[1].type)
371
-
372
- assert_equal('b3.*', b3.branch[2].name)
373
- assert_equal(503, b3.branch[2].size)
374
- assert_equal(1, b3.branch[2].leaf.size)
375
- assert_equal(55, b3.branch[2].leaf[0].weight)
376
- end
377
-
378
- test 'constructs confuguration object tree for Base4' do
379
- conf = e(
380
- 'ROOT',
381
- '',
382
- BASE_ATTRS,
383
- [
384
- e('node', '1', {type:"1"}), e('node', '2', {name:"node2"}),
385
- e('description3', '', {text:"dddd3-1"}),
386
- e('description2', 'd-2', {text:"dddd2"}),
387
- e('description1', '', {text:"dddd1"}),
388
- e('description3', 'd-3', {text:"dddd3-2"}),
389
- e('description3', 'd-3a', {text:"dddd3-3"}),
390
- e('node', '4', {type:"four"}),
391
- ],
392
- )
393
- b4 = ConfigurableSpec::Base4.new.configure(conf)
394
-
395
- assert_equal("node", b4.node)
396
-
397
- assert_equal("1", b4.name1)
398
- assert_equal("2", b4.name2)
399
- assert_equal("3", b4.name3)
400
- assert_equal("4", b4.name4)
401
- assert_equal("5", b4.name5)
402
- assert_equal("6", b4.name6)
403
-
404
- assert_instance_of(Array, b4.nodes)
405
- assert_equal(3, b4.nodes.size)
406
- assert_equal(1, b4.nodes[0].num)
407
- assert_equal("node", b4.nodes[0].name)
408
- assert_equal("1", b4.nodes[0].type)
409
- assert_equal(2, b4.nodes[1].num)
410
- assert_equal("node2", b4.nodes[1].name)
411
- assert_equal("b4", b4.nodes[1].type)
412
- assert_equal(4, b4.nodes[2].num)
413
- assert_equal("node", b4.nodes[2].name)
414
- assert_equal("four", b4.nodes[2].type)
415
-
416
- # e('description3', '', {text:"dddd3-1"}),
417
- # e('description3', 'd-3', {text:"dddd3-2"}),
418
- # e('description3', 'd-3a', {text:"dddd3-3"}),
419
-
420
- # NoMethodError: undefined method `class' for <Fluent::Config::Section {...}>:Fluent::Config::Section occurred. Should we add class method to Section?
421
- #assert_equal('Fluent::Config::Section', b4.description1.class.name)
422
- assert_equal("desc1", b4.description1.note)
423
- assert_equal("dddd1", b4.description1.text)
424
-
425
- # same with assert_equal('Fluent::Config::Section', b4.description1)
426
- #assert_equal('Fluent::Config::Section', b4.description2)
427
- assert_equal("d-2", b4.description2.note)
428
- assert_equal("dddd2", b4.description2.text)
429
-
430
- assert_instance_of(Array, b4.description3)
431
- assert_equal(3, b4.description3.size)
432
- assert_equal("desc3", b4.description3[0].note)
433
- assert_equal("dddd3-1", b4.description3[0].text)
434
- assert_equal('desc3: d-3', b4.description3[1].note)
435
- assert_equal('dddd3-2', b4.description3[1].text)
436
- assert_equal('desc3: d-3a', b4.description3[2].note)
437
- assert_equal('dddd3-3', b4.description3[2].text)
438
- end
439
-
440
- test 'checks missing of specifications' do
441
- conf0 = e('ROOT', '', {}, [])
442
- ex01 = ConfigurableSpec::Example0.new
443
- assert_raise(Fluent::ConfigError) { ex01.configure(conf0) }
444
-
445
- complete = {
446
- "stringvalue" => "s1", "boolvalue" => "yes", "integervalue" => "10",
447
- "sizevalue" => "10m", "timevalue" => "100s", "floatvalue" => "1.001",
448
- "hashvalue" => '{"foo":1, "bar":2}',
449
- "arrayvalue" => '[1,"ichi"]',
450
- }
451
-
452
- checker = lambda { |conf| ConfigurableSpec::Example0.new.configure(conf) }
453
-
454
- assert_nothing_raised { checker.call(complete) }
455
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "stringvalue" }) }
456
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "boolvalue" }) }
457
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "integervalue"}) }
458
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "sizevalue" }) }
459
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "timevalue" }) }
460
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "floatvalue" }) }
461
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "hashvalue" }) }
462
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "arrayvalue" }) }
463
- end
464
-
465
- test 'accepts configuration values as string representation' do
466
- conf = {
467
- "stringvalue" => "s1", "boolvalue" => "yes", "integervalue" => "10",
468
- "sizevalue" => "10m", "timevalue" => "10m", "floatvalue" => "1.001",
469
- "hashvalue" => '{"foo":1, "bar":2}',
470
- "arrayvalue" => '[1,"ichi"]',
471
- }
472
- ex = ConfigurableSpec::Example0.new.configure(conf)
473
- assert_equal("s1", ex.stringvalue)
474
- assert_true(ex.boolvalue)
475
- assert_equal(10, ex.integervalue)
476
- assert_equal(10 * 1024 * 1024, ex.sizevalue)
477
- assert_equal(10 * 60, ex.timevalue)
478
- assert_equal(1.001, ex.floatvalue)
479
- assert_equal({"foo" => 1, "bar" => 2}, ex.hashvalue)
480
- assert_equal([1, "ichi"], ex.arrayvalue)
481
- end
482
-
483
- test 'accepts configuration values as ruby value representation (especially for DSL)' do
484
- conf = {
485
- "stringvalue" => "s1", "boolvalue" => true, "integervalue" => 10,
486
- "sizevalue" => 10 * 1024 * 1024, "timevalue" => 10 * 60, "floatvalue" => 1.001,
487
- "hashvalue" => {"foo" => 1, "bar" => 2},
488
- "arrayvalue" => [1,"ichi"],
489
- }
490
- ex = ConfigurableSpec::Example0.new.configure(conf)
491
- assert_equal("s1", ex.stringvalue)
492
- assert_true(ex.boolvalue)
493
- assert_equal(10, ex.integervalue)
494
- assert_equal(10 * 1024 * 1024, ex.sizevalue)
495
- assert_equal(10 * 60, ex.timevalue)
496
- assert_equal(1.001, ex.floatvalue)
497
- assert_equal({"foo" => 1, "bar" => 2}, ex.hashvalue)
498
- assert_equal([1, "ichi"], ex.arrayvalue)
499
- end
500
-
501
- test 'gets both of true(yes) and false(no) for bool value parameter' do
502
- conf = {
503
- "stringvalue" => "s1", "integervalue" => 10,
504
- "sizevalue" => 10 * 1024 * 1024, "timevalue" => 10 * 60, "floatvalue" => 1.001,
505
- "hashvalue" => {"foo" => 1, "bar" => 2},
506
- "arrayvalue" => [1,"ichi"],
507
- }
508
- ex0 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "true"}))
509
- assert_true(ex0.boolvalue)
510
-
511
- ex1 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "yes"}))
512
- assert_true(ex1.boolvalue)
513
-
514
- ex2 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => true}))
515
- assert_true(ex2.boolvalue)
516
-
517
- ex3 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "false"}))
518
- assert_false(ex3.boolvalue)
519
-
520
- ex4 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "no"}))
521
- assert_false(ex4.boolvalue)
522
-
523
- ex5 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => false}))
524
- assert_false(ex5.boolvalue)
525
- end
526
- end
527
-
528
- sub_test_case '.config_section' do
529
- def e(name, arg = '', attrs = {}, elements = [])
530
- attrs_str_keys = {}
531
- attrs.each{|key, value| attrs_str_keys[key.to_s] = value }
532
- Fluent::Config::Element.new(name, arg, attrs_str_keys, elements)
533
- end
534
-
535
- test 'subclass configuration spec can overwrite superclass specs' do
536
- # conf0 = e('ROOT', '', {}, [])
537
-
538
- conf1 = e('ROOT', '', {
539
- 'name' => 'tagomoris',
540
- 'bool' => true,
541
- },
542
- )
543
- # <detail> section is required by overwriting of Example2 config_section spec
544
- assert_nothing_raised { ConfigurableSpec::Example1.new.configure(conf1) }
545
- assert_raise(Fluent::ConfigError.new("'<detail>' sections are required")) { ConfigurableSpec::Example2.new.configure(conf1) }
546
-
547
- conf2 = e('ROOT', '', {
548
- 'name' => 'tagomoris',
549
- 'bool' => true,
550
- },
551
- [e('detail', '', { 'phone_no' => "+81-00-0000-0000" }, [])],
552
- )
553
- # <detail> address </detail> default is overwritten by Example2
554
- assert_nothing_raised { ConfigurableSpec::Example1.new.configure(conf2) }
555
- assert_nothing_raised { ConfigurableSpec::Example2.new.configure(conf2) }
556
- ex1 = ConfigurableSpec::Example1.new.configure(conf2)
557
- assert_equal "x", ex1.detail.address
558
- ex2 = ConfigurableSpec::Example2.new.configure(conf2)
559
- assert_equal "y", ex2.detail.address
560
-
561
- conf3 = e('ROOT', '', {
562
- 'name' => 'tagomoris',
563
- 'bool' => true,
564
- },
565
- [e('detail', '', { 'address' => "Chiyoda Tokyo Japan" }, [])],
566
- )
567
- # <detail> phone_no </detail> is required by Example2 config_param spec
568
- assert_nothing_raised { ConfigurableSpec::Example1.new.configure(conf3) }
569
- assert_raise(Fluent::ConfigError.new("'phone_no' parameter is required, in section detail")) { ConfigurableSpec::Example2.new.configure(conf3) }
570
-
571
- conf4 = e('ROOT', '', {
572
- 'name' => 'tagomoris',
573
- 'bool' => true,
574
- },
575
- [e('detail', '', { 'address' => "Chiyoda Tokyo Japan", 'phone_no' => '+81-00-0000-0000' }, [])],
576
- )
577
- assert_nothing_raised { ConfigurableSpec::Example1.new.configure(conf4) } # phone_no is not used
578
- assert_nothing_raised { ConfigurableSpec::Example2.new.configure(conf4) }
579
-
580
- ex2 = ConfigurableSpec::Example2.new.configure(conf4)
581
- assert_equal "Chiyoda Tokyo Japan", ex2.detail.address
582
- assert_equal "+81-00-0000-0000", ex2.detail.phone_no
583
- end
584
-
585
- test 'adds only config_param definitions into configuration without overwriting existing finalized configuration elements' do
586
-
587
- conf1 = e('ROOT', '', {}, [])
588
- # <appendix> is required by Example3 and its not be overwritten by Example4
589
- assert_raise(Fluent::ConfigError.new("'<appendix>' sections are required")) { ConfigurableSpec::Example3.new.configure(conf1) }
590
- assert_raise(Fluent::ConfigError.new("'<appendix>' sections are required")) { ConfigurableSpec::Example4.new.configure(conf1) }
591
-
592
- conf2 = e('ROOT', '', {
593
- },
594
- [e('appendix', '', {'type' => '1'}, [])],
595
- )
596
- # default value of age is overwritten by Example4, because root proxy is not finalized
597
- ex3 = ConfigurableSpec::Example3.new.configure(conf2)
598
- assert_equal 10, ex3.age
599
- assert_equal '1', ex3.appendix.type
600
- ex4 = ConfigurableSpec::Example4.new.configure(conf2)
601
- assert_equal 20, ex4.age
602
- assert_equal '1', ex4.appendix.type
603
-
604
- conf3 = e('ROOT', '', {},
605
- [e('appendix', '', {'type' => '2'}, [])],
606
- )
607
- # default value of <appendix> name </appendix> cannot be overwritten because it is finalized
608
- ex3 = ConfigurableSpec::Example3.new.configure(conf2)
609
- assert_equal 10, ex3.age
610
- assert_equal '1', ex3.appendix.type
611
- ex4 = ConfigurableSpec::Example4.new.configure(conf2)
612
- assert_equal 20, ex4.age
613
- assert_equal '1', ex4.appendix.type
614
- # <appendix> age </appendix> can be added because it is missing in superclass spec
615
- assert_equal 10, ex4.appendix.age
616
- end
617
- end
618
- end
619
-
620
- sub_test_case 'class defined with config_param/config_section having :alias' do
621
- sub_test_case '#initialize' do
622
- test 'does not create methods for alias' do
623
- ex1 = ConfigurableSpec::Example1.new
624
- assert_nothing_raised { ex1.name }
625
- assert_raise(NoMethodError) { ex1.fullname }
626
- assert_nothing_raised { ex1.bool }
627
- assert_raise(NoMethodError) { ex1.flag }
628
- assert_nothing_raised { ex1.detail }
629
- assert_raise(NoMethodError) { ex1.information}
630
- end
631
- end
632
-
633
- sub_test_case '#configure' do
634
- def e(name, arg = '', attrs = {}, elements = [])
635
- attrs_str_keys = {}
636
- attrs.each{|key, value| attrs_str_keys[key.to_s] = value }
637
- Fluent::Config::Element.new(name, arg, attrs_str_keys, elements)
638
- end
639
-
640
- test 'provides accessible data for alias attribute keys' do
641
- ex1 = ConfigurableSpec::Example1.new
642
- ex1.configure(e('ROOT', '', {"fullname" => "foo bar", "bool" => false}, [e('information', '', {"address" => "Mountain View 0"})]))
643
- assert_equal("foo bar", ex1.name)
644
- assert_not_nil(ex1.bool)
645
- assert_false(ex1.bool)
646
- assert_not_nil(ex1.detail)
647
- assert_equal("Mountain View 0", ex1.detail.address)
648
- end
649
- end
650
- end
651
- end
652
- end