fluentd 1.15.2-x64-mingw-ucrt → 1.15.3-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ require 'fluent/test/driver/input'
3
3
  require 'fluent/plugin/in_tail'
4
4
  require 'fluent/plugin/buffer'
5
5
  require 'fluent/system_config'
6
+ require 'fluent/file_wrapper'
6
7
  require 'net/http'
7
8
  require 'flexmock/test_unit'
8
9
  require 'timecop'
@@ -378,9 +379,9 @@ class TailInputTest < Test::Unit::TestCase
378
379
  conf = ROOT_CONFIG + DEBUG_LOG_LEVEL + create_group_directive(tailing_group_pattern, '1m', rule1) + create_path_element("test*.txt") + SINGLE_LINE_CONFIG
379
380
 
380
381
  d = create_driver(conf, false)
381
- File.open("#{@tmp_dir}/test1.txt", 'w')
382
- File.open("#{@tmp_dir}/test2.txt", 'w')
383
- File.open("#{@tmp_dir}/test3.txt", 'w')
382
+ Fluent::FileWrapper.open("#{@tmp_dir}/test1.txt", 'w')
383
+ Fluent::FileWrapper.open("#{@tmp_dir}/test2.txt", 'w')
384
+ Fluent::FileWrapper.open("#{@tmp_dir}/test3.txt", 'w')
384
385
 
385
386
  d.run do
386
387
  ## checking default group_watcher's paths
@@ -419,10 +420,10 @@ class TailInputTest < Test::Unit::TestCase
419
420
  file4 = File.join(@tmp_dir, "test-podname4_test-namespace3_test-container-15fabq.log")
420
421
 
421
422
  d.run do
422
- File.open(file1, 'w')
423
- File.open(file2, 'w')
424
- File.open(file3, 'w')
425
- File.open(file4, 'w')
423
+ Fluent::FileWrapper.open(file1, 'w')
424
+ Fluent::FileWrapper.open(file2, 'w')
425
+ Fluent::FileWrapper.open(file3, 'w')
426
+ Fluent::FileWrapper.open(file4, 'w')
426
427
 
427
428
  instance = d.instance
428
429
  assert_equal(100, instance.find_group_from_metadata(file1).limit)
@@ -438,7 +439,7 @@ class TailInputTest < Test::Unit::TestCase
438
439
  parse: PARSE_SINGLE_LINE_CONFIG)
439
440
  def test_emit(data)
440
441
  config = data
441
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
442
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
442
443
  f.puts "test1"
443
444
  f.puts "test2"
444
445
  }
@@ -446,7 +447,7 @@ class TailInputTest < Test::Unit::TestCase
446
447
  d = create_driver(config)
447
448
 
448
449
  d.run(expect_emits: 1) do
449
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
450
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
450
451
  f.puts "test3\ntest4"
451
452
  }
452
453
  end
@@ -462,11 +463,11 @@ class TailInputTest < Test::Unit::TestCase
462
463
 
463
464
  def test_emit_with_emit_unmatched_lines_true
464
465
  config = config_element("", "", { "format" => "/^(?<message>test.*)/", "emit_unmatched_lines" => true })
465
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
466
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
466
467
 
467
468
  d = create_driver(config)
468
469
  d.run(expect_emits: 1) do
469
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
470
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
470
471
  f.puts "test line 1"
471
472
  f.puts "test line 2"
472
473
  f.puts "bad line 1"
@@ -498,7 +499,7 @@ class TailInputTest < Test::Unit::TestCase
498
499
  msg = 'test' * 2000 # in_tail reads 8192 bytes at once.
499
500
 
500
501
  d.run(expect_emits: num_events, timeout: 2) do
501
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
502
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
502
503
  f.puts msg
503
504
  f.puts msg
504
505
  }
@@ -544,7 +545,7 @@ class TailInputTest < Test::Unit::TestCase
544
545
 
545
546
  d = create_driver(config)
546
547
  d.run(expect_emits: 2) do
547
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
548
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
548
549
  100.times do
549
550
  f.puts msg
550
551
  end
@@ -567,7 +568,7 @@ class TailInputTest < Test::Unit::TestCase
567
568
  start_time = Fluent::Clock.now
568
569
  d = create_driver(config)
569
570
  d.run(expect_emits: 2) do
570
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
571
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
571
572
  8000.times do
572
573
  f.puts msg
573
574
  end
@@ -606,7 +607,7 @@ class TailInputTest < Test::Unit::TestCase
606
607
  io_handler
607
608
  end
608
609
 
