bunny 2.19.0 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -32
  3. data/lib/bunny/channel.rb +86 -10
  4. data/lib/bunny/consumer.rb +2 -2
  5. data/lib/bunny/delivery_info.rb +1 -1
  6. data/lib/bunny/queue.rb +33 -2
  7. data/lib/bunny/session.rb +1 -1
  8. data/lib/bunny/transport.rb +30 -1
  9. data/lib/bunny/version.rb +1 -1
  10. data/lib/bunny.rb +45 -4
  11. metadata +4 -144
  12. data/spec/config/enabled_plugins +0 -1
  13. data/spec/config/rabbitmq.conf +0 -13
  14. data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
  15. data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
  16. data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -357
  17. data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
  18. data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
  19. data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
  20. data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
  21. data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
  22. data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
  23. data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
  24. data/spec/higher_level_api/integration/channel_close_spec.rb +0 -66
  25. data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
  26. data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -483
  27. data/spec/higher_level_api/integration/connection_spec.rb +0 -589
  28. data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
  29. data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
  30. data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
  31. data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
  32. data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
  33. data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
  34. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
  35. data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
  36. data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
  37. data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
  38. data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
  39. data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
  40. data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
  41. data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
  42. data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -285
  43. data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
  44. data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
  45. data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
  46. data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
  47. data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
  48. data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -255
  49. data/spec/higher_level_api/integration/toxiproxy_spec.rb +0 -76
  50. data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
  51. data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
  52. data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
  53. data/spec/issues/issue100_spec.rb +0 -42
  54. data/spec/issues/issue141_spec.rb +0 -43
  55. data/spec/issues/issue202_spec.rb +0 -15
  56. data/spec/issues/issue224_spec.rb +0 -40
  57. data/spec/issues/issue465_spec.rb +0 -32
  58. data/spec/issues/issue549_spec.rb +0 -30
  59. data/spec/issues/issue609_spec.rb +0 -84
  60. data/spec/issues/issue78_spec.rb +0 -72
  61. data/spec/issues/issue83_spec.rb +0 -30
  62. data/spec/issues/issue97_attachment.json +0 -1
  63. data/spec/issues/issue97_spec.rb +0 -175
  64. data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
  65. data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
  66. data/spec/spec_helper.rb +0 -47
  67. data/spec/stress/channel_close_stress_spec.rb +0 -64
  68. data/spec/stress/channel_open_stress_spec.rb +0 -84
  69. data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
  70. data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
  71. data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
  72. data/spec/stress/connection_open_close_spec.rb +0 -52
  73. data/spec/stress/merry_go_round_spec.rb +0 -105
  74. data/spec/toxiproxy_helper.rb +0 -28
  75. data/spec/unit/bunny_spec.rb +0 -15
  76. data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
  77. data/spec/unit/concurrent/condition_spec.rb +0 -82
  78. data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
  79. data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
  80. data/spec/unit/exchange_recovery_spec.rb +0 -39
  81. data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -1,285 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Queue 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 "when queue name is specified" do
