|
2 | 2 | require "logstash/outputs/redis" |
3 | 3 | require "logstash/json" |
4 | 4 | require "redis" |
| 5 | +require "flores/random" |
5 | 6 |
|
6 | 7 | describe LogStash::Outputs::Redis, :redis => true do |
7 | 8 |
|
|
48 | 49 | end |
49 | 50 |
|
50 | 51 | describe "batch mode" do |
51 | | - key = 10.times.collect { rand(10).to_s }.join("") |
52 | | - event_count = 200000 |
| 52 | + let(:key) { 10.times.collect { rand(10).to_s }.join("") } |
| 53 | + let(:event_count) { Flores::Random.integer(0..10000) } |
| 54 | + let(:message) { Flores::Random.text(0..100) } |
53 | 55 |
|
54 | | - config <<-CONFIG |
55 | | - input { |
56 | | - generator { |
57 | | - message => "hello world" |
58 | | - count => #{event_count} |
59 | | - type => "generator" |
60 | | - } |
61 | | - } |
62 | | - output { |
63 | | - redis { |
64 | | - host => "127.0.0.1" |
65 | | - key => "#{key}" |
66 | | - data_type => list |
67 | | - batch => true |
68 | | - batch_timeout => 5 |
69 | | - timeout => 5 |
70 | | - } |
71 | | - } |
72 | | - CONFIG |
| 56 | + let(:redis_output) { |
| 57 | + LogStash::Plugin.lookup("output", "redis").new( |
| 58 | + "host" => "127.0.0.1", |
| 59 | + "key" => key, |
| 60 | + "data_type" => "list", |
| 61 | + "batch" => true, |
| 62 | + "batch_timeout" => 5, |
| 63 | + "timeout" => 5 |
| 64 | + ) |
| 65 | + } |
73 | 66 |
|
74 | | - agent do |
75 | | - # we have to wait for close to execute & flush the last batch. |
76 | | - # otherwise we might start doing assertions before everything has been |
77 | | - # sent out to redis. |
78 | | - sleep 2 |
| 67 | + before do |
| 68 | + redis_output.register |
| 69 | + event_count.times do |i| |
| 70 | + event = LogStash::Event.new("sequence" => i, "message" => message) |
| 71 | + redis_output.receive(event) |
| 72 | + end |
| 73 | + redis_output.close |
| 74 | + end |
79 | 75 |
|
| 76 | + it "should successfully send all events to redis" do |
80 | 77 | redis = Redis.new(:host => "127.0.0.1") |
81 | | - |
| 78 | + |
82 | 79 | # The list should contain the number of elements our agent pushed up. |
83 | 80 | insist { redis.llen(key) } == event_count |
84 | 81 |
|
|
87 | 84 | id, element = redis.blpop(key, 0) |
88 | 85 | event = LogStash::Event.new(LogStash::Json.load(element)) |
89 | 86 | insist { event["sequence"] } == value |
90 | | - insist { event["message"] } == "hello world" |
| 87 | + insist { event["message"] } == message |
91 | 88 | end |
92 | 89 |
|
93 | 90 | # The list should now be empty |
94 | 91 | insist { redis.llen(key) } == 0 |
95 | | - end # agent |
| 92 | + end |
96 | 93 | end |
97 | 94 | end |
98 | 95 |
|
0 commit comments