609
- File.open("#{@tmp_dir}/tail.txt", "ab") do |f|
610
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") do |f|
610
611
  100.times do
611
612
  f.puts msg
612
613
  end
@@ -616,7 +617,7 @@ class TailInputTest < Test::Unit::TestCase
616
617
  d.run do
617
618
  start_time = Fluent::Clock.now
618
619
  while Fluent::Clock.now - start_time < 0.8 do
619
- File.open("#{@tmp_dir}/tail.txt", "ab") do |f|
620
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") do |f|
620
621
  f.puts msg
621
622
  f.flush
622
623
  end
@@ -634,7 +635,7 @@ class TailInputTest < Test::Unit::TestCase
634
635
  num_lines = 1024 * 3
635
636
  msg = "08bytes"
636
637
 
637
- File.open("#{@tmp_dir}/tail.txt", "wb") do |f|
638
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") do |f|
638
639
  f.write("#{msg}\n" * num_lines)
639
640
  end
640
641
 
@@ -670,7 +671,7 @@ class TailInputTest < Test::Unit::TestCase
670
671
  num_lines = 1024 * 2
671
672
  msg = "08bytes"
672
673
 
673
- File.open("#{@tmp_dir}/tail.txt", "wb") do |f|
674
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") do |f|
674
675
  f.write("#{msg}\n" * num_lines)
675
676
  end
676
677
 
@@ -718,7 +719,7 @@ class TailInputTest < Test::Unit::TestCase
718
719
  parse: CONFIG_READ_FROM_HEAD + PARSE_SINGLE_LINE_CONFIG)
719
720
  def test_emit_with_read_from_head(data)
720
721
  config = data
721
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
722
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
722
723
  f.puts "test1"
723
724
  f.puts "test2"
724
725
  }
@@ -726,7 +727,7 @@ class TailInputTest < Test::Unit::TestCase
726
727
  d = create_driver(config)
727
728
 
728
729
  d.run(expect_emits: 2) do
729
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
730
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
730
731
  f.puts "test3"
731
732
  f.puts "test4"
732
733
  }
@@ -744,7 +745,7 @@ class TailInputTest < Test::Unit::TestCase
744
745
  parse: CONFIG_DISABLE_WATCH_TIMER + PARSE_SINGLE_LINE_CONFIG)
745
746
  def test_emit_without_watch_timer(data)
746
747
  config = data
747
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
748
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
748
749
  f.puts "test1"
749
750
  f.puts "test2"
750
751
  }
@@ -752,7 +753,7 @@ class TailInputTest < Test::Unit::TestCase
752
753
  d = create_driver(config)
753
754
 
754
755
  d.run(expect_emits: 1) do
755
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
756
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
756
757
  f.puts "test3"
757
758
  f.puts "test4"
758
759
  }
@@ -776,7 +777,7 @@ class TailInputTest < Test::Unit::TestCase
776
777
  })
777
778
  config = config + CONFIG_DISABLE_WATCH_TIMER + SINGLE_LINE_CONFIG
778
779
 
779
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
780
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
780
781
  f.puts "test1"
781
782
  f.puts "test2"
782
783
  }
@@ -784,7 +785,7 @@ class TailInputTest < Test::Unit::TestCase
784
785
  d = create_driver(config, false)
785
786
 
786
787
  d.run(expect_emits: 1, timeout: 1) do
787
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
788
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
788
789
  f.puts "test3"
789
790
  f.puts "test4"
790
791
  }
@@ -802,7 +803,7 @@ class TailInputTest < Test::Unit::TestCase
802
803
  parse: CONFIG_DISABLE_STAT_WATCHER + PARSE_SINGLE_LINE_CONFIG)
803
804
  def test_emit_with_disable_stat_watcher(data)
804
805
  config = data
805
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
806
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
806
807
  f.puts "test1"
807
808
  f.puts "test2"
808
809
  }
@@ -810,7 +811,7 @@ class TailInputTest < Test::Unit::TestCase
810
811
  d = create_driver(config)
811
812
 
812
813
  d.run(expect_emits: 1) do
813
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
814
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
814
815
  f.puts "test3"
815
816
  f.puts "test4"
816
817
  }
@@ -826,7 +827,7 @@ class TailInputTest < Test::Unit::TestCase
826
827
  d = create_driver(SINGLE_LINE_CONFIG)
827
828
 
828
829
  d.run(expect_emits: 1, timeout: 3) do
829
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
830
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
830
831
  f.puts "test1\ntest2\n"
831
832
  }
832
833
  end
@@ -873,7 +874,7 @@ class TailInputTest < Test::Unit::TestCase
873
874
  system_conf = parse_system(CONFIG_SYSTEM)
