fluentd 1.12.2-x64-mingw32 → 1.13.2-x64-mingw32

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

Potentially problematic release.


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

Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.yaml +69 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.yaml +38 -0
  4. data/.github/workflows/linux-test.yaml +1 -1
  5. data/.github/workflows/windows-test.yaml +19 -3
  6. data/.gitlab-ci.yml +19 -19
  7. data/CHANGELOG.md +153 -0
  8. data/CONTRIBUTING.md +2 -2
  9. data/MAINTAINERS.md +1 -1
  10. data/README.md +8 -5
  11. data/bin/fluentd +8 -1
  12. data/example/counter.conf +1 -1
  13. data/fluentd.gemspec +4 -3
  14. data/lib/fluent/command/cat.rb +19 -3
  15. data/lib/fluent/command/fluentd.rb +1 -2
  16. data/lib/fluent/command/plugin_generator.rb +42 -2
  17. data/lib/fluent/config.rb +1 -1
  18. data/lib/fluent/config/section.rb +5 -0
  19. data/lib/fluent/config/types.rb +15 -0
  20. data/lib/fluent/config/v1_parser.rb +3 -2
  21. data/lib/fluent/env.rb +2 -1
  22. data/lib/fluent/log.rb +1 -0
  23. data/lib/fluent/oj_options.rb +62 -0
  24. data/lib/fluent/plugin/file_wrapper.rb +49 -4
  25. data/lib/fluent/plugin/formatter.rb +1 -0
  26. data/lib/fluent/plugin/formatter_json.rb +9 -7
  27. data/lib/fluent/plugin/in_http.rb +10 -0
  28. data/lib/fluent/plugin/in_tail.rb +150 -39
  29. data/lib/fluent/plugin/in_tail/position_file.rb +15 -1
  30. data/lib/fluent/plugin/out_forward.rb +14 -33
  31. data/lib/fluent/plugin/output.rb +11 -9
  32. data/lib/fluent/plugin/parser_csv.rb +2 -2
  33. data/lib/fluent/plugin/parser_json.rb +2 -3
  34. data/lib/fluent/plugin/parser_syslog.rb +2 -2
  35. data/lib/fluent/plugin/service_discovery.rb +0 -15
  36. data/lib/fluent/plugin/storage_local.rb +1 -1
  37. data/lib/fluent/plugin_helper/http_server/router.rb +1 -1
  38. data/lib/fluent/plugin_helper/server.rb +4 -2
  39. data/lib/fluent/plugin_helper/service_discovery.rb +39 -1
  40. data/lib/fluent/plugin_helper/service_discovery/manager.rb +11 -5
  41. data/lib/fluent/plugin_helper/socket_option.rb +2 -2
  42. data/lib/fluent/supervisor.rb +15 -0
  43. data/lib/fluent/system_config.rb +14 -0
  44. data/lib/fluent/test/driver/storage.rb +30 -0
  45. data/lib/fluent/version.rb +1 -1
  46. data/templates/new_gem/fluent-plugin.gemspec.erb +3 -3
  47. data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
  48. data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
  49. data/test/command/test_cat.rb +99 -0
  50. data/test/command/test_plugin_generator.rb +2 -1
  51. data/test/config/test_section.rb +9 -0
  52. data/test/config/test_system_config.rb +46 -0
  53. data/test/config/test_types.rb +7 -0
  54. data/test/plugin/in_tail/test_io_handler.rb +4 -4
  55. data/test/plugin/in_tail/test_position_file.rb +54 -0
  56. data/test/plugin/out_forward/test_connection_manager.rb +0 -6
  57. data/test/plugin/test_file_wrapper.rb +115 -0
  58. data/test/plugin/test_in_forward.rb +59 -83
  59. data/test/plugin/test_in_http.rb +58 -40
  60. data/test/plugin/test_in_syslog.rb +66 -56
  61. data/test/plugin/test_in_tail.rb +329 -10
  62. data/test/plugin/test_in_tcp.rb +45 -32
  63. data/test/plugin/test_in_udp.rb +47 -33
  64. data/test/plugin/test_out_forward.rb +138 -105
  65. data/test/plugin/test_out_stream.rb +18 -8
  66. data/test/plugin/test_output.rb +15 -3
  67. data/test/plugin/test_output_as_buffered_backup.rb +2 -0
  68. data/test/plugin/test_parser_csv.rb +14 -0
  69. data/test/plugin/test_parser_syslog.rb +14 -0
  70. data/test/plugin_helper/http_server/test_route.rb +1 -1
  71. data/test/plugin_helper/service_discovery/test_manager.rb +1 -1
  72. data/test/plugin_helper/test_child_process.rb +1 -1
  73. data/test/plugin_helper/test_http_server_helper.rb +34 -27
  74. data/test/plugin_helper/test_server.rb +144 -139
  75. data/test/plugin_helper/test_service_discovery.rb +74 -14
  76. data/test/plugin_helper/test_socket.rb +16 -9
  77. data/test/test_config.rb +2 -1
  78. data/test/test_event_time.rb +2 -2
  79. data/test/test_oj_options.rb +55 -0
  80. data/test/test_output.rb +2 -2
  81. data/test/test_supervisor.rb +35 -0
  82. metadata +41 -11
  83. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  84. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Fluent
