- fix redis tests

This commit is contained in:
Jordan Sissel 2013-08-20 22:59:04 -07:00
parent a4aa87e691
commit 0ec869bca0
2 changed files with 12 additions and 46 deletions

View file

@ -5,23 +5,21 @@ def populate(key, event_count)
require "logstash/event" require "logstash/event"
redis = Redis.new(:host => "localhost") redis = Redis.new(:host => "localhost")
event_count.times do |value| event_count.times do |value|
event = LogStash::Event.new("@fields" => { "sequence" => value }) event = LogStash::Event.new("sequence" => value)
Stud::try(10.times) do Stud::try(10.times) do
redis.rpush(key, event.to_json) redis.rpush(key, event.to_json)
end end
end end
end end
def process(plugins, event_count) def process(pipeline, queue, event_count)
sequence = 0 sequence = 0
redis = plugins.first Thread.new { pipeline.run }
output = Shiftback.new do |event| event_count.times do |i|
insist { event["sequence"] } == sequence event = queue.pop
sequence += 1 insist { event["sequence"] } == i
redis.teardown if sequence == event_count
end end
redis.register pipeline.shutdown
redis.run(output)
end # process end # process
describe "inputs/redis" do describe "inputs/redis" do
@ -36,13 +34,13 @@ describe "inputs/redis" do
type => "blah" type => "blah"
key => "#{key}" key => "#{key}"
data_type => "list" data_type => "list"
format => json_event
} }
} }
CONFIG CONFIG
before(:each) { populate(key, event_count) } before(:each) { populate(key, event_count) }
input { |plugins| process(plugins, event_count) }
input { |pipeline, queue| process(pipeline, queue, event_count) }
end end
describe "read events from a list with batch_count=5" do describe "read events from a list with batch_count=5" do
@ -55,12 +53,11 @@ describe "inputs/redis" do
key => "#{key}" key => "#{key}"
data_type => "list" data_type => "list"
batch_count => #{rand(20)+1} batch_count => #{rand(20)+1}
format => json_event
} }
} }
CONFIG CONFIG
before(:each) { populate(key, event_count) } before(:each) { populate(key, event_count) }
input { |plugins| process(plugins, event_count) } input { |pipeline, queue| process(pipeline, queue, event_count) }
end end
end end

View file

@ -38,8 +38,7 @@ describe LogStash::Outputs::Redis do
id, element = redis.blpop(key, 0) id, element = redis.blpop(key, 0)
event = LogStash::Event.new(JSON.parse(element)) event = LogStash::Event.new(JSON.parse(element))
insist { event["sequence"] } == value insist { event["sequence"] } == value
insist { event.message } == "hello world" insist { event["message"] } == "hello world"
insist { event.type } == "generator"
end end
# The list should now be empty # The list should now be empty
@ -47,35 +46,6 @@ describe LogStash::Outputs::Redis do
end # agent end # agent
end end
describe "skips a message which can't be encoded as json" do
key = 10.times.collect { rand(10).to_s }.join("")
config <<-CONFIG
input {
generator {
message => "\xAD\u0000"
count => 1
type => "generator"
}
}
output {
redis {
host => "127.0.0.1"
key => "#{key}"
data_type => list
}
}
CONFIG
agent do
# Query redis directly and inspect the goodness.
redis = Redis.new(:host => "127.0.0.1")
# The list should contain no elements.
insist { redis.llen(key) } == 0
end # agent
end
describe "batch mode" do describe "batch mode" do
key = 10.times.collect { rand(10).to_s }.join("") key = 10.times.collect { rand(10).to_s }.join("")
event_count = 200000 event_count = 200000
@ -116,8 +86,7 @@ describe LogStash::Outputs::Redis do
id, element = redis.blpop(key, 0) id, element = redis.blpop(key, 0)
event = LogStash::Event.new(JSON.parse(element)) event = LogStash::Event.new(JSON.parse(element))
insist { event["sequence"] } == value insist { event["sequence"] } == value
insist { event.message } == "hello world" insist { event["message"] } == "hello world"
insist { event.type } == "generator"
end end
# The list should now be empty # The list should now be empty