message-driver 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.rbenv-version +1 -0
- data/.relish +2 -0
- data/.rspec +2 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +20 -0
- data/Guardfile +39 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +23 -0
- data/features/.nav +12 -0
- data/features/CHANGELOG.md +17 -0
- data/features/README.md +1 -0
- data/features/Rails.md +1 -0
- data/features/amqp_specific_features/README.md +3 -0
- data/features/amqp_specific_features/binding_amqp_destinations.feature +50 -0
- data/features/amqp_specific_features/declaring_amqp_exchanges.feature +22 -0
- data/features/amqp_specific_features/server_named_destinations.feature +35 -0
- data/features/destination_metadata.feature +33 -0
- data/features/dynamic_destinations.feature +41 -0
- data/features/error_handling.feature +47 -0
- data/features/getting_started.md +1 -0
- data/features/publishing_a_message.feature +19 -0
- data/features/publishing_with_transactions.feature +36 -0
- data/features/step_definitions/dynamic_destinations_steps.rb +12 -0
- data/features/step_definitions/error_handling_steps.rb +11 -0
- data/features/step_definitions/steps.rb +41 -0
- data/features/support/env.rb +7 -0
- data/features/support/firewall_helper.rb +59 -0
- data/features/support/message_table_matcher.rb +11 -0
- data/features/support/no_error_matcher.rb +13 -0
- data/features/support/test_runner.rb +50 -0
- data/features/support/transforms.rb +17 -0
- data/lib/message-driver.rb +1 -0
- data/lib/message_driver/adapters/base.rb +29 -0
- data/lib/message_driver/adapters/bunny_adapter.rb +270 -0
- data/lib/message_driver/adapters/in_memory_adapter.rb +58 -0
- data/lib/message_driver/broker.rb +95 -0
- data/lib/message_driver/destination.rb +31 -0
- data/lib/message_driver/exceptions.rb +18 -0
- data/lib/message_driver/message.rb +13 -0
- data/lib/message_driver/message_publisher.rb +15 -0
- data/lib/message_driver/version.rb +5 -0
- data/lib/message_driver.rb +18 -0
- data/message-driver.gemspec +27 -0
- data/spec/integration/amqp_integration_spec.rb +146 -0
- data/spec/integration/message_driver/adapters/bunny_adapter_spec.rb +301 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/shared/destination_examples.rb +41 -0
- data/spec/units/message_driver/adapters/base_spec.rb +44 -0
- data/spec/units/message_driver/adapters/in_memory_adapter_spec.rb +43 -0
- data/spec/units/message_driver/broker_spec.rb +98 -0
- data/spec/units/message_driver/destination_spec.rb +11 -0
- data/spec/units/message_driver/message_publisher_spec.rb +65 -0
- data/spec/units/message_driver/message_spec.rb +19 -0
- data/test_lib/broker_config.rb +25 -0
- metadata +203 -0
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
.rvmrc
|
7
|
+
.ruby-version
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
.adapter_under_test
|
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p327
|
data/.relish
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without tools darwin
|
3
|
+
services:
|
4
|
+
- rabbitmq
|
5
|
+
before_script:
|
6
|
+
- sudo rabbitmqctl add_vhost message-driver-test
|
7
|
+
- sudo rabbitmqctl set_permissions -p message-driver-test guest ".*" ".*" ".*"
|
8
|
+
rvm:
|
9
|
+
- 1.9.2
|
10
|
+
- 1.9.3
|
11
|
+
- 2.0.0
|
12
|
+
- jruby-19mode
|
13
|
+
- ruby-head
|
14
|
+
- jruby-head
|
15
|
+
- rbx-19mode
|
16
|
+
env:
|
17
|
+
- ADAPTER=in_memory
|
18
|
+
- ADAPTER=bunny
|
19
|
+
matrix:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: ruby-head
|
22
|
+
- rvm: jruby-head
|
23
|
+
- rvm: rbx-19mode
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## 0.1.0
|
4
|
+
|
5
|
+
Initial Release
|
6
|
+
|
7
|
+
* Features
|
8
|
+
* Publish a message
|
9
|
+
* Broker transactions for publishing
|
10
|
+
* Pop a message
|
11
|
+
* named and dynamic destinations
|
12
|
+
* message_count for destinations
|
13
|
+
* Adapters
|
14
|
+
* InMemory
|
15
|
+
* #reset_after_test method for clearing out queues
|
16
|
+
* Bunny (amqp 0.9)
|
17
|
+
* handle connection and channel errors transparently
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in message-driver.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :tools do
|
7
|
+
gem 'guard'
|
8
|
+
gem 'guard-bundler'
|
9
|
+
gem 'guard-rspec'
|
10
|
+
gem 'guard-cucumber'
|
11
|
+
gem 'pry'
|
12
|
+
platform :ruby do
|
13
|
+
gem 'pry-debugger'
|
14
|
+
end
|
15
|
+
group :darwin do
|
16
|
+
gem 'ruby_gntp'
|
17
|
+
gem 'rb-fsevent'
|
18
|
+
gem 'relish'
|
19
|
+
end
|
20
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), 'test_lib', 'broker_config')
|
5
|
+
|
6
|
+
guard 'bundler' do
|
7
|
+
watch('Gemfile')
|
8
|
+
watch(/^.+\.gemspec/)
|
9
|
+
end
|
10
|
+
|
11
|
+
unit_spec_opts = {spec_paths: ["spec/units"], cli: '-f doc', run_all: {cli: ''}}
|
12
|
+
acceptance_spec_opts = {spec_paths: ["spec/integration"], cli: '-f doc -t all_adapters', run_all: {cli: '-t all_adapters'}}
|
13
|
+
|
14
|
+
group 'specs' do
|
15
|
+
guard 'rspec', unit_spec_opts do
|
16
|
+
watch(%r{^spec/units/.+_spec\.rb$})
|
17
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/units/#{m[1]}_spec.rb" }
|
18
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
19
|
+
watch('spec/spec_helper.rb') { "spec" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
group 'integration' do
|
24
|
+
guard 'rspec', acceptance_spec_opts do
|
25
|
+
watch(%r{^spec/integration/.+_spec\.rb$})
|
26
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/integration/#{m[1]}_spec.rb" }
|
27
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
28
|
+
watch('spec/spec_helper.rb') { "spec" }
|
29
|
+
end
|
30
|
+
|
31
|
+
cucumber_cli = "--no-profile --color --format progress --strict --tag @all_adapters,@#{BrokerConfig.current_adapter} --tag ~@wip"
|
32
|
+
guard 'cucumber', change_format: 'pretty', cli: cucumber_cli do
|
33
|
+
watch(%r{^features/.+\.feature$})
|
34
|
+
watch(%r{^features/support/.+$}) { 'features' }
|
35
|
+
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matt Campbell
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Message::Driver
|
2
|
+
|
3
|
+
Easy message queues for ruby
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/soupmatt/message-driver.png?branch=master)](https://travis-ci.org/soupmatt/message-driver)
|
6
|
+
|
7
|
+
[![Dependency Status](https://gemnasium.com/soupmatt/message-driver.png)](https://gemnasium.com/soupmatt/message-driver)
|
8
|
+
|
9
|
+
[![Code Climate](https://codeclimate.com/github/soupmatt/message-driver.png)](https://codeclimate.com/github/soupmatt/message-driver)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'message-driver'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install message-driver
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Write your code with tests
|
34
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
require File.join(File.dirname(__FILE__), 'test_lib', 'broker_config')
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
+
t.pattern = "./spec/units{,/*/**}/*_spec.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new(:integrations) do |t|
|
13
|
+
t.rspec_opts = "--tag all_adapters"
|
14
|
+
t.pattern = "./spec/integration{,/*/**}/*_spec.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
cucumber_opts = "--format progress --tag @all_adapters,@#{BrokerConfig.current_adapter} --tag ~@wip"
|
18
|
+
cucumber_opts += " --tag ~@no_travis" if ENV['TRAVIS']=='true' && ENV['ADAPTER']=='bunny'
|
19
|
+
Cucumber::Rake::Task.new do |t|
|
20
|
+
t.cucumber_opts = cucumber_opts
|
21
|
+
end
|
22
|
+
|
23
|
+
task :default => [:spec, :integrations, :cucumber]
|
data/features/.nav
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
- getting_started.md (Getting Started)
|
2
|
+
- CHANGELOG.md (Changelog)
|
3
|
+
- publishing_a_message.feature
|
4
|
+
- publishing_with_transactions.feature
|
5
|
+
- dynamic_destinations.feature
|
6
|
+
- destination_metadata.feature
|
7
|
+
- amqp_specific_features (AMQP-Specific Features):
|
8
|
+
- declaring_amqp_destinations.feature
|
9
|
+
- binding_amqp_destinations.feature
|
10
|
+
- server_named_desitnations.feature
|
11
|
+
- error_handling.feature
|
12
|
+
- Rails.md
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## 0.1.0
|
4
|
+
|
5
|
+
Initial Release
|
6
|
+
|
7
|
+
* Features
|
8
|
+
* Publish a message
|
9
|
+
* Broker transactions for publishing
|
10
|
+
* Pop a message
|
11
|
+
* named and dynamic destinations
|
12
|
+
* message_count for destinations
|
13
|
+
* Adapters
|
14
|
+
* InMemory
|
15
|
+
* #reset_after_test method for clearing out queues
|
16
|
+
* Bunny (amqp 0.9)
|
17
|
+
* handle connection and channel errors transparently
|
data/features/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Welcome to MessageDriver! Easy message queues for ruby.
|
data/features/Rails.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Instructions for getting rails going
|
@@ -0,0 +1,50 @@
|
|
1
|
+
@bunny
|
2
|
+
Feature: Binding AMQP destinations to exchanges
|
3
|
+
Background:
|
4
|
+
Given the following broker configuration:
|
5
|
+
"""ruby
|
6
|
+
MessageDriver::Broker.define do |b|
|
7
|
+
b.destination :direct_exchange, "amq.direct", type: :exchange
|
8
|
+
end
|
9
|
+
"""
|
10
|
+
|
11
|
+
Scenario: Binding a queue to an exchange
|
12
|
+
When I execute the following code:
|
13
|
+
"""ruby
|
14
|
+
MessageDriver::Broker.define do |b|
|
15
|
+
b.destination :my_queue, "my_queue", exclusive: true, bindings: [
|
16
|
+
{source: "amq.direct", args: {routing_key: "test_binding"}},
|
17
|
+
{source: "amq.direct", args: {routing_key: "spec_binding"}}
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
publish(:direct_exchange, "Test Message", {}, {routing_key: "test_binding"})
|
22
|
+
publish(:direct_exchange, "Spec Message", {}, {routing_key: "spec_binding"})
|
23
|
+
"""
|
24
|
+
|
25
|
+
Then I expect to find 2 messages on :my_queue with:
|
26
|
+
| body |
|
27
|
+
| Test Message |
|
28
|
+
| Spec Message |
|
29
|
+
|
30
|
+
Scenario: Binding an exchange to an exchange
|
31
|
+
RabbitMQ's AMQP 0.9 extenstions support binding exchanges to exchanges
|
32
|
+
|
33
|
+
When I execute the following code:
|
34
|
+
"""ruby
|
35
|
+
MessageDriver::Broker.define do |b|
|
36
|
+
b.destination :fanout, "amq.fanout", type: :exchange, bindings: [
|
37
|
+
{source: "amq.direct", args: {routing_key: "test_binding"}},
|
38
|
+
{source: "amq.direct", args: {routing_key: "spec_binding"}}
|
39
|
+
]
|
40
|
+
b.destination :my_queue, "my_queue", exclusive: true, bindings: [{source: "amq.fanout"}]
|
41
|
+
end
|
42
|
+
|
43
|
+
publish(:direct_exchange, "Test Message", {}, {routing_key: "test_binding"})
|
44
|
+
publish(:direct_exchange, "Spec Message", {}, {routing_key: "spec_binding"})
|
45
|
+
"""
|
46
|
+
|
47
|
+
Then I expect to find 2 messages on :my_queue with:
|
48
|
+
| body |
|
49
|
+
| Test Message |
|
50
|
+
| Spec Message |
|
@@ -0,0 +1,22 @@
|
|
1
|
+
@bunny
|
2
|
+
Feature: Declaring AMQP exchanges
|
3
|
+
If you want to create an exchange that doesn't exist on the broker, you can do so by adding
|
4
|
+
the "declare" option to your destination.
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I am connected to the broker
|
8
|
+
|
9
|
+
Scenario: Declaring a direct exchange
|
10
|
+
When I execute the following code:
|
11
|
+
"""ruby
|
12
|
+
MessageDriver::Broker.define do |b|
|
13
|
+
b.destination :my_exchange, "my_exchange", type: :exchange, declare: {type: :direct, auto_delete: true}
|
14
|
+
b.destination :my_queue, "my_queue", exclusive: true, bindings: [{source: "my_exchange", routing_key: "my_queue"}]
|
15
|
+
end
|
16
|
+
|
17
|
+
publish(:my_exchange, "Test My New Exchange", routing_key: "my_queue")
|
18
|
+
"""
|
19
|
+
|
20
|
+
Then I expect to find 1 message on :my_queue with:
|
21
|
+
| body |
|
22
|
+
| Test My New Exchange |
|
@@ -0,0 +1,35 @@
|
|
1
|
+
@bunny
|
2
|
+
Feature: Server-Named Destinations
|
3
|
+
AMQP brokers allow you to create queues that are named by the server. Here's
|
4
|
+
how you do it with message_driver.
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I am connected to the broker
|
8
|
+
|
9
|
+
Scenario: Creating a server-named queue
|
10
|
+
I expect my destination to have the queue name given to it by the server
|
11
|
+
|
12
|
+
When I execute the following code:
|
13
|
+
"""ruby
|
14
|
+
destination = MessageDriver::Broker.dynamic_destination("", exclusive: true)
|
15
|
+
expect(destination.name).to_not be_empty
|
16
|
+
"""
|
17
|
+
|
18
|
+
Then I expect to have no errors
|
19
|
+
|
20
|
+
Scenario: sending and receiving messages through a server-named queue
|
21
|
+
Given the following broker configuration:
|
22
|
+
"""ruby
|
23
|
+
MessageDriver::Broker.define do |b|
|
24
|
+
b.destination :my_queue, "my_queue", exclusive: true
|
25
|
+
end
|
26
|
+
"""
|
27
|
+
|
28
|
+
When I execute the following code:
|
29
|
+
"""ruby
|
30
|
+
publish(:my_queue, "server-named queue message")
|
31
|
+
"""
|
32
|
+
|
33
|
+
Then I expect to find 1 message on :my_queue with:
|
34
|
+
| body |
|
35
|
+
| server-named queue message |
|
@@ -0,0 +1,33 @@
|
|
1
|
+
@bunny
|
2
|
+
@in_memory
|
3
|
+
Feature: Destination Metadata
|
4
|
+
Background:
|
5
|
+
Given the following broker configuration:
|
6
|
+
"""ruby
|
7
|
+
MessageDriver::Broker.define do |b|
|
8
|
+
b.destination :my_queue, "my_queue", exclusive: true
|
9
|
+
end
|
10
|
+
"""
|
11
|
+
|
12
|
+
Scenario: Checking the message count when the queue is empty
|
13
|
+
When I execute the following code:
|
14
|
+
"""ruby
|
15
|
+
destination = MessageDriver::Broker.find_destination(:my_queue)
|
16
|
+
expect(destination.message_count).to eq(0)
|
17
|
+
"""
|
18
|
+
|
19
|
+
Then I expect to have no errors
|
20
|
+
And I expect to find no messages on :my_queue
|
21
|
+
|
22
|
+
@no_travis
|
23
|
+
Scenario: Checking the message count when the queue has messages
|
24
|
+
When I execute the following code:
|
25
|
+
"""ruby
|
26
|
+
publish(:my_queue, "test message 1")
|
27
|
+
publish(:my_queue, "test message 2")
|
28
|
+
destination = MessageDriver::Broker.find_destination(:my_queue)
|
29
|
+
expect(destination.message_count).to eq(2)
|
30
|
+
"""
|
31
|
+
|
32
|
+
Then I expect to have no errors
|
33
|
+
And I expect to find 2 messages on :my_queue
|
@@ -0,0 +1,41 @@
|
|
1
|
+
@all_adapters
|
2
|
+
Feature: Dynamic Destinations
|
3
|
+
Sometime you want to connect to a queue that has some of it's characteristics
|
4
|
+
determined at runtime. Dynamic destinations allow you to do with without
|
5
|
+
leaking tons of destination definitions.
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given I am connected to the broker
|
9
|
+
|
10
|
+
Scenario: Sending to a dynamic destination
|
11
|
+
When I execute the following code:
|
12
|
+
"""ruby
|
13
|
+
my_new_destination = MessageDriver::Broker.dynamic_destination("temp_queue", exclusive: true)
|
14
|
+
my_new_destination.publish("Test Message")
|
15
|
+
"""
|
16
|
+
|
17
|
+
Then I expect to find 1 message on the dynamic destination "temp_queue" with:
|
18
|
+
| body |
|
19
|
+
| Test Message |
|
20
|
+
|
21
|
+
Scenario: Poping messages off a dynamic destination
|
22
|
+
Given I have a dynamic destination "temp_queue" with the following messages on it:
|
23
|
+
| body |
|
24
|
+
| Test Message 1 |
|
25
|
+
| Test Message 2 |
|
26
|
+
|
27
|
+
When I execute the following code:
|
28
|
+
"""ruby
|
29
|
+
my_new_destination = MessageDriver::Broker.dynamic_destination("temp_queue", exclusive: true)
|
30
|
+
|
31
|
+
msg1 = my_new_destination.pop_message
|
32
|
+
expect(msg1.body).to eq("Test Message 1")
|
33
|
+
|
34
|
+
msg2 = my_new_destination.pop_message
|
35
|
+
expect(msg2.body).to eq("Test Message 2")
|
36
|
+
|
37
|
+
msg3 = my_new_destination.pop_message
|
38
|
+
expect(msg3).to be_nil
|
39
|
+
"""
|
40
|
+
|
41
|
+
Then I expect to have no errors
|
@@ -0,0 +1,47 @@
|
|
1
|
+
Feature: Error Handling
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I am connected to the broker
|
5
|
+
|
6
|
+
@bunny
|
7
|
+
Scenario: Queue isn't found on the broker
|
8
|
+
When I execute the following code:
|
9
|
+
"""ruby
|
10
|
+
MessageDriver::Broker.dynamic_destination("missing_queue", passive: true)
|
11
|
+
"""
|
12
|
+
|
13
|
+
Then I expect it to raise a MessageDriver::QueueNotFound error
|
14
|
+
|
15
|
+
@no_travis
|
16
|
+
@bunny
|
17
|
+
Scenario: The broker goes down
|
18
|
+
Given the following broker configuration:
|
19
|
+
"""ruby
|
20
|
+
MessageDriver::Broker.define do |b|
|
21
|
+
b.destination :my_queue, "broker_down_queue", arguments: {:'x-expires' => 10000 }
|
22
|
+
end
|
23
|
+
"""
|
24
|
+
|
25
|
+
When I execute the following code:
|
26
|
+
"""ruby
|
27
|
+
publish(:my_queue, "Test Message 1")
|
28
|
+
"""
|
29
|
+
And the broker goes down
|
30
|
+
And I execute the following code:
|
31
|
+
"""ruby
|
32
|
+
publish(:my_queue, "Test Message 2")
|
33
|
+
"""
|
34
|
+
Then I expect it to raise a MessageDriver::ConnectionException error
|
35
|
+
|
36
|
+
When the broker comes up
|
37
|
+
And I execute the following code:
|
38
|
+
"""ruby
|
39
|
+
publish(:my_queue, "Test Message 3")
|
40
|
+
"""
|
41
|
+
|
42
|
+
Then I expect to have no errors
|
43
|
+
And I expect to find 2 messages on :my_queue with:
|
44
|
+
| body |
|
45
|
+
| Test Message 1 |
|
46
|
+
| Test Message 3 |
|
47
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
Here's how to get started!
|
@@ -0,0 +1,19 @@
|
|
1
|
+
@all_adapters
|
2
|
+
Feature: Publishing A Message
|
3
|
+
Background:
|
4
|
+
Given the following broker configuration:
|
5
|
+
"""ruby
|
6
|
+
MessageDriver::Broker.define do |b|
|
7
|
+
b.destination :my_queue, "my_queue", exclusive: true
|
8
|
+
end
|
9
|
+
"""
|
10
|
+
|
11
|
+
Scenario: Running within a with_message_transaction block
|
12
|
+
When I execute the following code:
|
13
|
+
"""ruby
|
14
|
+
publish(:my_queue, "Test Message")
|
15
|
+
"""
|
16
|
+
|
17
|
+
Then I expect to find 1 message on :my_queue with:
|
18
|
+
| body |
|
19
|
+
| Test Message |
|
@@ -0,0 +1,36 @@
|
|
1
|
+
@bunny
|
2
|
+
Feature: Publishing a Message within a Transaction
|
3
|
+
Background:
|
4
|
+
Given the following broker configuration:
|
5
|
+
"""ruby
|
6
|
+
MessageDriver::Broker.define do |b|
|
7
|
+
b.destination :my_queue, "my_queue", exclusive: true
|
8
|
+
end
|
9
|
+
"""
|
10
|
+
|
11
|
+
Scenario: The block completes successfully
|
12
|
+
When I execute the following code:
|
13
|
+
"""ruby
|
14
|
+
with_message_transaction do
|
15
|
+
publish(:my_queue, "Transacted Message 1")
|
16
|
+
publish(:my_queue, "Transacted Message 2")
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
|
20
|
+
Then I expect to find 2 messages on :my_queue with:
|
21
|
+
| body |
|
22
|
+
| Transacted Message 1 |
|
23
|
+
| Transacted Message 2 |
|
24
|
+
|
25
|
+
Scenario: An error is raised inside the block
|
26
|
+
When I execute the following code:
|
27
|
+
"""ruby
|
28
|
+
with_message_transaction do
|
29
|
+
publish(:my_queue, "Transacted Message 1")
|
30
|
+
raise "an error that causes a rollback"
|
31
|
+
publish(:my_queue, "Transacted Message 2")
|
32
|
+
end
|
33
|
+
"""
|
34
|
+
|
35
|
+
Then I expect it to raise "an error that causes a rollback"
|
36
|
+
And I expect to find no messages on :my_queue
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Given(/^I have a dynamic destination "(#{STRING_OR_SYM})" with the following messages on it:$/) do |destination, table|
|
2
|
+
dest = MessageDriver::Broker.dynamic_destination(destination, exclusive: true)
|
3
|
+
test_runner.publish_table_to_destination(dest, table)
|
4
|
+
end
|
5
|
+
|
6
|
+
Then(/^I expect to find (#{NUMBER}) messages? on the dynamic destination "(#{STRING_OR_SYM})" with:$/) do |count, destination, table|
|
7
|
+
expect(test_runner).to have_no_errors
|
8
|
+
dest = MessageDriver::Broker.dynamic_destination(destination, passive: true)
|
9
|
+
messages = test_runner.fetch_messages(dest)
|
10
|
+
expect(messages).to have(count).items
|
11
|
+
expect(messages).to match_message_table(table)
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
Given "I am connected to the broker" do
|
2
|
+
MessageDriver.configure(BrokerConfig.config)
|
3
|
+
end
|
4
|
+
|
5
|
+
Given "the following broker configuration:" do |src|
|
6
|
+
step "I am connected to the broker"
|
7
|
+
test_runner.config_broker(src)
|
8
|
+
end
|
9
|
+
|
10
|
+
When "I execute the following code:" do |src|
|
11
|
+
test_runner.run_test_code(src)
|
12
|
+
end
|
13
|
+
|
14
|
+
Then(/^I expect to find (#{NUMBER}) messages? on (#{STRING_OR_SYM})$/) do |count, destination|
|
15
|
+
expect(test_runner).to have_no_errors
|
16
|
+
messages = test_runner.fetch_messages(destination)
|
17
|
+
expect(messages).to have(count).items
|
18
|
+
end
|
19
|
+
|
20
|
+
Then(/^I expect to find (#{NUMBER}) messages? on (#{STRING_OR_SYM}) with:$/) do |count, destination, table|
|
21
|
+
expect(test_runner).to have_no_errors
|
22
|
+
messages = test_runner.fetch_messages(destination)
|
23
|
+
expect(messages).to have(count).items
|
24
|
+
expect(messages).to match_message_table(table)
|
25
|
+
end
|
26
|
+
|
27
|
+
Then(/^I expect it to raise "(.*?)"$/) do |error_msg|
|
28
|
+
expect(test_runner.raised_error).to_not be_nil
|
29
|
+
expect(test_runner.raised_error.to_s).to match error_msg
|
30
|
+
test_runner.raised_error = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
Then(/^I expect it to raise a (.*?) error$/) do |error_type|
|
34
|
+
expect(test_runner.raised_error).to_not be_nil
|
35
|
+
expect(test_runner.raised_error.class.to_s).to match error_type
|
36
|
+
test_runner.raised_error = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
Then "I expect to have no errors" do
|
40
|
+
expect(test_runner).to have_no_errors
|
41
|
+
end
|