fluentd 1.14.6-x86-mingw32 → 1.15.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/linux-test.yaml +1 -1
  3. data/.github/workflows/windows-test.yaml +4 -1
  4. data/CHANGELOG.md +85 -1
  5. data/fluentd.gemspec +1 -3
  6. data/lib/fluent/command/ctl.rb +4 -1
  7. data/lib/fluent/command/fluentd.rb +11 -6
  8. data/lib/fluent/config/literal_parser.rb +2 -2
  9. data/lib/fluent/config/yaml_parser/fluent_value.rb +47 -0
  10. data/lib/fluent/config/yaml_parser/loader.rb +91 -0
  11. data/lib/fluent/config/yaml_parser/parser.rb +166 -0
  12. data/lib/fluent/config/yaml_parser/section_builder.rb +107 -0
  13. data/lib/fluent/config/yaml_parser.rb +56 -0
  14. data/lib/fluent/config.rb +14 -1
  15. data/lib/fluent/error.rb +3 -0
  16. data/lib/fluent/plugin/base.rb +19 -0
  17. data/lib/fluent/plugin/file_wrapper.rb +57 -113
  18. data/lib/fluent/plugin/in_tail/group_watch.rb +204 -0
  19. data/lib/fluent/plugin/in_tail/position_file.rb +1 -15
  20. data/lib/fluent/plugin/in_tail.rb +68 -48
  21. data/lib/fluent/plugin/out_file.rb +11 -1
  22. data/lib/fluent/plugin/out_forward/socket_cache.rb +2 -0
  23. data/lib/fluent/plugin/output.rb +2 -1
  24. data/lib/fluent/plugin/parser_syslog.rb +1 -1
  25. data/lib/fluent/plugin_helper/child_process.rb +3 -0
  26. data/lib/fluent/plugin_helper/server.rb +3 -1
  27. data/lib/fluent/plugin_helper/service_discovery.rb +2 -2
  28. data/lib/fluent/supervisor.rb +125 -31
  29. data/lib/fluent/system_config.rb +4 -2
  30. data/lib/fluent/version.rb +1 -1
  31. data/lib/fluent/win32api.rb +38 -0
  32. data/lib/fluent/winsvc.rb +5 -8
  33. data/test/command/test_ctl.rb +0 -1
  34. data/test/command/test_fluentd.rb +33 -0
  35. data/test/config/test_system_config.rb +5 -1
  36. data/test/config/test_types.rb +1 -1
  37. data/test/plugin/in_tail/test_io_handler.rb +14 -4
  38. data/test/plugin/in_tail/test_position_file.rb +0 -63
  39. data/test/plugin/out_forward/test_socket_cache.rb +26 -1
  40. data/test/plugin/test_base.rb +34 -0
  41. data/test/plugin/test_file_wrapper.rb +0 -73
  42. data/test/plugin/test_in_object_space.rb +9 -3
  43. data/test/plugin/test_in_syslog.rb +1 -1
  44. data/test/plugin/test_in_tail.rb +629 -353
  45. data/test/plugin/test_out_forward.rb +30 -20
  46. data/test/plugin/test_parser_syslog.rb +1 -1
  47. data/test/plugin_helper/test_cert_option.rb +1 -1
  48. data/test/plugin_helper/test_child_process.rb +16 -4
  49. data/test/test_config.rb +135 -4
  50. data/test/test_supervisor.rb +155 -0
  51. metadata +12 -39
@@ -22,16 +22,17 @@ module Fluent
22
22
  include Configurable
23
23
 
24
24
  SYSTEM_CONFIG_PARAMETERS = [
25
- :workers, :root_dir, :log_level,
25
+ :workers, :restart_worker_interval, :root_dir, :log_level,
26
26
  :suppress_repeated_stacktrace, :emit_error_log_interval, :suppress_config_dump,
27
27
  :log_event_verbose, :ignore_repeated_log_interval, :ignore_same_log_interval,
28
28
  :without_source, :rpc_endpoint, :enable_get_dump, :process_name,
29
29
  :file_permission, :dir_permission, :counter_server, :counter_client,
30
30
  :strict_config_value, :enable_msgpack_time_support, :disable_shared_socket,
31
- :metrics, :enable_input_metrics, :enable_size_metrics
31
+ :metrics, :enable_input_metrics, :enable_size_metrics, :enable_jit
32
32
  ]
33
33
 
34
34
  config_param :workers, :integer, default: 1
