forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.rb
107 lines (93 loc) · 2.52 KB
/
file.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require "test_utils"
require "tempfile"
describe "inputs/file" do
extend LogStash::RSpec
describe "starts at the end of an existing file" do
tmp_file = Tempfile.new('logstash-spec-input-file')
config <<-CONFIG
input {
file {
type => "blah"
path => "#{tmp_file.path}"
sincedb_path => "/dev/null"
}
}
CONFIG
input do |pipeline, queue|
File.open(tmp_file, "a") do |fd|
fd.puts("ignore me")
fd.puts("ignore me 2")
end
Thread.new { pipeline.run }
sleep 0.1 while !pipeline.ready?
File.open(tmp_file, "a") do |fd|
fd.puts("hello")
fd.puts("world")
end
events = 2.times.collect { queue.pop }
insist { events[0]["message"] } == "hello"
insist { events[1]["message"] } == "world"
end
end
describe "can start at the beginning of an existing file" do
tmp_file = Tempfile.new('logstash-spec-input-file')
config <<-CONFIG
input {
file {
type => "blah"
path => "#{tmp_file.path}"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
CONFIG
before(:each) do
File.open(tmp_file, "w") do |fd|
fd.puts "hello"
fd.puts "world"
end
end
after(:each) do
tmp_file.close!
end
input do |pipeline, queue|
Thread.new { pipeline.run }
events = 2.times.collect { queue.pop }
insist { events[0]["message"] } == "hello"
insist { events[1]["message"] } == "world"
end
end
describe "restarts at the sincedb value" do
tmp_file = Tempfile.new('logstash-spec-input-file')
tmp_sincedb = Tempfile.new('logstash-spec-input-file-sincedb')
config <<-CONFIG
input {
file {
type => "blah"
path => "#{tmp_file.path}"
start_position => "beginning"
sincedb_path => "#{tmp_sincedb.path}"
}
}
CONFIG
input do |pipeline, queue|
File.open(tmp_file, "a") do |fd|
fd.puts "hello"
fd.puts "world"
end
Thread.new { pipeline.run }
events = 2.times.collect { queue.pop }
pipeline.shutdown
File.open(tmp_file, "a") do |fd|
fd.puts "foo"
fd.puts "bar"
fd.puts "baz"
end
Thread.new { pipeline.run }
events = 3.times.collect { queue.pop }
insist { events[0]["message"] } == "foo"
insist { events[1]["message"] } == "bar"
insist { events[2]["message"] } == "baz"
end
end
end