15
- let(:name) { "a queue declared at #{Time.now.to_i}" }
16
-
17
- it "declares a new queue with that name" do
18
- ch = connection.create_channel
19
-
20
- q = ch.queue(name)
21
- expect(q.name).to eq name
22
-
23
- q.delete
24
- ch.close
25
- end
26
-
27
- it "caches that queue" do
28
- ch = connection.create_channel
29
-
30
- q = ch.queue(name)
31
- expect(ch.queue(name).object_id).to eq q.object_id
32
-
33
- q.delete
34
- ch.close
35
- end
36
- end
37
-
38
-
39
- context "when queue name is passed as an empty string" do
40
- it "uses server-assigned queue name" do
41
- ch = connection.create_channel
42
-
43
- q = ch.queue("")
44
- expect(q.name).not_to be_empty
45
- expect(q.name).to match /^amq.gen.+/
46
- expect(q).to be_server_named
47
- q.delete
48
-
49
- ch.close
50
- end
51
- end
52
-
53
-
54
- context "when a nil is passed for queue name" do
55
- it "throws an error" do
56
- ch = connection.create_channel
57
-
58
- expect {
59
- ch.queue(nil, durable: true, auto_delete: false)
60
- }.to raise_error(ArgumentError)
61
- end
62
- end
63
-
64
-
65
- context "when queue is declared as durable" do
66
- it "declares it as durable" do
67
- ch = connection.create_channel
68
-
69
- q = ch.queue("bunny.tests.queues.durable", durable: true)
70
- expect(q).to be_durable
71
- expect(q).not_to be_auto_delete
72
- expect(q).not_to be_exclusive
73
- expect(q.arguments).to be_nil
74
- q.delete
75
-
76
- ch.close
77
- end
78
- end
79
-
80
-
81
- context "when queue is declared as exclusive" do
82
- it "declares it as exclusive" do
83
- ch = connection.create_channel
84
-
85
- q = ch.queue("bunny.tests.queues.exclusive", exclusive: true)
86
- expect(q).to be_exclusive
87
- expect(q).not_to be_durable
88
- q.delete
89
-
90
- ch.close
91
- end
92
- end
93
-
94
-
95
- context "when queue is declared as auto-delete" do
96
- it "declares it as auto-delete" do
97
- ch = connection.create_channel
98
-
99
- q = ch.queue("bunny.tests.queues.auto-delete", auto_delete: true)
100
- expect(q).to be_auto_delete
101
- expect(q).not_to be_exclusive
102
- expect(q).not_to be_durable
103
- q.delete
104
-
105
- ch.close
106
- end
107
- end
108
-
109
-
110
- context "when queue is declared with a mismatching auto-delete property value" do
111
- it "raises an exception" do
112
- ch = connection.create_channel
113
-
114
- q = ch.queue("bunny.tests.queues.auto-delete", auto_delete: true, durable: false)
115
- expect {
116
- # force re-declaration
117
- ch.queue_declare(q.name, auto_delete: false, durable: false)
118
- }.to raise_error(Bunny::PreconditionFailed)
119
-
120
- expect(ch).to be_closed
121
-
122
- cleanup_ch = connection.create_channel
123
- cleanup_ch.queue_delete(q.name)
124
- end
125
- end
126
-
127
- context "when queue is declared with a mismatching durable property value" do
128
- it "raises an exception" do
129
- ch = connection.create_channel
130
-
131
- q = ch.queue("bunny.tests.queues.durable", durable: true)
132
- expect {
133
- # force re-declaration
134
- ch.queue_declare(q.name, durable: false)
135
- }.to raise_error(Bunny::PreconditionFailed)
136
-
137
- expect(ch).to be_closed
138
-
139
- cleanup_ch = connection.create_channel
140
- cleanup_ch.queue_delete(q.name)
141
- end
142
- end
143
-
144
- context "when queue is declared with a mismatching exclusive property value" do
145
- it "raises an exception" do
146
- ch = connection.create_channel
147
-
148
- q = ch.queue("bunny.tests.queues.exclusive.#{rand}", exclusive: true)
149
- # when there's an exclusivity property mismatch, a different error
150
- # (405 RESOURCE_LOCKED) is used. This is a leaked queue exclusivity/ownership
151
- # implementation detail that's now basically a feature. MK.
152
- expect {
153
- # force re-declaration
154
- ch.queue_declare(q.name, exclusive: false)
155
- }.to raise_error(Bunny::ResourceLocked)
156
-
157
- expect(ch).to be_closed
158
- end
159
- end
160
-
161
- context "when queue is declared with a set of mismatching values" do
162
- it "raises an exception" do
163
- ch = connection.create_channel
164
-
165
- q = ch.queue("bunny.tests.queues.proprty-equivalence", auto_delete: true, durable: false)
166
- expect {
167
- # force re-declaration
168
- ch.queue_declare(q.name, auto_delete: false, durable: true)
169
- }.to raise_error(Bunny::PreconditionFailed)
170
-
171
- expect(ch).to be_closed
172
-
173
- cleanup_ch = connection.create_channel
174
- cleanup_ch.queue_delete(q.name)
175
- end
176
- end
177
-
178
-
179
- context "when queue is declared with message TTL" do
180
- let(:args) do
181
- # in ms
182
- {"x-message-ttl" => 1000}
183
- end
184
-
185
- it "causes all messages in it to have a TTL" do
186
- ch = connection.create_channel
187
-
188
- q = ch.queue("bunny.tests.queues.with-arguments.ttl", arguments: args, exclusive: true)
189
- expect(q.arguments).to eq args
190
-
191
- q.publish("xyzzy")
192
- sleep 0.1
193
-
194
- expect(q.message_count).to eq 1
195
- sleep 1.5
196
- expect(q.message_count).to eq 0
197
-
198
- ch.close
199
- end
200
- end
201
-
202
-
203
- context "when queue is declared with priorities" do
204
- let(:args) do
205
- {"x-max-priority" => 5}
206
- end
207
-
208
- it "enables priority implementation" do
209
- c = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
210
- c.start
211
-
212
- ch = c.create_channel
213
- ch.confirm_select
214
-
215
- q = ch.queue("bunny.tests.queues.with-arguments.priority #{rand}", arguments: args, exclusive: true)
216
- expect(q.arguments).to eq args
217
-
218
- q.publish("xyzzy")
219
- ch.wait_for_confirms
220
- sleep 0.1
221
-
222
- # this test only does sanity checking,
223
- # without trying to actually test prioritisation.
224
- #
225
- # added to guard against issues such as
226
- # https://github.com/rabbitmq/rabbitmq-server/issues/488
227
- expect(q.message_count).to eq 1
228
-
229
- ch.close
230
- end
231
- end
232
-
233
-
234
- describe "#queue_exists?" do
235
- context "when a queue exists" do
236
- it "returns true" do
237
- ch = connection.create_channel
238
- q = ch.queue("", exlusive: true)
239
-
240
- expect(connection.queue_exists?(q.name)).to eq true
241
- end
242
- end
243
-
244
- context "when a queue DOES NOT exist" do
245
- it "returns false" do
246
- expect(connection.queue_exists?("suf89u9a4jo3ndnakls##{Time.now.to_i}")).to eq false
247
- end
248
- end
249
- end
250
-
251
-
252
-
253
- unless ENV["CI"]
254
- # requires RabbitMQ 3.1+
255
- context "when queue is declared with bounded length" do
256
- let(:n) { 10 }
257
- let(:args) do
258
- # in ms
259
- {"x-max-length" => n}
260
- end
261
-
262
- # see http://www.rabbitmq.com/maxlength.html for more info
263
- it "causes the queue to be bounded" do
264
- ch = connection.create_channel
265
-
266
- q = ch.queue("bunny.tests.queues.with-arguments.max-length", arguments: args, exclusive: true)
267
- expect(q.arguments).to eq args
268
-
269
- (n * 10).times do
270
- q.publish("xyzzy")
271
- end
272
-
273
- expect(q.message_count).to eq n
274
- (n * 5).times do
275
- q.publish("xyzzy")
276
- end
277
-
278
- expect(q.message_count).to eq n
279
- q.delete
280
-
281
- ch.close
282
- end
283
- end
284
- end
285
- end
@@ -1,41 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Queue, "#delete" do
4
- let(:connection) do
5
- c = Bunny.new(username: "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
-
15
-
16
- context "with a name of an existing queue" do
17
- it "deletes that queue" do
18
- ch = connection.create_channel
19
- q = ch.queue("")
20
-
21
- q.delete
22
- # no exception as of RabbitMQ 3.2. MK.
23
- q.delete
24
-
25
- expect(ch.queues.size).to eq 0
26
- end
27
- end
28
-
29
-
30
- context "with a name of an existing queue" do
31
- it "DOES NOT raise an exception" do
32
- ch = connection.create_channel
33
-
34
- # no exception as of RabbitMQ 3.2. MK.
35
- ch.queue_delete("sdkhflsdjflskdjflsd#{rand}")
36
- ch.queue_delete("sdkhflsdjflskdjflsd#{rand}")
37
- ch.queue_delete("sdkhflsdjflskdjflsd#{rand}")
38
- ch.queue_delete("sdkhflsdjflskdjflsd#{rand}")
39
- end
40
- end
41
- end
@@ -1,30 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Queue do
4
- let(:connection) do
5
- c = Bunny.new(username: "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
-
15
- it "can be purged" do
16
- ch = connection.create_channel
17
-
18
- q = ch.queue("", exclusive: true)
19
- x = ch.default_exchange
20
-
21
- x.publish("xyzzy", routing_key: q.name)
22
- sleep(0.5)
23
-
24
- expect(q.message_count).to eq 1
25
- q.purge
26
- expect(q.message_count).to eq 0
27
-
28
- ch.close
29
- end
30
- end
@@ -1,54 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Queue, "bound to an exchange" do
4
- let(:connection) do
5
- c = Bunny.new(username: "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
-
15
- it "can be unbound from an exchange it was bound to" do
16
- ch = connection.create_channel
17
- x = ch.fanout("amq.fanout")
18
- q = ch.queue("", exclusive: true).bind(x)
19
-
20
- x.publish("")
21
- sleep 0.3
22
- expect(q.message_count).to eq 1
23
-
24
- q.unbind(x)
25
-
26
- x.publish("")
27
- expect(q.message_count).to eq 1
28
- end
29
- end
30
-
31
-
32
-
33
- describe Bunny::Queue, "NOT bound to an exchange" do
34
- let(:connection) do
35
- c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
36
- c.start
37
- c
38
- end
39
-
40
- after :each do
41
- connection.close
42
- end
43
-
44
-
45
- it "is idempotent (succeeds)" do
46
- ch = connection.create_channel
47
- x = ch.fanout("amq.fanout")
48
- q = ch.queue("", exclusive: true)
49
-
50
- # No exception as of RabbitMQ 3.2. MK.
51
- q.unbind(x)
52
- q.unbind(x)
53
- end
54
- end
@@ -1,60 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Bunny::Queue, "#subscribe" do
4
- let(:publisher_connection) do
5
- c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
6
- c.start
7
- c
8
- end
9
-
10
- let(:consumer_connection) do
11
- c = Bunny.new(username: "bunny_reader", password: "reader_password", vhost: "bunny_testbed")
12
- c.start
13
- c
14
- end
15
-
16
- after :each do
17
- publisher_connection.close if publisher_connection.open?
18
- consumer_connection.close if consumer_connection.open?
19
- end
20
-
21
- context "with automatic acknowledgement mode" do
22
- let(:queue_name) { "bunny.basic_consume#{rand}" }
23
-
24
- it "registers the consumer" do
25
- delivered_keys = []
26
- delivered_data = []
27
-
28
- ch = publisher_connection.create_channel
29
- # declare the queue because the read-only user won't be able to issue
30
- # queue.declare
31
- q = ch.queue(queue_name, auto_delete: true, durable: false)
32
-
33
- t = Thread.new do
34
- # give the main thread a bit of time to declare the queue
35
- sleep 0.5
36
- ch = consumer_connection.create_channel
37
- # this connection is read only, use passive declare to only get
38
- # a reference to the queue
39
- q = ch.queue(queue_name, auto_delete: true, durable: false, passive: true)
40
- q.subscribe(exclusive: false) do |delivery_info, properties, payload|
41
- delivered_keys << delivery_info.routing_key
42
- delivered_data << payload
43
- end
44
- end
45
- t.abort_on_exception = true
46
- sleep 0.5
47
-
48
- x = ch.default_exchange
49
- x.publish("hello", routing_key: queue_name)
50
-
51
- sleep 0.7
52
- expect(delivered_keys).to include(queue_name)
53
- expect(delivered_data).to include("hello")
54
-
55
- expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
56
-
57
- ch.close
58
- end
59
- end
60
- end # describe
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Sender-selected distribution" do
4
- let(:connection) do
5
- c = Bunny.new(username: "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
- it "lets publishers specify additional routing keys using CC and BCC headers" do
15
- ch = connection.create_channel
16
- x = ch.direct("bunny.tests.ssd.exchange")
17
- q1 = ch.queue("", exclusive: true).bind(x, routing_key: "one")
18
- q2 = ch.queue("", exclusive: true).bind(x, routing_key: "two")
19
- q3 = ch.queue("", exclusive: true).bind(x, routing_key: "three")
20
- q4 = ch.queue("", exclusive: true).bind(x, routing_key: "four")
21
-
22
- n = 10
23
- n.times do |i|
24
- x.publish("Message #{i}", routing_key: "one", headers: {"CC" => ["two", "three"]})
25
- end
26
-
27
- sleep 0.5
28
-
29
- expect(q1.message_count).to eq n
30
- expect(q2.message_count).to eq n
31
- expect(q3.message_count).to eq n
32
- expect(q4.message_count).to be_zero
33
-
34
- x.delete
35
- end
36
- end