bbk-app 1.1.0.219406 → 1.1.1.273312

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
  SHA256:
3
- metadata.gz: 55a723338b70bb2250f474d5fef6fb88e5d135987746b05da7e4e3c3272e4f11
4
- data.tar.gz: e271c3cd41137e88cf9f6c436ab06a39289054d071000cd63f1b926b4f4e0de0
3
+ metadata.gz: 716152cd0c1cef66d27cb033123d1ed53c6e9337014d289767199d582584a9d4
4
+ data.tar.gz: daa09c9c4dd3c2b312975ad7419ae66d90753ef6c76e46995126ceb019e2b5c0
5
5
  SHA512:
6
- metadata.gz: ca558f2ed451251a77202d0f94418ada07469fed42dadf50d5c5fd64838d7ccacd49d5cbbdc149504ddb57e7a4a0d8439467e79668060a07eb2e86a9d7ac8864
7
- data.tar.gz: 1e825f64ac2b80a70c325fb5feb7807152113589f7e3fdbf9b5be58899d73cf9610819a3ce7f6734db030743ccb7188e1c79f18a6d43497eacda50e44122a589
6
+ metadata.gz: 4c1f61c0cce0b42a3aa2e05de4ee6cd3d8c2ff6110f0ba07a95e28dc0cca3abcfcd68475a78c2c3afdcc68130f833a242ec09f6e476f57718681878ca8cbef2d
7
+ data.tar.gz: f48a3f847ddc875a62118cfc8c1a4f4566e6ee3fab4d5b66177adeaee0a2ed5af7f9d24e68ef8b024ac712abed90ff61f91126af9ea1e6d645190ec8122b4069
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bbk-app (1.1.0.219406)
4
+ bbk-app (1.1.1.273312)
5
5
  activesupport
6
6
  bbk-utils (> 1.0.1)
7
7
  timeouter
@@ -73,7 +73,7 @@ GEM
73
73
  public_suffix (4.0.6)
74
74
  rainbow (3.1.1)
75
75
  rake (12.3.3)
76
- rbtree (0.4.4)
76
+ rbtree (0.4.6)
77
77
  reek (6.0.6)
78
78
  kwalify (~> 0.7.0)
79
79
  parser (~> 3.0.0)
@@ -122,7 +122,7 @@ GEM
122
122
  virtus (~> 1.0)
123
123
  russian (0.6.0)
124
124
  i18n (>= 0.5.0)
125
- set (1.0.3)
125
+ set (1.1.0)
126
126
  sexp_processor (4.16.0)
127
127
  simplecov (0.21.2)
128
128
  docile (~> 1.1)
@@ -3,15 +3,19 @@ module BBK
3
3
  class Dispatcher
4
4
  class Message
5
5
 
6
- attr_reader :consumer, :delivery_info, :headers, :payload, :body
6
+ attr_reader :consumer, :delivery_info, :headers, :body
7
7
 
8
8
  def initialize(consumer, delivery_info, headers, body, *_args, **_kwargs)
9
9
  @consumer = consumer
10
10
  @delivery_info = delivery_info
11
11
  @headers = headers.to_h.with_indifferent_access
12
12
  @body = body
13
- @payload = begin
14
- JSON(body).with_indifferent_access
13
+ end
14
+
15
+ # Lazy body parsing
16
+ def payload
17
+ @payload ||= begin
18
+ JSON.parse(@body).with_indifferent_access
15
19
  rescue StandardError
16
20
  {}.with_indifferent_access
17
21
  end
@@ -26,7 +30,15 @@ module BBK
26
30
  end
27
31
 
28
32
  def message_id
29
- raise NotImplementedError
33
+ raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method")
34
+ end
35
+
36
+ def reply_to
37
+ raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method")
38
+ end
39
+
40
+ def user_id
41
+ raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method")
30
42
  end
31
43
 
32
44
  def reply_message_id(addon)
