queueing_rabbit 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  require "queueing_rabbit/version"
2
+ require "queueing_rabbit/misc/inheritable_class_variables"
2
3
  require "queueing_rabbit/callbacks"
3
4
  require "queueing_rabbit/configuration"
4
5
  require "queueing_rabbit/logging"
@@ -9,6 +10,9 @@ require "queueing_rabbit/client/bunny"
9
10
  require "queueing_rabbit/extensions/new_relic"
10
11
  require "queueing_rabbit/extensions/retryable"
11
12
  require "queueing_rabbit/extensions/direct_exchange"
13
+ require "queueing_rabbit/bus"
14
+ require "queueing_rabbit/buses/abstract_bus"
15
+ require "queueing_rabbit/buses/json_bus"
12
16
  require "queueing_rabbit/job"
13
17
  require "queueing_rabbit/jobs/abstract_job"
14
18
  require "queueing_rabbit/jobs/json_job"
@@ -49,15 +53,29 @@ module QueueingRabbit
49
53
 
50
54
  true
51
55
  end
52
- alias_method :publish, :enqueue
56
+
57
+ def publish(bus, payload = nil, options = {})
58
+ info "publishing to event bus #{bus}"
59
+
60
+ follow_bus_requirements(bus) do |ch, ex|
61
+ conn.enqueue(ex, payload, options)
62
+ ch.close
63
+ end
64
+ end
53
65
 
54
66
  def follow_job_requirements(job)
55
- conn.open_channel(job.channel_options) do |ch, _|
56
- conn.define_exchange(ch, job.exchange_name, job.exchange_options) do |ex|
57
- conn.define_queue(ch, job.queue_name, job.queue_options) do |q|
58
- conn.bind_queue(q, ex, job.binding_options) if job.bind_queue?
59
- yield ch, ex, q if block_given?
60
- end
67
+ follow_bus_requirements(job) do |ch, ex|
68
+ conn.define_queue(ch, job.queue_name, job.queue_options) do |q|
69
+ conn.bind_queue(q, ex, job.binding_options) if job.bind_queue?
70
+ yield ch, ex, q
71
+ end
72
+ end
73
+ end
74
+
75
+ def follow_bus_requirements(bus)
76
+ conn.open_channel(bus.channel_options) do |ch, _|
77
+ conn.define_exchange(ch, bus.exchange_name, bus.exchange_options) do |ex|
78
+ yield ch, ex
61
79
  end
62
80
  end
63
81
  end
@@ -0,0 +1,65 @@
1
+ module QueueingRabbit
2
+
3
+ module Bus
4
+ def self.extended(othermod)
5
+ othermod.extend(QueueingRabbit::InheritableClassVariables)
6
+
7
+ othermod.class_eval do
8
+ inheritable_variables :channel_options, :exchange_name,
9
+ :exchange_options, :publishing_defaults
10
+ end
11
+ end
12
+
13
+ def channel(options = {})
14
+ @channel_options ||= {}
15
+ @channel_options.update(options)
16
+ end
17
+
18
+ def channel_options
19
+ @channel_options ||= {}
20
+ end
21
+
22
+ def exchange(*args)
23
+ @exchange_options ||= {}
24
+ name, options = extract_name_and_options(*args)
25
+ @exchange_name = name if name
26
+ @exchange_options.update(options) if options
27
+ end
28
+
29
+ def exchange_name
30
+ @exchange_name || ''
31
+ end
32
+
33
+ def exchange_options
34
+ @exchange_options || {}
35
+ end
36
+
37
+ def publish_with(options = {})
38
+ @publishing_defaults ||= {}
39
+ @publishing_defaults.update(options)
40
+ end
41
+
42
+ def publishing_defaults
43
+ @publishing_defaults || {}
44
+ end
45
+
46
+ def publish(payload, options = {})
47
+ QueueingRabbit.publish(self, payload, publishing_defaults.merge(options))
48
+ end
49
+
50
+ protected
51
+
52
+ def extract_name_and_options(*args)
53
+ name = options = nil
54
+ if args.first.kind_of?(Hash)
55
+ options = args.first
56
+ elsif args.count > 1
57
+ name, options = args
58
+ else
59
+ name = args.first
60
+ end
61
+ [name, options]
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,9 @@
1
+ module QueueingRabbit
2
+
3
+ class AbstractBus
4
+
5
+ extend Bus
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,13 @@
1
+ module QueueingRabbit
2
+
3
+ class JSONBus < AbstractBus
4
+
5
+ extend QueueingRabbit::Serializer
6
+
7
+ def self.publish(payload, metadata = {})
8
+ super serialize(payload), metadata
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -1,7 +1,7 @@
1
1
  module QueueingRabbit
