Skip to content

Commit

Permalink
Deprecated Time.now.to_i in favor of Fluent::EventTime.now, and updat…
Browse files Browse the repository at this point in the history
…ed unit tests
  • Loading branch information
tranj3 committed Jan 25, 2017
1 parent deac084 commit f41943d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,26 @@ def test_emit(data)
assert_equal(1, d.emit_count)
end

data(flat: config_element("", "", { "format" => "/^(?<message>test.*)/", "emit_unmatched_lines" => true }),
parse: config_element("", "", { "format" => "/^(?<message>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" => "/^(?<message>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],
Expand Down Expand Up @@ -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|
Expand Down

0 comments on commit f41943d

Please sign in to comment.