From f41943d6d9328035498dd037d6dca5d86b0ec889 Mon Sep 17 00:00:00 2001 From: tranj3 Date: Wed, 25 Jan 2017 12:59:00 +1100 Subject: [PATCH] Deprecated Time.now.to_i in favor of Fluent::EventTime.now, and updated unit tests --- lib/fluent/plugin/in_tail.rb | 2 +- test/plugin/test_in_tail.rb | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index c7f36a19fe..625ed803c8 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -362,7 +362,7 @@ def convert_line_to_event(line, es, tail_watcher) if @emit_unmatched_lines record = {'unmatched_line' => line} record[@path_key] ||= tail_watcher.path unless @path_key.nil? - es.add(Time.now.to_i, record) + es.add(Fluent::EventTime.now, record) end log.warn "pattern not match: #{line.inspect}" end diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 2f688131ec..4621032949 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -149,27 +149,26 @@ def test_emit(data) assert_equal(1, d.emit_count) end - data(flat: config_element("", "", { "format" => "/^(?test.*)/", "emit_unmatched_lines" => true }), - parse: config_element("", "", { "format" => "/^(?test.*)/", "emit_unmatched_lines" => true })) - def test_emit_with_emit_unmatched_lines_true(data) - config = data + def test_emit_with_emit_unmatched_lines_true + config = config_element("", "", { "format" => "/^(?test.*)/", "emit_unmatched_lines" => true }) File.open("#{TMP_DIR}/tail.txt", "wb") { |f| } d = create_driver(config) - d.run(expect_emits: 1) do File.open("#{TMP_DIR}/tail.txt", "ab") {|f| f.puts "test line 1" f.puts "test line 2" f.puts "bad line 1" + f.puts "test line 3" } end events = d.events - assert_equal(3, events.length) + assert_equal(4, events.length) assert_equal({"message" => "test line 1"}, events[0][2]) assert_equal({"message" => "test line 2"}, events[1][2]) assert_equal({"unmatched_line" => "bad line 1"}, events[2][2]) + assert_equal({"message" => "test line 3"}, events[3][2]) end data('flat 1' => [:flat, 1, 2], @@ -539,11 +538,12 @@ def test_multiline(data) assert_equal({"message1" => "test8"}, events[3][2]) end - data(flat: MULTILINE_CONFIG + config_element("", "", { "emit_unmatched_lines" => true }), - parse: PARSE_MULTILINE_CONFIG + config_element("", "", { "emit_unmatched_lines" => true }),) + data(flat: MULTILINE_CONFIG, + parse: PARSE_MULTILINE_CONFIG) def test_multiline_with_emit_unmatched_lines_true(data) - config = data + config = data + config_element("", "", { "emit_unmatched_lines" => true }) File.open("#{TMP_DIR}/tail.txt", "wb") { |f| } + d = create_driver(config) d.run(expect_emits: 1) do File.open("#{TMP_DIR}/tail.txt", "ab") { |f|