Skip to content

Commit

Permalink
[test] Added test to verify the usage of java heap
Browse files Browse the repository at this point in the history
  • Loading branch information
andsel committed Apr 4, 2024
1 parent 5f072ab commit 0b65df4
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions qa/integration/specs/direct_heap_allocator_flag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,41 @@
let(:temp_dir) { Stud::Temporary.directory("logstash-pipelinelog-test") }
let(:config) { @fixture.config("root") }
let(:initial_config_file) { config_to_temp_file(@fixture.config("root")) }

let(:buffer_type) { "direct" }

let(:settings) do
{
"path.logs" => temp_dir,
"pipeline.receive_buffer.type" => buffer_type
}
end

it "should use Netty direct memory if configured to 'direct'" do
# IO.write(@ls.application_settings_file, settings.to_yaml)
# @ls.spawn_logstash("-w", "1", "-e", config)
#
# Stud.try(120.times, [StandardError, RSpec::Expectations::ExpectationNotMetError]) do
# # poll Logstash HTTP api to become active
# expect(@ls.rest_active?).to be true
# end
#
# # send some data to http pipeline (by default on port 8080)
# # in the mean time some dumps should appear in the logs
# #(> 5 seconds because the JRuby filter in test pipeline dumps Netty memory status every 5 seconds)
# stream_some_data_into_pipeline
start_logstash_and_process_some_events

last_dump_line = find_last_mem_dump_log_line("#{temp_dir}/logstash-plain.log")

# verify direct buffer are used while heap buffers remains at 0
direct_mem, heap_mem = last_dump_line.match(/\[logstash.filters.ruby\s*\]\[main\].*Direct mem: (\d*) .*Heap mem: (\d*)/).captures
expect(direct_mem.to_i).to be > 0
expect(heap_mem.to_i).to eq 0
context "running a pipeline that dump memory status" do
before(:each) { start_logstash_and_process_some_events }

context "when 'direct' is configured as receive_buffer type" do
let(:buffer_type) { "direct" }

it "should use Netty direct memory" do
last_dump_line = find_last_mem_dump_log_line("#{temp_dir}/logstash-plain.log")

# verify direct buffer are used while heap buffers remains at 0
direct_mem, heap_mem = last_dump_line.match(/\[logstash.filters.ruby\s*\]\[main\].*Direct mem: (\-?\d*) .*Heap mem: (\-?\d*)/).captures
expect(direct_mem.to_i).to be > 0
expect(heap_mem.to_i).to be <= 0
end
end

context "when 'heap' is configured as receive_buffer type" do
let(:buffer_type) { "heap" }

it "should use only Java heap memory" do
last_dump_line = find_last_mem_dump_log_line("#{temp_dir}/logstash-plain.log")

# verify java heap buffer are used while direct buffers remains at 0
direct_mem, heap_mem = last_dump_line.match(/\[logstash.filters.ruby\s*\]\[main\].*Direct mem: (\-?\d*) .*Heap mem: (\-?\d*)/).captures
expect(direct_mem.to_i).to be <= 0
expect(heap_mem.to_i).to be > 0
end
end
end

def start_logstash_and_process_some_events
Expand Down

0 comments on commit 0b65df4

Please sign in to comment.