cwyckoff-rosetta_queue 0.3.0 → 0.3.3

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.
Files changed (51) hide show
  1. data/History.txt +26 -3
  2. data/README.rdoc +4 -149
  3. data/Rakefile +3 -0
  4. data/VERSION.yml +2 -2
  5. data/cucumber.yml +1 -1
  6. data/examples/sample_amqp_consumer.rb +45 -0
  7. data/examples/sample_amqp_fanout_consumer.rb +52 -0
  8. data/examples/sample_amqp_fanout_producer.rb +18 -0
  9. data/examples/sample_amqp_producer.rb +16 -0
  10. data/features/filtering.feature +31 -0
  11. data/features/messaging.feature +47 -0
  12. data/features/step_definitions/common_messaging_steps.rb +82 -0
  13. data/features/step_definitions/filtering_steps.rb +17 -0
  14. data/features/step_definitions/point_to_point_steps.rb +22 -0
  15. data/features/step_definitions/publish_subscribe_steps.rb +25 -0
  16. data/features/support/env.rb +25 -0
  17. data/features/support/sample_consumers.rb +29 -0
  18. data/lib/rosetta_queue.rb +3 -2
  19. data/lib/rosetta_queue/adapter.rb +1 -1
  20. data/lib/rosetta_queue/adapters/amqp.rb +48 -0
  21. data/lib/rosetta_queue/adapters/amqp_evented.rb +132 -0
  22. data/lib/rosetta_queue/adapters/amqp_synch.rb +48 -69
  23. data/lib/rosetta_queue/adapters/beanstalk.rb +56 -0
  24. data/lib/rosetta_queue/adapters/stomp.rb +16 -1
  25. data/lib/rosetta_queue/consumer_managers/base.rb +3 -1
  26. data/lib/rosetta_queue/consumer_managers/threaded.rb +23 -4
  27. data/lib/rosetta_queue/core_ext/string.rb +22 -0
  28. data/lib/rosetta_queue/core_ext/time.rb +20 -0
  29. data/lib/rosetta_queue/filters.rb +1 -1
  30. data/lib/rosetta_queue/logger.rb +1 -1
  31. data/lib/rosetta_queue/message_handler.rb +6 -0
  32. data/spec/rosetta_queue/adapter_spec.rb +101 -0
  33. data/spec/rosetta_queue/adapters/amqp_synchronous_spec.rb +278 -0
  34. data/spec/rosetta_queue/adapters/beanstalk_spec.rb +47 -0
  35. data/spec/rosetta_queue/adapters/fake_spec.rb +72 -0
  36. data/spec/rosetta_queue/adapters/null_spec.rb +31 -0
  37. data/spec/rosetta_queue/adapters/shared_adapter_behavior.rb +38 -0
  38. data/spec/rosetta_queue/adapters/shared_fanout_behavior.rb +20 -0
  39. data/spec/rosetta_queue/adapters/stomp_spec.rb +126 -0
  40. data/spec/rosetta_queue/consumer_managers/evented_spec.rb +56 -0
  41. data/spec/rosetta_queue/consumer_managers/shared_manager_behavior.rb +26 -0
  42. data/spec/rosetta_queue/consumer_managers/threaded_spec.rb +51 -0
  43. data/spec/rosetta_queue/consumer_spec.rb +99 -0
  44. data/spec/rosetta_queue/core_ext/string_spec.rb +15 -0
  45. data/spec/rosetta_queue/destinations_spec.rb +34 -0
  46. data/spec/rosetta_queue/filters_spec.rb +44 -0
  47. data/spec/rosetta_queue/producer_spec.rb +66 -0
  48. data/spec/rosetta_queue/shared_messaging_behavior.rb +21 -0
  49. data/spec/spec.opts +4 -0
  50. data/spec/spec_helper.rb +47 -0
  51. metadata +68 -19
