|
8 | 8 |
|
9 | 9 | delimiter = (LogStash::Environment.windows? ? "\r\n" : "\n")
|
10 | 10 |
|
11 |
| - describe "starts at the end of an existing file" do |
| 11 | + it "should starts at the end of an existing file" do |
12 | 12 | tmpfile_path = Stud::Temporary.pathname
|
13 | 13 | sincedb_path = Stud::Temporary.pathname
|
14 | 14 |
|
15 |
| - config <<-CONFIG |
| 15 | + conf = <<-CONFIG |
16 | 16 | input {
|
17 | 17 | file {
|
18 | 18 | type => "blah"
|
|
23 | 23 | }
|
24 | 24 | CONFIG
|
25 | 25 |
|
26 |
| - input do |pipeline, queue| |
27 |
| - File.open(tmpfile_path, "w") do |fd| |
28 |
| - fd.puts("ignore me 1") |
29 |
| - fd.puts("ignore me 2") |
30 |
| - end |
| 26 | + File.open(tmpfile_path, "w") do |fd| |
| 27 | + fd.puts("ignore me 1") |
| 28 | + fd.puts("ignore me 2") |
| 29 | + end |
31 | 30 |
|
32 |
| - Thread.new { pipeline.run } |
33 |
| - sleep 0.1 while !pipeline.ready? |
| 31 | + events = input(conf) do |pipeline, queue| |
34 | 32 |
|
35 |
| - # at this point even if pipeline.ready? == true the plugins |
| 33 | + # at this point the plugins |
36 | 34 | # threads might still be initializing so we cannot know when the
|
37 | 35 | # file plugin will have seen the original file, it could see it
|
38 | 36 | # after the first(s) hello world appends below, hence the
|
39 | 37 | # retry logic.
|
40 | 38 |
|
41 |
| - retries = 0 |
42 |
| - loop do |
43 |
| - insist { retries } < 20 # 2 secs should be plenty? |
| 39 | + events = [] |
44 | 40 |
|
| 41 | + retries = 0 |
| 42 | + while retries < 20 |
45 | 43 | File.open(tmpfile_path, "a") do |fd|
|
46 | 44 | fd.puts("hello")
|
47 | 45 | fd.puts("world")
|
48 | 46 | end
|
49 | 47 |
|
50 | 48 | if queue.size >= 2
|
51 | 49 | events = 2.times.collect { queue.pop }
|
52 |
| - insist { events[0]["message"] } == "hello" |
53 |
| - insist { events[1]["message"] } == "world" |
54 | 50 | break
|
55 | 51 | end
|
56 | 52 |
|
57 | 53 | sleep(0.1)
|
58 | 54 | retries += 1
|
59 | 55 | end
|
| 56 | + |
| 57 | + events |
60 | 58 | end
|
| 59 | + |
| 60 | + insist { events[0]["message"] } == "hello" |
| 61 | + insist { events[1]["message"] } == "world" |
61 | 62 | end
|
62 | 63 |
|
63 |
| - describe "can start at the beginning of an existing file" do |
| 64 | + it "should start at the beginning of an existing file" do |
64 | 65 | tmpfile_path = Stud::Temporary.pathname
|
65 | 66 | sincedb_path = Stud::Temporary.pathname
|
66 | 67 |
|
67 |
| - config <<-CONFIG |
| 68 | + conf = <<-CONFIG |
68 | 69 | input {
|
69 | 70 | file {
|
70 | 71 | type => "blah"
|
|
76 | 77 | }
|
77 | 78 | CONFIG
|
78 | 79 |
|
79 |
| - input do |pipeline, queue| |
80 |
| - File.open(tmpfile_path, "a") do |fd| |
81 |
| - fd.puts("hello") |
82 |
| - fd.puts("world") |
83 |
| - end |
84 |
| - |
85 |
| - Thread.new { pipeline.run } |
86 |
| - sleep 0.1 while !pipeline.ready? |
| 80 | + File.open(tmpfile_path, "a") do |fd| |
| 81 | + fd.puts("hello") |
| 82 | + fd.puts("world") |
| 83 | + end |
87 | 84 |
|
88 |
| - events = 2.times.collect { queue.pop } |
89 |
| - insist { events[0]["message"] } == "hello" |
90 |
| - insist { events[1]["message"] } == "world" |
| 85 | + events = input(conf) do |pipeline, queue| |
| 86 | + 2.times.collect { queue.pop } |
91 | 87 | end
|
| 88 | + |
| 89 | + insist { events[0]["message"] } == "hello" |
| 90 | + insist { events[1]["message"] } == "world" |
92 | 91 | end
|
93 | 92 |
|
94 |
| - describe "restarts at the sincedb value" do |
| 93 | + it "should restarts at the sincedb value" do |
95 | 94 | tmpfile_path = Stud::Temporary.pathname
|
96 | 95 | sincedb_path = Stud::Temporary.pathname
|
97 | 96 |
|
98 |
| - config <<-CONFIG |
| 97 | + conf = <<-CONFIG |
99 | 98 | input {
|
100 | 99 | file {
|
101 | 100 | type => "blah"
|
102 | 101 | path => "#{tmpfile_path}"
|
103 |
| - start_position => "beginning" |
| 102 | + start_position => "beginning" |
104 | 103 | sincedb_path => "#{sincedb_path}"
|
105 | 104 | delimiter => "#{delimiter}"
|
106 | 105 | }
|
107 | 106 | }
|
108 | 107 | CONFIG
|
109 | 108 |
|
110 |
| - input do |pipeline, queue| |
111 |
| - File.open(tmpfile_path, "w") do |fd| |
112 |
| - fd.puts("hello") |
113 |
| - fd.puts("world") |
114 |
| - end |
115 |
| - |
116 |
| - t = Thread.new { pipeline.run } |
117 |
| - sleep 0.1 while !pipeline.ready? |
118 |
| - |
119 |
| - events = 2.times.collect { queue.pop } |
120 |
| - pipeline.shutdown |
121 |
| - t.join |
| 109 | + File.open(tmpfile_path, "w") do |fd| |
| 110 | + fd.puts("hello3") |
| 111 | + fd.puts("world3") |
| 112 | + end |
122 | 113 |
|
123 |
| - File.open(tmpfile_path, "a") do |fd| |
124 |
| - fd.puts("foo") |
125 |
| - fd.puts("bar") |
126 |
| - fd.puts("baz") |
127 |
| - end |
| 114 | + events = input(conf) do |pipeline, queue| |
| 115 | + 2.times.collect { queue.pop } |
| 116 | + end |
128 | 117 |
|
129 |
| - Thread.new { pipeline.run } |
130 |
| - sleep 0.1 while !pipeline.ready? |
| 118 | + insist { events[0]["message"] } == "hello3" |
| 119 | + insist { events[1]["message"] } == "world3" |
131 | 120 |
|
132 |
| - events = 3.times.collect { queue.pop } |
| 121 | + File.open(tmpfile_path, "a") do |fd| |
| 122 | + fd.puts("foo") |
| 123 | + fd.puts("bar") |
| 124 | + fd.puts("baz") |
| 125 | + end |
133 | 126 |
|
134 |
| - insist { events[0]["message"] } == "foo" |
135 |
| - insist { events[1]["message"] } == "bar" |
136 |
| - insist { events[2]["message"] } == "baz" |
| 127 | + events = input(conf) do |pipeline, queue| |
| 128 | + 3.times.collect { queue.pop } |
137 | 129 | end
|
| 130 | + |
| 131 | + insist { events[0]["message"] } == "foo" |
| 132 | + insist { events[1]["message"] } == "bar" |
| 133 | + insist { events[2]["message"] } == "baz" |
138 | 134 | end
|
139 | 135 | end
|
0 commit comments