freddy 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +49 -0
- data/.travis.yml +1 -1
- data/Gemfile +4 -2
- data/Rakefile +6 -4
- data/freddy.gemspec +21 -21
- data/lib/freddy.rb +7 -8
- data/lib/freddy/adapters.rb +2 -0
- data/lib/freddy/adapters/bunny_adapter.rb +7 -7
- data/lib/freddy/adapters/march_hare_adapter.rb +6 -4
- data/lib/freddy/consumers.rb +2 -0
- data/lib/freddy/consumers/respond_to_consumer.rb +14 -17
- data/lib/freddy/consumers/response_consumer.rb +4 -2
- data/lib/freddy/consumers/tap_into_consumer.rb +11 -14
- data/lib/freddy/delivery.rb +2 -0
- data/lib/freddy/error_response.rb +2 -0
- data/lib/freddy/invalid_request_error.rb +2 -0
- data/lib/freddy/message_handler.rb +3 -1
- data/lib/freddy/message_handler_adapaters.rb +2 -0
- data/lib/freddy/payload.rb +5 -3
- data/lib/freddy/producers.rb +2 -0
- data/lib/freddy/producers/reply_producer.rb +6 -6
- data/lib/freddy/producers/send_and_forget_producer.rb +8 -8
- data/lib/freddy/producers/send_and_wait_response_producer.rb +39 -31
- data/lib/freddy/request_manager.rb +7 -4
- data/lib/freddy/responder_handler.rb +2 -0
- data/lib/freddy/sync_response_container.rb +4 -4
- data/lib/freddy/timeout_error.rb +2 -0
- data/lib/freddy/trace_carrier.rb +4 -2
- data/spec/freddy/consumers/respond_to_consumer_spec.rb +1 -1
- data/spec/freddy/error_response_spec.rb +9 -9
- data/spec/freddy/freddy_spec.rb +38 -38
- data/spec/freddy/message_handler_spec.rb +2 -2
- data/spec/freddy/payload_spec.rb +5 -5
- data/spec/freddy/responder_handler_spec.rb +1 -1
- data/spec/freddy/sync_response_container_spec.rb +8 -8
- data/spec/freddy/trace_carrier_spec.rb +5 -5
- data/spec/integration/concurrency_spec.rb +9 -9
- data/spec/integration/reply_spec.rb +4 -4
- data/spec/integration/tap_into_with_group_spec.rb +2 -2
- data/spec/integration/tracing_spec.rb +19 -19
- data/spec/spec_helper.rb +6 -6
- metadata +9 -8
@@ -10,7 +10,7 @@ describe Freddy::MessageHandler do
|
|
10
10
|
it 'delegates to the adapter' do
|
11
11
|
expect(adapter).to receive(:success).with(delivery, x: 'y')
|
12
12
|
|
13
|
-
|
13
|
+
handler.success(x: 'y')
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -18,7 +18,7 @@ describe Freddy::MessageHandler do
|
|
18
18
|
it 'delegates to the adapter' do
|
19
19
|
expect(adapter).to receive(:error).with(delivery, error: 'text')
|
20
20
|
|
21
|
-
|
21
|
+
handler.error(error: 'text')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/spec/freddy/payload_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe Freddy::Payload do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'serializes time objects in a nested hash as iso8601 format strings' do
|
16
|
-
expect(dump(x: {time: Time.utc(2016, 1, 4, 20, 18)}))
|
16
|
+
expect(dump(x: { time: Time.utc(2016, 1, 4, 20, 18) }))
|
17
17
|
.to eq('{"x":{"time":"2016-01-04T20:18:00Z"}}')
|
18
18
|
end
|
19
19
|
|
@@ -28,22 +28,22 @@ describe Freddy::Payload do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'serializes date objects in a nested hash as iso8601 format strings' do
|
31
|
-
expect(dump(x: {date: Date.new(2016, 1, 4)}))
|
31
|
+
expect(dump(x: { date: Date.new(2016, 1, 4) }))
|
32
32
|
.to eq('{"x":{"date":"2016-01-04"}}')
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'serializes datetime objects as iso8601 format strings' do
|
36
|
-
expect(dump(datetime: DateTime.new(2016, 1, 4, 20, 18)))
|
36
|
+
expect(dump(datetime: DateTime.new(2016, 1, 4, 20, 18))) # rubocop:disable Style/DateTime
|
37
37
|
.to eq('{"datetime":"2016-01-04T20:18:00+00:00"}')
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'serializes datetime objects in an array as iso8601 format strings' do
|
41
|
-
expect(dump(datetime: [DateTime.new(2016, 1, 4, 20, 18)]))
|
41
|
+
expect(dump(datetime: [DateTime.new(2016, 1, 4, 20, 18)])) # rubocop:disable Style/DateTime
|
42
42
|
.to eq('{"datetime":["2016-01-04T20:18:00+00:00"]}')
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'serializes datetime objects in a nested hash as iso8601 format strings' do
|
46
|
-
expect(dump(x: {datetime: DateTime.new(2016, 1, 4, 20, 18)}))
|
46
|
+
expect(dump(x: { datetime: DateTime.new(2016, 1, 4, 20, 18) })) # rubocop:disable Style/DateTime
|
47
47
|
.to eq('{"x":{"datetime":"2016-01-04T20:18:00+00:00"}}')
|
48
48
|
end
|
49
49
|
|
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Freddy::SyncResponseContainer do
|
4
4
|
let(:container) { described_class.new(on_timeout) }
|
5
|
-
let(:on_timeout) {
|
5
|
+
let(:on_timeout) { proc {} }
|
6
6
|
|
7
7
|
context 'when timeout' do
|
8
|
-
subject { container.wait_for_response(0.01) }
|
8
|
+
subject(:wait_for_response) { container.wait_for_response(0.01) }
|
9
9
|
|
10
10
|
it 'raises timeout error' do
|
11
|
-
expect {
|
11
|
+
expect { wait_for_response }.to raise_error do |error|
|
12
12
|
expect(error).to be_a(Freddy::TimeoutError)
|
13
13
|
expect(error.response).to eq(
|
14
14
|
error: 'RequestTimeout',
|
@@ -22,15 +22,15 @@ describe Freddy::SyncResponseContainer do
|
|
22
22
|
let(:delivery) { {} }
|
23
23
|
|
24
24
|
it 'raises timeout error' do
|
25
|
-
expect
|
25
|
+
expect do
|
26
26
|
container.call(nil, delivery)
|
27
|
-
|
27
|
+
end.to raise_error(StandardError, 'unexpected nil value for response')
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '#wait_for_response' do
|
32
32
|
let(:timeout) { 2 }
|
33
|
-
let(:response) { {msg: 'response'} }
|
33
|
+
let(:response) { { msg: 'response' } }
|
34
34
|
let(:delivery) { OpenStruct.new(type: 'success') }
|
35
35
|
|
36
36
|
context 'when called after #call' do
|
@@ -45,9 +45,9 @@ describe Freddy::SyncResponseContainer do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'does not wait for timeout' do
|
48
|
-
expect
|
48
|
+
expect do
|
49
49
|
container.wait_for_response(timeout)
|
50
|
-
|
50
|
+
end.to change(Time, :now).by_at_most(max_wait_time_in_seconds)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -4,7 +4,7 @@ describe Freddy::TraceCarrier do
|
|
4
4
|
subject(:carrier) { described_class.new(properties) }
|
5
5
|
|
6
6
|
context 'when adding trace information' do
|
7
|
-
let(:properties) { {x: 'y'} }
|
7
|
+
let(:properties) { { x: 'y' } }
|
8
8
|
let(:key_name) { 'some-key' }
|
9
9
|
let(:key_value) { 'some-key' }
|
10
10
|
|
@@ -20,7 +20,7 @@ describe Freddy::TraceCarrier do
|
|
20
20
|
let(:key_value) { 'some-key' }
|
21
21
|
|
22
22
|
let(:properties) do
|
23
|
-
double(headers: {serialized_key_name => key_value})
|
23
|
+
double(headers: { serialized_key_name => key_value })
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'extracts a header with x-trace- prefix' do
|
@@ -33,9 +33,9 @@ describe Freddy::TraceCarrier do
|
|
33
33
|
let(:properties) do
|
34
34
|
double(
|
35
35
|
headers: {
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
'x-trace-key1' => 'value1',
|
37
|
+
'x-trace-key2' => 'value2',
|
38
|
+
'other-key' => 'value3'
|
39
39
|
}
|
40
40
|
)
|
41
41
|
end
|
@@ -9,7 +9,7 @@ describe 'Concurrency' do
|
|
9
9
|
after { [freddy1, freddy2, freddy3].each(&:close) }
|
10
10
|
|
11
11
|
it 'supports multiple requests in #respond_to' do
|
12
|
-
freddy1.respond_to 'Concurrency1' do |
|
12
|
+
freddy1.respond_to 'Concurrency1' do |_payload, msg_handler|
|
13
13
|
begin
|
14
14
|
freddy1.deliver_with_response 'Concurrency2', msg: 'noop'
|
15
15
|
result2 = freddy1.deliver_with_response 'Concurrency3', msg: 'noop'
|
@@ -19,16 +19,16 @@ describe 'Concurrency' do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
freddy2.respond_to 'Concurrency2' do |
|
22
|
+
freddy2.respond_to 'Concurrency2' do |_payload, msg_handler|
|
23
23
|
begin
|
24
|
-
msg_handler.success(
|
24
|
+
msg_handler.success(from: 'Concurrency2')
|
25
25
|
rescue Freddy::InvalidRequestError => e
|
26
26
|
msg_handler.error(e.response)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
freddy3.respond_to 'Concurrency3' do |
|
31
|
-
msg_handler.success(
|
30
|
+
freddy3.respond_to 'Concurrency3' do |_payload, msg_handler|
|
31
|
+
msg_handler.success(from: 'Concurrency3')
|
32
32
|
end
|
33
33
|
|
34
34
|
result =
|
@@ -51,8 +51,8 @@ describe 'Concurrency' do
|
|
51
51
|
received1 = true
|
52
52
|
end
|
53
53
|
|
54
|
-
freddy2.respond_to 'TapConcurrency' do |
|
55
|
-
msg_handler.success(
|
54
|
+
freddy2.respond_to 'TapConcurrency' do |_payload, msg_handler|
|
55
|
+
msg_handler.success(from: 'TapConcurrency')
|
56
56
|
received2 = true
|
57
57
|
end
|
58
58
|
|
@@ -86,9 +86,9 @@ describe 'Concurrency' do
|
|
86
86
|
expect(results.count).to eq(10)
|
87
87
|
end
|
88
88
|
|
89
|
-
context 'concurrent executions of deliver_with_response' do
|
89
|
+
context 'with concurrent executions of deliver_with_response' do
|
90
90
|
let(:nr_of_threads) { 50 }
|
91
|
-
let(:payload) { {pay: 'load'} }
|
91
|
+
let(:payload) { { pay: 'load' } }
|
92
92
|
let(:msg_counter) { Hamster::MutableSet[] }
|
93
93
|
let(:queue_name) { random_destination }
|
94
94
|
|
@@ -4,14 +4,14 @@ describe 'Reply' do
|
|
4
4
|
let(:freddy) { Freddy.build(logger, config) }
|
5
5
|
|
6
6
|
let(:destination) { random_destination }
|
7
|
-
let(:request_payload) { {req: 'load'} }
|
8
|
-
let(:response_payload) { {res: 'load'} }
|
7
|
+
let(:request_payload) { { req: 'load' } }
|
8
|
+
let(:response_payload) { { res: 'load' } }
|
9
9
|
|
10
10
|
after { freddy.close }
|
11
11
|
|
12
12
|
context 'when a synchronized request' do
|
13
13
|
before do
|
14
|
-
freddy.respond_to(destination) do |
|
14
|
+
freddy.respond_to(destination) do |_payload, msg_handler|
|
15
15
|
msg_handler.success(response_payload)
|
16
16
|
end
|
17
17
|
end
|
@@ -22,7 +22,7 @@ describe 'Reply' do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'does not send the reply to the topic queue' do
|
25
|
-
freddy.tap_into 'amq.*' do |
|
25
|
+
freddy.tap_into 'amq.*' do |_payload|
|
26
26
|
@message_received = true
|
27
27
|
end
|
28
28
|
|
@@ -14,8 +14,8 @@ describe 'Tapping into with group identifier' do
|
|
14
14
|
msg_counter = Hamster::MutableSet[]
|
15
15
|
|
16
16
|
group_id = arbitrary_id
|
17
|
-
responder1.tap_into(destination, group: group_id) {|
|
18
|
-
responder2.tap_into(destination, group: group_id) {|
|
17
|
+
responder1.tap_into(destination, group: group_id) { |_msg| msg_counter << 'r1' }
|
18
|
+
responder2.tap_into(destination, group: group_id) { |_msg| msg_counter << 'r2' }
|
19
19
|
deliverer.deliver(destination, {})
|
20
20
|
|
21
21
|
default_sleep
|
@@ -16,23 +16,23 @@ describe 'Tracing' do
|
|
16
16
|
let(:destination2) { random_destination }
|
17
17
|
|
18
18
|
before do
|
19
|
-
freddy.respond_to(destination) do |
|
20
|
-
msg_handler.success(
|
19
|
+
freddy.respond_to(destination) do |_payload, msg_handler|
|
20
|
+
msg_handler.success(
|
21
21
|
trace_initiator: {
|
22
22
|
trace_id: active_span.context.trace_id,
|
23
23
|
parent_id: active_span.context.parent_id,
|
24
24
|
span_id: active_span.context.span_id
|
25
25
|
},
|
26
26
|
current_receiver: freddy.deliver_with_response(destination2, {})
|
27
|
-
|
27
|
+
)
|
28
28
|
end
|
29
29
|
|
30
|
-
freddy2.respond_to(destination2) do |
|
31
|
-
msg_handler.success(
|
30
|
+
freddy2.respond_to(destination2) do |_payload, msg_handler|
|
31
|
+
msg_handler.success(
|
32
32
|
trace_id: active_span.context.trace_id,
|
33
33
|
parent_id: active_span.context.parent_id,
|
34
34
|
span_id: active_span.context.span_id
|
35
|
-
|
35
|
+
)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -51,15 +51,15 @@ describe 'Tracing' do
|
|
51
51
|
it 'has parent_id' do
|
52
52
|
response = freddy.deliver_with_response(destination, {})
|
53
53
|
current_receiver = response.fetch(:current_receiver)
|
54
|
-
expect(current_receiver.fetch(:parent_id)).
|
54
|
+
expect(current_receiver.fetch(:parent_id)).not_to be_nil
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'has generated span_id' do
|
58
58
|
response = freddy.deliver_with_response(destination, {})
|
59
59
|
trace_initiator = response.fetch(:trace_initiator)
|
60
60
|
current_receiver = response.fetch(:current_receiver)
|
61
|
-
expect(current_receiver.fetch(:span_id)).
|
62
|
-
expect(current_receiver.fetch(:span_id)).
|
61
|
+
expect(current_receiver.fetch(:span_id)).not_to be_nil
|
62
|
+
expect(current_receiver.fetch(:span_id)).not_to eq(trace_initiator.fetch(:span_id))
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -73,7 +73,7 @@ describe 'Tracing' do
|
|
73
73
|
let(:destination3) { random_destination }
|
74
74
|
|
75
75
|
before do
|
76
|
-
freddy.respond_to(destination) do |
|
76
|
+
freddy.respond_to(destination) do |_payload, msg_handler|
|
77
77
|
msg_handler.success({
|
78
78
|
trace_initiator: {
|
79
79
|
trace_id: active_span.context.trace_id,
|
@@ -83,23 +83,23 @@ describe 'Tracing' do
|
|
83
83
|
}.merge(freddy.deliver_with_response(destination2, {})))
|
84
84
|
end
|
85
85
|
|
86
|
-
freddy2.respond_to(destination2) do |
|
87
|
-
msg_handler.success(
|
86
|
+
freddy2.respond_to(destination2) do |_payload, msg_handler|
|
87
|
+
msg_handler.success(
|
88
88
|
previous_receiver: {
|
89
89
|
trace_id: active_span.context.trace_id,
|
90
90
|
parent_id: active_span.context.parent_id,
|
91
91
|
span_id: active_span.context.span_id
|
92
92
|
},
|
93
93
|
current_receiver: freddy2.deliver_with_response(destination3, {})
|
94
|
-
|
94
|
+
)
|
95
95
|
end
|
96
96
|
|
97
|
-
freddy3.respond_to(destination3) do |
|
98
|
-
msg_handler.success(
|
97
|
+
freddy3.respond_to(destination3) do |_payload, msg_handler|
|
98
|
+
msg_handler.success(
|
99
99
|
trace_id: active_span.context.trace_id,
|
100
100
|
parent_id: active_span.context.parent_id,
|
101
101
|
span_id: active_span.context.span_id
|
102
|
-
|
102
|
+
)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
@@ -119,15 +119,15 @@ describe 'Tracing' do
|
|
119
119
|
it 'has parent_id' do
|
120
120
|
response = freddy.deliver_with_response(destination, {})
|
121
121
|
current_receiver = response.fetch(:current_receiver)
|
122
|
-
expect(current_receiver.fetch(:parent_id)).
|
122
|
+
expect(current_receiver.fetch(:parent_id)).not_to be_nil
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'has generated span_id' do
|
126
126
|
response = freddy.deliver_with_response(destination, {})
|
127
127
|
previous_receiver = response.fetch(:previous_receiver)
|
128
128
|
current_receiver = response.fetch(:current_receiver)
|
129
|
-
expect(current_receiver.fetch(:span_id)).
|
130
|
-
expect(current_receiver.fetch(:span_id)).
|
129
|
+
expect(current_receiver.fetch(:span_id)).not_to be_nil
|
130
|
+
expect(current_receiver.fetch(:span_id)).not_to eq(previous_receiver.fetch(:span_id))
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,9 @@ Bundler.setup
|
|
5
5
|
require 'codeclimate-test-reporter'
|
6
6
|
SimpleCov.start do
|
7
7
|
formatter SimpleCov::Formatter::MultiFormatter.new([
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
SimpleCov::Formatter::HTMLFormatter,
|
9
|
+
CodeClimate::TestReporter::Formatter
|
10
|
+
])
|
11
11
|
add_filter '/spec/'
|
12
12
|
end
|
13
13
|
|
@@ -40,9 +40,9 @@ def default_sleep
|
|
40
40
|
sleep 0.05
|
41
41
|
end
|
42
42
|
|
43
|
-
def wait_for
|
43
|
+
def wait_for
|
44
44
|
100.times do
|
45
|
-
return if
|
45
|
+
return if yield
|
46
46
|
sleep 0.005
|
47
47
|
end
|
48
48
|
end
|
@@ -57,7 +57,7 @@ def logger
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def config
|
60
|
-
{host: 'localhost', port: 5672, user: 'guest', pass: 'guest'}
|
60
|
+
{ host: 'localhost', port: 5672, user: 'guest', pass: 'guest' }
|
61
61
|
end
|
62
62
|
|
63
63
|
def spawn_echo_responder(freddy, queue_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freddy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salemove TechMovers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,33 +67,33 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.13'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: opentracing
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.4'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.4'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: thread
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.1'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.1'
|
97
97
|
description: Messaging API
|
98
98
|
email:
|
99
99
|
- techmovers@salemove.com
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- ".gitignore"
|
105
105
|
- ".npmignore"
|
106
106
|
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
107
108
|
- ".ruby-gemset"
|
108
109
|
- ".ruby-version"
|
109
110
|
- ".travis.yml"
|