basquiat 1.3.2 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +1 -0
- data/Guardfile +17 -13
- data/basquiat.gemspec +1 -1
- data/lib/basquiat.rb +1 -0
- data/lib/basquiat/adapters.rb +1 -0
- data/lib/basquiat/adapters/base_adapter.rb +4 -1
- data/lib/basquiat/adapters/base_message.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/configuration.rb +6 -4
- data/lib/basquiat/adapters/rabbitmq/connection.rb +3 -1
- data/lib/basquiat/adapters/rabbitmq/events.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/message.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/auto_acknowledge.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/base_strategy.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/basic_acknowledge.rb +1 -0
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/dead_lettering.rb +7 -2
- data/lib/basquiat/adapters/rabbitmq/requeue_strategies/delayed_delivery.rb +3 -1
- data/lib/basquiat/adapters/rabbitmq/session.rb +3 -2
- data/lib/basquiat/adapters/rabbitmq_adapter.rb +6 -3
- data/lib/basquiat/adapters/test_adapter.rb +6 -1
- data/lib/basquiat/errors.rb +1 -0
- data/lib/basquiat/errors/strategy_not_registered.rb +1 -0
- data/lib/basquiat/errors/subclass_responsibility.rb +1 -0
- data/lib/basquiat/interfaces/base.rb +4 -2
- data/lib/basquiat/rails/railtie.rb +1 -0
- data/lib/basquiat/support.rb +1 -0
- data/lib/basquiat/support/configuration.rb +3 -2
- data/lib/basquiat/support/hash_refinements.rb +7 -2
- data/lib/basquiat/support/json.rb +1 -0
- data/lib/basquiat/version.rb +2 -1
- data/spec/lib/adapters/base_adapter_spec.rb +2 -3
- data/spec/lib/adapters/base_message_spec.rb +1 -2
- data/spec/lib/adapters/rabbitmq/configuration_spec.rb +4 -4
- data/spec/lib/adapters/rabbitmq/connection_spec.rb +3 -3
- data/spec/lib/adapters/rabbitmq/events_spec.rb +6 -5
- data/spec/lib/adapters/rabbitmq/message_spec.rb +2 -2
- data/spec/lib/adapters/rabbitmq/requeue_strategies/auto_acknowledge_spec.rb +2 -2
- data/spec/lib/adapters/rabbitmq/requeue_strategies/base_strategy_spec.rb +1 -1
- data/spec/lib/adapters/rabbitmq/requeue_strategies/basic_acknowledge_spec.rb +3 -4
- data/spec/lib/adapters/rabbitmq/requeue_strategies/dead_lettering_spec.rb +2 -2
- data/spec/lib/adapters/rabbitmq/requeue_strategies/delayed_delivery_spec.rb +2 -2
- data/spec/lib/adapters/rabbitmq_adapter_spec.rb +4 -4
- data/spec/lib/adapters/test_adapter_spec.rb +1 -2
- data/spec/lib/basquiat_spec.rb +1 -2
- data/spec/lib/interfaces/base_spec.rb +2 -3
- data/spec/lib/support/configuration_spec.rb +1 -2
- data/spec/lib/support/hash_refinements_spec.rb +1 -2
- data/spec/lib/support/json_spec.rb +2 -1
- data/spec/spec_helper.rb +14 -3
- data/spec/support/rabbitmq_queue_matchers.rb +4 -3
- data/spec/support/shared_examples/basquiat_adapter_shared_examples.rb +7 -6
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b56c04fa01dfd0ac7184fb888147847eaf32984b3f4c45288f320643d009f76c
|
4
|
+
data.tar.gz: c79977131ec506e134765047d91bd35cefb6b8c4c33abee851815bf08f81c1ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b086c6f28292cb39c7c26f27027e01489908a0301401e1a78b9fe42ca828925ae4a907779067eb7acc60400c03fb48c9ee9e1362265f0e88c7ad92f062436f47
|
7
|
+
data.tar.gz: 9902027d312973ba2e5eeace7712c76dbfbd7a7c87de6bcaae2ea8215ea886dfbf406170a3685c3d4df70f0b7414b98c549e2a3eb23c1d65be6c6aa765873232
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -4,20 +4,24 @@ guard :bundler do
|
|
4
4
|
watch('basquiat.gemspec')
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
group :bdd, halt_on_fail: true do
|
8
|
+
guard :rspec, cmd: 'bundle exec rspec', keep: true, all_on_start: true,
|
9
|
+
all_after_pass: true, run_all: { cmd: 'rspec -f progress' } do
|
10
|
+
watch(%r{^spec/.+_spec.rb$})
|
11
|
+
watch(%r{^spec/lib/.+_spec.rb$})
|
12
|
+
watch(%r{^lib/basquiat/(.+)\.rb$}) { |matchdata| "spec/lib/#{matchdata[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
14
|
+
watch(%r{spec/support/.+\.rb}) { 'spec' }
|
15
|
+
end
|
15
16
|
|
16
|
-
guard :rubocop, cmd: 'rubocop', cli: '-fs -c./.rubocop.yml' do
|
17
|
-
|
18
|
-
|
17
|
+
guard :rubocop, cmd: 'rubocop', cli: '-D -E -fs -c./.rubocop.yml' do
|
18
|
+
watch(%r{.+\.rb$})
|
19
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
group :docs do
|
24
|
+
guard 'yard', cli: '-r' do
|
25
|
+
watch(%r{lib/.+\.rb}) { 'lib' }
|
26
|
+
end
|
23
27
|
end
|
data/basquiat.gemspec
CHANGED
@@ -33,7 +33,7 @@ EOD
|
|
33
33
|
spec.add_development_dependency 'yajl-ruby'
|
34
34
|
spec.add_development_dependency 'simplecov'
|
35
35
|
spec.add_development_dependency 'rubocop'
|
36
|
-
spec.add_development_dependency '
|
36
|
+
spec.add_development_dependency 'rubycritic'
|
37
37
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
38
38
|
spec.add_development_dependency 'yard'
|
39
39
|
|
data/lib/basquiat.rb
CHANGED
data/lib/basquiat/adapters.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'delegate'
|
3
4
|
require 'basquiat/adapters/base_message'
|
4
5
|
|
@@ -91,10 +92,12 @@ module Basquiat
|
|
91
92
|
raise Basquiat::Errors::SubclassResponsibility
|
92
93
|
end
|
93
94
|
# @!endgroup
|
95
|
+
#
|
96
|
+
attr_reader :procs
|
94
97
|
|
95
98
|
private
|
96
99
|
|
97
|
-
attr_reader :
|
100
|
+
attr_reader :options
|
98
101
|
end
|
99
102
|
end
|
100
103
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Basquiat
|
3
4
|
module Adapters
|
4
5
|
class RabbitMq
|
@@ -10,16 +11,17 @@ module Basquiat
|
|
10
11
|
@options = { connection:
|
11
12
|
{ hosts: ['localhost'],
|
12
13
|
port: 5672,
|
13
|
-
auth: { user: 'guest', password: 'guest' }
|
14
|
-
},
|
14
|
+
auth: { user: 'guest', password: 'guest' } },
|
15
15
|
queue: {
|
16
16
|
name: Basquiat.configuration.queue_name,
|
17
17
|
durable: true,
|
18
|
-
options: {}
|
18
|
+
options: {}
|
19
|
+
},
|
19
20
|
exchange: {
|
20
21
|
name: Basquiat.configuration.exchange_name,
|
21
22
|
durable: true,
|
22
|
-
options: {}
|
23
|
+
options: {}
|
24
|
+
},
|
23
25
|
publisher: { confirm: true, persistent: false },
|
24
26
|
consumer: { prefetch: 1000, manual_ack: true },
|
25
27
|
requeue: { enabled: false } }
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Basquiat
|
3
4
|
module Adapters
|
4
5
|
class RabbitMq
|
@@ -60,7 +61,8 @@ module Basquiat
|
|
60
61
|
recovery_attempts: @failover.fetch(:max_retries, 5),
|
61
62
|
network_recovery_interval: @failover.fetch(:default_timeout, 5),
|
62
63
|
connection_timeout: @failover.fetch(:connection_timeout, 5),
|
63
|
-
logger: Basquiat.logger
|
64
|
+
logger: Basquiat.logger
|
65
|
+
)
|
64
66
|
__setobj__(@connection)
|
65
67
|
end
|
66
68
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Basquiat
|
3
4
|
module Adapters
|
4
5
|
class RabbitMq
|
@@ -11,8 +12,12 @@ module Basquiat
|
|
11
12
|
session: {
|
12
13
|
queue: {
|
13
14
|
options: {
|
14
|
-
'x-dead-letter-exchange' => opts.fetch(:exchange, 'basquiat.dlx')
|
15
|
-
|
15
|
+
'x-dead-letter-exchange' => opts.fetch(:exchange, 'basquiat.dlx')
|
16
|
+
}
|
17
|
+
}
|
18
|
+
},
|
19
|
+
dlx: { ttl: opts.fetch(:ttl, 1_000) }
|
20
|
+
}
|
16
21
|
end
|
17
22
|
|
18
23
|
def session_options
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Basquiat
|
3
4
|
module Adapters
|
4
5
|
class RabbitMq
|
@@ -76,7 +77,8 @@ module Basquiat
|
|
76
77
|
durable: true,
|
77
78
|
arguments: {
|
78
79
|
'x-dead-letter-exchange' => session.exchange.name,
|
79
|
-
'x-message-ttl' => timeout * 1_000
|
80
|
+
'x-message-ttl' => timeout * 1_000
|
81
|
+
})
|
80
82
|
queue.bind(@exchange, routing_key: "#{timeout * 1_000}.#")
|
81
83
|
end
|
82
84
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Basquiat
|
3
4
|
module Adapters
|
4
5
|
class RabbitMq
|
@@ -31,8 +32,8 @@ module Basquiat
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def queue
|
34
|
-
@queue ||= channel.queue(@options
|
35
|
-
durable: @options
|
35
|
+
@queue ||= channel.queue(@options.dig(:queue, :name),
|
36
|
+
durable: @options.dig(:queue, :durable),
|
36
37
|
arguments: (@options[:queue][:options] || {}))
|
37
38
|
end
|
38
39
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'bunny'
|
3
4
|
require 'delegate'
|
4
5
|
|
@@ -8,6 +9,8 @@ module Basquiat
|
|
8
9
|
class RabbitMq < Basquiat::Adapters::Base
|
9
10
|
using Basquiat::HashRefinements
|
10
11
|
|
12
|
+
attr_reader :procs
|
13
|
+
|
11
14
|
# Avoid superclass mismatch errors
|
12
15
|
require 'basquiat/adapters/rabbitmq/events'
|
13
16
|
require 'basquiat/adapters/rabbitmq/message'
|
@@ -17,8 +20,8 @@ module Basquiat
|
|
17
20
|
require 'basquiat/adapters/rabbitmq/requeue_strategies'
|
18
21
|
|
19
22
|
# Initializes the superclass using a {Events} object as the procs instance variable
|
20
|
-
def initialize
|
21
|
-
super(procs:
|
23
|
+
def initialize(procs: Events.new)
|
24
|
+
super(procs: procs)
|
22
25
|
end
|
23
26
|
|
24
27
|
# Since the RabbitMQ configuration options are quite vast and it's interations with the requeue strategies a bit
|
@@ -57,7 +60,7 @@ module Basquiat
|
|
57
60
|
|
58
61
|
def process_message(message, rescue_proc)
|
59
62
|
procs[message.routing_key].call(message)
|
60
|
-
rescue => ex
|
63
|
+
rescue StandardError => ex
|
61
64
|
rescue_proc.call(ex, message)
|
62
65
|
end
|
63
66
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Basquiat
|
3
4
|
module Adapters
|
4
5
|
# An adapter to be used in testing
|
@@ -9,7 +10,7 @@ module Basquiat
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def clean
|
12
|
-
@events
|
13
|
+
@events&.clear
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -39,6 +40,10 @@ module Basquiat
|
|
39
40
|
msg ? procs[event].call(BaseMessage.new(msg)) : nil
|
40
41
|
end
|
41
42
|
|
43
|
+
def connected?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
42
47
|
private
|
43
48
|
|
44
49
|
def subscribed_event
|
data/lib/basquiat/errors.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'set'
|
3
4
|
|
4
5
|
module Basquiat
|
@@ -19,7 +20,8 @@ module Basquiat
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def reload_adapter_from_configuration
|
22
|
-
@
|
23
|
+
@procs = adapter.procs
|
24
|
+
self.adapter = Kernel.const_get(Basquiat.configuration.default_adapter)
|
23
25
|
adapter_options Basquiat.configuration.adapter_options
|
24
26
|
end
|
25
27
|
|
@@ -28,7 +30,7 @@ module Basquiat
|
|
28
30
|
# @return [Basquiat::Adapter] the adapter instance for the current class
|
29
31
|
# @deprecated event_adapter is deprecated and will be removed eventually. Please use {#adapter}.
|
30
32
|
def adapter=(adapter_klass)
|
31
|
-
@adapter = adapter_klass.new
|
33
|
+
@adapter = @procs ? adapter_klass.new(procs: @procs) : adapter_klass.new
|
32
34
|
end
|
33
35
|
|
34
36
|
alias event_adapter= adapter=
|
data/lib/basquiat/support.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'naught'
|
3
4
|
require 'erb'
|
4
5
|
require 'basquiat/support/hash_refinements'
|
@@ -61,7 +62,7 @@ module Basquiat
|
|
61
62
|
|
62
63
|
# @return [Hash] return the configured adapter options. Defaults to an empty {::Hash}
|
63
64
|
def adapter_options
|
64
|
-
config.fetch(:adapter_options) {
|
65
|
+
config.fetch(:adapter_options) { {} }
|
65
66
|
end
|
66
67
|
|
67
68
|
# @return [String] return the configured default adapter. Defaults to {Adapters::Test}
|
@@ -81,7 +82,7 @@ module Basquiat
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def load_yaml(path)
|
84
|
-
@yaml = YAML.
|
85
|
+
@yaml = YAML.safe_load(ERB.new(IO.readlines(path).join).result).symbolize_keys
|
85
86
|
end
|
86
87
|
|
87
88
|
def setup_basic_options
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Basquiat
|
3
4
|
module HashRefinements
|
4
5
|
# @!method deep_merge
|
@@ -25,8 +26,12 @@ module Basquiat
|
|
25
26
|
|
26
27
|
def symbolize_keys
|
27
28
|
each_with_object({}) do |(key, value), new_hash|
|
28
|
-
new_key =
|
29
|
-
|
29
|
+
new_key = begin
|
30
|
+
key.to_sym
|
31
|
+
rescue StandardError
|
32
|
+
key
|
33
|
+
end
|
34
|
+
new_value = value.is_a?(Hash) ? value.symbolize_keys : value
|
30
35
|
new_hash[new_key] = new_value
|
31
36
|
end
|
32
37
|
end
|
data/lib/basquiat/version.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
2
|
|
4
3
|
# Sample class used for testing
|
5
|
-
describe Basquiat::Adapters::Base do
|
4
|
+
RSpec.describe Basquiat::Adapters::Base do
|
6
5
|
subject(:adapter) { Basquiat::Adapters::Base.new }
|
7
6
|
|
8
|
-
[
|
7
|
+
%i[disconnect subscribe_to publish].each do |meth|
|
9
8
|
it "raise a SubclassResponsibility error if #{meth} isn't implemented" do
|
10
9
|
expect { adapter.public_send(meth) }.to raise_error Basquiat::Errors::SubclassResponsibility
|
11
10
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
2
|
|
4
|
-
describe Basquiat::Adapters::BaseMessage do
|
3
|
+
RSpec.describe Basquiat::Adapters::BaseMessage do
|
5
4
|
subject(:message) { Basquiat::Adapters::BaseMessage.new({ data: 'everything is AWESOME!' }.to_json) }
|
6
5
|
|
7
6
|
it 'delegates calls to the JSON' do
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
5
|
class AwesomeStrategy < Basquiat::Adapters::RabbitMq::BaseStrategy
|
@@ -8,11 +8,11 @@ class AwesomeStrategy < Basquiat::Adapters::RabbitMq::BaseStrategy
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe Basquiat::Adapters::RabbitMq::Configuration do
|
11
|
+
RSpec.describe Basquiat::Adapters::RabbitMq::Configuration do
|
12
12
|
subject(:config) { Basquiat::Adapters::RabbitMq::Configuration.new }
|
13
13
|
|
14
14
|
# used by the Adapter::Base class
|
15
|
-
describe '#merge_user_options'
|
15
|
+
describe '#merge_user_options' do
|
16
16
|
it 'merges the user supplied options with the default ones' do
|
17
17
|
config.merge_user_options(queue: { name: 'config.test.queue' })
|
18
18
|
expect(config.base_options[:queue][:name]).to eq('config.test.queue')
|
@@ -39,7 +39,7 @@ describe Basquiat::Adapters::RabbitMq::Configuration do
|
|
39
39
|
expect { config.strategy }.to raise_error Basquiat::Errors::StrategyNotRegistered
|
40
40
|
end
|
41
41
|
|
42
|
-
it 'deals with the requeue strategy options'
|
42
|
+
it 'deals with the requeue strategy options' do
|
43
43
|
Basquiat::Adapters::RabbitMq.register_strategy :dlx, Basquiat::Adapters::RabbitMq::DeadLettering
|
44
44
|
config.merge_user_options(requeue: { enabled: true, strategy: 'dlx', options: { exchange: 'dlx.topic' } })
|
45
45
|
expect(config.session_options[:queue][:options]).to include('x-dead-letter-exchange' => 'dlx.topic')
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
|
-
describe Basquiat::Adapters::RabbitMq::Connection do
|
5
|
+
RSpec.describe Basquiat::Adapters::RabbitMq::Connection do
|
6
6
|
subject(:connection) { Basquiat::Adapters::RabbitMq::Connection }
|
7
7
|
|
8
8
|
let(:hosts) do
|
@@ -34,7 +34,7 @@ describe Basquiat::Adapters::RabbitMq::Connection do
|
|
34
34
|
it 'uses another server after all retries on a single one' do
|
35
35
|
conn = connection.new(hosts: hosts, failover: failover)
|
36
36
|
expect { conn.start }.to_not raise_error
|
37
|
-
expect(conn.host).to match
|
37
|
+
expect(conn.host).to match(ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' })
|
38
38
|
conn.close
|
39
39
|
end
|
40
40
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
|
-
describe Basquiat::Adapters::RabbitMq::Events do
|
5
|
+
RSpec.describe Basquiat::Adapters::RabbitMq::Events do
|
6
6
|
subject(:events) { Basquiat::Adapters::RabbitMq::Events.new }
|
7
7
|
|
8
8
|
context 'basic functionality' do
|
@@ -21,7 +21,7 @@ describe Basquiat::Adapters::RabbitMq::Events do
|
|
21
21
|
let(:proc) { -> { 'Hello from the lambda! o/' } }
|
22
22
|
|
23
23
|
describe '*' do
|
24
|
-
let(:words) { %w
|
24
|
+
let(:words) { %w[awesome lame dumb cool] }
|
25
25
|
|
26
26
|
it 'event.* does not match event_some_word' do
|
27
27
|
events['event.*'] = proc
|
@@ -64,18 +64,19 @@ describe Basquiat::Adapters::RabbitMq::Events do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
+
|
67
68
|
describe '#' do
|
68
69
|
context 'matches any number of words' do
|
69
70
|
it '# matches all events' do
|
70
71
|
events['#'] = proc
|
71
|
-
%w
|
72
|
+
%w[some.cool.event event cool.event].each do |event|
|
72
73
|
expect(events[event]).to eq(proc)
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
77
|
it 'matches specific events' do
|
77
78
|
events['#.event'] = proc
|
78
|
-
%w
|
79
|
+
%w[some.cool.event cool.event].each do |event|
|
79
80
|
expect(events[event]).to eq(proc)
|
80
81
|
end
|
81
82
|
expect { events['event'] }.to raise_error KeyError
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
|
-
describe Basquiat::Adapters::RabbitMq::Message do
|
5
|
+
RSpec.describe Basquiat::Adapters::RabbitMq::Message do
|
6
6
|
let(:json) do
|
7
7
|
{ key: 'value', date: Date.new.iso8601 }.to_json
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
|
-
describe Basquiat::Adapters::RabbitMq::AutoAcknowledge do
|
5
|
+
RSpec.describe Basquiat::Adapters::RabbitMq::AutoAcknowledge do
|
6
6
|
let(:adapter) { Basquiat::Adapters::RabbitMq.new }
|
7
7
|
let(:base_options) do
|
8
8
|
{ connection: { hosts: [ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' }],
|
@@ -1,15 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
|
-
describe 'Requeue Strategies' do
|
5
|
+
RSpec.describe 'Requeue Strategies' do
|
6
6
|
let(:adapter) { Basquiat::Adapters::RabbitMq.new }
|
7
7
|
let(:base_options) do
|
8
8
|
{ connection: { hosts: [ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' }],
|
9
9
|
port: ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_PORT') { 5672 } },
|
10
10
|
publisher: { persistent: true },
|
11
|
-
requeue: { enabled: true, strategy: 'basic_ack' }
|
12
|
-
}
|
11
|
+
requeue: { enabled: true, strategy: 'basic_ack' } }
|
13
12
|
end
|
14
13
|
|
15
14
|
before(:each) { adapter.adapter_options(base_options) }
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
|
-
describe Basquiat::Adapters::RabbitMq::DeadLettering do
|
5
|
+
RSpec.describe Basquiat::Adapters::RabbitMq::DeadLettering do
|
6
6
|
let(:adapter) { Basquiat::Adapters::RabbitMq.new }
|
7
7
|
let(:base_options) do
|
8
8
|
{ connection: { hosts: [ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' }],
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
|
-
describe Basquiat::Adapters::RabbitMq::DelayedDelivery do
|
5
|
+
RSpec.describe Basquiat::Adapters::RabbitMq::DelayedDelivery do
|
6
6
|
let(:adapter) { Basquiat::Adapters::RabbitMq.new }
|
7
7
|
let(:base_options) do
|
8
8
|
{ connection: { hosts: [ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' }],
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
require 'basquiat/adapters/rabbitmq_adapter'
|
4
4
|
|
5
|
-
describe Basquiat::Adapters::RabbitMq do
|
5
|
+
RSpec.describe Basquiat::Adapters::RabbitMq do
|
6
6
|
subject(:adapter) { Basquiat::Adapters::RabbitMq.new }
|
7
7
|
|
8
8
|
let(:base_options) do
|
@@ -32,8 +32,8 @@ describe Basquiat::Adapters::RabbitMq do
|
|
32
32
|
context 'listener' do
|
33
33
|
it 'runs the rescue block when an exception happens' do
|
34
34
|
coisa = ''
|
35
|
-
adapter.subscribe_to('some.event', ->(_msg) {
|
36
|
-
adapter.listen(block: false, rescue_proc: ->
|
35
|
+
adapter.subscribe_to('some.event', ->(_msg) { raise ArgumentError })
|
36
|
+
adapter.listen(block: false, rescue_proc: ->(ex, _msg) { coisa = ex.class.to_s })
|
37
37
|
adapter.publish('some.event', data: 'coisa')
|
38
38
|
sleep 0.3
|
39
39
|
|
data/spec/lib/basquiat_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
2
|
|
4
|
-
describe Basquiat::Base do
|
3
|
+
RSpec.describe Basquiat::Base do
|
5
4
|
# Sample class used for testing
|
6
5
|
class SampleClass
|
7
6
|
extend Basquiat::Base
|
@@ -87,7 +86,7 @@ describe Basquiat::Base do
|
|
87
86
|
end
|
88
87
|
|
89
88
|
subject.subscribe_to('some.event', :test_method)
|
90
|
-
expect(subject.listen(block: false)).to eq(%w
|
89
|
+
expect(subject.listen(block: false)).to eq(%w[e e e])
|
91
90
|
end
|
92
91
|
end
|
93
92
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
-
require 'codeclimate-test-reporter'
|
4
4
|
require 'simplecov'
|
5
5
|
|
6
|
-
CodeClimate::TestReporter.start
|
7
|
-
|
8
6
|
SimpleCov.start do
|
9
7
|
add_filter { |source| source.lines_of_code <= 3 }
|
10
8
|
add_filter { |source| source.filename =~ /spec/ }
|
@@ -22,3 +20,16 @@ require 'basquiat'
|
|
22
20
|
|
23
21
|
require 'support/shared_examples/basquiat_adapter_shared_examples'
|
24
22
|
require 'support/rabbitmq_queue_matchers'
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.mock_with :rspec do |mocks|
|
26
|
+
mocks.verify_partial_doubles = true
|
27
|
+
end
|
28
|
+
|
29
|
+
config.filter_run :focus
|
30
|
+
config.run_all_when_everything_filtered = true
|
31
|
+
config.disable_monkey_patching!
|
32
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
33
|
+
|
34
|
+
config.order = :random
|
35
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'uri'
|
3
4
|
require 'net/http'
|
4
5
|
|
@@ -7,11 +8,11 @@ class QueueStats
|
|
7
8
|
@queue = queue
|
8
9
|
host = ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_15672_TCP_ADDR', 'localhost')
|
9
10
|
port = ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_15672_TCP_PORT', 15_672)
|
10
|
-
@uri = URI.parse("http://#{host}:#{port}/api/queues/%
|
11
|
+
@uri = URI.parse("http://#{host}:#{port}/api/queues/%2f/#{@queue}")
|
11
12
|
end
|
12
13
|
|
13
14
|
def unacked_messages
|
14
|
-
queue_status.fetch(:messages_unacknowledged)
|
15
|
+
queue_status.fetch(:messages_unacknowledged) { 0 }
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
@@ -40,7 +41,7 @@ end
|
|
40
41
|
|
41
42
|
RSpec::Matchers.define :have_unacked_messages do
|
42
43
|
match do |queue|
|
43
|
-
QueueStats.new(queue.name).unacked_messages
|
44
|
+
QueueStats.new(queue.name).unacked_messages.positive?
|
44
45
|
end
|
45
46
|
|
46
47
|
failure_message_when_negated do |queue|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
shared_examples_for 'a Basquiat::Adapter' do
|
3
|
-
[
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
%i[adapter_options
|
5
|
+
base_options
|
6
|
+
default_options
|
7
|
+
publish
|
8
|
+
subscribe_to
|
9
|
+
disconnect].each do |meth|
|
9
10
|
it meth.to_s do
|
10
11
|
expect(adapter).to respond_to(:meth)
|
11
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basquiat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcello "mereghost" Rocha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -179,7 +179,7 @@ dependencies:
|
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: rubycritic
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
@@ -333,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
333
333
|
version: '0'
|
334
334
|
requirements: []
|
335
335
|
rubyforge_project:
|
336
|
-
rubygems_version: 2.
|
336
|
+
rubygems_version: 2.7.3
|
337
337
|
signing_key:
|
338
338
|
specification_version: 4
|
339
339
|
summary: A pluggable library that aims to hide message queue complexity
|
@@ -360,4 +360,3 @@ test_files:
|
|
360
360
|
- spec/support/basquiat.yml
|
361
361
|
- spec/support/rabbitmq_queue_matchers.rb
|
362
362
|
- spec/support/shared_examples/basquiat_adapter_shared_examples.rb
|
363
|
-
has_rdoc:
|