bunny 0.6.3.rc2 → 0.7

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 (68) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +9 -0
  5. data/CHANGELOG +3 -0
  6. data/Gemfile +39 -0
  7. data/Gemfile.lock +34 -0
  8. data/LICENSE +5 -4
  9. data/README.textile +54 -0
  10. data/Rakefile +15 -13
  11. data/bunny.gemspec +42 -61
  12. data/examples/simple_08.rb +4 -2
  13. data/examples/simple_09.rb +4 -2
  14. data/examples/simple_ack_08.rb +3 -1
  15. data/examples/simple_ack_09.rb +3 -1
  16. data/examples/simple_consumer_08.rb +4 -2
  17. data/examples/simple_consumer_09.rb +4 -2
  18. data/examples/simple_fanout_08.rb +3 -1
  19. data/examples/simple_fanout_09.rb +3 -1
  20. data/examples/simple_headers_08.rb +5 -3
  21. data/examples/simple_headers_09.rb +5 -3
  22. data/examples/simple_publisher_08.rb +3 -1
  23. data/examples/simple_publisher_09.rb +3 -1
  24. data/examples/simple_topic_08.rb +5 -3
  25. data/examples/simple_topic_09.rb +5 -3
  26. data/ext/amqp-0.8.json +616 -0
  27. data/ext/amqp-0.9.1.json +388 -0
  28. data/ext/config.yml +4 -0
  29. data/ext/qparser.rb +463 -0
  30. data/lib/bunny.rb +88 -66
  31. data/lib/bunny/channel08.rb +38 -38
  32. data/lib/bunny/channel09.rb +37 -37
  33. data/lib/bunny/client08.rb +184 -206
  34. data/lib/bunny/client09.rb +277 -363
  35. data/lib/bunny/consumer.rb +35 -0
  36. data/lib/bunny/exchange08.rb +37 -41
  37. data/lib/bunny/exchange09.rb +106 -124
  38. data/lib/bunny/queue08.rb +216 -202
  39. data/lib/bunny/queue09.rb +256 -326
  40. data/lib/bunny/subscription08.rb +30 -29
  41. data/lib/bunny/subscription09.rb +84 -83
  42. data/lib/bunny/version.rb +5 -0
  43. data/lib/qrack/amq-client-url.rb +165 -0
  44. data/lib/qrack/channel.rb +19 -17
  45. data/lib/qrack/client.rb +152 -151
  46. data/lib/qrack/errors.rb +5 -0
  47. data/lib/qrack/protocol/protocol08.rb +132 -130
  48. data/lib/qrack/protocol/protocol09.rb +133 -131
  49. data/lib/qrack/protocol/spec08.rb +2 -0
  50. data/lib/qrack/protocol/spec09.rb +2 -0
  51. data/lib/qrack/qrack08.rb +7 -10
  52. data/lib/qrack/qrack09.rb +7 -10
  53. data/lib/qrack/queue.rb +27 -40
  54. data/lib/qrack/subscription.rb +102 -101
  55. data/lib/qrack/transport/buffer08.rb +266 -264
  56. data/lib/qrack/transport/buffer09.rb +268 -264
  57. data/lib/qrack/transport/frame08.rb +13 -11
  58. data/lib/qrack/transport/frame09.rb +9 -7
  59. data/spec/spec_08/bunny_spec.rb +48 -45
  60. data/spec/spec_08/connection_spec.rb +10 -7
  61. data/spec/spec_08/exchange_spec.rb +145 -143
  62. data/spec/spec_08/queue_spec.rb +161 -161
  63. data/spec/spec_09/bunny_spec.rb +46 -44
  64. data/spec/spec_09/connection_spec.rb +15 -8
  65. data/spec/spec_09/exchange_spec.rb +147 -145
  66. data/spec/spec_09/queue_spec.rb +182 -184
  67. metadata +60 -41
  68. data/README.rdoc +0 -66
@@ -1,12 +1,19 @@
1
+ # encoding: utf-8
2
+
1
3
  # connection_spec.rb
2
4
 
