Skip to content

Commit

Permalink
removed unused kwarg "delimiter"
Browse files Browse the repository at this point in the history
It was originally for JSONL (json string per lines).
But currently it isn't needed because Yajl parser can process it in #read_message method.
I added a test case to confirm it.
  • Loading branch information
tagomoris committed Aug 26, 2016
1 parent 62abe94 commit ead3c77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
20 changes: 2 additions & 18 deletions lib/fluent/plugin/in_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,24 +551,8 @@ def on_connect
end

# API to register callback for data arrival
def on_data(delimiter: nil, &callback)
if delimiter.nil?
@on_read_callback = callback
return
end

# buffering and splitting
@buffer = "".force_encoding("ASCII-8BIT")
@on_read_callback = ->(data) {
@buffer << data
pos = 0
while i = @buffer.index(delimiter, pos)
msg = @buffer[pos...i]
callback.call(msg)
pos = i + delimiter.length
end
@buffer.slice!(0, pos) if pos > 0
}
def on_data(&callback)
@on_read_callback = callback
end

def on_read(data)
Expand Down
21 changes: 21 additions & 0 deletions test/plugin/test_in_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ def test_json

assert_equal(records, d.emits.sort_by {|a| a[1] })
end

def test_json_with_newline
d = create_driver

time = Time.parse("2011-01-02 13:14:15 UTC").to_i

records = [
["tag1", time, {"a"=>1}],
["tag2", time, {"a"=>2}],
]

d.expected_emits_length = records.length
d.run_timeout = 2
d.run do
records.each {|tag, _time, record|
send_data [tag, _time, record].to_json + "\n"
}
end

assert_equal(records, d.emits.sort_by {|a| a[1] })
end
end

class Forward < self
Expand Down

0 comments on commit ead3c77

Please sign in to comment.