bunny-mock 1.6.0 → 1.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/bunny_mock/channel.rb +20 -4
- data/lib/bunny_mock/queue.rb +1 -0
- data/lib/bunny_mock/version.rb +1 -1
- data/spec/integration/message_acknowledgement_spec.rb +75 -48
- data/spec/unit/bunny_mock/queue_spec.rb +5 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef8cbde025836118928a61e3d8d0b63f736c8b4c
|
4
|
+
data.tar.gz: d88bdce511227d6f4fd7dd4a3b70a38c363374cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 836978ddc5b9220044e6a3628631e8915e64995099fb86cbb5fe61a11bd9441057d8482919907a4c46c2de4f8b63719cb896f8c4526aae4fb21bcb70f588dec5
|
7
|
+
data.tar.gz: 45658e28e7d45880a424ac9a5132c962757820f74ee6d0f0a2b6e87f8584e23289cf0ea880e47db2e23620189104dbd295622583399a93c271a4a96f1d3d169e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
_Add contribution here_
|
4
4
|
|
5
|
+
## v1.7.0
|
6
|
+
|
7
|
+
* [#32](https://github.com/arempe93/bunny-mock/pull/32): Implement reject functionality - [@binaryberry](https://github.com/binaryberry)
|
8
|
+
* [#31](https://github.com/arempe93/bunny-mock/pull/31): Add `generate_consumer_tag` to `BunnyMock::Channel` - [@Jakenberg](https://github.com/Jakenberg)
|
9
|
+
* [#23](https://github.com/arempe93/bunny-mock/pull/23): Fix queue bind returning an array instead of self - [@fugufish](https://github.com/fugufish)
|
10
|
+
|
5
11
|
## v1.6.0
|
6
12
|
|
7
13
|
* [#27](https://github.com/arempe93/bunny-mock/pull/27): Allow `Session#create_channel` to accept additional args - [@eebs](https://github.com/eebs)
|
data/lib/bunny_mock/channel.rb
CHANGED
@@ -35,7 +35,7 @@ module BunnyMock
|
|
35
35
|
# initialize exchange and queue storage
|
36
36
|
@exchanges = {}
|
37
37
|
@queues = {}
|
38
|
-
@acknowledged_state = { pending: {}, acked: {}, nacked: {} }
|
38
|
+
@acknowledged_state = { pending: {}, acked: {}, nacked: {}, rejected: {} }
|
39
39
|
|
40
40
|
# set status to opening
|
41
41
|
@status = :opening
|
@@ -103,6 +103,14 @@ module BunnyMock
|
|
103
103
|
@connection.register_exchange xchg_find_or_create(name, opts)
|
104
104
|
end
|
105
105
|
|
106
|
+
# Unique string supposed to be used as a consumer tag.
|
107
|
+
#
|
108
|
+
# @return [String] Unique string.
|
109
|
+
# @api plugin
|
110
|
+
def generate_consumer_tag(name = 'bunny')
|
111
|
+
"#{name}-#{Time.now.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
|
112
|
+
end
|
113
|
+
|
106
114
|
##
|
107
115
|
# Mocks a fanout exchange
|
108
116
|
#
|
@@ -303,13 +311,21 @@ module BunnyMock
|
|
303
311
|
end
|
304
312
|
|
305
313
|
##
|
306
|
-
#
|
314
|
+
# Rejects a message. A rejected message can be requeued or
|
315
|
+
# dropped by RabbitMQ.
|
316
|
+
#
|
317
|
+
# @param [Integer] delivery_tag Delivery tag to reject
|
318
|
+
# @param [Boolean] requeue Should this message be requeued instead of dropping it?
|
307
319
|
#
|
308
320
|
# @return nil
|
309
321
|
# @api public
|
310
322
|
#
|
311
|
-
def reject(
|
312
|
-
|
323
|
+
def reject(delivery_tag, requeue = false)
|
324
|
+
if @acknowledged_state[:pending].key?(delivery_tag)
|
325
|
+
delivery, header, body = update_acknowledgement_state(delivery_tag, :rejected)
|
326
|
+
delivery.queue.publish(body, header.to_hash) if requeue
|
327
|
+
end
|
328
|
+
nil
|
313
329
|
end
|
314
330
|
|
315
331
|
# @endgroup
|
data/lib/bunny_mock/queue.rb
CHANGED
data/lib/bunny_mock/version.rb
CHANGED
@@ -27,61 +27,88 @@ describe BunnyMock::Channel, 'acknowledgement' do
|
|
27
27
|
expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
context 'when using nack to negatively acknowledge' do
|
31
|
+
it 'should allow messages which have been nacked to be identified' do
|
32
|
+
queue.publish 'Message to nack'
|
33
|
+
delivery_tag = delivery_tags['Message to nack']
|
34
|
+
@channel.nack delivery_tag
|
35
|
+
|
36
|
+
expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
|
37
|
+
expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
|
38
|
+
expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag)
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
it 'should requeue messages with have been nacked with `requeue` = true' do
|
42
|
+
queue.publish 'Message to nack'
|
43
|
+
delivery_tag = delivery_tags['Message to nack']
|
44
|
+
@channel.nack delivery_tag, false, true
|
45
|
+
new_delivery_tag = delivery_tags['Message to nack']
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@channel.nack delivery_tag, false, true
|
44
|
-
new_delivery_tag = delivery_tags['Message to nack']
|
47
|
+
expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
|
48
|
+
expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
|
49
|
+
expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag)
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag)
|
51
|
+
expect(@channel.acknowledged_state[:pending]).to include(new_delivery_tag)
|
52
|
+
end
|
49
53
|
|
50
|
-
|
51
|
-
|
54
|
+
it 'should allow multiple messages to be acked when `multiple` = true' do
|
55
|
+
queue.publish 'Message to be automatically acked'
|
56
|
+
delivery_tag_1 = delivery_tags['Message to be automatically acked']
|
57
|
+
queue.publish 'Message to acked'
|
58
|
+
delivery_tag_2 = delivery_tags['Message to acked']
|
59
|
+
queue.publish 'Message to be left as pending'
|
60
|
+
delivery_tag_3 = delivery_tags['Message to be left as pending']
|
61
|
+
|
62
|
+
@channel.ack delivery_tag_2, true
|
63
|
+
|
64
|
+
expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_1)
|
65
|
+
expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_2)
|
66
|
+
expect(@channel.acknowledged_state[:pending]).to include(delivery_tag_3)
|
67
|
+
expect(@channel.acknowledged_state[:acked]).to include(delivery_tag_1)
|
68
|
+
expect(@channel.acknowledged_state[:acked]).to include(delivery_tag_2)
|
69
|
+
end
|
52
70
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
71
|
+
it 'should allow multiple messages to be nacked when `multiple` = true' do
|
72
|
+
queue.publish 'Message to be automatically nacked'
|
73
|
+
delivery_tag_1 = delivery_tags['Message to be automatically nacked']
|
74
|
+
queue.publish 'Message to nacked'
|
75
|
+
delivery_tag_2 = delivery_tags['Message to nacked']
|
76
|
+
queue.publish 'Message to be left as pending'
|
77
|
+
delivery_tag_3 = delivery_tags['Message to be left as pending']
|
78
|
+
|
79
|
+
@channel.nack delivery_tag_2, true
|
80
|
+
|
81
|
+
expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_1)
|
82
|
+
expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_2)
|
83
|
+
expect(@channel.acknowledged_state[:pending]).to include(delivery_tag_3)
|
84
|
+
expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag_1)
|
85
|
+
expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag_2)
|
86
|
+
end
|
68
87
|
end
|
69
88
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
89
|
+
context 'when using reject to negatively acknowledge' do
|
90
|
+
it 'should allow messages which have been nacked to be identified' do
|
91
|
+
queue.publish 'Message to reject'
|
92
|
+
delivery_tag = delivery_tags['Message to reject']
|
93
|
+
@channel.reject delivery_tag
|
94
|
+
|
95
|
+
expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
|
96
|
+
expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
|
97
|
+
expect(@channel.acknowledged_state[:rejected]).to include(delivery_tag)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should requeue messages with have been rejected with `requeue` = true' do
|
101
|
+
queue.publish 'Message to reject'
|
102
|
+
delivery_tag = delivery_tags['Message to reject']
|
103
|
+
@channel.reject delivery_tag, true
|
104
|
+
new_delivery_tag = delivery_tags['Message to reject']
|
105
|
+
|
106
|
+
expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
|
107
|
+
expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
|
108
|
+
expect(@channel.acknowledged_state[:rejected]).to include(delivery_tag)
|
109
|
+
|
110
|
+
expect(@channel.acknowledged_state[:pending]).to include(new_delivery_tag)
|
111
|
+
end
|
85
112
|
end
|
86
113
|
end
|
87
114
|
end
|
@@ -39,6 +39,11 @@ describe BunnyMock::Queue do
|
|
39
39
|
it 'should raise error when exchange does not exists' do
|
40
40
|
expect { @receiver.bind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
|
41
41
|
end
|
42
|
+
|
43
|
+
it 'should return self' do
|
44
|
+
expect(@receiver.bind(@source)).to eq @receiver
|
45
|
+
end
|
46
|
+
|
42
47
|
end
|
43
48
|
|
44
49
|
context '#unbind' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunny-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Rempe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
version: '0'
|
189
189
|
requirements: []
|
190
190
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
191
|
+
rubygems_version: 2.5.1
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: Mocking for the popular Bunny client for RabbitMQ
|