2
2
 
3
3
  module Configuration
4
- attr_accessor :amqp_uri, :amqp_exchange_name, :amqp_exchange_options
4
+ attr_accessor :amqp_uri
5
5
  attr_writer :tcp_timeout, :heartbeat
6
6
 
7
7
  def configure
@@ -1,23 +1,8 @@
1
1
  module QueueingRabbit
2
- module InheritableClassVariables
3
- def inheritable_variables(*args)
4
- @inheritable_variables ||= [:inheritable_variables]
5
- @inheritable_variables += args
6
- end
7
-
8
- def inherited(subclass)
9
- @inheritable_variables ||= []
10
- @inheritable_variables.each do |var|
11
- if !subclass.instance_variable_get("@#{var}") ||
12
- subclass.instance_variable_get("@#{var}").empty?
13
- subclass.instance_variable_set("@#{var}",
14
- instance_variable_get("@#{var}"))
15
- end
16
- end
17
- end
18
- end
19
2
 
20
3
  module Job
4
+ include Bus
5
+
21
6
  def self.extended(othermod)
22
7
  othermod.extend(QueueingRabbit::InheritableClassVariables)
23
8
 
@@ -31,15 +16,9 @@ module QueueingRabbit
31
16
 
32
17
  def queue(*args)
33
18
  @queue_options ||= {}
34
- if args.first.kind_of?(Hash)
35
- @queue_options.update(args.first)
36
- elsif args.count > 1
37
- name, options = args
38
- @queue_name = name
39
- @queue_options.update(options)
40
- else
41
- @queue_name = args.first
42
- end
19
+ name, options = extract_name_and_options(*args)
20
+ @queue_name = name if name
21
+ @queue_options.update(options) if options
43
22
  end
44
23
 
45
24
  def queue_name
@@ -54,36 +33,6 @@ module QueueingRabbit
54
33
  QueueingRabbit.queue_size(self)
55
34
  end
56
35
 
57
- def channel(options = {})
58
- @channel_options ||= {}
59
- @channel_options.update(options)
60
- end
61
-
62
- def channel_options
63
- @channel_options ||= {}
64
- end
65
-
66
- def exchange(*args)
67
- @exchange_options ||= {}
68
- if args.first.kind_of?(Hash)
69
- @exchange_options.update(args.first)
70
- elsif args.count > 1
71
- name, options = args
72
- @exchange_name = name
73
- @exchange_options.update(options)
74
- else
75
- @exchange_name = args.first
76
- end
77
- end
78
-
79
- def exchange_name
80
- @exchange_name || ''
81
- end
82
-
83
- def exchange_options
84
- @exchange_options || {}
85
- end
86
-
87
36
  def bind(options = {})
88
37
  @binding_options ||= {}
89
38
  @binding_options.update(options)
@@ -107,11 +56,6 @@ module QueueingRabbit
107
56
  end
108
57
  alias_method :subscribe, :listen
109
58
 
110
- def publish(options = {})
111
- @publishing_defaults ||= {}
112
- @publishing_defaults.update(options)
113
- end
114
-
115
59
  def publishing_defaults
116
60
  @publishing_defaults ||= {}
117
61
  {:routing_key => queue_name.to_s}.merge(@publishing_defaults)
