bunny 2.19.0 → 2.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -32
- data/lib/bunny/channel.rb +86 -10
- data/lib/bunny/consumer.rb +2 -2
- data/lib/bunny/delivery_info.rb +1 -1
- data/lib/bunny/queue.rb +33 -2
- data/lib/bunny/session.rb +1 -1
- data/lib/bunny/transport.rb +30 -1
- data/lib/bunny/version.rb +1 -1
- data/lib/bunny.rb +45 -4
- metadata +4 -144
- data/spec/config/enabled_plugins +0 -1
- data/spec/config/rabbitmq.conf +0 -13
- data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
- data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
- data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -357
- data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
- data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
- data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
- data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
- data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
- data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
- data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
- data/spec/higher_level_api/integration/channel_close_spec.rb +0 -66
- data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
- data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -483
- data/spec/higher_level_api/integration/connection_spec.rb +0 -589
- data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
- data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
- data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
- data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
- data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
- data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
- data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
- data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
- data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
- data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
- data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
- data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
- data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
- data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
- data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -285
- data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
- data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
- data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
- data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
- data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
- data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -255
- data/spec/higher_level_api/integration/toxiproxy_spec.rb +0 -76
- data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
- data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
- data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
- data/spec/issues/issue100_spec.rb +0 -42
- data/spec/issues/issue141_spec.rb +0 -43
- data/spec/issues/issue202_spec.rb +0 -15
- data/spec/issues/issue224_spec.rb +0 -40
- data/spec/issues/issue465_spec.rb +0 -32
- data/spec/issues/issue549_spec.rb +0 -30
- data/spec/issues/issue609_spec.rb +0 -84
- data/spec/issues/issue78_spec.rb +0 -72
- data/spec/issues/issue83_spec.rb +0 -30
- data/spec/issues/issue97_attachment.json +0 -1
- data/spec/issues/issue97_spec.rb +0 -175
- data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
- data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
- data/spec/spec_helper.rb +0 -47
- data/spec/stress/channel_close_stress_spec.rb +0 -64
- data/spec/stress/channel_open_stress_spec.rb +0 -84
- data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
- data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
- data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
- data/spec/stress/connection_open_close_spec.rb +0 -52
- data/spec/stress/merry_go_round_spec.rb +0 -105
- data/spec/toxiproxy_helper.rb +0 -28
- data/spec/unit/bunny_spec.rb +0 -15
- data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
- data/spec/unit/concurrent/condition_spec.rb +0 -82
- data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
- data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
- data/spec/unit/exchange_recovery_spec.rb +0 -39
- data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -1,357 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "set"
|
3
|
-
|
4
|
-
describe Bunny::Queue, "#subscribe" do
|
5
|
-
let(:connection) do
|
6
|
-
c = Bunny.new(username: "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
|
-
expect(delivered_keys).to include(queue_name)
|
39
|
-
expect(delivered_data).to include("hello")
|
40
|
-
|
41
|
-
expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 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.5
|
66
|
-
100.times do |i|
|
67
|
-
expect(delivery_tags).to include(i + 1)
|
68
|
-
end
|
69
|
-
|
70
|
-
expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
|
71
|
-
|
72
|
-
ch.close
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
context "with multiple consumers on the same channel" do
|
78
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
79
|
-
|
80
|
-
it "provides delivery tag access" do
|
81
|
-
delivery_tags = SortedSet.new
|
82
|
-
|
83
|
-
cch = connection.create_channel
|
84
|
-
q = cch.queue(queue_name, auto_delete: true, durable: false)
|
85
|
-
|
86
|
-
7.times do
|
87
|
-
q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
88
|
-
delivery_tags << delivery_info.delivery_tag
|
89
|
-
end
|
90
|
-
end
|
91
|
-
sleep 1.0
|
92
|
-
|
93
|
-
ch = connection.create_channel
|
94
|
-
x = ch.default_exchange
|
95
|
-
100.times do
|
96
|
-
x.publish("hello", routing_key: queue_name)
|
97
|
-
end
|
98
|
-
|
99
|
-
sleep 1.5
|
100
|
-
100.times do |i|
|
101
|
-
expect(delivery_tags).to include(i + 1)
|
102
|
-
end
|
103
|
-
|
104
|
-
expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
|
105
|
-
|
106
|
-
ch.close
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "with manual acknowledgement mode" do
|
112
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
113
|
-
|
114
|
-
it "register a consumer with manual acknowledgements mode" do
|
115
|
-
delivered_keys = []
|
116
|
-
delivered_data = []
|
117
|
-
|
118
|
-
t = Thread.new do
|
119
|
-
ch = connection.create_channel
|
120
|
-
q = ch.queue(queue_name, auto_delete: true, durable: false)
|
121
|
-
q.subscribe(exclusive: false, manual_ack: true) do |delivery_info, properties, payload|
|
122
|
-
delivered_keys << delivery_info.routing_key
|
123
|
-
delivered_data << payload
|
124
|
-
|
125
|
-
ch.ack(delivery_info.delivery_tag)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
t.abort_on_exception = true
|
129
|
-
sleep 0.5
|
130
|
-
|
131
|
-
ch = connection.create_channel
|
132
|
-
x = ch.default_exchange
|
133
|
-
x.publish("hello", routing_key: queue_name)
|
134
|
-
|
135
|
-
sleep 0.7
|
136
|
-
expect(delivered_keys).to include(queue_name)
|
137
|
-
expect(delivered_data).to include("hello")
|
138
|
-
|
139
|
-
expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
|
140
|
-
|
141
|
-
ch.close
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
ENV.fetch("RUNS", 20).to_i.times do |i|
|
146
|
-
context "with a queue that already has messages (take #{i})" do
|
147
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
148
|
-
|
149
|
-
it "registers the consumer" do
|
150
|
-
delivered_keys = []
|
151
|
-
delivered_data = []
|
152
|
-
|
153
|
-
ch = connection.create_channel
|
154
|
-
q = ch.queue(queue_name, auto_delete: true, durable: false)
|
155
|
-
x = ch.default_exchange
|
156
|
-
100.times do
|
157
|
-
x.publish("hello", routing_key: queue_name)
|
158
|
-
end
|
159
|
-
|
160
|
-
sleep 0.7
|
161
|
-
expect(q.message_count).to be > 50
|
162
|
-
|
163
|
-
t = Thread.new do
|
164
|
-
ch = connection.create_channel
|
165
|
-
q = ch.queue(queue_name, auto_delete: true, durable: false)
|
166
|
-
q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
167
|
-
delivered_keys << delivery_info.routing_key
|
168
|
-
delivered_data << payload
|
169
|
-
end
|
170
|
-
end
|
171
|
-
t.abort_on_exception = true
|
172
|
-
sleep 0.5
|
173
|
-
|
174
|
-
expect(delivered_keys).to include(queue_name)
|
175
|
-
expect(delivered_data).to include("hello")
|
176
|
-
|
177
|
-
expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
|
178
|
-
|
179
|
-
ch.close
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end # 20.times
|
183
|
-
|
184
|
-
|
185
|
-
context "after consumer pool has already been shut down" do
|
186
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
187
|
-
|
188
|
-
it "registers the consumer" do
|
189
|
-
delivered_keys = []
|
190
|
-
delivered_data = []
|
191
|
-
|
192
|
-
t = Thread.new do
|
193
|
-
ch = connection.create_channel
|
194
|
-
q = ch.queue(queue_name)
|
195
|
-
|
196
|
-
c1 = q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
197
|
-
end
|
198
|
-
c1.cancel
|
199
|
-
|
200
|
-
c2 = q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
201
|
-
delivered_keys << delivery_info.routing_key
|
202
|
-
delivered_data << payload
|
203
|
-
end
|
204
|
-
c2.cancel
|
205
|
-
|
206
|
-
q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
207
|
-
delivered_keys << delivery_info.routing_key
|
208
|
-
delivered_data << payload
|
209
|
-
end
|
210
|
-
end
|
211
|
-
t.abort_on_exception = true
|
212
|
-
sleep 0.5
|
213
|
-
|
214
|
-
ch = connection.create_channel
|
215
|
-
x = ch.default_exchange
|
216
|
-
x.publish("hello", routing_key: queue_name)
|
217
|
-
|
218
|
-
sleep 0.7
|
219
|
-
expect(delivered_keys).to include(queue_name)
|
220
|
-
expect(delivered_data).to include("hello")
|
221
|
-
|
222
|
-
expect(ch.queue(queue_name).message_count).to eq 0
|
223
|
-
|
224
|
-
ch.queue_delete(queue_name)
|
225
|
-
ch.close
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
|
230
|
-
context "with uncaught exceptions in delivery handler" do
|
231
|
-
context "and defined exception handler" do
|
232
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
233
|
-
|
234
|
-
it "uses exception handler" do
|
235
|
-
caught = nil
|
236
|
-
t = Thread.new do
|
237
|
-
ch = connection.create_channel
|
238
|
-
q = ch.queue(queue_name, auto_delete: true, durable: false)
|
239
|
-
|
240
|
-
ch.on_uncaught_exception do |e, consumer|
|
241
|
-
caught = e
|
242
|
-
end
|
243
|
-
|
244
|
-
q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
245
|
-
raise RuntimeError.new(queue_name)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
t.abort_on_exception = true
|
249
|
-
sleep 0.5
|
250
|
-
|
251
|
-
ch = connection.create_channel
|
252
|
-
x = ch.default_exchange
|
253
|
-
x.publish("hello", routing_key: queue_name)
|
254
|
-
sleep 0.5
|
255
|
-
|
256
|
-
expect(caught.message).to eq queue_name
|
257
|
-
|
258
|
-
ch.close
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
|
263
|
-
context "and default exception handler" do
|
264
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
265
|
-
|
266
|
-
it "uses exception handler" do
|
267
|
-
caughts = []
|
268
|
-
t = Thread.new do
|
269
|
-
allow(connection.logger).to receive(:error) { |x| caughts << x }
|
270
|
-
|
271
|
-
ch = connection.create_channel
|
272
|
-
q = ch.queue(queue_name, auto_delete: true, durable: false)
|
273
|
-
|
274
|
-
q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
275
|
-
raise RuntimeError.new(queue_name)
|
276
|
-
end
|
277
|
-
end
|
278
|
-
t.abort_on_exception = true
|
279
|
-
sleep 0.5
|
280
|
-
|
281
|
-
ch = connection.create_channel
|
282
|
-
x = ch.default_exchange
|
283
|
-
5.times { x.publish("hello", routing_key: queue_name) }
|
284
|
-
sleep 1.5
|
285
|
-
|
286
|
-
expect(caughts.size).to eq(5)
|
287
|
-
|
288
|
-
ch.close
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
|
293
|
-
context "with a single consumer" do
|
294
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
295
|
-
|
296
|
-
it "provides delivery tag access" do
|
297
|
-
delivery_tags = SortedSet.new
|
298
|
-
|
299
|
-
cch = connection.create_channel
|
300
|
-
q = cch.queue(queue_name, auto_delete: true, durable: false)
|
301
|
-
q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
302
|
-
delivery_tags << delivery_info.delivery_tag
|
303
|
-
end
|
304
|
-
sleep 0.5
|
305
|
-
|
306
|
-
ch = connection.create_channel
|
307
|
-
x = ch.default_exchange
|
308
|
-
100.times do
|
309
|
-
x.publish("hello", routing_key: queue_name)
|
310
|
-
end
|
311
|
-
|
312
|
-
sleep 1.5
|
313
|
-
100.times do |i|
|
314
|
-
expect(delivery_tags).to include(i + 1)
|
315
|
-
end
|
316
|
-
|
317
|
-
expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
|
318
|
-
|
319
|
-
ch.close
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
|
324
|
-
context "with multiple consumers on the same channel" do
|
325
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
326
|
-
|
327
|
-
it "provides delivery tag access" do
|
328
|
-
delivery_tags = SortedSet.new
|
329
|
-
|
330
|
-
cch = connection.create_channel
|
331
|
-
q = cch.queue(queue_name, auto_delete: true, durable: false)
|
332
|
-
|
333
|
-
7.times do
|
334
|
-
q.subscribe(exclusive: false, manual_ack: false) do |delivery_info, properties, payload|
|
335
|
-
delivery_tags << delivery_info.delivery_tag
|
336
|
-
end
|
337
|
-
end
|
338
|
-
sleep 1.0
|
339
|
-
|
340
|
-
ch = connection.create_channel
|
341
|
-
x = ch.default_exchange
|
342
|
-
100.times do
|
343
|
-
x.publish("hello", routing_key: queue_name)
|
344
|
-
end
|
345
|
-
|
346
|
-
sleep 1.5
|
347
|
-
100.times do |i|
|
348
|
-
expect(delivery_tags).to include(i + 1)
|
349
|
-
end
|
350
|
-
|
351
|
-
expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
|
352
|
-
|
353
|
-
ch.close
|
354
|
-
end
|
355
|
-
end
|
356
|
-
end
|
357
|
-
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(username: "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, manual_ack: true)
|
48
|
-
sleep 2
|
49
|
-
ch1.close
|
50
|
-
|
51
|
-
expect(q2.message_count).to eq 50
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Queue, "#pop" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(username: "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
|
-
msg = "xyzzy"
|
23
|
-
x.publish(msg, routing_key: q.name)
|
24
|
-
|
25
|
-
sleep(0.5)
|
26
|
-
get_ok, properties, content = q.pop
|
27
|
-
expect(get_ok).to be_kind_of(Bunny::GetResponse)
|
28
|
-
expect(properties).to be_kind_of(Bunny::MessageProperties)
|
29
|
-
expect(properties.content_type).to eq("application/octet-stream")
|
30
|
-
expect(get_ok.routing_key).to eq(q.name)
|
31
|
-
expect(get_ok.delivery_tag).to be_kind_of(Bunny::VersionedDeliveryTag)
|
32
|
-
expect(content).to eq(msg)
|
33
|
-
expect(q.message_count).to eq 0
|
34
|
-
|
35
|
-
ch.close
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
context "with an empty queue" do
|
41
|
-
it "returns an empty response" do
|
42
|
-
ch = connection.create_channel
|
43
|
-
|
44
|
-
q = ch.queue("", exclusive: true)
|
45
|
-
q.purge
|
46
|
-
|
47
|
-
get_empty, properties, content = q.pop
|
48
|
-
expect(get_empty).to eq(nil)
|
49
|
-
expect(properties).to eq(nil)
|
50
|
-
expect(content).to eq(nil)
|
51
|
-
expect(q.message_count).to eq 0
|
52
|
-
|
53
|
-
ch.close
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
describe Bunny::Channel, "#basic_get" do
|
60
|
-
let(:connection) do
|
61
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
|
62
|
-
automatically_recover: false, continuation_timeout: 3000)
|
63
|
-
c.start
|
64
|
-
c
|
65
|
-
end
|
66
|
-
|
67
|
-
after :each do
|
68
|
-
connection.close if connection.open?
|
69
|
-
end
|
70
|
-
|
71
|
-
context "with a non-existent queue" do
|
72
|
-
it "throws a NOT_FOUND" do
|
73
|
-
ch = connection.create_channel
|
74
|
-
|
75
|
-
expect do
|
76
|
-
ch.basic_get "non_existent_#{rand.to_s}"
|
77
|
-
end.to raise_error(Bunny::NotFound)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#nack" 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
|
-
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
|
-
expect(q.message_count).to eq 1
|
26
|
-
delivery_info, _, content = q.pop(manual_ack: true)
|
27
|
-
|
28
|
-
subject.nack(delivery_info.delivery_tag, false, false)
|
29
|
-
sleep(0.5)
|
30
|
-
subject.close
|
31
|
-
|
32
|
-
ch = connection.create_channel
|
33
|
-
q = ch.queue("bunny.basic.nack.with-requeue-false", exclusive: true)
|
34
|
-
expect(q.message_count).to eq 0
|
35
|
-
ch.close
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with multiple = true" do
|
40
|
-
it "rejects multiple messages" do
|
41
|
-
q = subject.queue("bunny.basic.nack.with-requeue-true-multi-true", exclusive: true)
|
42
|
-
x = subject.default_exchange
|
43
|
-
|
44
|
-
3.times do
|
45
|
-
x.publish("bunneth", routing_key: q.name)
|
46
|
-
end
|
47
|
-
sleep(0.5)
|
48
|
-
expect(q.message_count).to eq 3
|
49
|
-
_, _, _ = q.pop(manual_ack: true)
|
50
|
-
_, _, _ = q.pop(manual_ack: true)
|
51
|
-
delivery_info, _, content = q.pop(manual_ack: true)
|
52
|
-
|
53
|
-
subject.nack(delivery_info.delivery_tag, true, true)
|
54
|
-
sleep(0.5)
|
55
|
-
expect(q.message_count).to eq 3
|
56
|
-
|
57
|
-
subject.close
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
context "with an invalid (random) delivery tag" do
|
63
|
-
it "causes a channel-level error" do
|
64
|
-
q = subject.queue("bunny.basic.nack.unknown-delivery-tag", exclusive: true)
|
65
|
-
x = subject.default_exchange
|
66
|
-
|
67
|
-
x.publish("bunneth", routing_key: q.name)
|
68
|
-
sleep(0.25)
|
69
|
-
expect(q.message_count).to eq 1
|
70
|
-
_, _, content = q.pop(manual_ack: true)
|
71
|
-
|
72
|
-
subject.on_error do |ch, channel_close|
|
73
|
-
@channel_close = channel_close
|
74
|
-
end
|
75
|
-
subject.nack(82, false, true)
|
76
|
-
|
77
|
-
sleep 0.5
|
78
|
-
|
79
|
-
expect(@channel_close.reply_text).to eq "PRECONDITION_FAILED - unknown delivery tag 82"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Published message" 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
|
-
context "with all default delivery and a 254 character long routing key" do
|
15
|
-
it "routes the messages" do
|
16
|
-
ch = connection.create_channel
|
17
|
-
|
18
|
-
q = ch.queue("", exclusive: true)
|
19
|
-
x = ch.fanout("amq.fanout")
|
20
|
-
q.bind(x)
|
21
|
-
|
22
|
-
rk = "a" * 254
|
23
|
-
x.publish("xyzzy", routing_key: rk, persistent: true)
|
24
|
-
|
25
|
-
sleep(1)
|
26
|
-
expect(q.message_count).to eq 1
|
27
|
-
|
28
|
-
_, _, payload = q.pop
|
29
|
-
|
30
|
-
expect(payload).to eq "xyzzy"
|
31
|
-
|
32
|
-
ch.close
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "with all default delivery and a 255 character long routing key" do
|
37
|
-
it "routes the messages" do
|
38
|
-
ch = connection.create_channel
|
39
|
-
|
40
|
-
q = ch.queue("", exclusive: true)
|
41
|
-
x = ch.fanout("amq.fanout")
|
42
|
-
q.bind(x)
|
43
|
-
|
44
|
-
rk = "a" * 255
|
45
|
-
x.publish("xyzzy", routing_key: rk, persistent: true)
|
46
|
-
|
47
|
-
sleep(1)
|
48
|
-
expect(q.message_count).to eq 1
|
49
|
-
|
50
|
-
_, _, payload = q.pop
|
51
|
-
|
52
|
-
expect(payload).to eq "xyzzy"
|
53
|
-
|
54
|
-
ch.close
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "with all default delivery and a 256 character long routing key" do
|
59
|
-
it "fails with a connection exception" do
|
60
|
-
ch = connection.create_channel
|
61
|
-
|
62
|
-
q = ch.queue("", exclusive: true)
|
63
|
-
x = ch.fanout("amq.fanout")
|
64
|
-
q.bind(x)
|
65
|
-
|
66
|
-
rk = "a" * 256
|
67
|
-
expect do
|
68
|
-
x.publish("xyzzy", routing_key: rk, persistent: true)
|
69
|
-
end.to raise_error(ArgumentError)
|
70
|
-
|
71
|
-
ch.close
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#prefetch" 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
|
-
context "with a positive integer < 65535" do
|
15
|
-
it "sets that prefetch level via basic.qos" do
|
16
|
-
ch = connection.create_channel
|
17
|
-
expect(ch.prefetch_count).not_to eq 10
|
18
|
-
expect(ch.prefetch_global).to be_nil
|
19
|
-
expect(ch.prefetch(10)).to be_instance_of(AMQ::Protocol::Basic::QosOk)
|
20
|
-
expect(ch.prefetch_count).to eq 10
|
21
|
-
expect(ch.prefetch_global).to be false
|
22
|
-
end
|
23
|
-
|
24
|
-
it "sets that prefetch global via basic.qos" do
|
25
|
-
ch = connection.create_channel
|
26
|
-
expect(ch.prefetch_count).not_to eq 42
|
27
|
-
expect(ch.prefetch_global).to be_nil
|
28
|
-
expect(ch.prefetch(42, true)).to be_instance_of(AMQ::Protocol::Basic::QosOk)
|
29
|
-
expect(ch.prefetch_count).to eq 42
|
30
|
-
expect(ch.prefetch_global).to be true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with a positive integer > 65535" do
|
35
|
-
it "raises an ArgumentError" do
|
36
|
-
ch = connection.create_channel
|
37
|
-
expect {
|
38
|
-
ch.prefetch(100_000)
|
39
|
-
}.to raise_error(
|
40
|
-
ArgumentError,
|
41
|
-
"prefetch count must be no greater than #{Bunny::Channel::MAX_PREFETCH_COUNT}, given: 100000"
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with a negative integer" do
|
47
|
-
it "raises an ArgumentError" do
|
48
|
-
ch = connection.create_channel
|
49
|
-
expect {
|
50
|
-
ch.prefetch(-2)
|
51
|
-
}.to raise_error(
|
52
|
-
ArgumentError,
|
53
|
-
"prefetch count must be a positive integer, given: -2"
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|