From 9c829d515c98a8cad41024571d2060a272e1e71b Mon Sep 17 00:00:00 2001 From: Andrew Cholakian Date: Thu, 24 Sep 2015 16:36:51 -0500 Subject: [PATCH] This makes this plugin stoppable as per the LS2.0 API Fixes #28 --- lib/logstash/outputs/influxdb.rb | 2 +- spec/outputs/influxdb_spec.rb | 46 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/logstash/outputs/influxdb.rb b/lib/logstash/outputs/influxdb.rb index 8fdb87d..8c55937 100644 --- a/lib/logstash/outputs/influxdb.rb +++ b/lib/logstash/outputs/influxdb.rb @@ -223,7 +223,7 @@ def post(body) end end # def post - def teardown + def close buffer_flush(:final => true) end # def teardown end # class LogStash::Outputs::InfluxDB diff --git a/spec/outputs/influxdb_spec.rb b/spec/outputs/influxdb_spec.rb index 7e16f4c..59f335f 100644 --- a/spec/outputs/influxdb_spec.rb +++ b/spec/outputs/influxdb_spec.rb @@ -7,36 +7,38 @@ context "complete pipeline run with 2 events" do - let(:config) do <<-CONFIG - input { - generator { - message => "foo=1 bar=2 time=3" - count => 2 - type => "generator" - } + let(:config) do + { + "host" => "localhost", + "user" => "someuser", + "password" => "somepwd", + "allow_time_override" => true, + "data_points" => { + "foo" => "%{foo}", + "bar" => "%{bar}", + "time" => "%{time}" } + } + end - filter { - kv { } - } + subject { LogStash::Outputs::InfluxDB.new(config) } - output { - influxdb { - host => "localhost" - user => "someuser" - password => "somepwd" - allow_time_override => true - data_points => {"foo" => "%{foo}" "bar" => "%{bar}" "time" => "%{time}"} - } - } - CONFIG + before do + subject.register + allow(subject).to receive(:post).with(json_result) + + 2.times do + subject.receive(LogStash::Event.new("foo" => "1", "bar" => "2", "time" => "3", "type" => "generator")) + end + + # Close / flush the buffer + subject.close end let(:json_result) { "[{\"name\":\"logstash\",\"columns\":[\"foo\",\"bar\",\"time\"],\"points\":[[\"1\",\"2\",\"3\"],[\"1\",\"2\",\"3\"]]}]" } it "should receive 2 events, flush and call post with 2 items json array" do - expect_any_instance_of(LogStash::Outputs::InfluxDB).to receive(:post).with(json_result) - pipeline.run + expect(subject).to have_received(:post).with(json_result) end end