18
18
 
19
- VERSION = '1.12.2'
19
+ VERSION = '1.13.2'
20
20
 
21
21
  end
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = test_files
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.14"
24
- spec.add_development_dependency "rake", "~> 12.0"
25
- spec.add_development_dependency "test-unit", "~> 3.0"
23
+ spec.add_development_dependency "bundler", "~> <%= bundler_version %>"
24
+ spec.add_development_dependency "rake", "~> <%= rake_version %>"
25
+ spec.add_development_dependency "test-unit", "~> <%= test_unit_version %>"
26
26
  spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
27
27
  end
@@ -0,0 +1,40 @@
1
+ <%= preamble %>
2
+
3
+ require "fluent/plugin/storage"
4
+
5
+ module Fluent
6
+ module Plugin
7
+ class <%= class_name %> < Fluent::Plugin::Storage
8
+ Fluent::Plugin.register_storage("<%= plugin_name %>", self)
9
+
10
+ def initialize
11
+ super
12
+ end
13
+
14
+ def configure(conf)
15
+ super
16
+ end
17
+
18
+ def load
19
+ end
20
+
21
+ def save
22
+ end
23
+
24
+ def get(key)
25
+ end
26
+
27
+ def fetch(key, defval)
28
+ end
29
+
30
+ def put(key, value)
31
+ end
32
+
33
+ def delete(key)
34
+ end
35
+
36
+ def update(key, &block)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ require "helper"
2
+ require "fluent/plugin/<%= plugin_filename %>"
3
+
4
+ class <%= class_name %>Test < Test::Unit::TestCase
5
+ setup do
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ test "failure" do
10
+ flunk
11
+ end
12
+
13
+ private
14
+
15
+ def create_driver(conf)
16
+ Fluent::Test::Driver::Storage.new(Fluent::Plugin::<%= class_name %>).configure(conf)
17
+ end
18
+ end
@@ -0,0 +1,99 @@
1
+ require_relative '../helper'
2
+
3
+ require 'test-unit'
4
+ require 'open3'
5
+ require 'fluent/plugin/output'
6
+ require 'fluent/plugin/in_forward'
7
+ require 'fluent/plugin/out_secondary_file'
8
+ require 'fluent/test/driver/output'
9
+ require 'fluent/test/driver/input'
10
+
11
+ class TestFluentCat < ::Test::Unit::TestCase
12
+ def setup
13
+ Fluent::Test.setup
14
+ FileUtils.mkdir_p(TMP_DIR)
15
+ @record = { 'key' => 'value' }
16
+ @time = event_time
17
+ @es = Fluent::OneEventStream.new(@time, @record)
18
+ @primary = create_primary
19
+ metadata = @primary.buffer.new_metadata
20
+ @chunk = create_chunk(@primary, metadata, @es)
21
+ @port = unused_port
22
+ end
23
+
24
+ def teardown
25
+ FileUtils.rm_rf(TMP_DIR)
26
+ @port = nil
27
+ end
28
+
29
+ TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/command/fluent_cat#{ENV['TEST_ENV_NUMBER']}")
30
+ FLUENT_CAT_COMMAND = File.expand_path(File.dirname(__FILE__) + "/../../bin/fluent-cat")
31
+
32
+ def config
33
+ %[
34
+ port #{@port}
35
+ bind 127.0.0.1
36
+ ]
37
+ end
38
+
39
+ SECONDARY_CONFIG = %[
40
+ directory #{TMP_DIR}
41
+ ]
42
+
43
+ class DummyOutput < Fluent::Plugin::Output
44
+ def write(chunk); end
45
+ end
46
+
47
+ def create_driver(conf=config)
48
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::ForwardInput).configure(conf)
49
+ end
50
+
51
+ def create_primary(buffer_cofig = config_element('buffer'))
52
+ DummyOutput.new.configure(config_element('ROOT','',{}, [buffer_cofig]))
53
+ end
54
+
55
+ def create_secondary_driver(conf=SECONDARY_CONFIG)
56
+ c = Fluent::Test::Driver::Output.new(Fluent::Plugin::SecondaryFileOutput)
57
+ c.instance.acts_as_secondary(@primary)
58
+ c.configure(conf)
59
+ end
60
+
61
+ def create_chunk(primary, metadata, es)
62
+ primary.buffer.generate_chunk(metadata).tap do |c|
63
+ c.concat(es.to_msgpack_stream, es.size)
64
+ c.commit
65
+ end
66
+ end
67
+
68
+ sub_test_case "json" do
69
+ def test_cat_json
70
+ d = create_driver
71
+ d.run(expect_records: 1) do
72
+ Open3.pipeline_w("ruby #{FLUENT_CAT_COMMAND} --port #{@port} json") do |stdin|
73
+ stdin.puts('{"key":"value"}')
74
+ stdin.close
75
+ end
76
+ end
77
+ event = d.events.first
78
+ assert_equal([1, "json", @record],
79
+ [d.events.size, event.first, event.last])
80
+ end
81
+ end
82
+
83
+ sub_test_case "msgpack" do
84
+ def test_cat_secondary_file
85
+ d = create_secondary_driver
86
+ path = d.instance.write(@chunk)
87
+ d = create_driver
88
+ d.run(expect_records: 1) do
89
+ Open3.pipeline_w("ruby #{FLUENT_CAT_COMMAND} --port #{@port} --format msgpack secondary") do |stdin|
90
+ stdin.write(File.read(path))
91
+ stdin.close
92
+ end
93
+ end
94
+ event = d.events.first
95
+ assert_equal([1, "secondary", @record],
96
+ [d.events.size, event.first, event.last])
97
+ end
98
+ end
99
+ end
@@ -29,7 +29,8 @@ class TestFluentPluginGenerator < Test::Unit::TestCase
29
29
  output: ["output", "out"],