874
875
  sc = Fluent::SystemConfig.new(system_conf)
875
876
  Fluent::Engine.init(sc)
876
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
877
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
877
878
  f.puts "test1"
878
879
  f.puts "test2"
879
880
  }
@@ -881,7 +882,7 @@ class TailInputTest < Test::Unit::TestCase
881
882
  d = create_driver
882
883
 
883
884
  d.run(expect_emits: 1) do
884
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
885
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
885
886
  f.puts "test3"
886
887
  f.puts "test4"
887
888
  }
@@ -938,13 +939,13 @@ class TailInputTest < Test::Unit::TestCase
938
939
  def test_rotate_file_with_write_old(data)
939
940
  config = data
940
941
  events = sub_test_rotate_file(config, expect_emits: 3) { |rotated_file|
941
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
942
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
942
943
  rotated_file.puts "test7"
943
944
  rotated_file.puts "test8"
944
945
  rotated_file.flush
945
946
 
946
947
  sleep 1
947
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
948
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
948
949
  f.puts "test5"
949
950
  f.puts "test6"
950
951
  }
@@ -994,10 +995,10 @@ class TailInputTest < Test::Unit::TestCase
994
995
  if block_given?
995
996
  yield file
996
997
  else
997
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
998
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
998
999
  sleep 1
999
1000
 
1000
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1001
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1001
1002
  f.puts "test5"
1002
1003
  f.puts "test6"
1003
1004
  }
@@ -1012,7 +1013,7 @@ class TailInputTest < Test::Unit::TestCase
1012
1013
 
1013
1014
  def test_truncate_file
1014
1015
  config = SINGLE_LINE_CONFIG
1015
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1016
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1016
1017
  f.puts "test1"
1017
1018
  f.puts "test2"
1018
1019
  f.flush
@@ -1021,7 +1022,7 @@ class TailInputTest < Test::Unit::TestCase
1021
1022
  d = create_driver(config)
1022
1023
 
1023
1024
  d.run(expect_emits: 2) do
1024
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1025
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1025
1026
  f.puts "test3\ntest4"
1026
1027
  f.flush
1027
1028
  }
@@ -1052,7 +1053,7 @@ class TailInputTest < Test::Unit::TestCase
1052
1053
 
1053
1054
  def test_move_truncate_move_back
1054
1055
  config = SINGLE_LINE_CONFIG
1055
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1056
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1056
1057
  f.puts "test1"
1057
1058
  f.puts "test2"
1058
1059
  }
@@ -1089,17 +1090,17 @@ class TailInputTest < Test::Unit::TestCase
1089
1090
  end
1090
1091
 
1091
1092
  def test_lf
1092
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f| }
1093
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f| }
1093
1094
 
1094
1095
  d = create_driver
1095
1096
 
1096
1097
  d.run(expect_emits: 1) do
1097
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1098
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1098
1099
  f.print "test3"
1099
1100
  }
1100
1101
  sleep 1
1101
1102
 
1102
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1103
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1103
1104
  f.puts "test4"
1104
1105
  }
1105
1106
  end
@@ -1110,12 +1111,12 @@ class TailInputTest < Test::Unit::TestCase
1110
1111
  end
1111
1112
 
1112
1113
  def test_whitespace
1113
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f| }
1114
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f| }
1114
1115
 
1115
1116
  d = create_driver
1116
1117
 
1117
1118
  d.run(expect_emits: 1) do
1118
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1119
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1119
1120
  f.puts " " # 4 spaces
1120
1121
  f.puts " 4 spaces"
1121
1122
  f.puts "4 spaces "
@@ -1146,7 +1147,7 @@ class TailInputTest < Test::Unit::TestCase
1146
1147
  d = create_driver(CONFIG_READ_FROM_HEAD + encoding_config)
1147
1148
 
1148
1149
  d.run(expect_emits: 1) do
1149
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1150
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1150
1151
  f.puts "test"
1151
1152
  }
1152
1153
  end
@@ -1168,7 +1169,7 @@ class TailInputTest < Test::Unit::TestCase
1168
1169
  utf8_message = cp932_message.encode(Encoding::UTF_8)
1169
1170
 
1170
1171
  d.run(expect_emits: 1) do
1171
- File.open("#{@tmp_dir}/tail.txt", "w:cp932") {|f|
1172
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "w:cp932") {|f|
1172
1173
  f.puts cp932_message
1173
1174
  }
1174
1175
  end
@@ -1191,7 +1192,7 @@ class TailInputTest < Test::Unit::TestCase
1191
1192
  utf8_message = utf16_message.encode(Encoding::UTF_8).strip
