bunny 1.0.7 → 2.24.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.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +92 -87
  3. data/lib/amq/protocol/extensions.rb +2 -0
  4. data/lib/bunny/authentication/credentials_encoder.rb +2 -0
  5. data/lib/bunny/authentication/external_mechanism_encoder.rb +2 -0
  6. data/lib/bunny/authentication/plain_mechanism_encoder.rb +2 -0
  7. data/lib/bunny/channel.rb +485 -186
  8. data/lib/bunny/channel_id_allocator.rb +8 -4
  9. data/lib/bunny/concurrent/atomic_fixnum.rb +2 -0
  10. data/lib/bunny/concurrent/condition.rb +2 -0
  11. data/lib/bunny/concurrent/continuation_queue.rb +37 -13
  12. data/lib/bunny/concurrent/synchronized_sorted_set.rb +2 -0
  13. data/lib/bunny/consumer.rb +20 -13
  14. data/lib/bunny/consumer_tag_generator.rb +6 -2
  15. data/lib/bunny/consumer_work_pool.rb +37 -7
  16. data/lib/bunny/cruby/socket.rb +51 -22
  17. data/lib/bunny/cruby/ssl_socket.rb +68 -5
  18. data/lib/bunny/delivery_info.rb +3 -1
  19. data/lib/bunny/exceptions.rb +27 -4
  20. data/lib/bunny/exchange.rb +35 -29
  21. data/lib/bunny/framing.rb +2 -0
  22. data/lib/bunny/get_response.rb +85 -0
  23. data/lib/bunny/heartbeat_sender.rb +9 -6
  24. data/lib/bunny/message_properties.rb +2 -0
  25. data/lib/bunny/queue.rb +89 -41
  26. data/lib/bunny/reader_loop.rb +72 -28
  27. data/lib/bunny/return_info.rb +2 -0
  28. data/lib/bunny/session.rb +621 -225
  29. data/lib/bunny/socket.rb +7 -12
  30. data/lib/bunny/ssl_socket.rb +7 -12
  31. data/lib/bunny/test_kit.rb +15 -0
  32. data/lib/bunny/timeout.rb +3 -12
  33. data/lib/bunny/timestamp.rb +24 -0
  34. data/lib/bunny/transport.rb +223 -98
  35. data/lib/bunny/version.rb +2 -1
  36. data/lib/bunny/versioned_delivery_tag.rb +2 -0
  37. data/lib/bunny.rb +54 -8
  38. metadata +38 -224
  39. data/.gitignore +0 -22
  40. data/.rspec +0 -3
  41. data/.ruby-version +0 -1
  42. data/.travis.yml +0 -23
  43. data/.yardopts +0 -8
  44. data/ChangeLog.md +0 -1092
  45. data/Gemfile +0 -54
  46. data/LICENSE +0 -21
  47. data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
  48. data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
  49. data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
  50. data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
  51. data/benchmarks/channel_open.rb +0 -28
  52. data/benchmarks/mutex_and_monitor.rb +0 -42
  53. data/benchmarks/queue_declare.rb +0 -29
  54. data/benchmarks/queue_declare_and_bind.rb +0 -29
  55. data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
  56. data/benchmarks/synchronized_sorted_set.rb +0 -53
  57. data/benchmarks/write_vs_write_nonblock.rb +0 -49
  58. data/bin/ci/before_build.sh +0 -31
  59. data/bunny.gemspec +0 -40
  60. data/examples/connection/authentication_failure.rb +0 -16
  61. data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
  62. data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
  63. data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
  64. data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
  65. data/examples/connection/channel_level_exception.rb +0 -35
  66. data/examples/connection/disabled_automatic_recovery.rb +0 -34
  67. data/examples/connection/heartbeat.rb +0 -17
  68. data/examples/connection/manually_reconnecting_consumer.rb +0 -23
  69. data/examples/connection/manually_reconnecting_publisher.rb +0 -28
  70. data/examples/connection/unknown_host.rb +0 -16
  71. data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
  72. data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
  73. data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
  74. data/examples/guides/exchanges/mandatory_messages.rb +0 -30
  75. data/examples/guides/extensions/alternate_exchange.rb +0 -28
  76. data/examples/guides/extensions/basic_nack.rb +0 -33
  77. data/examples/guides/extensions/connection_blocked.rb +0 -35
  78. data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
  79. data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
  80. data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
  81. data/examples/guides/extensions/per_message_ttl.rb +0 -36
  82. data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
  83. data/examples/guides/extensions/publisher_confirms.rb +0 -28
  84. data/examples/guides/extensions/queue_lease.rb +0 -26
  85. data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
  86. data/examples/guides/getting_started/blabbr.rb +0 -27
  87. data/examples/guides/getting_started/hello_world.rb +0 -20
  88. data/examples/guides/getting_started/weathr.rb +0 -47
  89. data/examples/guides/queues/one_off_consumer.rb +0 -23
  90. data/examples/guides/queues/redeliveries.rb +0 -79
  91. data/lib/bunny/compatibility.rb +0 -24
  92. data/lib/bunny/concurrent/linked_continuation_queue.rb +0 -61
  93. data/lib/bunny/jruby/socket.rb +0 -40
  94. data/lib/bunny/jruby/ssl_socket.rb +0 -53
  95. data/lib/bunny/system_timer.rb +0 -20
  96. data/profiling/basic_publish/with_4K_messages.rb +0 -33
  97. data/repl +0 -3
  98. data/spec/compatibility/queue_declare_spec.rb +0 -44
  99. data/spec/compatibility/queue_declare_with_default_channel_spec.rb +0 -33
  100. data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -71
  101. data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -76
  102. data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -225
  103. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
  104. data/spec/higher_level_api/integration/basic_get_spec.rb +0 -48
  105. data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -79
  106. data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -89
  107. data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -29
  108. data/spec/higher_level_api/integration/basic_recover_spec.rb +0 -18
  109. data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -74
  110. data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
  111. data/spec/higher_level_api/integration/channel_close_spec.rb +0 -25
  112. data/spec/higher_level_api/integration/channel_flow_spec.rb +0 -21
  113. data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
  114. data/spec/higher_level_api/integration/confirm_select_spec.rb +0 -19
  115. data/spec/higher_level_api/integration/connection_spec.rb +0 -400
  116. data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -26
  117. data/spec/higher_level_api/integration/consistent_hash_exchange_spec.rb +0 -50
  118. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
  119. data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -52
  120. data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
  121. data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -204
  122. data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
  123. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
  124. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
  125. data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -31
  126. data/spec/higher_level_api/integration/merry_go_round_spec.rb +0 -85
  127. data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
  128. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
  129. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -77
  130. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -65
  131. data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
  132. data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -190
  133. data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
  134. data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
  135. data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
  136. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
  137. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
  138. data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -127
  139. data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
  140. data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
  141. data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
  142. data/spec/issues/issue100_spec.rb +0 -42
  143. data/spec/issues/issue141_spec.rb +0 -44
  144. data/spec/issues/issue78_spec.rb +0 -75
  145. data/spec/issues/issue83_spec.rb +0 -31
  146. data/spec/issues/issue97_attachment.json +0 -1
  147. data/spec/issues/issue97_spec.rb +0 -176
  148. data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -69
  149. data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -100
  150. data/spec/spec_helper.rb +0 -64
  151. data/spec/stress/channel_open_stress_spec.rb +0 -51
  152. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
  153. data/spec/stress/concurrent_consumers_stress_spec.rb +0 -69
  154. data/spec/stress/concurrent_publishers_stress_spec.rb +0 -57
  155. data/spec/stress/connection_open_close_spec.rb +0 -40
  156. data/spec/stress/long_running_consumer_spec.rb +0 -83
  157. data/spec/tls/cacert.pem +0 -18
  158. data/spec/tls/client_cert.pem +0 -18
  159. data/spec/tls/client_key.pem +0 -27
  160. data/spec/tls/server_cert.pem +0 -18
  161. data/spec/tls/server_key.pem +0 -27
  162. data/spec/unit/bunny_spec.rb +0 -15
  163. data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
  164. data/spec/unit/concurrent/condition_spec.rb +0 -82
  165. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
  166. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
  167. data/spec/unit/system_timer_spec.rb +0 -10
  168. data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -1,76 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Consumer, "#cancel" do
