jls-lumberjack 0.0.25.beta1 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2b2959f02e7f417cf30eb4d840508950edf0808
4
- data.tar.gz: a1f37209be258dbcc97617b8eed7e5c61ca66db5
3
+ metadata.gz: 55126155d83d8600b7bdb19be71a4c1ea995ca9f
4
+ data.tar.gz: c4ec4e35094641991017a659963291587225c1e3
5
5
  SHA512:
6
- metadata.gz: a87220c6b45a3c53f4bf685c2309c37cdd953c06d489f56cb442eb9ebc482357067b3fcad526b7e44c28455117be4c189226815184d65049bb6b429326ef5d42
7
- data.tar.gz: 8d326476bf7fe3d76873fc998dae45fbaf94cbe776de1a9e276fe8d4fadcfe6243a3ac2db7c90568056998c8296dabe44424fc3b03dfb1a7f91f7d87a5df41ae
6
+ metadata.gz: e9d2d85c73ca79c218b7d951095bf49a3962fa43e992f3ba4d667ef7a1ba7bbaecba4841706eba2de5db0c3ebbffa72e13181aecacb8509dc58bc67dfd2fa28b
7
+ data.tar.gz: ea44f28977d8eb96c78c68b913a1c61b37d1e936ad190a7b07d947b6f2bc9f131f15491a0705f0745e718fb77733157d760537ff362634d89e196093bfa56d6e
@@ -1,22 +1,3 @@
1
- require "json"
2
-
3
1
  module Lumberjack
4
2
  SEQUENCE_MAX = (2**32-1).freeze
5
-
6
- @@json = Class.new do
7
- def self.load(blob)
8
- JSON.parse(blob)
9
- end
10
- def self.dump(v)
11
- v.to_json
12
- end
13
- end
14
-
15
- def self.json
16
- @@json
17
- end
18
-
19
- def self.json=(j)
20
- @@json = j
21
- end
22
3
  end
@@ -13,7 +13,6 @@ module Lumberjack
13
13
  :addresses => [],
14
14
  :ssl_certificate => nil,
15
15
  :ssl => true,
16
- :json => false,
17
16
  }.merge(opts)
18
17
 
19
18
  @opts[:addresses] = [@opts[:addresses]] if @opts[:addresses].class == String
@@ -22,6 +21,7 @@ module Lumberjack
22
21
  raise "Must set a ssl certificate or path" if @opts[:ssl_certificate].nil? && @opts[:ssl]
23
22
 
24
23
  @socket = connect
24
+
25
25
  end
26
26
 
27
27
  private
@@ -38,8 +38,8 @@ module Lumberjack
38
38
  end
39
39
 
40
40
  public
41
- def write(elements, opts={})
42
- @socket.write_sync(elements, opts)
41
+ def write(elements)
42
+ @socket.write_sync(elements)
43
43
  end
44
44
 
45
45
  public
@@ -69,7 +69,6 @@ module Lumberjack
69
69
  :address => "127.0.0.1",
70
70
  :ssl_certificate => nil,
71
71
  :ssl => true,
72
- :json => false,
73
72
  }.merge(opts)
74
73
  @host = @opts[:address]
75
74
 
@@ -118,16 +117,11 @@ module Lumberjack
118
117
  end
119
118
 
120
119
  public
121
- def write_sync(elements, opts={})
122
- options = {
123
- :json => @opts[:json],
124
- }.merge(opts)
125
-
120
+ def write_sync(elements)
126
121
  elements = [elements] if elements.is_a?(Hash)
127
122
  send_window_size(elements.size)
128
123
 
129
- encoder = options[:json] ? JsonEncoder : FrameEncoder
130
- payload = elements.map { |element| encoder.to_frame(element, inc) }.join
124
+ payload = elements.map { |element| Encoder.to_frame(element, inc) }.join
131
125
  compress = compress_payload(payload)
132
126
  send_payload(compress)
133
127
 
@@ -165,17 +159,7 @@ module Lumberjack
165
159
  end
166
160
  end
167
161
 
168
- module JsonEncoder
169
- def self.to_frame(hash, sequence)
170
- json = Lumberjack::json.dump(hash)
171
- json_length = json.bytesize
172
- pack = "AANNA#{json_length}"
173
- frame = ["1", "J", sequence, json_length, json]
174
- frame.pack(pack)
175
- end
176
- end # JsonEncoder
177
-
178
- module FrameEncoder
162
+ module Encoder
179
163
  def self.to_frame(hash, sequence)