35
+ config_param :restart_worker_interval, :time, default: 0
35
36
  config_param :root_dir, :string, default: nil
36
37
  config_param :log_level, :enum, list: [:trace, :debug, :info, :warn, :error, :fatal], default: 'info'
37
38
  config_param :suppress_repeated_stacktrace, :bool, default: nil
@@ -49,6 +50,7 @@ module Fluent
49
50
  config_param :disable_shared_socket, :bool, default: nil
50
51
  config_param :enable_input_metrics, :bool, default: nil
51
52
  config_param :enable_size_metrics, :bool, default: nil
53
+ config_param :enable_jit, :bool, default: false
52
54
  config_param :file_permission, default: nil do |v|
53
55
  v.to_i(8)
54
56
  end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Fluent
18
18
 
19
- VERSION = '1.14.6'
19
+ VERSION = '1.15.2'
20
20
 
21
21
  end
@@ -0,0 +1,38 @@
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
+ require 'fluent/env'
18
+
19
+ module Fluent
20
+ module Win32API
21
+ require 'fiddle/import'
22
+ require 'fiddle/types'
23
+ extend Fiddle::Importer
24
+
25
+ if RUBY_PLATFORM.split('-')[-1] == "ucrt"
26
+ MSVCRT_DLL = 'ucrtbase.dll'
27
+ else
28
+ MSVCRT_DLL = 'msvcrt.dll'
29
+ end
30
+
31
+ dlload MSVCRT_DLL, "kernel32.dll"
32
+ include Fiddle::Win32Types
33
+
34
+ extern "intptr_t _get_osfhandle(int)"
35
+ extern "BOOL GetFileInformationByHandle(HANDLE, void *)"
36
+ extern "BOOL GetFileInformationByHandleEx(HANDLE, int, void *, DWORD)"
37
+ end if Fluent.windows?
38
+ end
data/lib/fluent/winsvc.rb CHANGED
@@ -17,14 +17,12 @@
17
17
  begin
18
18
 
19
19
  require 'optparse'
20
- require 'windows/debug'
21
- require 'Windows/Library'
22
20
  require 'win32/daemon'
23
21
  require 'win32/event'
22
+ require 'win32/registry'
23
+ require 'serverengine'
24
24
 
25
25
  include Win32
26
- include Windows::Library
27
- include Windows::Debug
28
26
 
29
27
  op = OptionParser.new
30
28
  opts = {service_name: nil}
@@ -37,16 +35,13 @@ begin
37
35
  end
38
36
 
39
37
  def read_fluentdopt(service_name)
40
- require 'win32/Registry'
41
38
  Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\#{service_name}") do |reg|
42
39
  reg.read("fluentdopt")[1] rescue ""
43
40
  end
44
41
  end
45
42
 
46
43
  def service_main_start(service_name)
47
- ruby_path = 0.chr * 260
48
- GetModuleFileName.call(0, ruby_path,260)
49
- ruby_path = ruby_path.rstrip.gsub(/\\/, '/')
44
+ ruby_path = ServerEngine.ruby_bin_path
50
45
  rubybin_dir = ruby_path[0, ruby_path.rindex("/")]
51
46
  opt = read_fluentdopt(service_name)
52
47
  Process.spawn("\"#{rubybin_dir}/ruby.exe\" \"#{rubybin_dir}/fluentd\" #{opt} -x #{service_name}")
@@ -84,6 +79,8 @@ begin
84
79
  set_event("#{@service_name}_HUP")
85
80
  when 129
86
81
  set_event("#{@service_name}_USR1")
82
+ when 130
83
+ set_event("#{@service_name}_CONT")
87
84
  end
88
85
  end
89
86
 
@@ -7,7 +7,6 @@ require 'fluent/command/ctl'
7
7
 
8
8
  class TestFluentdCtl < ::Test::Unit::TestCase
9
9
  def assert_win32_event(event_name, command, pid_or_svcname)
10
- command, event_suffix = data
11
10
  event = Win32::Event.new(event_name)
12
11
  ipc = Win32::Ipc.new(event.handle)
13
12
  ret = Win32::Ipc::TIMEOUT
@@ -589,6 +589,39 @@ CONF
589
589
  )
590
590
  end
591
591
 