3
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
5
+ require "bunny"
4
6
 
5
7
  describe Bunny do
6
-
7
- it "should raise an error if the wrong user name or password is used" do
8
- b = Bunny.new(:spec => '0.9', :user => 'wrong')
9
- lambda { b.start}.should raise_error(Bunny::ProtocolError)
10
- end
11
-
12
- end
8
+
9
+ it "should raise an error if the wrong user name or password is used" do
10
+ b = Bunny.new(:spec => '0.9', :user => 'wrong')
11
+ lambda { b.start}.should raise_error(Bunny::ProtocolError)
12
+ end
13
+
14
+ it "should merge custom settings from AMQP URL with default settings" do
15
+ b = Bunny.new("amqp://tagadab", :spec => "0.9")
16
+ b.host.should eql("tagadab")
17
+ end
18
+
19
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # exchange_spec.rb
2
4
 
3
5
  # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
@@ -6,157 +8,157 @@
6
8
  # If this is not the case, please change the 'Bunny.new' call below to include
7
9
  # the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
8
10
 
9
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
11
+ require "bunny"
10
12
 
11
13
  describe 'Exchange' do
12
-
13
- before(:each) do
14
+
15
+ before(:each) do
14
16
  @b = Bunny.new(:spec => '09')
15
- @b.start
16
- end
17
-
18
- it "should raise an error if instantiated as non-existent type" do
19
- lambda { @b.exchange('bogus_ex', :type => :bogus) }.should raise_error(Bunny::ForcedConnectionCloseError)
20
- @b.status.should == :not_connected
21
- end
22
-
23
- it "should allow a default direct exchange to be instantiated by specifying :type" do
24
- exch = @b.exchange('amq.direct', :type => :direct)
25
- exch.should be_an_instance_of(Bunny::Exchange09)
26
- exch.name.should == 'amq.direct'
27
- exch.type.should == :direct
28
- @b.exchanges.has_key?('amq.direct').should be(true)
29
- end
30
-
31
- it "should allow a default direct exchange to be instantiated without specifying :type" do
32
- exch = @b.exchange('amq.direct')
33
- exch.should be_an_instance_of(Bunny::Exchange09)
34
- exch.name.should == 'amq.direct'
35
- exch.type.should == :direct
36
- @b.exchanges.has_key?('amq.direct').should be(true)
37
- end
38
-
39
- it "should allow a default fanout exchange to be instantiated without specifying :type" do
40
- exch = @b.exchange('amq.fanout')
41
- exch.should be_an_instance_of(Bunny::Exchange09)
42
- exch.name.should == 'amq.fanout'
43
- exch.type.should == :fanout
44
- @b.exchanges.has_key?('amq.fanout').should be(true)
45
- end
46
-
47
- it "should allow a default topic exchange to be instantiated without specifying :type" do
48
- exch = @b.exchange('amq.topic')
49
- exch.should be_an_instance_of(Bunny::Exchange09)
50
- exch.name.should == 'amq.topic'
51
- exch.type.should == :topic
52
- @b.exchanges.has_key?('amq.topic').should be(true)
53
- end
54
-
55
- it "should allow a default headers (amq.match) exchange to be instantiated without specifying :type" do
56
- exch = @b.exchange('amq.match')
57
- exch.should be_an_instance_of(Bunny::Exchange09)
58
- exch.name.should == 'amq.match'
59
- exch.type.should == :headers
60
- @b.exchanges.has_key?('amq.match').should be(true)
61
- end
62
-
63
- it "should allow a default headers (amq.headers) exchange to be instantiated without specifying :type" do
64
- exch = @b.exchange('amq.headers')
65
- exch.should be_an_instance_of(Bunny::Exchange09)
66
- exch.name.should == 'amq.headers'
67
- exch.type.should == :headers
68
- @b.exchanges.has_key?('amq.headers').should be(true)
69
- end
70
-
71
- it "should create an exchange as direct by default" do
72
- exch = @b.exchange('direct_defaultex')
73
- exch.should be_an_instance_of(Bunny::Exchange09)
74
- exch.name.should == 'direct_defaultex'
75
- exch.type.should == :direct
76
- @b.exchanges.has_key?('direct_defaultex').should be(true)
77
- end
78
-
79
- it "should be able to be instantiated as a direct exchange" do
80
- exch = @b.exchange('direct_exchange', :type => :direct)
81
- exch.should be_an_instance_of(Bunny::Exchange09)
82
- exch.name.should == 'direct_exchange'
83
- exch.type.should == :direct
84
- @b.exchanges.has_key?('direct_exchange').should be(true)
85
- end
86
-
87
- it "should be able to be instantiated as a topic exchange" do
88
- exch = @b.exchange('topic_exchange', :type => :topic)
89
- exch.should be_an_instance_of(Bunny::Exchange09)
90
- exch.name.should == 'topic_exchange'
91
- exch.type.should == :topic
92
- @b.exchanges.has_key?('topic_exchange').should be(true)
93
- end
94
-
95
- it "should be able to be instantiated as a fanout exchange" do
96
- exch = @b.exchange('fanout_exchange', :type => :fanout)
97
- exch.should be_an_instance_of(Bunny::Exchange09)
98
- exch.name.should == 'fanout_exchange'
99
- exch.type.should == :fanout
100
- @b.exchanges.has_key?('fanout_exchange').should be(true)
101
- end
102
-
103
- it "should be able to be instantiated as a headers exchange" do
104
- exch = @b.exchange('headers_exchange', :type => :headers)
105
- exch.should be_an_instance_of(Bunny::Exchange09)
106
- exch.name.should == 'headers_exchange'
107
- exch.type.should == :headers
108
- @b.exchanges.has_key?('headers_exchange').should be(true)
109
- end
110
-
111
- it "should ignore the :nowait option when instantiated" do
112
- exch = @b.exchange('direct2_exchange', :nowait => true)
113
- end
114
-
115
- it "should be able to publish a message" do
116
- exch = @b.exchange('direct_exchange')
117
- exch.publish('This is a published message')
118
- end
17
+ @b.start
18
+ end
19
+
20
+ it "should raise an error if instantiated as non-existent type" do
21
+ lambda { @b.exchange('bogus_ex', :type => :bogus) }.should raise_error(Bunny::ForcedConnectionCloseError)
22
+ @b.status.should == :not_connected
23
+ end
24
+
25
+ it "should allow a default direct exchange to be instantiated by specifying :type" do
26
+ exch = @b.exchange('amq.direct', :type => :direct)
27
+ exch.should be_an_instance_of(Bunny::Exchange09)
28
+ exch.name.should == 'amq.direct'
29
+ exch.type.should == :direct
30
+ @b.exchanges.has_key?('amq.direct').should be(true)
31
+ end
32
+
33
+ it "should allow a default direct exchange to be instantiated without specifying :type" do
34
+ exch = @b.exchange('amq.direct')
35
+ exch.should be_an_instance_of(Bunny::Exchange09)
36
+ exch.name.should == 'amq.direct'
37
+ exch.type.should == :direct
38
+ @b.exchanges.has_key?('amq.direct').should be(true)
39
+ end
40
+
41
+ it "should allow a default fanout exchange to be instantiated without specifying :type" do
42
+ exch = @b.exchange('amq.fanout')
43
+ exch.should be_an_instance_of(Bunny::Exchange09)
44
+ exch.name.should == 'amq.fanout'
45
+ exch.type.should == :fanout
46
+ @b.exchanges.has_key?('amq.fanout').should be(true)
47
+ end
48
+
49
+ it "should allow a default topic exchange to be instantiated without specifying :type" do
50
+ exch = @b.exchange('amq.topic')
51
+ exch.should be_an_instance_of(Bunny::Exchange09)
52
+ exch.name.should == 'amq.topic'
53
+ exch.type.should == :topic
54
+ @b.exchanges.has_key?('amq.topic').should be(true)
55
+ end
56
+
57
+ it "should allow a default headers (amq.match) exchange to be instantiated without specifying :type" do
58
+ exch = @b.exchange('amq.match')
59
+ exch.should be_an_instance_of(Bunny::Exchange09)
60
+ exch.name.should == 'amq.match'
61
+ exch.type.should == :headers
62
+ @b.exchanges.has_key?('amq.match').should be(true)
63
+ end
64
+
65
+ it "should allow a default headers (amq.headers) exchange to be instantiated without specifying :type" do
66
+ exch = @b.exchange('amq.headers')
67
+ exch.should be_an_instance_of(Bunny::Exchange09)
68
+ exch.name.should == 'amq.headers'
69
+ exch.type.should == :headers
70
+ @b.exchanges.has_key?('amq.headers').should be(true)
71
+ end
72
+
73
+ it "should create an exchange as direct by default" do
74
+ exch = @b.exchange('direct_defaultex')
75
+ exch.should be_an_instance_of(Bunny::Exchange09)
76
+ exch.name.should == 'direct_defaultex'
77
+ exch.type.should == :direct
78
+ @b.exchanges.has_key?('direct_defaultex').should be(true)
79
+ end
80
+
81
+ it "should be able to be instantiated as a direct exchange" do
82
+ exch = @b.exchange('direct_exchange', :type => :direct)
83
+ exch.should be_an_instance_of(Bunny::Exchange09)
84
+ exch.name.should == 'direct_exchange'
85
+ exch.type.should == :direct
86
+ @b.exchanges.has_key?('direct_exchange').should be(true)
87
+ end
88
+
89
+ it "should be able to be instantiated as a topic exchange" do
90
+ exch = @b.exchange('topic_exchange', :type => :topic)
91
+ exch.should be_an_instance_of(Bunny::Exchange09)
92
+ exch.name.should == 'topic_exchange'
93
+ exch.type.should == :topic
94
+ @b.exchanges.has_key?('topic_exchange').should be(true)
95
+ end
96
+
97
+ it "should be able to be instantiated as a fanout exchange" do
98
+ exch = @b.exchange('fanout_exchange', :type => :fanout)
99
+ exch.should be_an_instance_of(Bunny::Exchange09)
100
+ exch.name.should == 'fanout_exchange'
101
+ exch.type.should == :fanout
102
+ @b.exchanges.has_key?('fanout_exchange').should be(true)
103
+ end
104
+
105
+ it "should be able to be instantiated as a headers exchange" do
106
+ exch = @b.exchange('headers_exchange', :type => :headers)
107
+ exch.should be_an_instance_of(Bunny::Exchange09)
108
+ exch.name.should == 'headers_exchange'
109
+ exch.type.should == :headers
110
+ @b.exchanges.has_key?('headers_exchange').should be(true)
111
+ end
112
+
113
+ it "should ignore the :nowait option when instantiated" do
114
+ exch = @b.exchange('direct2_exchange', :nowait => true)
115
+ end
116
+
117
+ it "should be able to publish a message" do
118
+ exch = @b.exchange('direct_exchange')
119
+ exch.publish('This is a published message')
120
+ end
119
121
 