180
164
  frame = ["1", "D", sequence]
181
165
  pack = "AAN"
@@ -4,7 +4,6 @@ require "socket"
4
4
  require "thread"
5
5
  require "openssl"
6
6
  require "zlib"
7
- require "json"
8
7
  require "concurrent"
9
8
 
10
9
  module Lumberjack
@@ -66,6 +65,7 @@ module Lumberjack
66
65
  # unless the server is closing
67
66
  next unless connection
68
67
 
68
+
69
69
  Thread.new(connection) do |connection|
70
70
  connection.run(&block)
71
71
  end
@@ -94,7 +94,7 @@ module Lumberjack
94
94
  begin
95
95
  IO.select([@server], nil, nil, SOCKET_TIMEOUT)
96
96
  retry unless closed?
97
- rescue IOError, Errno::EBADF => e # we currently closing
97
+ rescue IOError => e # we currently closing
98
98
  raise e unless closed?
99
99
  end
100
100
  end
@@ -128,11 +128,6 @@ module Lumberjack
128
128
  end # class Server
129
129
 
130
130
  class Parser
131
- PROTOCOL_VERSION_1 = "1".ord
132
- PROTOCOL_VERSION_2 = "2".ord
133
-
134
- SUPPORTED_PROTOCOLS = [PROTOCOL_VERSION_1, PROTOCOL_VERSION_2]
135
-
136
131
  def initialize
137
132
  @buffer_offset = 0
138
133
  @buffer = ""
@@ -201,52 +196,24 @@ module Lumberjack
201
196
 
202
197
  FRAME_WINDOW = "W".ord
203
198
  FRAME_DATA = "D".ord
204
- FRAME_JSON_DATA = "J".ord
205
199
  FRAME_COMPRESSED = "C".ord
206
200
  def header(&block)
207
201
  version, frame_type = get.bytes.to_a[0..1]
208
- version ||= PROTOCOL_VERSION_1
209
-
210
- handle_version(version, &block)
211
202
 
212
203
  case frame_type
213
204
  when FRAME_WINDOW; transition(:window_size, 4)
214
205
  when FRAME_DATA; transition(:data_lead, 8)
215
- when FRAME_JSON_DATA; transition(:json_data_lead, 8)
216
206
  when FRAME_COMPRESSED; transition(:compressed_lead, 4)
217
- else; raise "Unknown frame type: `#{frame_type}`"
218
- end
219
- end
220
-
221
- def handle_version(version, &block)
222
- if supported_protocol?(version)
223
- yield :version, version
224
- else
225
- raise "unsupported protocol #{version}"
207
+ else; raise "Unknown frame type: #{frame_type}"
226
208
  end
227
209
  end
228
210
 
229
- def supported_protocol?(version)
230
- SUPPORTED_PROTOCOLS.include?(version)
231
- end
232
-
233
211
  def window_size(&block)
234
212
  @window_size = get.unpack("N").first
235
213
  transition(:header, 2)
236
214
  yield :window_size, @window_size
237
215
  end # def window_size
238
216
 
239
- def json_data_lead(&block)
240
- @sequence, payload_size = get.unpack("NN")
241
- transition(:json_data_payload, payload_size)
242
- end
243
-
244
- def json_data_payload(&block)
245
- payload = get
246
- yield :json, @sequence, Lumberjack::json.load(payload)
247
- transition(:header, 2)
248
- end
249
-
250
217
  def data_lead(&block)
251
218
  @sequence, @data_count = get.unpack("NN")
252
219
  @data = {}
@@ -307,7 +274,8 @@ module Lumberjack
307
274
  @fd = fd
308
275
 
309
276
  @server = server
310
- @ack_handler = nil
277
+ # a safe default until we are told by the client what window size to use
278
+ @window_size = 1
311
279
  end
312
280
 
313
281
  def run(&block)
@@ -329,97 +297,42 @@ module Lumberjack
329
297
  # X: too many events after errors.
330
298
  @parser.feed(@fd.sysread(READ_SIZE)) do |event, *args|
331
299
  case event
332
- when :version
333
- version(*args)
334
300
  when :window_size
335
- reset_next_ack(*args)
301
+ # We receive a new payload
302
+ window_size(*args)
303
+ reset_next_ack
336
304
  when :data