1192
1193
 
1193
1194
  d.run(expect_emits: 1) do
1194
- File.open("#{@tmp_dir}/tail.txt", "w:utf-16le") { |f|
1195
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "w:utf-16le") { |f|
1195
1196
  f.write utf16_message
1196
1197
  }
1197
1198
  end
@@ -1212,7 +1213,7 @@ class TailInputTest < Test::Unit::TestCase
1212
1213
  d = create_driver(conf)
1213
1214
 
1214
1215
  d.run(expect_emits: 1) do
1215
- File.open("#{@tmp_dir}/tail.txt", "w") { |f|
1216
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "w") { |f|
1216
1217
  f.write "te\x86st\n"
1217
1218
  }
1218
1219
  end
@@ -1227,11 +1228,11 @@ class TailInputTest < Test::Unit::TestCase
1227
1228
  parse: PARSE_MULTILINE_CONFIG)
1228
1229
  def test_multiline(data)
1229
1230
  config = data
1230
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1231
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1231
1232
 
1232
1233
  d = create_driver(config)
1233
1234
  d.run(expect_emits: 1) do
1234
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1235
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1235
1236
  f.puts "f test1"
1236
1237
  f.puts "s test2"
1237
1238
  f.puts "f test3"
@@ -1255,11 +1256,11 @@ class TailInputTest < Test::Unit::TestCase
1255
1256
  parse: PARSE_MULTILINE_CONFIG)
1256
1257
  def test_multiline_with_emit_unmatched_lines_true(data)
1257
1258
  config = data + config_element("", "", { "emit_unmatched_lines" => true })
1258
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1259
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1259
1260
 
1260
1261
  d = create_driver(config)
1261
1262
  d.run(expect_emits: 1) do
1262
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1263
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1263
1264
  f.puts "f test1"
1264
1265
  f.puts "s test2"
1265
1266
  f.puts "f test3"
@@ -1285,11 +1286,11 @@ class TailInputTest < Test::Unit::TestCase
1285
1286
  parse: PARSE_MULTILINE_CONFIG_WITH_NEWLINE)
1286
1287
  def test_multiline_with_emit_unmatched_lines2(data)
1287
1288
  config = data + config_element("", "", { "emit_unmatched_lines" => true })
1288
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1289
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1289
1290
 
1290
1291
  d = create_driver(config)
1291
1292
  d.run(expect_emits: 0, timeout: 1) do
1292
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1293
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1293
1294
  f.puts "s test0"
1294
1295
  f.puts "f test1"
1295
1296
  f.puts "f test2"
@@ -1311,7 +1312,7 @@ class TailInputTest < Test::Unit::TestCase
1311
1312
  data(flat: MULTILINE_CONFIG,
1312
1313
  parse: PARSE_MULTILINE_CONFIG)
1313
1314
  def test_multiline_with_flush_interval(data)
1314
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1315
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1315
1316
 
1316
1317
  config = data + config_element("", "", { "multiline_flush_interval" => "2s" })
1317
1318
  d = create_driver(config)
@@ -1319,7 +1320,7 @@ class TailInputTest < Test::Unit::TestCase
1319
1320
  assert_equal(2, d.instance.multiline_flush_interval)
1320
1321
 
1321
1322
  d.run(expect_emits: 1) do
1322
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1323
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1323
1324
  f.puts "f test1"
1324
1325
  f.puts "s test2"
1325
1326
  f.puts "f test3"
@@ -1354,7 +1355,7 @@ class TailInputTest < Test::Unit::TestCase
1354
1355
  d = create_driver(config + encoding_config)
1355
1356
 
1356
1357
  d.run(expect_emits: 1) do
1357
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f|
1358
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f|
1358
1359
  f.puts "s test"
1359
1360
  }
1360
1361
  end
@@ -1377,7 +1378,7 @@ class TailInputTest < Test::Unit::TestCase
1377
1378
  cp932_message = "s \x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932)
1378
1379
  utf8_message = "\x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".encode(Encoding::UTF_8, Encoding::CP932)
1379
1380
  d.run(expect_emits: 1) do
1380
- File.open("#{@tmp_dir}/tail.txt", "w:cp932") { |f|
1381
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "w:cp932") { |f|
1381
1382
  f.puts cp932_message
1382
1383
  }
1383
1384
  end
@@ -1409,11 +1410,11 @@ class TailInputTest < Test::Unit::TestCase
1409
1410
  )
1410
1411
  def test_multiline_with_multiple_formats(data)