120
122
  it "should not modify the passed options hash when publishing a message" do
121
- exch = @b.exchange('direct_exchange')
123
+ exch = @b.exchange('direct_exchange')
122
124
  opts = {:key => 'a', :persistent => true}
123
- exch.publish('', opts)
125
+ exch.publish('', opts)
124
126
  opts.should == {:key => 'a', :persistent => true}
125
127
  end
126
-
127
- it "should be able to return an undeliverable message" do
128
- exch = @b.exchange('return_exch')
129
- exch.publish('This message should be undeliverable', :immediate => true)
130
- ret_msg = @b.returned_message
131
- ret_msg.should be_an_instance_of(Hash)
132
- ret_msg[:payload].should == 'This message should be undeliverable'
133
- end
134
-
135
- it "should be able to return a message that exceeds maximum frame size" do
136
- exch = @b.exchange('return_exch')
137
- lg_msg = 'z' * 142000
138
- exch.publish(lg_msg, :immediate => true)
139
- ret_msg = @b.returned_message
140
- ret_msg.should be_an_instance_of(Hash)
141
- ret_msg[:payload].should == lg_msg
142
- end
143
-
144
- it "should report an error if delete fails" do
145
- exch = @b.exchange('direct_exchange')
146
- lambda { exch.delete(:exchange => 'bogus_ex') }.should raise_error(Bunny::ForcedChannelCloseError)
147
- @b.channel.active.should == false
148
- end
149
-
150
- it "should be able to be deleted" do
151
- exch = @b.exchange('direct_exchange')
152
- res = exch.delete
153
- res.should == :delete_ok
154
- @b.exchanges.has_key?('direct_exchange').should be(false)
155
- end
156
-
157
- it "should ignore the :nowait option when deleted" do
158
- exch = @b.exchange('direct2_exchange')
159
- exch.delete(:nowait => true)
160
- end
161
-
128
+
129
+ it "should be able to return an undeliverable message" do
130
+ exch = @b.exchange('return_exch')
131
+ exch.publish('This message should be undeliverable', :immediate => true)
132
+ ret_msg = @b.returned_message
133
+ ret_msg.should be_an_instance_of(Hash)
134
+ ret_msg[:payload].should == 'This message should be undeliverable'
135
+ end
136
+
137
+ it "should be able to return a message that exceeds maximum frame size" do
138
+ exch = @b.exchange('return_exch')
139
+ lg_msg = 'z' * 142000
140
+ exch.publish(lg_msg, :immediate => true)
141
+ ret_msg = @b.returned_message
142
+ ret_msg.should be_an_instance_of(Hash)
143
+ ret_msg[:payload].should == lg_msg
144
+ end
145
+
146
+ it "should report an error if delete fails" do
147
+ exch = @b.exchange('direct_exchange')
148
+ lambda { exch.delete(:exchange => 'bogus_ex') }.should raise_error(Bunny::ForcedChannelCloseError)
149
+ @b.channel.active.should == false
150
+ end
151
+
152
+ it "should be able to be deleted" do
153
+ exch = @b.exchange('direct_exchange')
154
+ res = exch.delete
155
+ res.should == :delete_ok
156
+ @b.exchanges.has_key?('direct_exchange').should be(false)
157
+ end
158
+
159
+ it "should ignore the :nowait option when deleted" do
160
+ exch = @b.exchange('direct2_exchange')
161
+ exch.delete(:nowait => true)
162
+ end
163
+
162
164
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # queue_spec.rb
2
4
 