337
- sequence, map = args
338
- ack_if_needed(sequence) { data(map, &block) }
339
- when :json
340
- # If the payload is an array of items we will emit multiple events
341
- # this behavior was moved from the plugin to the library.
342
- # see this commit: https://github.com/logstash-plugins/logstash-input-lumberjack/pull/57/files#diff-1b9590423b15f04f215635164e7376ecR158
343
- sequence, map = args
344
-
345
- ack_if_needed(sequence) do
346
- if map.is_a?(Array)
347
- map.each { |e| data(e, &block) }
348
- else
349
- data(map, &block)
350
- end
351
- end
305
+ data(*args, &block)
352
306
  end
353
307
  end
354
308
  end
355
309
 
356
- def version(version)
357
- @version = version
358
- end
359
-
360
- def ack_if_needed(sequence, &block)
361
- block.call
362
- send_ack(sequence) if @ack_handler.ack?(sequence)
363
- end
364
-
365
310
  def close
366
311
  @fd.close unless @fd.closed?
367
312
  end
368
313
 
369
- def data(map, &block)
370
- block.call(map) if block_given?
371
- end
372
-
373
- def reset_next_ack(window_size)
374
- klass = (@version == Parser::PROTOCOL_VERSION_1) ? AckingProtocolV1 : AckingProtocolV2
375
- @ack_handler = klass.new(window_size)
376
- end
377
-
378
- def send_ack(sequence)
379
- @fd.syswrite(["1A", sequence].pack("A*N"))
314
+ def window_size(size)
315
+ @window_size = size
380
316
  end
381
- end # class Connection
382
317
 
383
- class AckingProtocolV1
384
- def initialize(window_size)
318
+ def reset_next_ack
385
319
  @next_ack = nil
386
- @window_size = window_size
387
320
  end
388
321
 
389
- def ack?(sequence)
390
- # The first encoded event will contain the sequence number
391
- # this is needed to know when we should ack.
392
- @next_ack = compute_next_ack(sequence) if @next_ack.nil?
393
- sequence == @next_ack
322
+ def data(sequence, map, &block)
323
+ block.call(map) if block_given?
324
+ ack_if_needed(sequence)
394
325
  end
395
-
396
- private
326
+
397
327
  def compute_next_ack(sequence)
398
328
  (sequence + @window_size - 1) % SEQUENCE_MAX
399
329
  end
400
- end
401
-
402
- # Allow lumberjack to send partial ack back to the producer
403
- # only V2 client support partial Acks
404
- #
405
- # Send Ack on every 20% of the data, so with default settings every 200 events
406
- # This should reduce the congestion on retransmit.
407
- class AckingProtocolV2
408
- ACK_RATIO = 5
409
-
410
- def initialize(window_size)
411
- @window_size = window_size
412
- @every = (window_size / ACK_RATIO).round
413
- end
414
330
 
415
- def ack?(sequence)
416
- if @window_size == sequence
417
- true
418
- elsif sequence % @every == 0
419
- true
420
- else
421
- false
422
- end
331
+ def ack_if_needed(sequence)
332
+ # The first encoded event will contain the sequence number
333
+ # this is needed to know when we should ack.
334
+ @next_ack = compute_next_ack(sequence) if @next_ack.nil?
335
+ @fd.syswrite(["1A", sequence].pack("A*N")) if sequence == @next_ack
423
336
  end
424
- end
337
+ end # class Connection
425
338
  end # module Lumberjack
@@ -7,7 +7,6 @@ require "fileutils"
7
7
  require "thread"
8
8
  require "spec_helper"
9
9
 
10
- Thread.abort_on_exception = true
11
10
  describe "A client" do
12
11
  let(:certificate) { Flores::PKI.generate }
13
12
  let(:certificate_file_crt) { "certificate.crt" }
@@ -135,17 +134,10 @@ describe "A client" do
135
134
  end
136
135
 
137
136
  context "When transmitting a payload" do
138
- let(:options) { {:port => tcp_port, :host => host, :addresses => host, :ssl => false } }
139
- let(:client) { Lumberjack::Client.new(options) }
140
-
141
- context "json" do
142
- let(:options) { super.merge({ :json => true }) }
143
- include_examples "transmit payloads"
144
- end
145
-
146
- context "v1 frame" do
147
- include_examples "transmit payloads"
137
+ let(:client) do
138
+ Lumberjack::Client.new(:port => tcp_port, :host => host, :addresses => host, :ssl => false)
148
139
  end
140
+ include_examples "transmit payloads"
149
141
  end
150
142
  end
151
143
 
@@ -196,15 +188,7 @@ describe "A client" do
196
188
  :addresses => host,
197
189
  :ssl_certificate => certificate_file_crt)
198
190
  end