@@ -0,0 +1,23 @@
1
+ module QueueingRabbit
2
+
3
+ module InheritableClassVariables
4
+
5
+ def inheritable_variables(*args)
6
+ @inheritable_variables ||= [:inheritable_variables]
7
+ @inheritable_variables += args
8
+ end
9
+
10
+ def inherited(subclass)
11
+ @inheritable_variables ||= []
12
+ @inheritable_variables.each do |var|
13
+ if !subclass.instance_variable_get("@#{var}") ||
14
+ subclass.instance_variable_get("@#{var}").empty?
15
+ subclass.instance_variable_set("@#{var}",
16
+ instance_variable_get("@#{var}"))
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -1,3 +1,3 @@
1
1
  module QueueingRabbit
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'integration/jobs/print_line_job'
3
+
4
+ describe 'Binary synchronous publishing via bus and asynchronous consuming via job' do
5
+ include_context "StringIO logger"
6
+ include_context "Evented spec"
7
+
8
+ let(:bus) {
9
+ Class.new(QueueingRabbit::AbstractBus) do
10
+ publish_with :routing_key => 'print_line_job'
11
+ end
12
+ }
13
+ let(:job) { PrintLineJob }
14
+ let(:worker) { QueueingRabbit::Worker.new(job.to_s) }
15
+ let(:line) { "Hello, world!" }
16
+ let(:io) { StringIO.new }
17
+
18
+ before do
19
+ job.io = io
20
+ bus.publish(line)
21
+ QueueingRabbit.drop_connection
22
+ end
23
+
24
+ it "works" do
25
+ em {
26
+ worker.work
27
+
28
+ done(1.0) {
29
+ io.string.should include(line)
30
+ }
31
+ }
32
+ end
33
+ end
@@ -8,7 +8,7 @@ describe 'Configuring jobs' do
8
8
  channel :prefetch => 15
9
9
  queue :durable => true
10
10
  bind :ack => true
11
- publish :persistent => true
11
+ publish_with :persistent => true
12
12
  end
13
13
  }
14
14
 
@@ -35,7 +35,7 @@ describe 'Configuring jobs' do
35
35
  channel :prefetch => 15
36
36
  queue :durable => true
37
37
  bind :ack => true
38
- publish :persistent => true
38
+ publish_with :persistent => true
39
39
  end
40
40
  }
41
41
 
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'integration/jobs/print_line_job'
3
+
4
+ describe 'JSON synchronous publishing via bus and asynchronous consuming via job' do
5
+ include_context "StringIO logger"
6
+ include_context "Evented spec"
7
+
8
+ let(:bus) {
9
+ Class.new(QueueingRabbit::JSONBus) do
10
+ publish_with :routing_key => 'print_line_job'
11
+ end
12
+ }
13
+ let(:job) {
14
+ Class.new(QueueingRabbit::JSONJob) do
15
+ class << self
16
+ attr_accessor :io
17
+ end
18
+
19
+ queue 'print_line_job'
20
+
21
+ def perform
22
+ self.class.io.puts arguments[:line]
23
+ end
24
+ end
25
+ }
26
+ let(:job_name) { 'PrintLineJob' }
27
+ let(:worker) { QueueingRabbit::Worker.new(job_name) }
28
+ let(:line) { "Hello, world!" }
29
+ let(:io) { StringIO.new }
30
+
31
+ before do
32
+ stub_const(job_name, job)
33
+ end
34
+
35
+ before do
36
+ job.io = io
37
+ bus.publish(:line => line)
38
+ QueueingRabbit.drop_connection
39
+ end
40
+
41
+ it "works" do
42
+ em {
43
+ worker.work
44
+
45
+ done(1.0) {
46
+ io.string.should include(line)
47
+ }
48
+ }
49
+ end
50
+ end
@@ -15,7 +15,7 @@ describe "Persistent asynchronous publishing and consuming" do
15
15
  Class.new(PrintLineJob) do
16
16
  queue 'persistent_print_line_job'
17
17
  listen :ack => true
