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

Make usage of stop new semantics of LS #9

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 4 additions & 3 deletions lib/logstash/inputs/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def connect
end

def run(queue)
@run_thread = Thread.current
Stud.interval(@check_interval) do
check_mail(queue)
end
Expand Down Expand Up @@ -143,10 +144,10 @@ def parse_mail(mail)
end # def handle

public
def teardown
def stop
Stud.stop!(@run_thread)
$stdin.close
finished
end # def teardown
end

private

Expand Down
3 changes: 1 addition & 2 deletions logstash-input-imap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Gem::Specification.new do |s|

# Gem dependencies
s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'

s.add_runtime_dependency 'logstash-codec-plain'
s.add_runtime_dependency 'mail'
s.add_runtime_dependency 'stud'
s.add_runtime_dependency 'stud', '~> 0.0.22'

s.add_development_dependency 'logstash-devutils'
end
Expand Down
31 changes: 30 additions & 1 deletion spec/inputs/imap_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
# encoding: utf-8
#
require "logstash/devutils/rspec/spec_helper"
require "logstash/inputs/imap"
require "mail"
require "net/imap"


describe LogStash::Inputs::IMAP do

context "when interrupting the plugin" do
it_behaves_like "an interruptible input plugin" do
let(:config) do
{ "type" => "imap",
"host" => "localhost",
"user" => "logstash",
"password" => "secret" }
end
let(:imap) { double("imap") }
let(:ids) { double("ids") }
before(:each) do
allow(imap).to receive(:login)
allow(imap).to receive(:select)
allow(imap).to receive(:close)
allow(imap).to receive(:disconnect)
allow(imap).to receive(:store)
allow(ids).to receive(:each_slice).and_return([])

allow(imap).to receive(:search).with("NOT SEEN").and_return(ids)
allow(Net::IMAP).to receive(:new).and_return(imap)
end
end
end

end

describe LogStash::Inputs::IMAP do
user = "logstash"
Expand Down