4
- let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close if connection.open?
12
- end
13
-
14
- context "with a non-blocking consumer" do
15
- let(:queue_name) { "bunny.queues.#{rand}" }
16
-
17
- it "cancels the consumer" do
18
- delivered_data = []
19
-
20
- t = Thread.new do
21
- ch = connection.create_channel
22
- q = ch.queue(queue_name, :auto_delete => true, :durable => false)
23
- consumer = q.subscribe(:block => false) do |_, _, payload|
24
- delivered_data << payload
25
- end
26
-
27
- consumer.consumer_tag.should_not be_nil
28
- cancel_ok = consumer.cancel
29
- cancel_ok.consumer_tag.should == consumer.consumer_tag
30
-
31
- ch.close
32
- end
33
- t.abort_on_exception = true
34
- sleep 0.5
35
-
36
- ch = connection.create_channel
37
- ch.default_exchange.publish("", :routing_key => queue_name)
38
-
39
- sleep 0.7
40
- delivered_data.should be_empty
41
- end
42
- end
43
-
44
-
45
- context "with a blocking consumer" do
46
- let(:queue_name) { "bunny.queues.#{rand}" }
47
-
48
- it "cancels the consumer" do
49
- delivered_data = []
50
- consumer = nil
51
-
52
- t = Thread.new do
53
- ch = connection.create_channel
54
- q = ch.queue(queue_name, :auto_delete => true, :durable => false)
55
-
56
- consumer = Bunny::Consumer.new(ch, q)
57
- consumer.on_delivery do |_, _, payload|
58
- delivered_data << payload
59
- end
60
-
61
- q.subscribe_with(consumer, :block => false)
62
- end
63
- t.abort_on_exception = true
64
- sleep 1.0
65
-
66
- consumer.cancel
67
- sleep 1.0
68
-
69
- ch = connection.create_channel
70
- ch.default_exchange.publish("", :routing_key => queue_name)
71
-
72
- sleep 0.7
73
- delivered_data.should be_empty
74
- end
75
- end
76
- end
@@ -1,225 +0,0 @@
1
- require "spec_helper"
2
- require "set"
3
-
4
- describe Bunny::Queue, "#subscribe" do
5
- let(:connection) do
6
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
7
- c.start
8
- c
9
- end
10
-
11
- after :each do
12
- connection.close if connection.open?
13
- end
14
-
15
- context "with automatic acknowledgement mode" do
16
- let(:queue_name) { "bunny.basic_consume#{rand}" }
17
-
18
- it "registers the consumer" do
19
- delivered_keys = []
20
- delivered_data = []
21
-
22
- t = Thread.new do
23
- ch = connection.create_channel
24
- q = ch.queue(queue_name, :auto_delete => true, :durable => false)
25
- q.subscribe(:exclusive => false, :manual_ack => false) do |delivery_info, properties, payload|
26
- delivered_keys << delivery_info.routing_key
27
- delivered_data << payload
28
- end
29
- end
30
- t.abort_on_exception = true
31
- sleep 0.5
32
-
33
- ch = connection.create_channel
34
- x = ch.default_exchange
35
- x.publish("hello", :routing_key => queue_name)
36
-
37
- sleep 0.7
38
- delivered_keys.should include(queue_name)
39
- delivered_data.should include("hello")
40
-
41
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
42
-
43
- ch.close
44
- end
45
-
46
- context "with a single consumer" do
47
- let(:queue_name) { "bunny.basic_consume#{rand}" }
48
-
49
- it "provides delivery tag access" do
50
- delivery_tags = SortedSet.new
51
-
52
- cch = connection.create_channel
53
- q = cch.queue(queue_name, :auto_delete => true, :durable => false)
54
- q.subscribe(:exclusive => false, :manual_ack => false) do |delivery_info, properties, payload|
55
- delivery_tags << delivery_info.delivery_tag
56
- end
57
- sleep 0.5
58
-
59
- ch = connection.create_channel
60
- x = ch.default_exchange
61
- 100.times do
62
- x.publish("hello", :routing_key => queue_name)
63
- end
64
-
65
- sleep 1.0
66
- delivery_tags.should == SortedSet.new(Range.new(1, 100).to_a)
67
-
68
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
69
-
70
- ch.close
71
- end
72
- end
73
-
74
-
75
- context "with multiple consumers on the same channel" do
76
- let(:queue_name) { "bunny.basic_consume#{rand}" }
77
-
78
- it "provides delivery tag access" do
79
- delivery_tags = SortedSet.new
80
-
81
- cch = connection.create_channel
82
- q = cch.queue(queue_name, :auto_delete => true, :durable => false)
83
-
84
- 7.times do
85
- q.subscribe(:exclusive => false, :manual_ack => false) do |delivery_info, properties, payload|
86
- delivery_tags << delivery_info.delivery_tag
87
- end
88
- end
89
- sleep 1.0
90
-
91
- ch = connection.create_channel
92
- x = ch.default_exchange
93
- 100.times do
94
- x.publish("hello", :routing_key => queue_name)
95
- end
96
-
97
- sleep 1.5
98
- delivery_tags.should == SortedSet.new(Range.new(1, 100).to_a)
99
-
100
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
101
-
102
- ch.close
103
- end
104
- end
105
- end
106
-
107
- context "with manual acknowledgement mode" do
108
- let(:queue_name) { "bunny.basic_consume#{rand}" }
109
-
110
- it "register a consumer with manual acknowledgements mode" do
111
- delivered_keys = []
112
- delivered_data = []
113
-
114
- t = Thread.new do
115
- ch = connection.create_channel
116
- q = ch.queue(queue_name, :auto_delete => true, :durable => false)
117
- q.subscribe(:exclusive => false, :manual_ack => true) do |delivery_info, properties, payload|
118
- delivered_keys << delivery_info.routing_key
119
- delivered_data << payload
120
-
121
- ch.ack(delivery_info.delivery_tag)
122
- end
123
- end
124
- t.abort_on_exception = true
125
- sleep 0.5
126
-
127
- ch = connection.create_channel
128
- x = ch.default_exchange
129
- x.publish("hello", :routing_key => queue_name)
130
-
131
- sleep 0.7
132
- delivered_keys.should include(queue_name)
133
- delivered_data.should include("hello")
134
-
135
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
136
-
137
- ch.close
138
- end
139
- end
140
-
141
- ENV.fetch("RUNS", 20).to_i.times do |i|
142
- context "with a queue that already has messages (take #{i})" do
143
- let(:queue_name) { "bunny.basic_consume#{rand}" }
144
-
145
- it "registers the consumer" do
146
- delivered_keys = []
147
- delivered_data = []
148
-
149
- ch = connection.create_channel
150
- q = ch.queue(queue_name, :auto_delete => true, :durable => false)
151
- x = ch.default_exchange
152
- 100.times do
153
- x.publish("hello", :routing_key => queue_name)
154
- end
155
-
156
- sleep 0.7
157
- q.message_count.should be > 50
158
-
159
- t = Thread.new do
160
- ch = connection.create_channel
161
- q = ch.queue(queue_name, :auto_delete => true, :durable => false)
162
- q.subscribe(:exclusive => false, :manual_ack => false) do |delivery_info, properties, payload|
163
- delivered_keys << delivery_info.routing_key
164
- delivered_data << payload
165
- end
166
- end
167
- t.abort_on_exception = true
168
- sleep 0.5
169
-
170
- delivered_keys.should include(queue_name)
171
- delivered_data.should include("hello")
172
-
173
- ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
174
-
175
- ch.close
176
- end
177
- end
178
- end # 20.times
179
-
180
-
181
- context "after consumer pool has already been shut down" do
182
- let(:queue_name) { "bunny.basic_consume#{rand}" }
183
-
184
- it "registers the consumer" do
185
- delivered_keys = []
186
- delivered_data = []
187
-
188
- t = Thread.new do
189
- ch = connection.create_channel
190
- q = ch.queue(queue_name)
191
-
192
- c1 = q.subscribe(:exclusive => false, :manual_ack => false, :block => false) do |delivery_info, properties, payload|
193
- end
194
- c1.cancel
195
-
196
- c2 = q.subscribe(:exclusive => false, :manual_ack => false, :block => false) do |delivery_info, properties, payload|
197
- delivered_keys << delivery_info.routing_key
198
- delivered_data << payload
199
- end
200
- c2.cancel
201
-
202
- q.subscribe(:exclusive => false, :manual_ack => false, :block => true) do |delivery_info, properties, payload|
203
- delivered_keys << delivery_info.routing_key
204
- delivered_data << payload
205
- end
206
- end
207
- t.abort_on_exception = true
208
- sleep 0.5
209
-
210
- ch = connection.create_channel
211
- x = ch.default_exchange
212
- x.publish("hello", :routing_key => queue_name)
213
-
214
- sleep 0.7
215
- delivered_keys.should include(queue_name)
216
- delivered_data.should include("hello")
217
-
218
- ch.queue(queue_name).message_count.should == 0
219
-
220
- ch.queue_delete(queue_name)
221
- ch.close
222
- end
223
- end
224
-
225
- end # describe
@@ -1,54 +0,0 @@
1
- require "spec_helper"
2
- require "set"
3
-
4
- describe Bunny::Queue, "#subscribe_with" do
5
- let(:connection) do
6
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
7
- c.start
8
- c
9
- end
10
-
11
- after :each do
12
- connection.close if connection.open?
13
- end
14
-
15
- context "with explicit acknowledgements mode" do
16
- class ExampleConsumer < Bunny::Consumer
17
- def cancelled?
18
- @cancelled
19
- end
20
-
21
- def handle_cancellation(_)
22
- @cancelled = true
23
- end
24
-
25
- def call(delivery_info, metadata, payload)
26
- # no-op
27
- end
28
- end
29
-
30
- # demonstrates that manual acknowledgement mode is actually
31
- # used. MK.
32
- it "requeues messages on channel closure" do
33
- ch1 = connection.create_channel
34
- ch2 = connection.create_channel
35
- q1 = ch1.queue("bunny.tests.consumer_object1", :exclusive => true)
36
- q2 = ch2.queue("bunny.tests.consumer_object1", :exclusive => true)
37
- ec = ExampleConsumer.new(ch1, q1, "", false)
38
- x = ch2.default_exchange
39
-
40
- t = Thread.new do
41
- 50.times do
42
- x.publish("hello", :routing_key => q2.name)
43
- end
44
- end
45
- t.abort_on_exception = true
46
-
47
- q1.subscribe_with(ec, :ack => true)
48
- sleep 2
49
- ch1.close
50
-
51
- q2.message_count.should == 50
52
- end
53
- end
54
- end
@@ -1,48 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Queue, "#pop" do
4
- let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed",
6
- :automatically_recover => false)
7
- c.start
8
- c
9
- end
10
-
11
- after :each do
12
- connection.close if connection.open?
13
- end
14
-
15
- context "with all defaults" do
16
- it "fetches a messages which is automatically acknowledged" do
17
- ch = connection.create_channel
18
-
19
- q = ch.queue("", :exclusive => true)
20
- x = ch.default_exchange
21
-
22
- x.publish("xyzzy", :routing_key => q.name)
23
-
24
- sleep(0.5)
25
- delivery_info, properties, content = q.pop
26
- content.should == "xyzzy"
27
- q.message_count.should == 0
28
-
29
- ch.close
30
- end
31
- end
32
-
33
-
34
- context "with an empty queue" do
35
- it "returns an empty response" do
36
- ch = connection.create_channel
37
-
38
- q = ch.queue("", :exclusive => true)
39
- q.purge
40
-
41
- _, _, content = q.pop
42
- content.should be_nil
43
- q.message_count.should == 0
44
-
45
- ch.close
46
- end
47
- end
48
- end
@@ -1,79 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Channel, "#nack" do
4
- let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close if connection.open?
12
- end
13
-
14
- subject do
15
- connection.create_channel
16
- end
17
-
18
- context "with requeue = false" do
19
- it "rejects a message" do
20
- q = subject.queue("bunny.basic.nack.with-requeue-false", :exclusive => true)
21
- x = subject.default_exchange
22
-
23
- x.publish("bunneth", :routing_key => q.name)
24
- sleep(0.5)
25
- q.message_count.should == 1
26
- delivery_info, _, content = q.pop(:ack => true)
27
-
28
- subject.nack(delivery_info.delivery_tag, false, false)
29
- sleep(0.5)
30
- q.message_count.should == 0
31
-
32
- subject.close
33
- end
34
- end
35
-
36
- context "with multiple = true" do
37
- it "rejects multiple messages" do
38
- q = subject.queue("bunny.basic.nack.with-requeue-true-multi-true", :exclusive => true)
39
- x = subject.default_exchange
40
-
41
- 3.times do
42
- x.publish("bunneth", :routing_key => q.name)
43
- end
44
- sleep(0.5)
45
- q.message_count.should == 3
46
- _, _, _ = q.pop(:ack => true)
47
- _, _, _ = q.pop(:ack => true)
48
- delivery_info, _, content = q.pop(:ack => true)
49
-
50
- subject.nack(delivery_info.delivery_tag, true, true)
51
- sleep(0.5)
52
- q.message_count.should == 3
53
-
54
- subject.close
55
- end
56
- end
57
-
58
-
59
- context "with an invalid (random) delivery tag" do
60
- it "causes a channel-level error" do
61
- q = subject.queue("bunny.basic.nack.unknown-delivery-tag", :exclusive => true)
62
- x = subject.default_exchange
63
-
64
- x.publish("bunneth", :routing_key => q.name)
65
- sleep(0.25)
66
- q.message_count.should == 1
67
- _, _, content = q.pop(:ack => true)
68
-
69
- subject.on_error do |ch, channel_close|
70
- @channel_close = channel_close
71
- end
72
- subject.nack(82, false, true)
73
-
74
- sleep 0.5
75
-
76
- @channel_close.reply_text.should == "PRECONDITION_FAILED - unknown delivery tag 82"
77
- end
78
- end
79
- end
@@ -1,89 +0,0 @@
1
- require "spec_helper"
2
-
3
- if RUBY_VERSION <= "1.9"
4
- describe "Publishing a message to the default exchange" do
5
- let(:connection) do
6
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
7
- c.start
8
- c
9
- end
10
-
11
- after :each do
12
- connection.close if connection.open?
13
- end
14
-
15
-
16
- context "with all default delivery and message properties" do
17
- it "routes messages to a queue with the same name as the routing key" do
18
- connection.should be_threaded
19
- ch = connection.create_channel
20
-
21
- q = ch.queue("", :exclusive => true)
22
- x = ch.default_exchange
23
-
24
- x.publish("xyzzy", :routing_key => q.name).
25
- publish("xyzzy", :routing_key => q.name).
26
- publish("xyzzy", :routing_key => q.name).
27
- publish("xyzzy", :routing_key => q.name)
28
-
29
- sleep(1)
30
- q.message_count.should == 4
31
-
32
- ch.close
33
- end
34
- end
35
-
36
-
37
- context "with all default delivery and message properties" do
38
- it "routes the messages and preserves all the metadata" do
39
- connection.should be_threaded
40
- ch = connection.create_channel
41
-
42
- q = ch.queue("", :exclusive => true)
43
- x = ch.default_exchange
44
-
45
- x.publish("xyzzy", :routing_key => q.name, :persistent => true)
46
-
47
- sleep(1)
48
- q.message_count.should == 1
49
-
50
- envelope, headers, payload = q.pop
51
-
52
- payload.should == "xyzzy"
53
-
54
- headers[:content_type].should == "application/octet-stream"
55
- headers[:delivery_mode].should == 2
56
- headers[:priority].should == 0
57
-
58
- ch.close
59
- end
60
- end
61
-
62
-
63
- context "with all default delivery and message properties on a single-threaded connection" do
64
- let(:connection) do
65
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :threaded => false)
66
- c.start
67
- c
68
- end
69
-
70
- it "routes messages to a queue with the same name as the routing key" do
71
- connection.should_not be_threaded
72
- ch = connection.create_channel
73
-
74
- q = ch.queue("", :exclusive => true)
75
- x = ch.default_exchange
76
-
77
- x.publish("xyzzy", :routing_key => q.name).
78
- publish("xyzzy", :routing_key => q.name).
79
- publish("xyzzy", :routing_key => q.name).
80
- publish("xyzzy", :routing_key => q.name)
81
-
82
- sleep(1)
83
- q.message_count.should == 4
84
-
85
- ch.close
86
- end
87
- end
88
- end
89
- end
@@ -1,29 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Channel, "#prefetch" do
4
- let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close
12
- end
13
-
14
- context "with a positive integer" do
15
- it "sets that prefetch level via basic.qos" do
16
- ch = connection.create_channel
17
- ch.prefetch(10).should be_instance_of(AMQ::Protocol::Basic::QosOk)
18
- end
19
- end
20
-
21
- context "with a negative integer" do
22
- it "raises an ArgumentError" do
23
- ch = connection.create_channel
24
- expect {
25
- ch.prefetch(-2)
26
- }.to raise_error(ArgumentError)
27
- end
28
- end
29
- end
@@ -1,18 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Channel, "#recover" do
4
- let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- subject do
11
- connection.create_channel
12
- end
13
-
14
- it "is supported" do
15
- subject.recover(true).should be_instance_of(AMQ::Protocol::Basic::RecoverOk)
16
- subject.recover(true).should be_instance_of(AMQ::Protocol::Basic::RecoverOk)
17
- end
18
- end
@@ -1,74 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Channel, "#reject" do
4
- let(:connection) do
5
- c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- after :each do
11
- connection.close if connection.open?
12
- end
13
-
14
- context "with requeue = true" do
15
- it "requeues a message" do
16
- ch = connection.create_channel
17
- q = ch.queue("bunny.basic.reject.manual-acks", :exclusive => true)
18
- x = ch.default_exchange
19
-
20
- x.publish("bunneth", :routing_key => q.name)
21
- sleep(0.5)
22
- q.message_count.should == 1
23
- delivery_info, _, _ = q.pop(:ack => true)
24
-
25
- ch.reject(delivery_info.delivery_tag, true)
26
- sleep(0.5)
27
- q.message_count.should == 1
28
-
29
- ch.close
30
- end
31
- end
32
-
33
- context "with requeue = false" do
34
- it "rejects a message" do
35
- ch = connection.create_channel
36
- q = ch.queue("bunny.basic.reject.with-requeue-false", :exclusive => true)
37
- x = ch.default_exchange
38
-
39
- x.publish("bunneth", :routing_key => q.name)
40
- sleep(0.5)
41
- q.message_count.should == 1
42
- delivery_info, _, _ = q.pop(:ack => true)
43
-
44
- ch.reject(delivery_info.delivery_tag, false)
45
- sleep(0.5)
46
- q.message_count.should == 0
47
-
48
- ch.close
49
- end
50
- end
51
-
52
-
53
- context "with an invalid (random) delivery tag" do
54
- it "causes a channel-level error" do
55
- ch = connection.create_channel
56
- q = ch.queue("bunny.basic.reject.unknown-delivery-tag", :exclusive => true)
57
- x = ch.default_exchange
58
-
59
- x.publish("bunneth", :routing_key => q.name)
60
- sleep(0.25)
61
- q.message_count.should == 1
62
- _, _, content = q.pop(:ack => true)
63
-
64
- ch.on_error do |ch, channel_close|
65
- @channel_close = channel_close
66
- end
67
- ch.reject(82, true)
68
-
69
- sleep 0.5
70
-
71
- @channel_close.reply_text.should == "PRECONDITION_FAILED - unknown delivery tag 82"
72
- end
73
- end
74
- end