199
-
200
- context "json" do
201
- let(:options) { super.merge({ :json => true }) }
202
- include_examples "transmit payloads"
203
- end
204
-
205
- context "v1 frame" do
206
- include_examples "transmit payloads"
207
- end
191
+ include_examples "transmit payloads"
208
192
  end
209
193
  end
210
194
  end
@@ -8,7 +8,9 @@ require "openssl"
8
8
  require "zlib"
9
9
 
10
10
  describe "Lumberjack::Client" do
11
+
11
12
  describe "Lumberjack::Socket" do
13
+
12
14
  let(:port) { 5000 }
13
15
 
14
16
  subject(:socket) { Lumberjack::Socket.new(:port => port, :ssl_certificate => "" ) }
@@ -36,60 +38,16 @@ describe "Lumberjack::Client" do
36
38
  end
37
39
  end
38
40
 
39
- describe Lumberjack::FrameEncoder do
40
- it 'should creates frames without truncating accentued characters' do
41
- content = {
42
- "message" => "Le Canadien de Montréal est la meilleure équipe au monde!",
43
- "other" => "éléphant"
44
- }
45
- parser = Lumberjack::Parser.new
46
- parser.feed(Lumberjack::FrameEncoder.to_frame(content, 0)) do |code, sequence, data|
47
- if code == :data
48
- expect(data["message"].force_encoding('UTF-8')).to eq(content["message"])
49
- expect(data["other"].force_encoding('UTF-8')).to eq(content["other"])
50
- end
51
- end
52
- end
53
-
54
- it 'should creates frames without dropping multibytes characters' do
55
- content = {
56
- "message" => "国際ホッケー連盟" # International Hockey Federation
57
- }
58
- parser = Lumberjack::Parser.new
59
- parser.feed(Lumberjack::FrameEncoder.to_frame(content, 0)) do |code, sequence, data|
60
- expect(data["message"].force_encoding('UTF-8')).to eq(content["message"]) if code == :data
61
- end
62
- end
63
- end
64
-
65
- describe Lumberjack::JsonEncoder do
66
- it 'should create frames from nested hash' do
67
- content = {
68
- "number" => 1,
69
- "string" => "hello world",
70
- "array" => [1,2,3],
71
- "sub" => {
72
- "a" => 1
73
- }
74
- }
75
- parser = Lumberjack::Parser.new
76
- frame = Lumberjack::JsonEncoder.to_frame(content, 0)
77
- parser.feed(frame) do |code, sequence, data|
78
- expect(data).to eq(content) if code == :json
79
- end
80
- end
81
-
41
+ describe Lumberjack::Encoder do
82
42
  it 'should creates frames without truncating accentued characters' do
83
43
  content = {
84
44
  "message" => "Le Canadien de Montréal est la meilleure équipe au monde!",
85
45
  "other" => "éléphant"
86
46
  }
87
47
  parser = Lumberjack::Parser.new
88
- parser.feed(Lumberjack::JsonEncoder.to_frame(content, 0)) do |code, sequence, data|
89
- if code == :json
90
- expect(data["message"]).to eq(content["message"])
91
- expect(data["other"]).to eq(content["other"])
92
- end
48
+ parser.feed(Lumberjack::Encoder.to_frame(content, 0)) do |code, sequence, data|
49
+ expect(data["message"].force_encoding('UTF-8')).to eq(content["message"])
50
+ expect(data["other"].force_encoding('UTF-8')).to eq(content["other"])
93
51
  end
94
52
  end
95
53
 
@@ -98,8 +56,8 @@ describe "Lumberjack::Client" do
98
56
  "message" => "国際ホッケー連盟" # International Hockey Federation
99
57
  }
100
58
  parser = Lumberjack::Parser.new
101
- parser.feed(Lumberjack::JsonEncoder.to_frame(content, 0)) do |code, sequence, data|
102
- expect(data["message"]).to eq(content["message"]) if code == :json
59
+ parser.feed(Lumberjack::Encoder.to_frame(content, 0)) do |code, sequence, data|
60
+ expect(data["message"].force_encoding('UTF-8')).to eq(content["message"])
103
61
  end
104
62
  end
105
63
  end
@@ -17,10 +17,8 @@ describe "Connnection" do
17
17
  allow(socket).to receive(:syswrite).with(anything).and_return(true)
18
18
  allow(socket).to receive(:close)
19
19
 
20
-
21
20
  expectation = receive(:feed)
22
21
  .with("")
