This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex_spec.rb
91 lines (82 loc) · 2.41 KB
/
index_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require_relative "../../../spec/es_spec_helper"
require "insist"
shared_examples "an indexer" do
let(:index) { 10.times.collect { rand(10).to_s }.join("") }
let(:type) { 10.times.collect { rand(10).to_s }.join("") }
let(:event_count) { 10000 + rand(500) }
let(:flush_size) { rand(200) + 1 }
let(:config) { "not implemented" }
it "ships events" do
insist { config } != "not implemented"
pipeline = LogStash::Pipeline.new(config)
pipeline.run
index_url = "http://#{get_host}:#{get_port('http')}/#{index}"
ftw = FTW::Agent.new
ftw.post!("#{index_url}/_refresh")
# Wait until all events are available.
Stud::try(10.times) do
data = ""
response = ftw.get!("#{index_url}/_count?q=*")
response.read_body { |chunk| data << chunk }
result = LogStash::Json.load(data)
cur_count = result["count"]
insist { cur_count } == event_count
end
response = ftw.get!("#{index_url}/_search?q=*&size=1000")
data = ""
response.read_body { |chunk| data << chunk }
result = LogStash::Json.load(data)
result["hits"]["hits"].each do |doc|
insist { doc["_type"] } == type
insist { doc["_index"] } == index
end
end
end
describe "an indexer with custom index_type", :integration => true do
it_behaves_like "an indexer" do
let(:config) {
<<-CONFIG
input {
generator {
message => "hello world"
count => #{event_count}
type => "#{type}"
}
}
output {
elasticsearch_java {
hosts => "#{get_host()}:#{get_port('transport')}"
network_host => "#{get_local_host}"
protocol => "transport"
index => "#{index}"
flush_size => #{flush_size}
}
}
CONFIG
}
end
end
describe "an indexer with no type value set (default to logs)", :integration => true do
it_behaves_like "an indexer" do
let(:type) { "logs" }
let(:config) {
<<-CONFIG
input {
generator {
message => "hello world"
count => #{event_count}
}
}
output {
elasticsearch_java {
hosts => "#{get_host()}:#{get_port('transport')}"
network_host => "#{get_local_host}"
protocol => "transport"
index => "#{index}"
flush_size => #{flush_size}
}
}
CONFIG
}
end
end