mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
parent
6480c9c89b
commit
ec2a180b86
2 changed files with 60 additions and 4 deletions
|
@ -39,7 +39,7 @@ class LogStash::Inputs::Generator < LogStash::Inputs::Threadable
|
|||
# }
|
||||
# }
|
||||
#
|
||||
# The above will emit "line 1" then "line 2" then "line", then "line 1", etc...
|
||||
# The above will emit "line 1" then "line 2" then "line", then "line 1", etc...
|
||||
config :lines, :validate => :array
|
||||
|
||||
# Set how many messages should be generated.
|
||||
|
@ -51,7 +51,6 @@ class LogStash::Inputs::Generator < LogStash::Inputs::Threadable
|
|||
def register
|
||||
@host = Socket.gethostname
|
||||
@count = @count.first if @count.is_a?(Array)
|
||||
@lines = [@message] if @lines.nil?
|
||||
end # def register
|
||||
|
||||
def run(queue)
|
||||
|
@ -62,6 +61,7 @@ class LogStash::Inputs::Generator < LogStash::Inputs::Threadable
|
|||
@message = $stdin.readline
|
||||
@logger.debug("Generator line read complete", :message => @message)
|
||||
end
|
||||
@lines = [@message] if @lines.nil?
|
||||
|
||||
while !finished? && (@count <= 0 || number < @count)
|
||||
@lines.each do |line|
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require "test_utils"
|
||||
|
||||
describe "inputs/generator", :performance => true do
|
||||
describe "inputs/generator" do
|
||||
extend LogStash::RSpec
|
||||
|
||||
describe "generate events" do
|
||||
context "performance", :performance => true do
|
||||
event_count = 100000 + rand(50000)
|
||||
|
||||
config <<-CONFIG
|
||||
|
@ -27,4 +27,60 @@ describe "inputs/generator", :performance => true do
|
|||
pipeline.shutdown
|
||||
end # input
|
||||
end
|
||||
|
||||
context "generate configured message" do
|
||||
config <<-CONFIG
|
||||
input {
|
||||
generator {
|
||||
count => 2
|
||||
message => "foo"
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
input do |pipeline, queue|
|
||||
Thread.new { pipeline.run }
|
||||
event = queue.pop
|
||||
insist { event["sequence"] } == 0
|
||||
insist { event["message"] } == "foo"
|
||||
|
||||
event = queue.pop
|
||||
insist { event["sequence"] } == 1
|
||||
insist { event["message"] } == "foo"
|
||||
|
||||
insist { queue.size } == 0
|
||||
pipeline.shutdown
|
||||
end # input
|
||||
|
||||
context "generate message from stdin" do
|
||||
config <<-CONFIG
|
||||
input {
|
||||
generator {
|
||||
count => 2
|
||||
message => "stdin"
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
input do |pipeline, queue|
|
||||
saved_stdin = $stdin
|
||||
stdin_mock = StringIO.new
|
||||
$stdin = stdin_mock
|
||||
stdin_mock.should_receive(:readline).once.and_return("bar")
|
||||
|
||||
Thread.new { pipeline.run }
|
||||
event = queue.pop
|
||||
insist { event["sequence"] } == 0
|
||||
insist { event["message"] } == "bar"
|
||||
|
||||
event = queue.pop
|
||||
insist { event["sequence"] } == 1
|
||||
insist { event["message"] } == "bar"
|
||||
|
||||
insist { queue.size } == 0
|
||||
pipeline.shutdown
|
||||
$stdin = saved_stdin
|
||||
end # input
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue