diff --git a/logstash-core/spec/logstash/agent_spec.rb b/logstash-core/spec/logstash/agent_spec.rb index 2c4aa6d79..98eafba9d 100644 --- a/logstash-core/spec/logstash/agent_spec.rb +++ b/logstash-core/spec/logstash/agent_spec.rb @@ -411,19 +411,19 @@ describe LogStash::Agent do # We need to create theses dummy classes to know how many # events where actually generated by the pipeline and successfully send to the output. # Theses values are compared with what we store in the metric store. - class DummyOutput2 < LogStash::Outputs::DummyOutput; end + class DummyOutput2 < LogStash::Outputs::DroppingDummyOutput; end - let!(:dummy_output) { DummyOutput.new } + let!(:dummy_output) { LogStash::Outputs::DroppingDummyOutput.new } let!(:dummy_output2) { DummyOutput2.new } let(:initial_generator_threshold) { 1000 } before :each do - allow(DummyOutput).to receive(:new).at_least(:once).with(anything).and_return(dummy_output) + allow(LogStash::Outputs::DroppingDummyOutput).to receive(:new).at_least(:once).with(anything).and_return(dummy_output) allow(DummyOutput2).to receive(:new).at_least(:once).with(anything).and_return(dummy_output2) allow(LogStash::Plugin).to receive(:lookup).with("input", "generator").and_return(LogStash::Inputs::Generator) allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(LogStash::Codecs::Plain) - allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput) + allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(LogStash::Outputs::DroppingDummyOutput) allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput2").and_return(DummyOutput2) @abort_on_exception = Thread.abort_on_exception @@ -435,7 +435,7 @@ describe LogStash::Agent do end # wait for some events to reach the dummy_output - sleep(0.01) until dummy_output.events.size > initial_generator_threshold + sleep(0.01) until dummy_output.events_received > initial_generator_threshold end after :each do @@ -461,7 +461,7 @@ describe LogStash::Agent do subject.send(:"reload_pipeline!", "main") # wait until pipeline restarts - sleep(0.01) until dummy_output2.events.size > 0 + sleep(0.01) until dummy_output2.events_received > 0 end it "resets the pipeline metric collector" do diff --git a/logstash-core/spec/support/mocks_classes.rb b/logstash-core/spec/support/mocks_classes.rb index 3cdf0a6dc..5ae99a68f 100644 --- a/logstash-core/spec/support/mocks_classes.rb +++ b/logstash-core/spec/support/mocks_classes.rb @@ -48,4 +48,32 @@ module LogStash module Outputs def close end end + + class DroppingDummyOutput < LogStash::Outputs::Base + config_name "droppingdummyoutput" + milestone 2 + + attr_reader :num_closes + + def initialize(params={}) + super + @num_closes = 0 + @events_received = Concurrent::AtomicFixnum.new(0) + end + + def register + end + + def receive(event) + @events_received.increment + end + + def events_received + @events_received.value + end + + def close + @num_closes = 1 + end + end end end