30
30
  filter: ["filter", "filter"],
31
31
  parser: ["parser", "parser"],
32
- formatter: ["formatter", "formatter"])
32
+ formatter: ["formatter", "formatter"],
33
+ storage: ["storage", "storage"])
33
34
  test "generate plugin" do |(type, part)|
34
35
  generator = FluentPluginGenerator.new([type, "fake"])
35
36
  stub_git_process(generator)
@@ -1,5 +1,6 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/config/section'
3
+ require 'pp'
3
4
 
4
5
  module Fluent::Config
5
6
  class TestSection < ::Test::Unit::TestCase
@@ -176,6 +177,14 @@ module Fluent::Config
176
177
  s1 = Fluent::Config::Section.new(h1)
177
178
  assert_equal(expected, s1.respond_to?(method))
178
179
  end
180
+
181
+ test '#pretty_print' do
182
+ q = PP.new
183
+ h1 = {name: "s1", klass: "A"}
184
+ s1 = Fluent::Config::Section.new(h1)
185
+ s1.pretty_print(q)
186
+ assert_equal s1.inspect, q.output
187
+ end
179
188
  end
180
189
  end
181
190
  end
@@ -143,5 +143,51 @@ module Fluent::Config
143
143
  sc.overwrite_variables(**s.for_system_config)
144
144
  assert_equal(level, sc.log_level)
145
145
  end