@@ -0,0 +1,99 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module RosettaQueue
4
+ describe Consumer do
5
+
6
+ class TestConsumer
7
+ include MessageHandler
8
+
9
+ subscribes_to :test_queue
10
+ options :persistent => false, :ack => "client"
11
+
12
+ def on_message(msg)
13
+
14
+ end
15
+ end
16
+
17
+ before(:each) do
18
+ @message = mock("message", "headers" => "foo", "body" => "message body")
19
+ @adapter = mock("adpater", :subscribe => true, :unsubscribe => true, :disconnect => true, :receive_with => TestConsumer.new,
20
+ :receive_once => @message.body, :ack => true)
21
+ Adapter.stub!(:instance).and_return(@adapter)
22
+ Destinations.stub!(:lookup).and_return("/queue/foo")
23
+ end
24
+
25
+ it_should_behave_like "a messaging gateway object"
26
+
27
+ attr_reader :adapter
28
+ def gateway
29
+ @gateway ||= Consumer.new(TestConsumer.new)
30
+ end
31
+
32
+ describe "#receive" do
33
+ before(:each) do
34
+ @consumer = Consumer.new( @message_handler = TestConsumer.new)
35
+ end
36
+
37
+ def when_receiving
38
+ yield if block_given?
39
+ @consumer.receive
40
+ end
41
+
42
+ it "should pass message handler onto the adpater with #receive" do
43
+ when_receiving {
44
+ @adapter.should_receive("receive_with").with(@message_handler)
45
+ }
46
+ end
47
+ end
48
+
49
+
50
+ describe ".delete" do
51
+
52
+ before(:each) do
53
+ @adapter.stub!(:delete)
54
+ Destinations.stub!(:lookup).and_return("/queue/foo")
55
+ end
56
+
57
+ it "should look up the destination" do
58
+ # expect
59
+ Destinations.should_receive(:lookup).with(:test_queue_passed_in).and_return("/queue/foo")
60
+
61
+ # when
62
+ Consumer.delete(:test_queue_passed_in)
63
+ end
64
+
65
+ it "should delegate to the adapter" do
66
+ # expect
67
+ @adapter.should_receive(:delete).with("/queue/foo", {})
68
+
69
+ # when
70
+ Consumer.delete(:test_queue_passed_in)
71
+ end
72
+ end
73
+
74
+ describe ".receive" do
75
+
76
+ def when_receiving
77
+ yield if block_given?
78
+ Consumer.receive(:test_queue_passed_in, {:persistent => false})
79
+ end
80
+
81
+ it "should look up the destination" do
82
+ when_receiving {
83
+ Destinations.should_receive(:lookup).with(:test_queue_passed_in).and_return("/queue/foo")
84
+ }
85
+ end
86
+
87
+ it "should pass destination and options to adapter" do
88
+ when_receiving {
89
+ @adapter.should_receive(:receive_once).with("/queue/foo", {:persistent => false}).and_return(@message)
90
+ }
91
+ end
92
+
93
+ it "should return the body of the message received" do
94
+ Consumer.receive(:test_queue, {:persistent => false}).should == @message.body
95
+ end
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe String do
4
+ describe "#camelize" do
5
+ it "should have code examples"
6
+ end
7
+
8
+ describe "#classify" do
9
+ it "should have code examples"
10
+ end
11
+
12
+ describe "#underscore" do
13
+ it "should have code examples"
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module RosettaQueue
4
+
5
+ describe Destinations do
6
+
7
+ before(:each) do
8
+ Destinations.clear
9
+ end
10
+
11
+ after(:each) do
12
+ Destinations.clear
13
+ end
14
+
15
+ it "should map destination to hash" do
16
+
17
+ Destinations.define do |queue|
18
+ queue.map :test_queue, "/queue/test_queue"
19
+ end
20
+
21
+ Destinations.lookup(:test_queue).should == "/queue/test_queue"
22
+ end
23
+
24
+ it "#queue_names should return an array of the actuual queue names" do
25
+ Destinations.define do |queue|
26
+ queue.map :foo, "/queue/foo"
27
+ queue.map :bar, "/queue/bar"
28
+ end
29
+
30
+ Destinations.queue_names.should include("/queue/foo")
31
+ Destinations.queue_names.should include("/queue/bar")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module RosettaQueue
4
+
5
+ describe Filters do
6
+
7
+ after(:each) do
8
+ Filters.reset
9
+ end
10
+
11
+ describe "#process_receiving" do
12
+ it "should process the passed in message with the defined receiving filter" do
13
+ Filters.define do |f|
14
+ f.receiving {|message| "Foo #{message}"}
15
+ end
16
+
17
+ Filters.process_receiving("Bar").should == "Foo Bar"
18
+ end
19
+
20
+ it "should return the same message when no filter is defined" do
21
+ Filters.process_receiving("Bar").should == "Bar"
22
+ end
23
+ end
24
+
25
+
26
+ describe "#process_sending" do
27
+ it "should process the passed in message with the defined sending filter" do
28
+ Filters.define do |f|
29
+ f.sending {|message| "Foo #{message}"}
30
+ end
31
+
32
+ Filters.process_sending("Bar").should == "Foo Bar"
33
+ end
34
+
35
+ it "should return the same message when no filter is defined" do
36
+ Filters.process_sending("Bar").should == "Bar"
37
+ end
38
+ end
39
+
40
+
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module RosettaQueue
4
+
5
+ class TestProducer < Producer
6
+
7
+ publishes_to :test_queue
8
+ options :persistent => false
9
+
10
+ end
11
+
12
+ describe Producer do
13
+
14
+ before(:each) do
15
+ @adapter = mock("adapter", :send_message => nil)
16
+ RosettaQueue::Adapter.stub!(:instance).and_return(@adapter)
17
+ @gateway = TestProducer.new
18
+
19
+ Destinations.stub!(:lookup).and_return("/queue/test_queue")
20
+ end
21
+
22
+ it_should_behave_like "a messaging gateway object"
23
+ attr_reader :adapter, :gateway
24
+
25
+
26
+ describe "#publish" do
27
+
28
+ before(:each) do
29
+ @adapter = mock("adpater", :send_message => nil)
30
+ RosettaQueue::Adapter.stub!(:instance).and_return(@adapter)
31
+ end
32
+
33
+ # it "should look up the destination defined on the class" do
34
+ # Destinations.should_receive(:lookup).with(:test_queue).and_return("/queue/test_queue")
35
+ # # when
36
+ # @gateway.publish('some message')
37
+ # end
38
+
39
+ it "should publish messages to queue with the options defined in the class" do
40
+ # TO DO: REFACTOR #publish METHOD SO THAT YOU PASS IN MESSAGE HANDLER AS WITH CONSUMER
41
+ pending
42
+ # expect
43
+ @adapter.should_receive(:send_message).with("/queue/test_queue", "Hello World!", {:persistent => false})
44
+ # when
45
+ @gateway.publish("Hello World!")
46
+ end
47
+
48
+ end
49
+
50
+ describe ".publish" do
51
+ # it "should look up the destination defined on the class" do
52
+ # Destinations.should_receive(:lookup).with(:test_queue).and_return("/queue/test_queue")
53
+ # # when
54
+ # Producer.publish(:test_queue, "blah")
55
+ # end
56
+
57
+ it "should send the message to the adpater along with the options" do
58
+ # expect
59
+ @adapter.should_receive(:send_message).with("/queue/test_queue", "Hello World!", {:persistent => true})
60
+ # when
61
+ Producer.publish(:test_queue, "Hello World!", {:persistent => true})
62
+ end
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,21 @@
1
+ module RosettaQueue
2
+
3
+ describe "a messaging gateway object", :shared => true do
4
+
5
+ it "#unsubscribe should be delegated to the adapter" do
6
+ pending
7
+ # expect
8
+ adapter.should_receive("unsubscribe")
9
+ # when
10
+ gateway.unsubscribe
11
+ end
12
+
13
+ it "#disconnect should be delegated to the adapter" do
14
+ # expect
15
+ adapter.should_receive("disconnect")
16
+ # when
17
+ gateway.disconnect
18
+ end
19
+
20
+ end
21
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --loadby
3
+ mtime
4
+ --reverse
@@ -0,0 +1,47 @@
1
+ ENV["MESSAGING_ENV"] = "test"
2
+
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'ruby-debug'
6
+
7
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
8
+ require 'rosetta_queue'
9
+ require 'rosetta_queue/adapters/null'
10
+ require 'rosetta_queue/adapters/fake'
11
+ require 'rosetta_queue/adapters/stomp'
12
+ require 'rosetta_queue/adapters/amqp'
13
+ require 'rosetta_queue/consumer_managers/base'
14
+ require 'rosetta_queue/consumer_managers/evented'
15
+ require 'rosetta_queue/consumer_managers/threaded'
16
+ require 'rosetta_queue/spec_helpers'
17
+ require 'rosetta_queue/consumer_managers/base'
18
+ require 'rosetta_queue/consumer_managers/evented'
19
+ require 'rosetta_queue/consumer_managers/threaded'
20
+ require File.dirname(__FILE__) + '/rosetta_queue/shared_messaging_behavior.rb'
21
+
22
+ class NullLogger
23
+ def info(*args); end
24
+ def debug(*args); end
25
+ def fatal(*args); end
26
+ def error(*args); end
27
+ def warn(*args); end
28
+ end
29
+
30
+ RosettaQueue.logger = NullLogger.new
31
+
32
+ alias :running :lambda
33
+
34
+ [:process, :receiving_with_handler, :receiving_once, :publishing, :disconnecting, :receiving_single_exchange, :receiving_exchange, :receiving].each do |action|
35
+ eval %Q{
36
+ def before_#{action}
37
+ yield
38
+ do_#{action}
39
+ end
40
+ alias during_#{action} before_#{action}
41
+ alias when_#{action} before_#{action}
42
+ def after_#{action}
43
+ do_#{action}
44
+ yield
45
+ end
46
+ }
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cwyckoff-rosetta_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Mabey
@@ -10,57 +10,85 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-01-28 00:00:00 -08:00
13
+ date: 2009-08-26 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
17
17
  description: Messaging gateway API with adapters for many messaging systems available in Ruby. Messaging systems can be easily switched out with a small configuration change. Code for testing on the object and application level is also provided.