18
- publish :persistent => true
18
+ publish_with :persistent => true
19
19
  channel :use_publisher_confirms => true
20
20
 
21
21
  def perform
data/spec/spec_helper.rb CHANGED
@@ -20,10 +20,4 @@ RSpec.configure do |config|
20
20
  config.exclusion_filter = {
21
21
  :ruby => RUBY_VERSION
22
22
  }
23
-
24
- QueueingRabbit.configure do |qr|
25
- qr.amqp_uri = "amqp://guest:guest@localhost:5672"
26
- qr.amqp_exchange_name = "queueing_rabbit_test"
27
- qr.amqp_exchange_options = {:durable => true}
28
- end
29
23
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe QueueingRabbit::AbstractBus do
4
+ let(:bus_class) {
5
+ Class.new(QueueingRabbit::AbstractBus) do
6
+ exchange 'test_exchange', :durable => false
7
+ publish_with :routing_key => 'test_queue'
8
+ end
9
+ }
10
+
11
+ subject { bus_class }
12
+
13
+ it { should respond_to(:exchange).with(1).argument }
14
+ it { should respond_to(:exchange).with(2).arguments }
15
+ it { should respond_to(:exchange_name) }
16
+ it { should respond_to(:exchange_options) }
17
+ it { should respond_to(:channel_options) }
18
+ it { should respond_to(:channel).with(1).argument }
19
+ it { should respond_to(:publishing_defaults) }
20
+
21
+ its(:exchange_name) { should == 'test_exchange' }
22
+ its(:exchange_options) { should include(:durable => false) }
23
+ its(:publishing_defaults) { should include(:routing_key => 'test_queue') }
24
+
25
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe QueueingRabbit::JSONBus do
4
+ let(:json_bus) { QueueingRabbit::JSONBus }
5
+ let(:payload) { JSON.dump(:foo => 'bar') }
6
+
7
+ describe '.publish' do
8
+ let(:options) { {:persistent => true} }
9
+
10
+ it 'dumps payload to JSON' do
11
+ QueueingRabbit.should_receive(:publish).
12
+ with(json_bus, payload, options)
13
+ json_bus.publish({:foo => 'bar'}, options)
14
+ end
15
+ end
16
+ end
@@ -7,9 +7,7 @@ describe QueueingRabbit::Client::AMQP do
7
7
  let(:connection) { mock :on_tcp_connection_loss => nil, :on_recovery => nil }
8
8
 
9
9
  before do
10
- QueueingRabbit.stub(:amqp_uri => 'amqp://localhost:5672',
11
- :amqp_exchange_name => 'queueing_rabbit_test',
12
- :amqp_exchange_options => {:durable => true})
10
+ QueueingRabbit.stub(:amqp_uri => 'amqp://localhost:5672')
13
11
  end
14
12
 
15
13
  context "class" do
@@ -4,9 +4,7 @@ describe QueueingRabbit::Client::Bunny do
4
4
  let(:connection) { stub(:start => true) }
5
5
 
6
6
  before do
7
- QueueingRabbit.stub(:amqp_uri => 'amqp://localhost:5672',
8
- :amqp_exchange_name => 'queueing_rabbit_test',
9
- :amqp_exchange_options => {:durable => true})
7
+ QueueingRabbit.stub(:amqp_uri => 'amqp://localhost:5672')
10
8
  end
11
9
 
12
10
  context 'class' do
@@ -4,9 +4,6 @@ describe QueueingRabbit::Configuration do
4
4
  subject { Class.new { extend QueueingRabbit::Configuration} }
5
5
 
6
6
  it { should respond_to(:amqp_uri) }
7
- it { should respond_to(:amqp_exchange_name) }
8
- it { should respond_to(:amqp_exchange_options) }
9
-
10
7
  its(:tcp_timeout) { should == 1 }
11
8
  its(:heartbeat) { should == 10 }
12
9
  its(:default_client) { should == QueueingRabbit::Client::Bunny }