146
+
147
+ sub_test_case "log rotation" do
148
+ data('daily' => "daily",
149
+ 'weekly' => 'weekly',
150
+ 'monthly' => 'monthly')
151
+ test "symbols for rotate_age" do |age|
152
+ conf = parse_text(<<-EOS)
153
+ <system>
154
+ <log>
155
+ rotate_age #{age}
156
+ </log>
157
+ </system>
158
+ EOS
159
+ sc = Fluent::SystemConfig.new(conf)
160
+ assert_equal(age.to_sym, sc.log.rotate_age)
161
+ end
162
+
163
+ test "numeric number for rotate age" do
164
+ conf = parse_text(<<-EOS)
165
+ <system>
166
+ <log>
167
+ rotate_age 3
168
+ </log>
169
+ </system>
170
+ EOS
171
+ s = FakeSupervisor.new
172
+ sc = Fluent::SystemConfig.new(conf)
173
+ assert_equal(3, sc.log.rotate_age)
174
+ end
175
+
176
+ data(h: ['100', 100],
177
+ k: ['1k', 1024],
178
+ m: ['1m', 1024 * 1024],
179
+ g: ['1g', 1024 * 1024 * 1024])
180
+ test "numeric and SI prefix for rotate_size" do |(label, size)|
181
+ conf = parse_text(<<-EOS)
182
+ <system>
183
+ <log>
184
+ rotate_size #{label}
185
+ </log>
186
+ </system>
187
+ EOS
188
+ sc = Fluent::SystemConfig.new(conf)
189
+ assert_equal(size, sc.log.rotate_size)
190
+ end
191
+ end
146
192
  end
147
193
  end
@@ -180,6 +180,13 @@ class TestConfigTypes < ::Test::Unit::TestCase
180
180
  assert_equal Encoding::UTF_8, actual.encoding
181
181
  end
182
182
 
183
+ data('starts_with_semicolon' => [:conor, ':conor'],
184
+ 'simple_string' => [:conor, 'conor'],
185
+ 'empty_string' => [nil, ''])
186
+ test 'symbol' do |(expected, val)|
187
+ assert_equal Config::SYMBOL_TYPE.call(val, {}), expected
188
+ end
189
+
183
190
  data("val" => [:val, 'val'],
184
191
  "v" => [:v, 'v'],
185
192
  "value" => [:value, 'value'])
@@ -30,7 +30,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  returned_lines = ''
33
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, log: $log, open_on_every_update: false) do |lines, _watcher|
33
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
34
34
  returned_lines << lines.join
35
35
  true
36
36
  end
@@ -62,7 +62,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
62
62
  end
63
63
 
64
64
  returned_lines = ''
65
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, log: $log, open_on_every_update: true) do |lines, _watcher|
65
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: true) do |lines, _watcher|
66
66
  returned_lines << lines.join
67
67
  true
68
68
  end
@@ -93,7 +93,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
93
93
  end
94
94
 
95
95
  returned_lines = []
96
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, log: $log, open_on_every_update: false) do |lines, _watcher|
96
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
97
97
  returned_lines << lines.dup
98
98
  true
99
99
  end
@@ -119,7 +119,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
119
119
  end
120
120
 
121
121
  returned_lines = []
122
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, log: $log, open_on_every_update: false) do |lines, _watcher|
122
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
123
123
  returned_lines << lines.dup
124
124
  true
125
125
  end
@@ -282,4 +282,58 @@ class IntailPositionFileTest < Test::Unit::TestCase
282
282
  assert_equal 2, f.read_inode
283
283
  end
284
284
  end
285
+
286
+ sub_test_case "TargetInfo equality rules" do
287
+ sub_test_case "== operator" do
288
+ def test_equal
289
+ t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
290
+ t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1235)
291
+
292
+ assert_equal t1, t2
293
+ end
294
+
295
+ def test_not_equal
296
+ t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
297
+ t2 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234)
298
+
299
+ assert_not_equal t1, t2
300
+ end
301
+ end
302
+
303
+ sub_test_case "eql? method" do
304
+ def test_eql?
305
+ t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
306
+ t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 5321)
307
+
308
+ assert do
309
+ t1.eql? t2
310
+ end
311
+ end
312
+
313
+ def test_not_eql?
314
+ t1 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234)
315
+ t2 = Fluent::Plugin::TailInput::TargetInfo.new("test3", 1234)
316
+
317
+ assert do
318
+ !t1.eql? t2
319
+ end
320
+ end
321
+ end
322
+
323
+ sub_test_case "hash" do
324
+ def test_equal
325
+ t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
326
+ t2 = Fluent::Plugin::TailInput::TargetInfo.new("test", 7321)
327
+
328
+ assert_equal t1.hash, t2.hash
329
+ end
330
+
331
+ def test_not_equal
332
+ t1 = Fluent::Plugin::TailInput::TargetInfo.new("test", 1234)
333
+ t2 = Fluent::Plugin::TailInput::TargetInfo.new("test2", 1234)
334
+
335
+ assert_not_equal t1.hash, t2.hash
336
+ end
337
+ end
338
+ end
285
339
  end