18
- email: ben@benmabey.com
18
+ email: cbwyckoff@gmail.com
19
19
  executables: []
20
20
 
21
21
  extensions: []
22
22
 
23
23
  extra_rdoc_files:
24
- - README.rdoc
25
24
  - MIT-LICENSE.txt
25
+ - README.rdoc
26
26
  files:
27
27
  - History.txt
28
28
  - MIT-LICENSE.txt
29
29
  - README.rdoc
30
+ - Rakefile
30
31
  - VERSION.yml
31
- - lib/rosetta_queue
32
+ - cucumber.yml
33
+ - features/filtering.feature
34
+ - features/messaging.feature
35
+ - features/step_definitions/common_messaging_steps.rb
36
+ - features/step_definitions/filtering_steps.rb
37
+ - features/step_definitions/point_to_point_steps.rb
38
+ - features/step_definitions/publish_subscribe_steps.rb
39
+ - features/support/env.rb
40
+ - features/support/sample_consumers.rb
41
+ - lib/rosetta_queue.rb
32
42
  - lib/rosetta_queue/adapter.rb
33
- - lib/rosetta_queue/adapters
43
+ - lib/rosetta_queue/adapters/amqp.rb
44
+ - lib/rosetta_queue/adapters/amqp_evented.rb
34
45
  - lib/rosetta_queue/adapters/amqp_synch.rb