1411
1412
  config = data
1412
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1413
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1413
1414
 
1414
1415
  d = create_driver(config)
1415
1416
  d.run(expect_emits: 1) do
1416
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1417
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1417
1418
  f.puts "f test1"
1418
1419
  f.puts "s test2"
1419
1420
  f.puts "f test3"
@@ -1450,7 +1451,7 @@ class TailInputTest < Test::Unit::TestCase
1450
1451
  )
1451
1452
  def test_multilinelog_with_multiple_paths(data)
1452
1453
  files = ["#{@tmp_dir}/tail1.txt", "#{@tmp_dir}/tail2.txt"]
1453
- files.each { |file| File.open(file, "wb") { |f| } }
1454
+ files.each { |file| Fluent::FileWrapper.open(file, "wb") { |f| } }
1454
1455
 
1455
1456
  config = data + config_element("", "", {
1456
1457
  "path" => "#{files[0]},#{files[1]}",
@@ -1459,7 +1460,7 @@ class TailInputTest < Test::Unit::TestCase
1459
1460
  d = create_driver(config, false)
1460
1461
  d.run(expect_emits: 2) do
1461
1462
  files.each do |file|
1462
- File.open(file, 'ab') { |f|
1463
+ Fluent::FileWrapper.open(file, 'ab') { |f|
1463
1464
  f.puts "f #{file} line should be ignored"
1464
1465
  f.puts "s test1"
1465
1466
  f.puts "f test2"
@@ -1494,12 +1495,12 @@ class TailInputTest < Test::Unit::TestCase
1494
1495
  ])
1495
1496
  )
1496
1497
  def test_multiline_without_firstline(data)
1497
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1498
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
1498
1499
 
1499
1500
  config = data
1500
1501
  d = create_driver(config)
1501
1502
  d.run(expect_emits: 1) do
1502
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1503
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
1503
1504
  f.puts "foo 1"
1504
1505
  f.puts "bar 1"
1505
1506
  f.puts "baz 1"
@@ -1605,10 +1606,10 @@ class TailInputTest < Test::Unit::TestCase
1605
1606
  d = create_driver(config, false)
1606
1607
  d.end_if { d.instance.instance_variable_get(:@tails).keys.size >= 1 }
1607
1608
  d.run(expect_emits: 1, shutdown: false) do
1608
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f| f.puts "test3\n" }
1609
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f| f.puts "test3\n" }
1609
1610
  end
1610
1611
 
1611
- cleanup_directory(@tmp_dir)
1612
+ cleanup_file("#{@tmp_dir}/tail.txt")
1612
1613
  waiting(20) { sleep 0.1 until Dir.glob("#{@tmp_dir}/*.txt").size == 0 } # Ensure file is deleted on Windows
1613
1614
  waiting(5) { sleep 0.1 until d.instance.instance_variable_get(:@tails).keys.size <= 0 }
1614
1615
 
@@ -1624,6 +1625,7 @@ class TailInputTest < Test::Unit::TestCase
1624
1625
  )
1625
1626
  ensure
1626
1627
  d.instance_shutdown if d && d.instance
1628
+ cleanup_directory(@tmp_dir)
1627
1629
  end
1628
1630
 
1629
1631
  def count_timer_object
@@ -1882,7 +1884,7 @@ class TailInputTest < Test::Unit::TestCase
1882
1884
  "max_line_size" => label,
1883
1885
  "log_level" => "debug"
1884
1886
  })
1885
- File.open("#{@tmp_dir}/with_long_lines.txt", "w+") do |f|
1887
+ Fluent::FileWrapper.open("#{@tmp_dir}/with_long_lines.txt", "w+") do |f|
1886
1888
  f.puts "foo"
1887
1889
  f.puts "x" * size # 'x' * size + \n > @max_line_size
1888
1890
  f.puts "bar"
@@ -1908,7 +1910,7 @@ class TailInputTest < Test::Unit::TestCase
1908
1910
  # Ensure that no fatal exception is raised when a file is missing and that
1909
1911
  # files that do exist are still tailed as expected.
1910
1912
  def test_missing_file
1911
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1913
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1912
1914
  f.puts "test1"
1913
1915
  f.puts "test2"
1914
1916
  }
@@ -1926,7 +1928,7 @@ class TailInputTest < Test::Unit::TestCase
1926
1928
  [config1, config2].each do |config|
1927
1929
  d = create_driver(config, false)
1928
1930
  d.run(expect_emits: 1) do
1929
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1931
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
1930
1932
  f.puts "test3"
1931
1933
  f.puts "test4"
1932
1934
  }