@@ -81,8 +81,6 @@ class ConnectionManager < Test::Unit::TestCase
81
81
 
82
82
  sub_test_case 'when socket_cache exists' do
83
83
  test 'calls connect_keepalive' do
84
- omit "Proxy of RR doesn't support kwargs of Ruby 3 yet" if RUBY_VERSION.split('.')[0].to_i >= 3
85
-
86
84
  cache = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
87
85
  mock(cache).checkin('sock').never
88
86
 
@@ -101,8 +99,6 @@ class ConnectionManager < Test::Unit::TestCase
101
99
  end
102
100
 
103
101
  test 'calls connect_keepalive and closes socket with block' do
104
- omit "Proxy of RR doesn't support kwargs of Ruby 3 yet" if RUBY_VERSION.split('.')[0].to_i >= 3
105
-
106
102
  cache = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
107
103
  mock(cache).checkin('sock').once
108
104
 
@@ -122,8 +118,6 @@ class ConnectionManager < Test::Unit::TestCase
122
118
  end
123
119
 
124
120
  test 'does not call dec_ref when ack is passed' do
125
- omit "Proxy of RR doesn't support kwargs of Ruby 3 yet" if RUBY_VERSION.split('.')[0].to_i >= 3
126
-
127
121
  cache = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
128
122
  mock(cache).checkin('sock').never
129
123
  sock = 'sock'
@@ -0,0 +1,115 @@
1
+ require_relative '../helper'
2
+ require 'fluent/plugin/file_wrapper'
3
+
4
+ class FileWrapperTest < Test::Unit::TestCase
5
+ require 'windows/file'
6
+ require 'windows/error'
7
+ include Windows::File
8
+ include Windows::Error
9
+
10
+ TMP_DIR = File.dirname(__FILE__) + "/../tmp/file_wrapper#{ENV['TEST_ENV_NUMBER']}"
11
+
12
+ def setup
13
+ FileUtils.mkdir_p(TMP_DIR)
14
+ end
15
+
16
+ def teardown
17
+ FileUtils.rm_rf(TMP_DIR)
18
+ end
19
+
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
+ sub_test_case 'WindowsFile exceptions' do
73
+ test 'nothing raised' do
74
+ begin
75
+ path = "#{TMP_DIR}/test_windows_file.txt"
76
+ file1 = file2 = nil
77
+ file1 = File.open(path, "wb") do |f|
78
+ end
79
+ assert_nothing_raised do
80
+ file2 = Fluent::WindowsFile.new(path)
81
+ ensure
82
+ file2.close
83
+ end
84
+ ensure
85
+ file1.close if file1
86
+ end
87
+ end
88
+
89
+ test 'Errno::ENOENT raised' do
90
+ path = "#{TMP_DIR}/nofile.txt"
91
+ file = nil
92
+ assert_raise(Errno::ENOENT) do
93
+ file = Fluent::WindowsFile.new(path)
94
+ ensure
95
+ file.close if file
96
+ end
97
+ end
98
+
99
+ test 'ERROR_SHARING_VIOLATION raised' do
100
+ begin
101
+ path = "#{TMP_DIR}/test_windows_file.txt"
102
+ file1 = file2 = nil
103
+ file1 = File.open(path, "wb")
104
+ win32err = Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, path)
105
+ assert_raise(Errno::EACCES.new(win32err.message)) do
106
+ file2 = Fluent::WindowsFile.new(path, 'r', FILE_SHARE_READ)
107
+ ensure
108
+ file2.close if file2
109
+ end
110
+ ensure
111
+ file1.close if file1
112
+ end
113
+ end
114
+ end
115
+ end if Fluent.windows?