Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure inputSize state value is reset during buftok.flush #16760

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions logstash-core/spec/logstash/util/buftok_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@
expect(subject.extract("\n\n\n")).to eq(["", "", ""])
end

describe 'flush' do
let(:data) { "content without a delimiter" }
before(:each) do
subject.extract(data)
end

it "emits the contents of the buffer" do
expect(subject.flush).to eq(data)
end

it "resets the state of the buffer" do
subject.flush
expect(subject).to be_empty
end

context 'with decode_size_limit_bytes' do
subject { FileWatch::BufferedTokenizer.new("\n", 100) }

it "emits the contents of the buffer" do
expect(subject.flush).to eq(data)
end

it "resets the state of the buffer" do
subject.flush
expect(subject).to be_empty
end
end
end

context 'with delimiter' do
subject { FileWatch::BufferedTokenizer.new(delimiter) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ public RubyArray extract(final ThreadContext context, IRubyObject data) {
public IRubyObject flush(final ThreadContext context) {
final IRubyObject buffer = input.join(context);
input.clear();
inputSize = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 this change does actually fix the issue where inputSize is not reset on a flush.

return buffer;
}

@JRubyMethod(name = "empty?")
public IRubyObject isEmpty(final ThreadContext context) {
return input.empty_p();
return RubyUtil.RUBY.newBoolean(input.isEmpty() && (inputSize == 0));
jsvd marked this conversation as resolved.
Show resolved Hide resolved
}

}
Loading