@@ -1947,14 +1949,14 @@ class TailInputTest < Test::Unit::TestCase
1947
1949
  path = "#{@tmp_dir}/tail.txt"
1948
1950
  ino = 1
1949
1951
  pos = 1234
1950
- File.open("#{@tmp_dir}/tail.pos", "wb") {|f|
1952
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.pos", "wb") {|f|
1951
1953
  f.puts ("%s\t%016x\t%016x\n" % [path, pos, ino])
1952
1954
  }
1953
1955
 
1954
1956
  d = create_driver(config, false)
1955
1957
  d.run
1956
1958
 
1957
- pos_file = File.open("#{@tmp_dir}/tail.pos", "r")
1959
+ pos_file = Fluent::FileWrapper.open("#{@tmp_dir}/tail.pos", "r")
1958
1960
  pos_file.pos = 0
1959
1961
 
1960
1962
  assert_raise(EOFError) do
@@ -1964,20 +1966,20 @@ class TailInputTest < Test::Unit::TestCase
1964
1966
 
1965
1967
  def test_should_write_latest_offset_after_rotate_wait
1966
1968
  config = common_follow_inode_config
1967
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1969
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
1968
1970
  f.puts "test1"
1969
1971
  f.puts "test2"
1970
1972
  }
1971
1973
 
1972
1974
  d = create_driver(config, false)
1973
1975
  d.run(expect_emits: 2, shutdown: false) do
1974
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
1976
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
1975
1977
  FileUtils.move("#{@tmp_dir}/tail.txt", "#{@tmp_dir}/tail.txt" + "1")
1976
1978
  sleep 1
1977
- File.open("#{@tmp_dir}/tail.txt" + "1", "ab") {|f| f.puts "test4\n"}
1979
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt" + "1", "ab") {|f| f.puts "test4\n"}
1978
1980
  end
1979
1981
 
1980
- pos_file = File.open("#{@tmp_dir}/tail.pos", "r")
1982
+ pos_file = Fluent::FileWrapper.open("#{@tmp_dir}/tail.pos", "r")
1981
1983
  pos_file.pos = 0
1982
1984
  line_parts = /^([^\t]+)\t([0-9a-fA-F]+)\t([0-9a-fA-F]+)/.match(pos_file.readline)
1983
1985
  waiting(5) {
@@ -1997,13 +1999,13 @@ class TailInputTest < Test::Unit::TestCase
1997
1999
  path = "#{@tmp_dir}/tail.txt"
1998
2000
  ino = 1
1999
2001
  pos = 1234
2000
- File.open("#{@tmp_dir}/tail.pos", "wb") {|f|
2002
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.pos", "wb") {|f|
2001
2003
  f.puts ("%s\t%016x\t%016x\n" % [path, pos, ino])
2002
2004
  }
2003
2005
 
2004
2006
  d = create_driver(config)
2005
2007
  d.run do
2006
- pos_file = File.open("#{@tmp_dir}/tail.pos", "r")
2008
+ pos_file = Fluent::FileWrapper.open("#{@tmp_dir}/tail.pos", "r")
2007
2009
  pos_file.pos = 0
2008
2010
  assert_equal([], pos_file.readlines)
2009
2011
  end
@@ -2024,14 +2026,14 @@ class TailInputTest < Test::Unit::TestCase
2024
2026
 
2025
2027
  d = create_driver(config, false)
2026
2028
 
2027
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2029
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2028
2030
  f.puts "test1"
2029
2031
  f.puts "test2"
2030
2032
  }
2031
2033
  target_info = create_target_info("#{@tmp_dir}/tail.txt")
2032
2034
 
2033
2035
  d.run(expect_emits: 1, shutdown: false) do
2034
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2036
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2035
2037
  end
2036
2038
 
2037
2039
 
@@ -2062,13 +2064,13 @@ class TailInputTest < Test::Unit::TestCase
2062
2064
 
2063
2065
  d = create_driver(config, false)
2064
2066
 
2065
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2067
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2066
2068
  f.puts "test1"
2067
2069
  f.puts "test2"
2068
2070
  }
2069
2071
 
2070
2072
  d.run(expect_emits: 2, shutdown: false) do
2071
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2073
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2072
2074
  FileUtils.move("#{@tmp_dir}/tail.txt", "#{@tmp_dir}/tail.txt1")
2073
2075
  end
2074
2076
 
@@ -2082,13 +2084,13 @@ class TailInputTest < Test::Unit::TestCase
2082
2084
 
2083
2085
  d = create_driver(config, false)
2084
2086
 