592
+ sub_test_case "YAML config format" do
593
+ test 'success to start the number of workers specified in configuration' do
594
+ conf = <<'CONF'
595
+ system:
596
+ workers: 2
597
+ root_dir: "#{@root_path}"
598
+ config:
599
+ - source:
600
+ $type: dummy
601
+ $id: !fluent/s "dummy.#{worker_id}" # check worker_id works or not with actual command
602
+ $label: '@dummydata'
603
+ tag: dummy
604
+ dummy: !fluent/json {"message": !fluent/s "yay from #{hostname}!"}
605
+
606
+ - label:
607
+ $name: '@dummydata'
608
+ config:
609
+ - match:
610
+ $tag: dummy
611
+ $type: "null"
612
+ $id: blackhole
613
+ CONF
614
+ conf_path = create_conf_file('workers1.yaml', conf)
615
+ assert Dir.exist?(@root_path)
616
+
617
+ assert_log_matches(
618
+ create_cmdline(conf_path),
619
+ "#0 fluentd worker is now running worker=0",
620
+ "#1 fluentd worker is now running worker=1"
621
+ )
622
+ end
623
+ end
624
+
592
625
  test 'success to start the number of workers specified by command line option' do
593
626
  conf = <<CONF
594
627
  <system>
@@ -19,6 +19,7 @@ module Fluent::Config
19
19
  @system_config = nil