@@ -74,13 +74,11 @@ describe QueueingRabbit do
74
74
  subject.instance_variable_set(:@connection, connection)
75
75
  end
76
76
 
77
- it 'opens a channel, defines an exchange and a queue, binds the queue to ' \
78
- 'the exchange, yields' do
79
- connection.should_receive(:open_channel).with(job.channel_options).
80
- and_yield(channel, nil)
81
- connection.should_receive(:define_exchange).
82
- with(channel, job.exchange_name, job.exchange_options).
83
- and_yield(exchange)
77
+ it 'follows bus requirements, creates a queue, binds the queue to ' \
78
+ 'the exchange and yields' do
79
+ subject.should_receive(:follow_bus_requirements).
80
+ with(job).
81
+ and_yield(channel, exchange)
84
82
  connection.should_receive(:define_queue).
85
83
  with(channel, job.queue_name, job.queue_options).
86
84
  and_yield(queue)
@@ -95,6 +93,33 @@ describe QueueingRabbit do
95
93
  end
96
94
  end
97
95
 
96
+ describe '.follow_bus_requirements' do
97
+ let(:channel) { mock }
98
+ let(:exchange) { mock }
99
+ let(:bus) {
100
+ stub(:channel_options => channel_options,
101
+ :exchange_name => exchange_name,
102
+ :exchange_options => exchange_options)
103
+ }
104
+
105
+ before do
106
+ subject.instance_variable_set(:@connection, connection)
107
+ end
108
+
109
+ it 'opens a channel, defines an exchange and yields' do
110
+ connection.should_receive(:open_channel).with(bus.channel_options).
111
+ and_yield(channel, nil)
112
+ connection.should_receive(:define_exchange).
113
+ with(channel, bus.exchange_name, bus.exchange_options).
114
+ and_yield(exchange)
115
+
116
+ subject.follow_bus_requirements(bus) do |ch, ex|
117
+ ch.should == channel
118
+ ex.should == exchange
119
+ end
120
+ end
121
+ end
122
+
98
123
  describe ".queue_size" do
99
124
  let(:size) { mock }
100
125
  let(:queue) { mock }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queueing_rabbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-02 00:00:00.000000000 Z
12
+ date: 2013-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp
@@ -101,6 +101,9 @@ files:
101
101
  - README.md
102
102
  - Rakefile
103
103
  - lib/queueing_rabbit.rb
104
+ - lib/queueing_rabbit/bus.rb
105
+ - lib/queueing_rabbit/buses/abstract_bus.rb
106
+ - lib/queueing_rabbit/buses/json_bus.rb
104
107
  - lib/queueing_rabbit/callbacks.rb
105
108
  - lib/queueing_rabbit/client/amqp.rb
106
109
  - lib/queueing_rabbit/client/bunny.rb
@@ -113,6 +116,7 @@ files:
113
116
  - lib/queueing_rabbit/jobs/abstract_job.rb
114
117
  - lib/queueing_rabbit/jobs/json_job.rb
115
118
  - lib/queueing_rabbit/logging.rb
119
+ - lib/queueing_rabbit/misc/inheritable_class_variables.rb
116
120
  - lib/queueing_rabbit/serializer.rb
117
121
  - lib/queueing_rabbit/tasks.rb
118
122
  - lib/queueing_rabbit/version.rb
@@ -121,15 +125,19 @@ files:
121
125
  - queueing_rabbit.gemspec
122
126
  - spec/integration/asynchronous_publishing_and_consuming_spec.rb
123
127
  - spec/integration/asynchronous_publishing_and_consuming_with_retries_spec.rb
128
+ - spec/integration/binary_synchronous_publishing_via_bus_and_asynchronous_consuming_via_job_spec.rb
124
129
  - spec/integration/configuration_spec.rb
125
130
  - spec/integration/direct_exchange_asynchronous_publishing_and_consuming_spec.rb
126
131
  - spec/integration/jobs/print_line_job.rb
127
132
  - spec/integration/json_job_asynchronous_publishing_and_consuming_spec.rb
