bbk-app 1.1.0.219406 → 1.1.1.273294
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ae2e240a1d5d65204508e8afd18535bd3fc3187fbbaf2c62173a2814da2fa47
|
4
|
+
data.tar.gz: 43d196ddb7f225440a4037aefb77d37d982bad90431e64067eeb7e776c217ec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d43bf2bf2e832eccc98e755c87da7634c8453ace1e87b4457c4c7df90a3524d39b3e95eb593c29b519c7e8622a4fed7105af1cc2aab972da5a00c2370e0fec75
|
7
|
+
data.tar.gz: 5ffcb34418265115f5fa51e7dac019c7694edbf678b804aa81658b108179ff61f58c04bee2eb3a245687d047f47f1606bfb4e3afe50ecb6fba27e59179eb79db
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bbk-app (1.1.
|
4
|
+
bbk-app (1.1.1.273294)
|
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.
|
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
|
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, :
|
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
|
-
|
14
|
-
|
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,96 @@
|
|
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: delivery_info) }
|
46
|
+
it { is_expected.to have_attributes(headers: 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
|
data/lib/bbk/app/version.rb
CHANGED
@@ -16,7 +16,7 @@ module BBK
|
|
16
16
|
def delivery_info: () -> untyped
|
17
17
|
def body: () -> String
|
18
18
|
|
19
|
-
def ack: (*untyped, ?answer:
|
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
|
-
|
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.
|
4
|
+
version: 1.1.1.273294
|
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-
|
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
|