20
20
  @cl_opt = {
21
21
  wokers: nil,
22
+ restart_worker_interval: nil,
22
23
  root_dir: nil,
23
24
  log: FakeLoggerInitializer.new,
24
25
  log_level: Fluent::Log::LEVEL_INFO,
@@ -72,6 +73,7 @@ module Fluent::Config
72
73
  sc = Fluent::SystemConfig.new(conf)
73
74
  sc.overwrite_variables(**s.for_system_config)
74
75
  assert_equal(1, sc.workers)
76
+ assert_equal(0, sc.restart_worker_interval)
75
77
  assert_nil(sc.root_dir)
76
78
  assert_equal(Fluent::Log::LEVEL_INFO, sc.log_level)
77
79
  assert_nil(sc.suppress_repeated_stacktrace)
@@ -82,12 +84,14 @@ module Fluent::Config
82
84
  assert_nil(sc.enable_input_metrics)
83
85
  assert_nil(sc.enable_size_metrics)
84
86
  assert_nil(sc.enable_msgpack_time_support)
87
+ assert(!sc.enable_jit)
85
88
  assert_equal(:text, sc.log.format)
86
89
  assert_equal('%Y-%m-%d %H:%M:%S %z', sc.log.time_format)
87
90
  end
88
91
 
89
92
  data(
90
93
  'workers' => ['workers', 3],
94
+ 'restart_worker_interval' => ['restart_worker_interval', 60],
91
95
  'root_dir' => ['root_dir', File.join(TMP_DIR, 'root')],
92
96
  'log_level' => ['log_level', 'error'],
93
97
  'suppress_repeated_stacktrace' => ['suppress_repeated_stacktrace', true],
@@ -99,6 +103,7 @@ module Fluent::Config
99
103
  'enable_msgpack_time_support' => ['enable_msgpack_time_support', true],
100
104
  'enable_input_metrics' => ['enable_input_metrics', true],
101
105
  'enable_size_metrics' => ['enable_size_metrics', true],
106
+ 'enable_jit' => ['enable_jit', true],
102
107
  )
103
108
  test "accepts parameters" do |(k, v)|
104
109
  conf = parse_text(<<-EOS)
@@ -174,7 +179,6 @@ module Fluent::Config
174
179
  </log>
175
180
  </system>
176
181
  EOS
177
- s = FakeSupervisor.new
178
182
  sc = Fluent::SystemConfig.new(conf)
179
183
  assert_equal(3, sc.log.rotate_age)
180
184
  end
@@ -190,7 +190,7 @@ class TestConfigTypes < ::Test::Unit::TestCase
190
190
  data("val" => [:val, 'val'],
191
191
  "v" => [:v, 'v'],
192
192
  "value" => [:value, 'value'])
193
- test 'enum' do |(expected, val, list)|
193
+ test 'enum' do |(expected, val)|
194
194
  assert_equal expected, Config::ENUM_TYPE.call(val, {list: [:val, :value, :v]})
195
195
  end
196
196
 
@@ -21,12 +21,20 @@ class IntailIOHandlerTest < Test::Unit::TestCase
21
21
  @file.unlink rescue nil
22
22
  end
23
23
 
24
+ def create_target_info
25
+ Fluent::Plugin::TailInput::TargetInfo.new(@file.path, Fluent::FileWrapper.stat(@file.path).ino)
26
+ end
27
+
28
+ def create_watcher
29
+ Fluent::Plugin::TailInput::TailWatcher.new(create_target_info, nil, nil, nil, nil, nil, nil, nil, nil)
30
+ end
31
+
24
32
  test '#on_notify load file content and passed it to receive_lines method' do
25
33
  text = "this line is test\ntest line is test\n"
26
34
  @file.write(text)
27
35
  @file.close
28
36
 
29
- watcher = 'watcher'
37
+ watcher = create_watcher
30
38
 
31
39
  update_pos = 0
32
40
 
@@ -61,7 +69,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
61
69
 
62
70
  update_pos = 0
63
71
 
64
- watcher = 'watcher'
72
+ watcher = create_watcher
65
73
  stub(watcher).pe do
66
74
  pe = 'position_file'
67
75
  stub(pe).read_pos { 0 }
@@ -92,7 +100,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
92
100
 
93
101
  update_pos = 0
94
102
 
95
- watcher = 'watcher'
103
+ watcher = create_watcher
96
104
  stub(watcher).pe do
97
105
  pe = 'position_file'
98
106
  stub(pe).read_pos { 0 }
@@ -107,6 +115,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
107
115
  end
108
116
 
109
117
  r.on_notify
118
+ assert_equal text.bytesize, update_pos
110
119
  assert_equal 8, returned_lines[0].size
111
120
  end
112
121
 
@@ -118,7 +127,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
118
127
 
119
128
  update_pos = 0
120
129
 
121
- watcher = 'watcher'
130
+ watcher = create_watcher
122
131
  stub(watcher).pe do
123
132
  pe = 'position_file'
124
133
  stub(pe).read_pos { 0 }
@@ -133,6 +142,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
133
142
  end
134
143
 
135
144
  r.on_notify
145
+ assert_equal text.bytesize, update_pos
136
146
  assert_equal 5, returned_lines[0].size
137
147
  assert_equal 3, returned_lines[1].size
138
148
  end
@@ -40,10 +40,6 @@ class IntailPositionFileTest < Test::Unit::TestCase
40
40
 
41
41
  test '.load' do
42
42
  write_data(@file, TEST_CONTENT)
43
- paths = {
44
- "valid_path" => Fluent::Plugin::TailInput::TargetInfo.new("valid_path", 1),
45
- "inode23bit" => Fluent::Plugin::TailInput::TargetInfo.new("inode23bit", 2),
46
- }
47
43
  Fluent::Plugin::TailInput::PositionFile.load(@file, false, TEST_CONTENT_PATHS, **{logger: $log})
48
44
 
49
45
  @file.seek(0)
@@ -146,11 +142,6 @@ class IntailPositionFileTest < Test::Unit::TestCase
146
142
  sub_test_case '#load' do
147
143
  test 'compact invalid and convert 32 bit inode value' do
148
144
  write_data(@file, TEST_CONTENT)
149
- invalid_path = "invalidpath100000000000000000000000000000000"
150
- paths = TEST_CONTENT_PATHS.merge({
151
- invalid_path => Fluent::Plugin::TailInput::TargetInfo.new(invalid_path, 0),
152
- "unwatched" => Fluent::Plugin::TailInput::TargetInfo.new("unwatched", 0),
153
- })
154
145
  Fluent::Plugin::TailInput::PositionFile.load(@file, false, TEST_CONTENT_PATHS, **{logger: $log})
155
146
 
156
147
  @file.seek(0)
@@ -322,58 +313,4 @@ class IntailPositionFileTest < Test::Unit::TestCase
322
313
  assert_equal 2, f.read_inode
323
314
  end
324
315
  end
325
-
326
- sub_test_case "TargetInfo equality rules" do
327
- sub_test_case "== operator" do
328
- def test_equal
329
- t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
330
- t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1235)
331
-
332
- assert_equal t1, t2
333
- end
334
-
335
- def test_not_equal
336
- t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
337
- t2 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234)
338
-
339
- assert_not_equal t1, t2
340
- end
341
- end
342
-
343
- sub_test_case "eql? method" do
344
- def test_eql?
345
- t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
346
- t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 5321)
347
-
348
- assert do
349
- t1.eql? t2
350
- end
351
- end
352
-
353
- def test_not_eql?
354
- t1 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234)
355
- t2 = Fluent::Plugin::TailInput::TargetInfo.new("test3", 1234)
356
-
357
- assert do
358
- !t1.eql? t2
359
- end
360
- end
361
- end
362
-
363
- sub_test_case "hash" do
364
- def test_equal
365
- t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
366
- t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 7321)
367
-
368
- assert_equal t1.hash, t2.hash
369
- end
370
-
371
- def test_not_equal
372
- t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
373
- t2 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234)
374
-
375
- assert_not_equal t1.hash, t2.hash
376
- end
377
- end
378
- end
379
316
  end