2085
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2087
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2086
2088
  f.puts "test1"
2087
2089
  f.puts "test2"
2088
2090
  }
2089
2091
 
2090
2092
  d.run(expect_emits: 1, shutdown: false) do
2091
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2093
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2092
2094
  end
2093
2095
 
2094
2096
  FileUtils.move("#{@tmp_dir}/tail.txt", "#{@tmp_dir}/tail.txt1")
@@ -2106,16 +2108,16 @@ class TailInputTest < Test::Unit::TestCase
2106
2108
 
2107
2109
  d = create_driver(config, false)
2108
2110
 
2109
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2111
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2110
2112
  f.puts "test1"
2111
2113
  f.puts "test2"
2112
2114
  }
2113
2115
  target_info = create_target_info("#{@tmp_dir}/tail.txt")
2114
2116
 
2115
2117
  d.run(expect_emits: 2, shutdown: false) do
2116
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2118
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2117
2119
  cleanup_file("#{@tmp_dir}/tail.txt")
2118
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f| f.puts "test4\n"}
2120
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f| f.puts "test4\n"}
2119
2121
  end
2120
2122
 
2121
2123
  new_target_info = create_target_info("#{@tmp_dir}/tail.txt")
@@ -2147,7 +2149,7 @@ class TailInputTest < Test::Unit::TestCase
2147
2149
  @metrics = Fluent::Plugin::TailInput::MetricsInfo.new(opened_file_metrics, closed_file_metrics, rotated_file_metrics)
2148
2150
  end
2149
2151
 
2150
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2152
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2151
2153
  f.puts "test1"
2152
2154
  f.puts "test2"
2153
2155
  }
@@ -2171,18 +2173,18 @@ class TailInputTest < Test::Unit::TestCase
2171
2173
 
2172
2174
  d = create_driver(config, false)
2173
2175
 
2174
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2176
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2175
2177
  f.puts "test1"
2176
2178
  f.puts "test2"
2177
2179
  }
2178
2180
  path_ino = create_target_info("#{@tmp_dir}/tail.txt")
2179
2181
 
2180
2182
  d.run(expect_emits: 1, shutdown: false) do
2181
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2183
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2182
2184
  end
2183
2185
 
2184
2186
  cleanup_file("#{@tmp_dir}/tail.txt")
2185
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2187
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2186
2188
  f.puts "test3"
2187
2189
  f.puts "test4"
2188
2190
  }
@@ -2208,15 +2210,15 @@ class TailInputTest < Test::Unit::TestCase
2208
2210
 
2209
2211
  d = create_driver(config, false)
2210
2212
 
2211
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2213
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2212
2214
  f.puts "test1"
2213
2215
  f.puts "test2"
2214
2216
  }
2215
2217
 
2216
2218
  d.run(expect_emits: 3, shutdown: false) do
2217
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2219
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f| f.puts "test3\n"}
2218
2220
  sleep 2
2219
- File.open("#{@tmp_dir}/tail.txt", "w+b") {|f| f.puts "test4\n"}
2221
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "w+b") {|f| f.puts "test4\n"}
2220
2222
  end
2221
2223
 
2222
2224
  events = d.events
@@ -2230,7 +2232,7 @@ class TailInputTest < Test::Unit::TestCase
2230
2232
 
2231
2233
  # issue #3464
2232
2234
  def test_should_replace_target_info
2233
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2235
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2234
2236
  f.puts "test1\n"
2235
2237
  }
2236
2238
  target_info = create_target_info("#{@tmp_dir}/tail.txt")
@@ -2257,7 +2259,7 @@ class TailInputTest < Test::Unit::TestCase
2257
2259
  assert_equal([target_info.ino], inodes)
2258
2260
 
2259
2261
  cleanup_file("#{@tmp_dir}/tail.txt")
2260
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f| f.puts "test2\n"}
2262
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f| f.puts "test2\n"}
2261
2263
 
2262
2264
  while d.events.size < 2 do
2263
2265
  sleep 0.1
@@ -2274,7 +2276,7 @@ class TailInputTest < Test::Unit::TestCase
2274
2276
 
2275
2277
  sub_test_case "tail_path" do
2276
2278
  def test_tail_path_with_singleline
2277
- File.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2279
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") {|f|
2278
2280
  f.puts "test1"
2279
2281
  f.puts "test2"
2280
2282
  }
@@ -2282,7 +2284,7 @@ class TailInputTest < Test::Unit::TestCase
2282
2284
  d = create_driver(SINGLE_LINE_CONFIG + config_element("", "", { "path_key" => "path" }))
2283
2285
 