133
+ - spec/integration/json_synchronous_publishing_via_bus_and_asynchronous_consuming_via_job_spec.rb
128
134
  - spec/integration/persistent_asynchronous_publishing_and_consuming_spec.rb
129
135
  - spec/integration/synchronous_publishing_and_asynchronous_consuming_spec.rb
130
136
  - spec/integration/synchronous_publishing_spec.rb
131
137
  - spec/spec_helper.rb
132
138
  - spec/support/shared_contexts.rb
139
+ - spec/unit/queueing_rabbit/buses/abstract_bus_spec.rb
140
+ - spec/unit/queueing_rabbit/buses/json_bus_spec.rb
133
141
  - spec/unit/queueing_rabbit/callbacks_spec.rb
134
142
  - spec/unit/queueing_rabbit/client/amqp_spec.rb
135
143
  - spec/unit/queueing_rabbit/client/bunny_spec.rb
@@ -138,7 +146,6 @@ files:
138
146
  - spec/unit/queueing_rabbit/extensions/direct_exchange_spec.rb
139
147
  - spec/unit/queueing_rabbit/extensions/new_relic_spec.rb
140
148
  - spec/unit/queueing_rabbit/extensions/retryable_spec.rb
141
- - spec/unit/queueing_rabbit/job_spec.rb
142
149
  - spec/unit/queueing_rabbit/jobs/abstract_job_spec.rb
143
150
  - spec/unit/queueing_rabbit/jobs/json_job_spec.rb
144
151
  - spec/unit/queueing_rabbit/logging_spec.rb
@@ -160,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
167
  version: '0'
161
168
  segments:
162
169
  - 0
163
- hash: -615049155772679483
170
+ hash: 1557293148620146716
164
171
  required_rubygems_version: !ruby/object:Gem::Requirement
165
172
  none: false
166
173
  requirements:
@@ -169,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
176
  version: '0'
170
177
  segments:
171
178
  - 0
172
- hash: -615049155772679483
179
+ hash: 1557293148620146716
173
180
  requirements: []
174
181
  rubyforge_project:
175
182
  rubygems_version: 1.8.25
@@ -179,15 +186,19 @@ summary: QueueingRabbit is an AMQP-based queueing system
179
186
  test_files:
180
187
  - spec/integration/asynchronous_publishing_and_consuming_spec.rb
181
188
  - spec/integration/asynchronous_publishing_and_consuming_with_retries_spec.rb
189
+ - spec/integration/binary_synchronous_publishing_via_bus_and_asynchronous_consuming_via_job_spec.rb
182
190
  - spec/integration/configuration_spec.rb
183
191
  - spec/integration/direct_exchange_asynchronous_publishing_and_consuming_spec.rb
184
192
  - spec/integration/jobs/print_line_job.rb
185
193
  - spec/integration/json_job_asynchronous_publishing_and_consuming_spec.rb
194
+ - spec/integration/json_synchronous_publishing_via_bus_and_asynchronous_consuming_via_job_spec.rb
186
195
  - spec/integration/persistent_asynchronous_publishing_and_consuming_spec.rb
187
196
  - spec/integration/synchronous_publishing_and_asynchronous_consuming_spec.rb
188
197
  - spec/integration/synchronous_publishing_spec.rb
189
198
  - spec/spec_helper.rb
190
199
  - spec/support/shared_contexts.rb
200
+ - spec/unit/queueing_rabbit/buses/abstract_bus_spec.rb
201
+ - spec/unit/queueing_rabbit/buses/json_bus_spec.rb
191
202
  - spec/unit/queueing_rabbit/callbacks_spec.rb
192
203
  - spec/unit/queueing_rabbit/client/amqp_spec.rb
193
204
  - spec/unit/queueing_rabbit/client/bunny_spec.rb
@@ -196,7 +207,6 @@ test_files:
196
207
  - spec/unit/queueing_rabbit/extensions/direct_exchange_spec.rb
197
208
  - spec/unit/queueing_rabbit/extensions/new_relic_spec.rb