@@ -110,6 +110,10 @@ class SocketCacheTest < Test::Unit::TestCase
110
110
  end
111
111
 
112
112
  sub_test_case 'purge_obsolete_socks' do
113
+ def teardown
114
+ Timecop.return
115
+ end
116
+
113
117
  test 'delete key in inactive_socks' do
114
118
  c = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
115
119
  sock = mock!.close { 'closed' }.subject
@@ -134,7 +138,7 @@ class SocketCacheTest < Test::Unit::TestCase
134
138
  c.checkin(sock)
135
139
 
136
140
  # wait timeout
137
- Timecop.freeze(Time.parse('2016-04-13 14:20:00 +0900'))
141
+ Timecop.freeze(Time.parse('2016-04-13 14:00:11 +0900'))
138
142
  c.checkout_or('key') { sock2 }
139
143
 
140
144
  assert_equal(1, c.instance_variable_get(:@inflight_sockets).size)
@@ -145,5 +149,26 @@ class SocketCacheTest < Test::Unit::TestCase
145
149
  assert_equal(1, c.instance_variable_get(:@inflight_sockets).size)
146
150
  assert_equal(sock2, c.instance_variable_get(:@inflight_sockets).values.first.sock)
147
151
  end
152
+
153
+ test 'should not purge just after checkin and purge after timeout' do
154
+ Timecop.freeze(Time.parse('2016-04-13 14:00:00 +0900'))
155
+
156
+ c = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
157
+ sock = dont_allow(mock!).close
158
+ stub(sock).inspect
159
+ c.checkout_or('key') { sock }
160
+
161
+ Timecop.freeze(Time.parse('2016-04-13 14:00:11 +0900'))
162
+ c.checkin(sock)
163
+
164
+ assert_equal(1, c.instance_variable_get(:@available_sockets).size)
165
+ c.purge_obsolete_socks
166
+ assert_equal(1, c.instance_variable_get(:@available_sockets).size)
167
+
168
+ Timecop.freeze(Time.parse('2016-04-13 14:00:22 +0900'))
169
+ assert_equal(1, c.instance_variable_get(:@available_sockets).size)
170
+ c.purge_obsolete_socks
171
+ assert_equal(0, c.instance_variable_get(:@available_sockets).size)
172
+ end
148
173
  end
149
174
  end
@@ -1,4 +1,5 @@
1
1
  require_relative '../helper'
2
+ require 'tmpdir'
2
3
  require 'fluent/plugin/base'
3
4
 
4
5
  module FluentPluginBaseTest
@@ -112,4 +113,37 @@ class BaseTest < Test::Unit::TestCase
112
113
  assert_equal 1, logger.logs.size
113
114
  assert{ logger.logs.first.include?("invalid byte sequence is replaced in ") }
114
115
  end
116
+
117
+ test 'generates worker lock path safely' do
118
+ Dir.mktmpdir("test-fluentd-lock-") do |lock_dir|
119
+ ENV['FLUENTD_LOCK_DIR'] = lock_dir
120
+ p = FluentPluginBaseTest::DummyPlugin.new
121
+ path = p.get_lock_path("Aa\\|=~/_123");
122
+
123
+ assert_equal lock_dir, File.dirname(path)
124
+ assert_equal "fluentd-Aa______123.lock", File.basename(path)
125
+ end
126
+ end
127
+
128
+ test 'can acquire inter-worker locking' do
129
+ Dir.mktmpdir("test-fluentd-lock-") do |lock_dir|
130
+ ENV['FLUENTD_LOCK_DIR'] = lock_dir
131
+ p = FluentPluginBaseTest::DummyPlugin.new
132
+ lock_path = p.get_lock_path("test_base")
133
+
134
+ p.acquire_worker_lock("test_base") do
135
+ # With LOCK_NB set, flock() returns `false` when the
136
+ # file is already locked.
137
+ File.open(lock_path, "w") do |f|
138
+ assert_equal false, f.flock(File::LOCK_EX|File::LOCK_NB)
139
+ end
140
+ end
141
+
142
+ # Lock should be release by now. In that case, flock
143
+ # must return 0.
144
+ File.open(lock_path, "w") do |f|
145
+ assert_equal 0, f.flock(File::LOCK_EX|File::LOCK_NB)
146
+ end
147
+ end
148
+ end
115
149
  end