2284
2286
  d.run(expect_emits: 1) do
2285
- File.open("#{@tmp_dir}/tail.txt", "ab") {|f|
2287
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") {|f|
2286
2288
  f.puts "test3"
2287
2289
  f.puts "test4"
2288
2290
  }
@@ -2296,7 +2298,7 @@ class TailInputTest < Test::Unit::TestCase
2296
2298
  end
2297
2299
 
2298
2300
  def test_tail_path_with_multiline_with_firstline
2299
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
2301
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
2300
2302
 
2301
2303
  config = config_element("", "", {
2302
2304
  "path_key" => "path",
@@ -2306,7 +2308,7 @@ class TailInputTest < Test::Unit::TestCase
2306
2308
  })
2307
2309
  d = create_driver(config)
2308
2310
  d.run(expect_emits: 1) do
2309
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
2311
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
2310
2312
  f.puts "f test1"
2311
2313
  f.puts "s test2"
2312
2314
  f.puts "f test3"
@@ -2326,7 +2328,7 @@ class TailInputTest < Test::Unit::TestCase
2326
2328
  end
2327
2329
 
2328
2330
  def test_tail_path_with_multiline_without_firstline
2329
- File.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
2331
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") { |f| }
2330
2332
 
2331
2333
  config = config_element("", "", {
2332
2334
  "path_key" => "path",
@@ -2337,7 +2339,7 @@ class TailInputTest < Test::Unit::TestCase
2337
2339
  })
2338
2340
  d = create_driver(config)
2339
2341
  d.run(expect_emits: 1) do
2340
- File.open("#{@tmp_dir}/tail.txt", "ab") { |f|
2342
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "ab") { |f|
2341
2343
  f.puts "foo 1"
2342
2344
  f.puts "bar 1"
2343
2345
  f.puts "baz 1"
@@ -2356,7 +2358,7 @@ class TailInputTest < Test::Unit::TestCase
2356
2358
  omit "This testcase is unstable on AppVeyor."
2357
2359
  end
2358
2360
  files = ["#{@tmp_dir}/tail1.txt", "#{@tmp_dir}/tail2.txt"]
2359
- files.each { |file| File.open(file, "wb") { |f| } }
2361
+ files.each { |file| Fluent::FileWrapper.open(file, "wb") { |f| } }
2360
2362
 
2361
2363
  config = config_element("", "", {
2362
2364
  "path" => "#{files[0]},#{files[1]}",
@@ -2369,7 +2371,7 @@ class TailInputTest < Test::Unit::TestCase
2369
2371
  d = create_driver(config, false)
2370
2372
  d.run(expect_emits: 2) do
2371
2373
  files.each do |file|
2372
- File.open(file, 'ab') { |f|
2374
+ Fluent::FileWrapper.open(file, 'ab') { |f|
2373
2375
  f.puts "f #{file} line should be ignored"
2374
2376
  f.puts "s test1"
2375
2377
  f.puts "f test2"
@@ -2500,7 +2502,7 @@ class TailInputTest < Test::Unit::TestCase
2500
2502
  end
2501
2503
 
2502
2504
  def test_shutdown_timeout
2503
- File.open("#{@tmp_dir}/tail.txt", "wb") do |f|
2505
+ Fluent::FileWrapper.open("#{@tmp_dir}/tail.txt", "wb") do |f|
2504
2506
  # Should be large enough to take too long time to consume
2505
2507
  (1024 * 1024 * 5).times do
2506
2508
  f.puts "{\"test\":\"fizzbuzz\"}"
@@ -2548,7 +2550,7 @@ class TailInputTest < Test::Unit::TestCase
2548
2550
 
2549
2551
  conf = ROOT_CONFIG + group + path_element + CONFIG_READ_FROM_HEAD + SINGLE_LINE_CONFIG
2550
2552
 
2551
- File.open("#{@tmp_dir}/#{file}", 'wb') do |f|
2553
+ Fluent::FileWrapper.open("#{@tmp_dir}/#{file}", 'wb') do |f|
2552
2554
  num_lines.times do
2553
2555
  f.puts "#{msg}\n"
2554
2556
  end
@@ -2594,7 +2596,7 @@ class TailInputTest < Test::Unit::TestCase
2594
2596
  d = create_driver(conf, false)
2595
2597
  file_path = "#{@tmp_dir}/#{file}"
2596
2598
 
2597
- File.open(file_path, 'wb') do |f|
2599
+ Fluent::FileWrapper.open(file_path, 'wb') do |f|
2598
2600
  num_lines.times do
2599
2601
  f.puts msg
2600
2602
  end