23
- .and_yield(:version, Lumberjack::Parser::PROTOCOL_VERSION_1)
24
22
  .and_yield(:window_size, random_number_of_events)
25
23
 
26
24
  random_number_of_events.times { |n| expectation.and_yield(:data, start_sequence + n + 1, payload) }
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jls-lumberjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25.beta1
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Sissel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-17 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - '>='
17
+ - - ">="
17
18
  - !ruby/object:Gem::Version
18
19
  version: '0'
19
- name: concurrent-ruby
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: flores
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: 0.0.6
33
- name: flores
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.6
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rspec
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - '>='
45
+ - - ">="
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
47
- name: rspec
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: stud
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - '>='
59
+ - - ">="
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
- name: stud
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: pry
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - '>='
73
+ - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: pry
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
+ name: rspec-wait
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
- - - '>='
87
+ - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
- name: rspec-wait
90
- prerelease: false
91
90
  type: :development
91
+ prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: lumberjack log transport library
@@ -105,8 +105,6 @@ files:
105
105
  - lib/lumberjack/client.rb
106
106
  - lib/lumberjack/server.rb
107
107
  - spec/integration_spec.rb
108
- - spec/lumberjack/acking_protocol_v1_spec.rb
109
- - spec/lumberjack/acking_protocol_v2_spec.rb
110
108
  - spec/lumberjack/client_spec.rb
111
109
  - spec/lumberjack/connection_spec.rb
112
110
  - spec/lumberjack/server_spec.rb
@@ -114,31 +112,29 @@ files:
114
112
  homepage: https://github.com/jordansissel/lumberjack
115
113
  licenses: []
116
114
  metadata: {}
117
- post_install_message:
115
+ post_install_message:
118
116
  rdoc_options: []
119
117
  require_paths:
120
118
  - lib
121
119
  required_ruby_version: !ruby/object:Gem::Requirement
122
120
  requirements:
123
- - - '>='
121
+ - - ">="
124
122
  - !ruby/object:Gem::Version
125
123
  version: '0'
126
124
  required_rubygems_version: !ruby/object:Gem::Requirement
127
125
  requirements:
128
- - - '>'
126
+ - - ">="
129
127
  - !ruby/object:Gem::Version
130
- version: 1.3.1
128
+ version: '0'
131
129
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.4.8
134
- signing_key:
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.6
132
+ signing_key:
135
133
  specification_version: 4
136
134
  summary: lumberjack log transport library
137
135
  test_files:
138
136
  - spec/integration_spec.rb
139
- - spec/spec_helper.rb
140
- - spec/lumberjack/acking_protocol_v1_spec.rb
141
- - spec/lumberjack/acking_protocol_v2_spec.rb
142
137
  - spec/lumberjack/client_spec.rb
143
138
  - spec/lumberjack/connection_spec.rb
144
139
  - spec/lumberjack/server_spec.rb
140
+ - spec/spec_helper.rb
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
- require "lumberjack/server"
3
- require "flores/random"
4
-
5
- describe Lumberjack::AckingProtocolV1 do
6
- let(:number_of_events) { Flores::Random.integer(100..1024) }
7
-
8
- subject { Lumberjack::AckingProtocolV1.new(number_of_events) }
9
-
10
- it "should return true only once" do
11
- results = []
12
- number_of_events.times { |n| results << subject.ack?(n) }
13
- expect(results.size).to eq(number_of_events)
14
- expect(results.count(true)).to eq(1)
15
- end
16
- end
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
- require "lumberjack/server"
3
- require "flores/random"
4
-
5
- describe Lumberjack::AckingProtocolV2 do
6
- let(:results) { [] }
7
- subject { Lumberjack::AckingProtocolV2.new(number_of_events) }
8
- before { 1.upto(number_of_events) { |n| results << subject.ack?(n) } }
9
-
10
- context "with multiples events" do
11
- let(:number_of_events) { Flores::Random.integer(100..1024) }
12
-
13
- it "should return multiples partial acks" do
14
- expect(results.size).to eq(number_of_events)
15
- expect(results.count(true)).to eq((number_of_events / number_of_events * Lumberjack::AckingProtocolV2::ACK_RATIO).ceil + 1)
16
- end
17
-
18
- it "last ack should be true" do
19
- expect(results.last).to be_truthy
20
- end
21
- end
22
-
23
- context "with only one event" do
24
- let(:number_of_events) { 1 }
25
-
26
- it "should return true only once" do
27
- expect(results.size).to eq(number_of_events)
28
- expect(results.count(true)).to eq(1)
29
- end
30
- end
31
- end