3
5
  # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
@@ -6,151 +8,148 @@
6
8
  # If this is not the case, please change the 'Bunny.new' call below to include
7
9
  # the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
8
10
 
9
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
11
+ require "bunny"
10
12
 
11
13
  describe 'Queue' do
12
-
13
- before(:each) do
14
+
15
+ before(:each) do
14
16
  @b = Bunny.new(:spec => '09')
15
- @b.start
16
- end
17
-
18
- it "should ignore the :nowait option when instantiated" do
19
- q = @b.queue('test0', :nowait => true)
20
- end
21
-
22
- it "should ignore the :nowait option when binding to an exchange" do
23
- exch = @b.exchange('direct_exch')
24
- q = @b.queue('test0')
25
- q.bind(exch, :nowait => true).should == :bind_ok
26
- end
27
-
28
- it "should raise an error when trying to bind to a non-existent exchange" do
29
- q = @b.queue('test1')
30
- lambda {q.bind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
31
- @b.channel.active.should == false
32
- end
33
-
34
- it "should be able to bind to an existing exchange" do
35
- exch = @b.exchange('direct_exch')
36
- q = @b.queue('test1')
37
- q.bind(exch).should == :bind_ok
38
- end
39
-
40
- it "should ignore the :nowait option when unbinding from an existing exchange" do
41
- exch = @b.exchange('direct_exch')
42
- q = @b.queue('test0')
43
- q.unbind(exch, :nowait => true).should == :unbind_ok
44
- end
45
-
46
- it "should raise an error if unbinding from a non-existent exchange" do
47
- q = @b.queue('test1')
48
- lambda {q.unbind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
49
- @b.channel.active.should == false
50
- end
51
-
52
- it "should be able to unbind from an exchange" do
53
- exch = @b.exchange('direct_exch')
54
- q = @b.queue('test1')
55
- q.unbind(exch).should == :unbind_ok
56
- end
57
-
58
- it "should be able to publish a message" do
59
- q = @b.queue('test1')
60
- q.publish('This is a test message')
61
- q.message_count.should == 1
62
- end
63
-
64
- it "should be able to pop a message complete with header and delivery details" do
65
- q = @b.queue('test1')
66
- msg = q.pop()
67
- msg.should be_an_instance_of(Hash)
68
- msg[:header].should be_an_instance_of(Bunny::Protocol09::Header)
69
- msg[:payload].should == 'This is a test message'
70
- msg[:delivery_details].should be_an_instance_of(Hash)
71
- q.message_count.should == 0
72
- end
73
-
74
- it "should be able to pop a message and just get the payload" do
75
- q = @b.queue('test1')
76
- q.publish('This is another test message')
77
- msg = q.pop[:payload]
78
- msg.should == 'This is another test message'
79
- q.message_count.should == 0
80
- end
81
-
82
- it "should be able to pop a message where body length exceeds max frame size" do
83
- q = @b.queue('test1')
84
- lg_msg = 'z' * 142000
85
- q.publish(lg_msg)
86
- msg = q.pop[:payload]
87
- msg.should == lg_msg
88
- end
89
-
90
- it "should be able call a block when popping a message" do
91
- q = @b.queue('test1')
92
- q.publish('This is another test message')
93
- q.pop { |msg| msg[:payload].should == 'This is another test message' }
94
- q.pop { |msg| msg[:payload].should == :queue_empty }
95
- end
96
-
97
- it "should raise an error if purge fails" do
98
- q = @b.queue('test1')
99
- 5.times {q.publish('This is another test message')}
100
- q.message_count.should == 5
101
- lambda {q.purge(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
102
- end
103
-
104
- it "should be able to be purged to remove all of its messages" do
105
- q = @b.queue('test1')
106
- q.message_count.should == 5
107
- q.purge.should == :purge_ok
108
- q.message_count.should == 0
109
- end
110
-
111
- it "should return an empty message when popping an empty queue" do
112
- q = @b.queue('test1')
113
- q.publish('This is another test message')
114
- q.pop
115
- msg = q.pop[:payload]
116
- msg.should == :queue_empty
117
- end
118
-
119
- it "should stop subscription without processing messages if max specified is 0" do
120
- q = @b.queue('test1')
121
- 5.times {q.publish('Yet another test message')}
122
- q.message_count.should == 5
123
- q.subscribe(:message_max => 0)
124
- q.message_count.should == 5
125
- q.purge.should == :purge_ok
126
- end
127
-
128
- it "should stop subscription after processing number of messages specified > 0" do
129
- q = @b.queue('test1')
130
- 5.times {q.publish('Yet another test message')}
131
- q.message_count.should == 5
132
- q.subscribe(:message_max => 5)
133
- end
134
-
135
- it "should stop subscription after processing message_max messages < total in queue" do
136
- q = @b.queue('test1')
137
- @b.qos()
138
- 10.times {q.publish('Yet another test message')}
139
- q.message_count.should == 10
140
- q.subscribe(:message_max => 5, :ack => true)
141
- q.message_count.should == 5
142
- q.purge.should == :purge_ok
143
- end
144
-
145
- it "should raise an error when delete fails" do
146
- q = @b.queue('test1')
147
- lambda {q.delete(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
148
- @b.channel.active.should == false
149
- end
150
-
151
- it "should pass correct block parameters through on subscribe" do
152
- q = @b.queue('test1')
153
- q.publish("messages pop\'n")
17
+ @b.start
18
+
19
+ @default_exchange = @b.exchange("")
20
+ end
21
+
22
+ it "should ignore the :nowait option when instantiated" do
23
+ q = @b.queue('test0', :nowait => true)
24
+ end
25
+
26
+ it "should ignore the :nowait option when binding to an exchange" do
27
+ exch = @b.exchange('direct_exch')
28
+ q = @b.queue('test0')
29
+ q.bind(exch, :nowait => true).should == :bind_ok
30
+ end
31
+
32
+ it "should raise an error when trying to bind to a non-existent exchange" do
33
+ q = @b.queue('test1')
34
+ lambda {q.bind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
35
+ @b.channel.active.should == false
36
+ end
37
+
38
+ it "should be able to bind to an existing exchange" do
39
+ exch = @b.exchange('direct_exch')
40
+ q = @b.queue('test1')
41
+ q.bind(exch).should == :bind_ok
42
+ end
43
+
44
+ it "should ignore the :nowait option when unbinding from an existing exchange" do
45
+ exch = @b.exchange('direct_exch')
46
+ q = @b.queue('test0')
47
+ q.unbind(exch, :nowait => true).should == :unbind_ok
48
+ end
49
+
50
+ it "should raise an error if unbinding from a non-existent exchange" do
51
+ q = @b.queue('test1')
52
+ lambda {q.unbind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
53
+ @b.channel.active.should == false
54
+ end
55
+
56
+ it "should be able to unbind from an exchange" do
57
+ exch = @b.exchange('direct_exch')
58
+ q = @b.queue('test1')
59
+ q.unbind(exch).should == :unbind_ok
60
+ end
61
+
62
+ it "should be able to pop a message complete with header and delivery details" do
63
+ q = @b.queue('test1')
64
+ @default_exchange.publish('This is a test message', :key => 'test1')
65
+ msg = q.pop()
66
+ msg.should be_an_instance_of(Hash)
67
+ msg[:header].should be_an_instance_of(Bunny::Protocol09::Header)
68
+ msg[:payload].should == 'This is a test message'
69
+ msg[:delivery_details].should be_an_instance_of(Hash)
70
+ q.message_count.should == 0
71
+ end
72
+
73
+ it "should be able to pop a message and just get the payload" do
74
+ q = @b.queue('test1')
75
+ @default_exchange.publish('This is another test message', :key => 'test1')
76
+ msg = q.pop[:payload]
77
+ msg.should == 'This is another test message'
78
+ q.message_count.should == 0
79
+ end
80
+
81
+ it "should be able to pop a message where body length exceeds max frame size" do
82
+ q = @b.queue('test1')
83
+ lg_msg = 'z' * 142000
84
+ @default_exchange.publish(lg_msg, :key => 'test1')
85
+ msg = q.pop[:payload]
86
+ msg.should == lg_msg
87
+ end
88
+
89
+ it "should be able call a block when popping a message" do
90
+ q = @b.queue('test1')
91
+ @default_exchange.publish('This is another test message', :key => 'test1')
92
+ q.pop { |msg| msg[:payload].should == 'This is another test message' }
93
+ q.pop { |msg| msg[:payload].should == :queue_empty }
94
+ end
95
+
96
+ it "should raise an error if purge fails" do
97
+ q = @b.queue('test1')
98
+ 5.times { @default_exchange.publish('This is another test message', :key => 'test1') }
99
+ q.message_count.should == 5
100
+ lambda {q.purge(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
101
+ end
102
+
103
+ it "should be able to be purged to remove all of its messages" do
104
+ q = @b.queue('test1')
105
+ q.message_count.should == 5
106
+ q.purge.should == :purge_ok
107
+ q.message_count.should == 0
108
+ end
109
+
110
+ it "should return an empty message when popping an empty queue" do
111
+ q = @b.queue('test1')
112
+ @default_exchange.publish('This is another test message', :key => 'test1')
113
+ q.pop
114
+ msg = q.pop[:payload]
115
+ msg.should == :queue_empty
116
+ end
117
+
118
+ it "should stop subscription without processing messages if max specified is 0" do
119
+ q = @b.queue('test1')
120
+ 5.times { @default_exchange.publish('Yet another test message', :key => 'test1') }
121
+ q.message_count.should == 5
122
+ q.subscribe(:message_max => 0)
123
+ q.message_count.should == 5
124
+ q.purge.should == :purge_ok
125
+ end
126
+
127
+ it "should stop subscription after processing number of messages specified > 0" do
128
+ q = @b.queue('test1')
129
+ 5.times { @default_exchange.publish('Yet another test message', :key => 'test1') }
130
+ q.message_count.should == 5
131
+ q.subscribe(:message_max => 5)
132
+ end
133
+
134
+ it "should stop subscription after processing message_max messages < total in queue" do
135
+ q = @b.queue('test1')
136
+ @b.qos()
137
+ 10.times { @default_exchange.publish('Yet another test message', :key => 'test1') }
138
+ q.message_count.should == 10
139
+ q.subscribe(:message_max => 5, :ack => true)
140
+ q.message_count.should == 5
141
+ q.purge.should == :purge_ok
142
+ end
143
+
144
+ it "should raise an error when delete fails" do
145
+ q = @b.queue('test1')
146
+ lambda {q.delete(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
147
+ @b.channel.active.should == false
148
+ end
149
+
150
+ it "should pass correct block parameters through on subscribe" do
151
+ q = @b.queue('test1')
152
+ @default_exchange.publish("messages pop'n", :key => 'test1')
154
153
 
155
154
  q.subscribe do |msg|
156
155
  msg[:header].should be_an_instance_of Qrack::Protocol09::Header
@@ -158,48 +157,47 @@ describe 'Queue' do
158
157
  msg[:delivery_details].should_not be_nil
159
158
 
160
159
  q.unsubscribe
161
- break
160
+ break
161
+ end
162
+ end
163
+
164
+ it "should finish processing subscription messages if break is called in block" do
165
+ q = @b.queue('test1')
166
+ @default_exchange.publish('messages in my quezen', :key => 'test1')
167
+
168
+ q.subscribe do |msg|
169
+ msg[:payload].should == 'messages in my quezen'
170
+ q.unsubscribe
171
+ break
172
+ end
173
+
174
+ 5.times {|i| @default_exchange.publish("#{i}", :key => 'test1') }
175
+ q.subscribe do |msg|
176
+ if msg[:payload] == '4'
177
+ q.unsubscribe
178
+ break
179
+ end
162
180
  end
181
+ end
182
+
183
+ it "should be able to be deleted" do
184
+ q = @b.queue('test1')
185
+ res = q.delete
186
+ res.should == :delete_ok
187
+ @b.queues.has_key?('test1').should be(false)
188
+ end
189
+
190
+ it "should ignore the :nowait option when deleted" do
191
+ q = @b.queue('test0')
192
+ q.delete(:nowait => true)
193
+ end
194
+
195
+ it "should support server named queues" do
196
+ q = @b.queue
197
+ q.name.should_not == nil
198
+
199
+ @b.queue(q.name).should == q
200
+ q.delete
201
+ end
163
202
 
164
- end
165
-
166
- it "should finish processing subscription messages if break is called in block" do
167
- q = @b.queue('test1')
168
- q.publish('messages in my quezen')
169
-
170
- q.subscribe do |msg|
171
- msg[:payload].should == 'messages in my quezen'
172
- q.unsubscribe
173
- break
174
- end
175
-
176
- 5.times {|i| q.publish("#{i}")}
177
- q.subscribe do |msg|
178
- if msg[:payload] == '4'
179
- q.unsubscribe
180
- break
181
- end
182
- end
183
- end
184
-
185
- it "should be able to be deleted" do
186
- q = @b.queue('test1')
187
- res = q.delete
188
- res.should == :delete_ok
189
- @b.queues.has_key?('test1').should be(false)
190
- end
191
-
192
- it "should ignore the :nowait option when deleted" do
193
- q = @b.queue('test0')
194
- q.delete(:nowait => true)
195
- end
196
-
197
- it "should support server named queues" do
198
- q = @b.queue
199
- q.name.should_not == nil
200
-
201
- @b.queue(q.name).should == q
202
- q.delete
203
- end
204
-
205
203
  end