198
209
  - spec/unit/queueing_rabbit/extensions/retryable_spec.rb
199
- - spec/unit/queueing_rabbit/job_spec.rb
200
210
  - spec/unit/queueing_rabbit/jobs/abstract_job_spec.rb
201
211
  - spec/unit/queueing_rabbit/jobs/json_job_spec.rb
202
212
  - spec/unit/queueing_rabbit/logging_spec.rb
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe QueueingRabbit::AbstractJob do
4
- let(:job_class) {
5
- Class.new(QueueingRabbit::AbstractJob) do
6
- queue 'test_queue', :durable => true
7
- exchange 'test_exchange', :durable => false
8
- bind :routing_key => 'test.*'
9
- end
10
- }
11
-
12
- subject { job_class }
13
-
14
- it { should respond_to(:exchange).with(1).argument }
15
- it { should respond_to(:exchange).with(2).arguments }
16
- it { should respond_to(:exchange_name) }
17
- it { should respond_to(:exchange_options) }
18
- it { should respond_to(:queue).with(1).argument }
19
- it { should respond_to(:queue).with(2).arguments }
20
- it { should respond_to(:queue_name) }
21
- it { should respond_to(:queue_options) }
22
- it { should respond_to(:channel_options) }
23
- it { should respond_to(:channel).with(1).argument }
24
- it { should respond_to(:enqueue).with(1).argument }
25
- it { should respond_to(:enqueue).with(2).arguments }
26
- it { should respond_to(:listening_options) }
27
- it { should respond_to(:listen) }
28
- it { should respond_to(:listen).with(1).argument }
29
- it { should respond_to(:publishing_defaults) }
30
-
31
- its(:queue_name) { should == 'test_queue' }
32
- its(:queue_options) { should include(:durable => true) }
33
- its(:exchange_options) { should include(:durable => false) }
34
- its(:binding_options) { should include(:routing_key => 'test.*') }
35
- its(:publishing_defaults) { should include(:routing_key => 'test_queue') }
36
-
37
- describe ".queue_size" do
38
- let(:size) { mock }
39
-
40
- before do
41
- QueueingRabbit.should_receive(:queue_size).with(subject).and_return(size)
42
- end
43
-
44
- its(:queue_size) { should == size }
45
- end
46
-
47
- describe '.enqueue' do
48
- let(:payload) { mock }
49
- let(:options) { {:persistent => true} }
50
- let(:result_options) { options.merge(job_class.publishing_defaults) }
51
-
52
- it 'enqueues a job of its own type with given argument' do
53
- QueueingRabbit.should_receive(:enqueue).
54
- with(subject, payload, result_options)
55
- subject.enqueue(payload, options)
56
- end
57
- end
58
-
59
- context 'instance methods' do
60
- let(:payload) { mock }
61
- let(:headers) { mock }
62
- let(:metadata) { stub(:headers => headers) }
63
-
64
- subject { job_class.new(payload, metadata) }
65
-
66
- its(:payload) { should == payload }
67
- its(:metadata) { should == metadata }
68
- its(:headers) { should == headers }
69
-
70
- it { should respond_to(:perform) }
71
- end
72
- end
73
-
74
- describe QueueingRabbit::JSONJob do
75
- let(:json_job) { QueueingRabbit::JSONJob }
76
- let(:payload) { JSON.dump(:foo => 'bar') }
77
- let(:metadata) { mock }
78
-
79
- subject { json_job.new(payload, metadata) }
80
-
81
- its(:payload) { should include(:foo => 'bar') }
82
-
83
- describe '.enqueue' do
84
- let(:options) { {:persistent => true} }
85
- let(:result_options) { options.merge(:routing_key => 'JSONJob') }
86
-
87
- it 'dumps payload to JSON' do
88
- QueueingRabbit.should_receive(:enqueue).
89
- with(json_job, payload, result_options)
90
- json_job.enqueue({:foo => 'bar'}, options)
91
- end
92
- end
93
- end
94
-