@@ -0,0 +1,97 @@
1
+ RSpec.shared_examples 'BBK::App::Dispatcher::Message' do
2
+ let(:consumer) { double(stop: nil) }
3
+
4
+ let(:delivery_info) do
5
+ {
6
+ routing_code: SecureRandom.hex,
7
+ delivery_tag: SecureRandom.hex,
8
+ redelivered?: [true, false].sample
9
+ }
10
+ end
11
+
12
+ let(:headers) do
13
+ {
14
+ user_id: SecureRandom.hex,
15
+ reply_to: SecureRandom.hex,
16
+ message_id: SecureRandom.uuid
17
+ }
18
+ end
19
+
20
+ let(:body) { JSON.generate(Hash[Random.rand(2..6).times.map { [SecureRandom.hex, SecureRandom.hex] }]) }
21
+ let(:payload) { JSON.parse(body) }
22
+
23
+ describe 'Interface' do
24
+ it { is_expected.to respond_to(:consumer).with(0).argument }
25
+ it { is_expected.to respond_to(:delivery_info).with(0).argument }
26
+ it { is_expected.to respond_to(:headers).with(0).argument }
27
+ it { is_expected.to respond_to(:body).with(0).argument }
28
+ it { is_expected.to respond_to(:payload).with(0).argument }
29
+
30
+ it { is_expected.to respond_to(:ack).with_unlimited_arguments.with_keywords(:answer).with_any_keywords }
31
+ it { is_expected.to respond_to(:nack).with_unlimited_arguments.with_keywords(:error).with_any_keywords }
32
+
33
+ it { is_expected.to respond_to(:message_id).with(0).argument }
34
+ it { is_expected.to respond_to(:reply_to).with(0).argument }
35
+ it { is_expected.to respond_to(:user_id).with(0).argument }
36
+ it { is_expected.to respond_to(:reply_message_id).with(1).argument }
37
+ it { is_expected.to respond_to(:to_h).with(0).argument }
38
+ end
39
+
40
+ describe '#initialize' do
41
+ it { expect { message }.not_to raise_error }
42
+ end
43
+
44
+ describe 'methods' do
45
+ it { is_expected.to have_attributes(delivery_info: include(delivery_info)) }
46
+ it { is_expected.to have_attributes(headers: include(headers)) }
47
+ it { is_expected.to have_attributes(body: body) }
48
+ it { is_expected.to have_attributes(payload: payload) }
49
+
50
+ context 'with invalid body' do
51
+ let(:body) { ']invalid_trash' }
52
+
53
+ it { is_expected.to have_attributes(body: body) }
54
+ it { is_expected.to have_attributes(payload: {}) }
55
+ end
56
+
57
+ describe '#ack' do
58
+ let(:answer) { double(BBK::App::Dispatcher::Result, route: nil, message: nil) }
59
+ it do
60
+ expect(consumer).to receive(:ack).with(message, 1, 2, answer: answer, a1: :a1)
61
+ subject.ack(1, 2, answer: answer, a1: :a1)
62
+ end
63
+ end
64
+
65
+ describe '#nack' do
66
+ it do
67
+ expect(consumer).to receive(:nack).with(message, 1, 2, error: :error, a1: :a1)
68
+ subject.nack(1, 2, error: :error, a1: :a1)
69
+ end
70
+ end
71
+
72
+ describe '#to_h' do
73
+ subject(:hash) { message.to_h }
74
+
75
+ it { is_expected.to include(headers: headers) }
76
+ it { is_expected.to include(body: body) }
77
+ end
78
+
79
+ describe '#reply_message_id' do
80
+ let(:message_id) { SecureRandom.hex }
81
+ let(:addon) { SecureRandom.hex }
82
+ let(:first_call) { message.reply_message_id(addon) }
83
+ subject(:messagreply_message_ide_id) { message.message_id }
84
+
85
+ it {
86
+ expect(message).to receive(:message_id).and_return(message_id)
87
+ expect(first_call).to be_a(String)
88
+ }
89
+ it {
90
+ allow(message).to receive(:message_id).and_return(message_id)
91
+ # multuiple calls has same results
92
+ expect(first_call).to eq(message.reply_message_id(addon))
93
+ }
94
+ end
95
+ end
96
+ end
97
+
@@ -1,7 +1,7 @@
1
1
  module BBK
2
2
  module App
3
3
 
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
 
6
6
  end
7
7
  end
@@ -16,7 +16,7 @@ module BBK
16
16
  def delivery_info: () -> untyped
17
17
  def body: () -> String
18
18
 
19
- def ack: (*untyped, ?answer: Result?, **untyped) -> void
19
+ def ack: (*untyped, ?answer: _Result?, **untyped) -> void
20
20
  def nack: (*untyped, ?error: untyped, **untyped) -> void
21
21
  def message_id: () -> String
22
22
  end
@@ -1,9 +1,14 @@
1
1
  module BBK
2
2
  module App
3
3
  class Dispatcher
4
+
5
+ interface _Result
6
+ def route: () -> Route
7
+ def message: () -> _Message
8
+ end
9
+
4
10
  class Result
5
- attr_accessor route: Route
6
- attr_accessor message: _Message
11
+ include _Result
7
12
 
8
13
  def initialize: (String|Route route, _Message message) -> void
9
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbk-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.219406
4
+ version: 1.1.1.273312
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-19 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -288,6 +288,7 @@ files:
288
288
  - lib/bbk/app/processors/ping.rb
289
289
  - lib/bbk/app/processors/pong.rb
290
290
  - lib/bbk/app/proxy_logger.rb
291
+ - lib/bbk/app/spec/shared/dispatcher/message.rb
291
292
  - lib/bbk/app/thread_pool.rb
292
293
  - lib/bbk/app/version.rb
293
294
  - sig/bbk/app/callable.rbs