@@ -2,11 +2,6 @@ require_relative '../helper'
2
2
  require 'fluent/plugin/file_wrapper'
3
3
 
4
4
  class FileWrapperTest < Test::Unit::TestCase
5
- require 'windows/file'
6
- require 'windows/error'
7
- include Windows::File
8
- include Windows::Error
9
-
10
5
  TMP_DIR = File.dirname(__FILE__) + "/../tmp/file_wrapper#{ENV['TEST_ENV_NUMBER']}"
11
6
 
12
7
  def setup
@@ -17,58 +12,6 @@ class FileWrapperTest < Test::Unit::TestCase
17
12
  FileUtils.rm_rf(TMP_DIR)
18
13
  end
19
14
 
20
- sub_test_case 'Win32Error' do
21
- test 'equal' do
22
- assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "message"),
23
- Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "message"))
24
- end
25
-
26
- test 'different error code' do
27
- assert_not_equal(Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND),
28
- Fluent::Win32Error.new(ERROR_SHARING_VIOLATION))
29
- end
30
-
31
- test 'different error message' do
32
- assert_not_equal(Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND, "message1"),
33
- Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND, "message2"))
34
- end
35
-
36
- test 'different class' do
37
- assert_not_equal(Errno::EPIPE,
38
- Fluent::Win32Error.new(ERROR_SHARING_VIOLATION))
39
- end
40
-
41
- test 'ERROR_SHARING_VIOLATION message' do
42
- assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION).message,
43
- "Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process.")
44
- end
45
-
46
- test 'ERROR_SHARING_VIOLATION with a message' do
47
- assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "cannot open the file").message,
48
- "Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process." +
49
- " - cannot open the file")
50
- end
51
-
52
- test 'to_s' do
53
- assert_equal("Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process. - C:\file.txt",
54
- Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "C:\file.txt").to_s)
55
- end
56
-
57
- test 'inspect' do
58
- assert_equal("#<Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process. - C:\file.txt>",
59
- Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "C:\file.txt").inspect)
60
- end
61
-
62
- data('0' => [false, 0],
63
- '9999' => [false, 9999],
64
- '10000' => [true, 10000],
65
- '10001' => [true, 10001])
66
- test 'wsaerr?' do |data|
67
- expected, code = data
68
- assert_equal(expected, Fluent::Win32Error.new(code).wsaerr?)
69
- end
70
- end
71
-
72
15
  sub_test_case 'WindowsFile exceptions' do
73
16
  test 'nothing raised' do
74
17
  begin
@@ -106,21 +49,5 @@ class FileWrapperTest < Test::Unit::TestCase
106
49
  file.close if file
107
50
  end
108
51
  end
109
-
110
- test 'ERROR_SHARING_VIOLATION raised' do
111
- begin
112
- path = "#{TMP_DIR}/test_windows_file.txt"
113
- file1 = file2 = nil
114
- file1 = File.open(path, "wb")
115
- win32err = Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, path)
116
- assert_raise(Errno::EACCES.new(win32err.message)) do
117
- file2 = Fluent::WindowsFile.new(path, 'r', FILE_SHARE_READ)
118
- ensure
119
- file2.close if file2
120
- end
121
- ensure
122
- file1.close if file1
123
- end
124
- end
125
52
  end
126
53
  end if Fluent.windows?
@@ -17,13 +17,19 @@ class ObjectSpaceInputTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  class FailObject
20
- def self.class
21
- raise "error"
22
- end
23
20
  end
24
21
 
25
22
  def setup
26
23
  Fluent::Test.setup
24
+ # Overriding this behavior in the global scope will have an unexpected influence on other tests.
25
+ # So this should be overridden here and be removed in `teardown`.
26
+ def FailObject.class
27
+ raise "FailObject error for tests in ObjectSpaceInputTest."
28
+ end
29
+ end
30
+
31
+ def teardown
32
+ FailObject.singleton_class.remove_method(:class)
27
33
  end
28
34
 
29
35
  TESTCONFIG = %[
@@ -497,7 +497,7 @@ EOS
497
497
 
498
498
  def test_send_keepalive_packet_can_not_be_enabled_for_udp
499
499
  assert_raise(Fluent::ConfigError) do
500
- d = create_driver(ipv4_config + %[
500
+ create_driver(ipv4_config + %[
501
501
  send_keepalive_packet true
502
502
  ])
503
503
  end