|
204 | 204 | end |
205 | 205 |
|
206 | 206 | describe "#bulk" do |
207 | | - subject { described_class.new(base_options) } |
| 207 | + subject(:http_client) { described_class.new(base_options) } |
208 | 208 |
|
209 | 209 | require "json" |
210 | 210 | let(:message) { "hey" } |
211 | 211 | let(:actions) { [ |
212 | 212 | ["index", {:_id=>nil, :_index=>"logstash"}, {"message"=> message}], |
213 | 213 | ]} |
214 | 214 |
|
215 | | - context "if a message is over TARGET_BULK_BYTES" do |
216 | | - let(:target_bulk_bytes) { LogStash::Outputs::ElasticSearch::TARGET_BULK_BYTES } |
217 | | - let(:message) { "a" * (target_bulk_bytes + 1) } |
| 215 | + [true,false].each do |http_compression_enabled| |
| 216 | + context "with `http_compression => #{http_compression_enabled}`" do |
218 | 217 |
|
219 | | - it "should be handled properly" do |
220 | | - allow(subject).to receive(:join_bulk_responses) |
221 | | - expect(subject).to receive(:bulk_send).once do |data| |
222 | | - expect(data.size).to be > target_bulk_bytes |
| 218 | + let(:base_options) { super().merge(:client_settings => {:http_compression => http_compression_enabled}) } |
| 219 | + |
| 220 | + before(:each) do |
| 221 | + if http_compression_enabled |
| 222 | + expect(http_client).to receive(:gzip_writer).at_least(:once).and_call_original |
| 223 | + else |
| 224 | + expect(http_client).to_not receive(:gzip_writer) |
| 225 | + end |
223 | 226 | end |
224 | | - s = subject.send(:bulk, actions) |
225 | | - end |
226 | | - end |
227 | 227 |
|
228 | | - context "with two messages" do |
229 | | - let(:message1) { "hey" } |
230 | | - let(:message2) { "you" } |
231 | | - let(:actions) { [ |
232 | | - ["index", {:_id=>nil, :_index=>"logstash"}, {"message"=> message1}], |
233 | | - ["index", {:_id=>nil, :_index=>"logstash"}, {"message"=> message2}], |
234 | | - ]} |
235 | | - it "executes one bulk_send operation" do |
236 | | - allow(subject).to receive(:join_bulk_responses) |
237 | | - expect(subject).to receive(:bulk_send).once |
238 | | - s = subject.send(:bulk, actions) |
239 | | - end |
| 228 | + context "if a message is over TARGET_BULK_BYTES" do |
| 229 | + let(:target_bulk_bytes) { LogStash::Outputs::ElasticSearch::TARGET_BULK_BYTES } |
| 230 | + let(:message) { "a" * (target_bulk_bytes + 1) } |
| 231 | + |
| 232 | + it "should be handled properly" do |
| 233 | + allow(subject).to receive(:join_bulk_responses) |
| 234 | + expect(subject).to receive(:bulk_send).once do |data| |
| 235 | + if !http_compression_enabled |
| 236 | + expect(data.size).to be > target_bulk_bytes |
| 237 | + else |
| 238 | + expect(Zlib::gunzip(data.string).size).to be > target_bulk_bytes |
| 239 | + end |
| 240 | + end |
| 241 | + s = subject.send(:bulk, actions) |
| 242 | + end |
| 243 | + end |
| 244 | + |
| 245 | + context "with two messages" do |
| 246 | + let(:message1) { "hey" } |
| 247 | + let(:message2) { "you" } |
| 248 | + let(:actions) { [ |
| 249 | + ["index", {:_id=>nil, :_index=>"logstash"}, {"message"=> message1}], |
| 250 | + ["index", {:_id=>nil, :_index=>"logstash"}, {"message"=> message2}], |
| 251 | + ]} |
| 252 | + it "executes one bulk_send operation" do |
| 253 | + allow(subject).to receive(:join_bulk_responses) |
| 254 | + expect(subject).to receive(:bulk_send).once |
| 255 | + s = subject.send(:bulk, actions) |
| 256 | + end |
240 | 257 |
|
241 | | - context "if one exceeds TARGET_BULK_BYTES" do |
242 | | - let(:target_bulk_bytes) { LogStash::Outputs::ElasticSearch::TARGET_BULK_BYTES } |
243 | | - let(:message1) { "a" * (target_bulk_bytes + 1) } |
244 | | - it "executes two bulk_send operations" do |
245 | | - allow(subject).to receive(:join_bulk_responses) |
246 | | - expect(subject).to receive(:bulk_send).twice |
247 | | - s = subject.send(:bulk, actions) |
| 258 | + context "if one exceeds TARGET_BULK_BYTES" do |
| 259 | + let(:target_bulk_bytes) { LogStash::Outputs::ElasticSearch::TARGET_BULK_BYTES } |
| 260 | + let(:message1) { "a" * (target_bulk_bytes + 1) } |
| 261 | + it "executes two bulk_send operations" do |
| 262 | + allow(subject).to receive(:join_bulk_responses) |
| 263 | + expect(subject).to receive(:bulk_send).twice |
| 264 | + s = subject.send(:bulk, actions) |
| 265 | + end |
| 266 | + end |
248 | 267 | end |
249 | | - end |
250 | | - end |
| 268 | + end |
| 269 | + end |
251 | 270 | end |
252 | 271 |
|
253 | 272 | describe "sniffing" do |
|
0 commit comments