35
46
  - lib/rosetta_queue/adapters/base.rb
47
+ - lib/rosetta_queue/adapters/beanstalk.rb
36
48
  - lib/rosetta_queue/adapters/fake.rb
37
49
  - lib/rosetta_queue/adapters/null.rb
38
50
  - lib/rosetta_queue/adapters/stomp.rb
39
51
  - lib/rosetta_queue/base.rb
40
52
  - lib/rosetta_queue/consumer.rb
41
- - lib/rosetta_queue/consumer_managers
42
53
  - lib/rosetta_queue/consumer_managers/base.rb
43
54
  - lib/rosetta_queue/consumer_managers/evented.rb
44
55
  - lib/rosetta_queue/consumer_managers/threaded.rb
56
+ - lib/rosetta_queue/core_ext/string.rb
57
+ - lib/rosetta_queue/core_ext/time.rb
45
58
  - lib/rosetta_queue/destinations.rb
46
59
  - lib/rosetta_queue/exceptions.rb
47
60
  - lib/rosetta_queue/filters.rb
48
61
  - lib/rosetta_queue/logger.rb
49
62
  - lib/rosetta_queue/message_handler.rb
50
63
  - lib/rosetta_queue/producer.rb
51
- - lib/rosetta_queue/spec_helpers
64
+ - lib/rosetta_queue/spec_helpers.rb
52
65
  - lib/rosetta_queue/spec_helpers/hash.rb
53
66
  - lib/rosetta_queue/spec_helpers/helpers.rb
54
67
  - lib/rosetta_queue/spec_helpers/publishing_matchers.rb
55
- - lib/rosetta_queue/spec_helpers.rb
56
- - lib/rosetta_queue.rb
57
- - Rakefile
58
- - cucumber.yml
59
- has_rdoc: true
60
- homepage: http://github.com/bmabey/rosetta_queue
68
+ - spec/rosetta_queue/adapter_spec.rb
69
+ - spec/rosetta_queue/adapters/amqp_synchronous_spec.rb
70
+ - spec/rosetta_queue/adapters/beanstalk_spec.rb
71
+ - spec/rosetta_queue/adapters/fake_spec.rb
72
+ - spec/rosetta_queue/adapters/null_spec.rb
73
+ - spec/rosetta_queue/adapters/shared_adapter_behavior.rb
74
+ - spec/rosetta_queue/adapters/shared_fanout_behavior.rb
75
+ - spec/rosetta_queue/adapters/stomp_spec.rb
76
+ - spec/rosetta_queue/consumer_managers/evented_spec.rb
77
+ - spec/rosetta_queue/consumer_managers/shared_manager_behavior.rb
78
+ - spec/rosetta_queue/consumer_managers/threaded_spec.rb
79
+ - spec/rosetta_queue/consumer_spec.rb
80
+ - spec/rosetta_queue/core_ext/string_spec.rb
81
+ - spec/rosetta_queue/destinations_spec.rb
82
+ - spec/rosetta_queue/filters_spec.rb
83
+ - spec/rosetta_queue/producer_spec.rb
84
+ - spec/rosetta_queue/shared_messaging_behavior.rb
85
+ - spec/spec.opts
86
+ - spec/spec_helper.rb
87
+ has_rdoc: false
88
+ homepage: http://github.com/cwyckoff/rosetta_queue
89
+ licenses:
61
90
  post_install_message:
62
91
  rdoc_options:
63
- - --inline-source
64
92
  - --charset=UTF-8
65
93
  require_paths:
66
94
  - lib
@@ -79,9 +107,30 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
107
  requirements: []
80
108
 
81
109
  rubyforge_project: rosetta-queue
82
- rubygems_version: 1.2.0
110
+ rubygems_version: 1.3.5
83
111
  signing_key:
84
- specification_version: 2
112
+ specification_version: 3
85
113
  summary: Messaging gateway API with adapters for many messaging systems available in Ruby.
86
- test_files: []
87
-
114
+ test_files:
115
+ - spec/rosetta_queue/adapter_spec.rb
116
+ - spec/rosetta_queue/adapters/amqp_synchronous_spec.rb
117
+ - spec/rosetta_queue/adapters/beanstalk_spec.rb
118
+ - spec/rosetta_queue/adapters/fake_spec.rb
119
+ - spec/rosetta_queue/adapters/null_spec.rb
120
+ - spec/rosetta_queue/adapters/shared_adapter_behavior.rb
121
+ - spec/rosetta_queue/adapters/shared_fanout_behavior.rb
122
+ - spec/rosetta_queue/adapters/stomp_spec.rb
123
+ - spec/rosetta_queue/consumer_managers/evented_spec.rb
124
+ - spec/rosetta_queue/consumer_managers/shared_manager_behavior.rb
125
+ - spec/rosetta_queue/consumer_managers/threaded_spec.rb
126
+ - spec/rosetta_queue/consumer_spec.rb
127
+ - spec/rosetta_queue/core_ext/string_spec.rb
128
+ - spec/rosetta_queue/destinations_spec.rb
129
+ - spec/rosetta_queue/filters_spec.rb
130
+ - spec/rosetta_queue/producer_spec.rb
131
+ - spec/rosetta_queue/shared_messaging_behavior.rb
132
+ - spec/spec_helper.rb
133
+ - examples/sample_amqp_consumer.rb
134
+ - examples/sample_amqp_fanout_consumer.rb
135
+ - examples/sample_amqp_fanout_producer.rb
136
+ - examples/sample_amqp_producer.rb