amq-protocol 2.3.3 → 2.8.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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +85 -2
  3. data/LICENSE +1 -1
  4. data/README.md +2 -7
  5. data/lib/amq/bit_set.rb +2 -1
  6. data/lib/amq/endianness.rb +2 -0
  7. data/lib/amq/int_allocator.rb +3 -3
  8. data/lib/amq/pack.rb +33 -42
  9. data/lib/amq/protocol/channel_close.rb +24 -0
  10. data/lib/amq/protocol/client.rb +31 -40
  11. data/lib/amq/protocol/constants.rb +2 -0
  12. data/lib/amq/protocol/exceptions.rb +3 -1
  13. data/lib/amq/protocol/float_32bit.rb +2 -0
  14. data/lib/amq/protocol/frame.rb +16 -10
  15. data/lib/amq/protocol/table.rb +20 -17
  16. data/lib/amq/protocol/table_value_decoder.rb +49 -53
  17. data/lib/amq/protocol/table_value_encoder.rb +2 -1
  18. data/lib/amq/protocol/type_constants.rb +1 -0
  19. data/lib/amq/protocol/version.rb +1 -1
  20. data/lib/amq/protocol.rb +1 -0
  21. data/lib/amq/settings.rb +1 -0
  22. data/lib/amq/uri.rb +30 -17
  23. metadata +5 -45
  24. data/.github/ISSUE_TEMPLATE.md +0 -18
  25. data/.github/workflows/ci.yml +0 -31
  26. data/.gitignore +0 -18
  27. data/.gitmodules +0 -3
  28. data/.rspec +0 -1
  29. data/.travis.yml +0 -17
  30. data/Gemfile +0 -22
  31. data/Rakefile +0 -55
  32. data/amq-protocol.gemspec +0 -27
  33. data/benchmarks/int_allocator.rb +0 -34
  34. data/benchmarks/pure/body_framing_with_256k_payload.rb +0 -28
  35. data/benchmarks/pure/body_framing_with_2k_payload.rb +0 -28
  36. data/codegen/__init__.py +0 -0
  37. data/codegen/amqp_0.9.1_changes.json +0 -1
  38. data/codegen/codegen.py +0 -151
  39. data/codegen/codegen_helpers.py +0 -162
  40. data/codegen/protocol.rb.pytemplate +0 -320
  41. data/generate.rb +0 -24
  42. data/profiling/README.md +0 -9
  43. data/profiling/stackprof/body_framing_with_2k_payload.rb +0 -33
  44. data/spec/amq/bit_set_spec.rb +0 -227
  45. data/spec/amq/int_allocator_spec.rb +0 -113
  46. data/spec/amq/pack_spec.rb +0 -68
  47. data/spec/amq/protocol/basic_spec.rb +0 -325
  48. data/spec/amq/protocol/blank_body_encoding_spec.rb +0 -9
  49. data/spec/amq/protocol/channel_spec.rb +0 -127
  50. data/spec/amq/protocol/confirm_spec.rb +0 -41
  51. data/spec/amq/protocol/connection_spec.rb +0 -146
  52. data/spec/amq/protocol/constants_spec.rb +0 -10
  53. data/spec/amq/protocol/exchange_spec.rb +0 -106
  54. data/spec/amq/protocol/frame_spec.rb +0 -92
  55. data/spec/amq/protocol/method_spec.rb +0 -43
  56. data/spec/amq/protocol/queue_spec.rb +0 -126
  57. data/spec/amq/protocol/table_spec.rb +0 -259
  58. data/spec/amq/protocol/tx_spec.rb +0 -55
  59. data/spec/amq/protocol/value_decoder_spec.rb +0 -86
  60. data/spec/amq/protocol/value_encoder_spec.rb +0 -140
  61. data/spec/amq/protocol_spec.rb +0 -812
  62. data/spec/amq/settings_spec.rb +0 -22
  63. data/spec/amq/uri_parsing_spec.rb +0 -280
  64. data/spec/spec_helper.rb +0 -29
@@ -1,113 +0,0 @@
1
- require "amq/int_allocator"
2
-
3
- RSpec.describe AMQ::IntAllocator do
4
-
5
- #
6
- # Environment
7
- #
8
-
9
- subject do
10
- described_class.new(1, 5)
11
- end
12
-
13
-
14
- # ...
15
-
16
-
17
- #
18
- # Examples
19
- #
20
-
21
- describe "#number_of_bits" do
22
- it "returns number of bits available for allocation" do
23
- expect(subject.number_of_bits).to eq(4)
24
- end
25
- end
26
-
27
-
28
- describe "#hi" do
29
- it "returns upper bound of the allocation range" do
30
- expect(subject.hi).to eq(5)
31
- end
32
- end
33
-
34
- describe "#lo" do
35
- it "returns lower bound of the allocation range" do
36
- expect(subject.lo).to eq(1)
37
- end
38
- end
39
-
40
-
41
- describe "#allocate" do
42
- context "when integer in the range is available" do
43
- it "returns allocated integer" do
44
- expect(subject.allocate).to eq(1)
45
- expect(subject.allocate).to eq(2)
46
- expect(subject.allocate).to eq(3)
47
- expect(subject.allocate).to eq(4)
48
-
49
- expect(subject.allocate).to eq(-1)
50
- end
51
- end
52
-
53
- context "when integer in the range IS NOT available" do
54
- it "returns -1" do
55
- 4.times { subject.allocate }
56
-
57
- expect(subject.allocate).to eq(-1)
58
- expect(subject.allocate).to eq(-1)
59
- expect(subject.allocate).to eq(-1)
60
- expect(subject.allocate).to eq(-1)
61
- end
62
- end
63
- end
64
-
65
-
66
- describe "#free" do
67
- context "when the integer WAS allocated" do
68
- it "returns frees that integer" do
69
- 4.times { subject.allocate }
70
- expect(subject.allocate).to eq(-1)
71
-
72
- subject.free(1)
73
- expect(subject.allocate).to eq(1)
74
- expect(subject.allocate).to eq(-1)
75
- subject.free(2)
76
- expect(subject.allocate).to eq(2)
77
- expect(subject.allocate).to eq(-1)
78
- subject.free(3)
79
- expect(subject.allocate).to eq(3)
80
- expect(subject.allocate).to eq(-1)
81
- end
82
- end
83
-
84
- context "when the integer WAS NOT allocated" do
85
- it "has no effect" do
86
- 32.times { subject.free(1) }
87
- expect(subject.allocate).to eq(1)
88
- end
89
- end
90
- end
91
-
92
-
93
- describe "#allocated?" do
94
- context "when given position WAS allocated" do
95
- it "returns true" do
96
- 3.times { subject.allocate }
97
-
98
- expect(subject.allocated?(1)).to be_truthy
99
- expect(subject.allocated?(2)).to be_truthy
100
- expect(subject.allocated?(3)).to be_truthy
101
- end
102
- end
103
-
104
- context "when given position WAS NOT allocated" do
105
- it "returns false" do
106
- 2.times { subject.allocate }
107
-
108
- expect(subject.allocated?(3)).to be_falsey
109
- expect(subject.allocated?(4)).to be_falsey
110
- end
111
- end
112
- end
113
- end
@@ -1,68 +0,0 @@
1
- # encoding: binary
2
-
3
- RSpec.describe AMQ::Pack do
4
- context "16-bit big-endian packing / unpacking" do
5
- let(:examples_16bit) {
6
- {
7
- 0x068D => "\x06\x8D" # 1677
8
- }
9
- }
10
-
11
- it "unpacks signed integers from a string to a number" do
12
- examples_16bit.each do |key, value|
13
- expect(described_class.unpack_int16_big_endian(value)[0]).to eq(key)
14
- end
15
- end
16
- end
17
-
18
- context "64-bit big-endian packing / unpacking" do
19
- let(:examples) {
20
- {
21
- 0x0000000000000000 => "\x00\x00\x00\x00\x00\x00\x00\x00",
22
- 0x000000000000000A => "\x00\x00\x00\x00\x00\x00\x00\x0A",
23
- 0x00000000000000A0 => "\x00\x00\x00\x00\x00\x00\x00\xA0",
24
- 0x000000000000B0A0 => "\x00\x00\x00\x00\x00\x00\xB0\xA0",
25
- 0x00000000000CB0AD => "\x00\x00\x00\x00\x00\x0C\xB0\xAD",
26
- 0x8BADF00DDEFEC8ED => "\x8B\xAD\xF0\x0D\xDE\xFE\xC8\xED",
27
- 0x0D15EA5EFEE1DEAD => "\x0D\x15\xEA\x5E\xFE\xE1\xDE\xAD",
28
- 0xDEADBEEFDEADBABE => "\xDE\xAD\xBE\xEF\xDE\xAD\xBA\xBE"
29
- }
30
- }
31
-
32
- it "packs integers into big-endian string" do
33
- examples.each do |key, value|
34
- expect(described_class.pack_uint64_big_endian(key)).to eq(value)
35
- end
36
- end
37
-
38
- it "should unpack string representation into integer" do
39
- examples.each do |key, value|
40
- expect(described_class.unpack_uint64_big_endian(value)[0]).to eq(key)
41
- end
42
- end
43
-
44
- if RUBY_VERSION < '1.9'
45
- describe "with utf encoding" do
46
- before do
47
- $KCODE = 'u'
48
- end
49
-
50
- after do
51
- $KCODE = 'NONE'
52
- end
53
-
54
- it "packs integers into big-endian string" do
55
- examples.each do |key, value|
56
- expect(described_class.pack_uint64_big_endian(key)).to eq(value)
57
- end
58
- end
59
-
60
- it "should unpack string representation into integer" do
61
- examples.each do |key, value|
62
- expect(described_class.unpack_uint64_big_endian(value)[0]).to eq(key)
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,325 +0,0 @@
1
- # encoding: binary
2
-
3
- module AMQ
4
- module Protocol
5
- RSpec.describe AMQ::Protocol::Basic do
6
- describe '.encode_timestamp' do
7
- it 'encodes the timestamp as a 64 byte big endian integer' do
8
- expect(Basic.encode_timestamp(12345).last).to eq("\x00\x00\x00\x00\x00\x0009")
9
- end
10
- end
11
-
12
- # describe '.decode_timestamp' do
13
- # it 'decodes the timestamp from a 64 byte big endian integer and returns a Time object' do
14
- # expect(Basic.decode_timestamp("\x00\x00\x00\x00\x00\x0009")).to eq(Time.at(12345))
15
- # end
16
- # end
17
-
18
- describe '.encode_headers' do
19
- it 'encodes the headers as a table' do
20
- expect(Basic.encode_headers(:hello => 'world').last).to eq("\x00\x00\x00\x10\x05helloS\x00\x00\x00\x05world")
21
- end
22
- end
23
-
24
- # describe '.decode_headers' do
25
- # it 'decodes the headers from a table' do
26
- # expect(Basic.decode_headers("\x00\x00\x00\x10\x05helloS\x00\x00\x00\x05world")).to eq({'hello' => 'world'})
27
- # end
28
- # end
29
-
30
- describe '.encode_properties' do
31
- it 'packs the parameters into a byte array using the other encode_* methods' do
32
- result = Basic.encode_properties(10, {:priority => 0, :delivery_mode => 2, :content_type => 'application/octet-stream'})
33
- expect(result).to eq("\x00<\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x98\x00\x18application/octet-stream\x02\x00")
34
- end
35
- end
36
-
37
- describe '.decode_properties' do
38
- it 'unpacks the properties from a byte array using the decode_* methods' do
39
- result = Basic.decode_properties("\x98@\x18application/octet-stream\x02\x00\x00\x00\x00\x00\x00\x00\x00{")
40
- expect(result).to eq({:priority => 0, :delivery_mode => 2, :content_type => 'application/octet-stream', :timestamp => Time.at(123)})
41
- end
42
-
43
- it 'unpacks the properties from a byte array using the decode_* methods, including a table' do
44
- result = Basic.decode_properties("\xB8@\x18application/octet-stream\x00\x00\x00\x10\x05helloS\x00\x00\x00\x05world\x02\x00\x00\x00\x00\x00\x00\x00\x00{")
45
- expect(result).to eq({:priority => 0, :delivery_mode => 2, :content_type => 'application/octet-stream', :timestamp => Time.at(123), :headers => {'hello' => 'world'}})
46
- end
47
- end
48
-
49
- %w(content_type content_encoding correlation_id reply_to expiration message_id type user_id app_id cluster_id).each do |method|
50
- describe ".encode_#{method}" do
51
- it 'encodes the parameter as a Pascal string' do
52
- expect(Basic.send("encode_#{method}", 'hello world').last).to eq("\x0bhello world")
53
- end
54
- end
55
-
56
- # describe ".decode_#{method}" do
57
- # it 'returns the string' do
58
- # # the length has been stripped in .decode_properties
59
- # expect(Basic.send("decode_#{method}", 'hello world')).to eq('hello world')
60
- # end
61
- # end
62
- end
63
-
64
- %w(delivery_mode priority).each do |method|
65
- describe ".encode_#{method}" do
66
- it 'encodes the parameter as a char' do
67
- expect(Basic.send("encode_#{method}", 10).last).to eq("\x0a")
68
- end
69
- end
70
-
71
- # describe ".decode_#{method}" do
72
- # it 'decodes the value from a char' do
73
- # expect(Basic.send("decode_#{method}", "\x10")).to eq(16)
74
- # end
75
- # end
76
- end
77
- end
78
-
79
- class Basic
80
- RSpec.describe Qos do
81
- describe '.encode' do
82
- it 'encodes the parameters into a MethodFrame' do
83
- channel = 1
84
- prefetch_size = 3
85
- prefetch_count = 5
86
- global = false
87
- method_frame = Qos.encode(channel, prefetch_size, prefetch_count, global)
88
- expect(method_frame.payload).to eq("\x00<\x00\n\x00\x00\x00\x03\x00\x05\x00")
89
- expect(method_frame.channel).to eq(1)
90
- end
91
- end
92
- end
93
-
94
- # RSpec.describe QosOk do
95
- # describe '.decode' do
96
- # end
97
- # end
98
-
99
- RSpec.describe Consume do
100
- describe '.encode' do
101
- it 'encodes the parameters into a MethodFrame' do
102
- channel = 1
103
- queue = 'foo'
104
- consumer_tag = 'me'
105
- no_local = false
106
- no_ack = false
107
- exclusive = true
108
- nowait = false
109
- arguments = nil
110
- method_frame = Consume.encode(channel, queue, consumer_tag, no_local, no_ack, exclusive, nowait, arguments)
111
- expect(method_frame.payload).to eq("\x00<\x00\x14\x00\x00\x03foo\x02me\x04\x00\x00\x00\x00")
112
- expect(method_frame.channel).to eq(1)
113
- end
114
- end
115
- end
116
-
117
- RSpec.describe ConsumeOk do
118
- describe '.decode' do
119
- subject do
120
- ConsumeOk.decode("\x03foo")
121
- end
122
-
123
- its(:consumer_tag) { should eq('foo') }
124
- end
125
- end
126
-
127
- RSpec.describe Cancel do
128
- describe '.encode' do
129
- it 'encodes the parameters into a MethodFrame' do
130
- channel = 1
131
- consumer_tag = 'foo'
132
- nowait = true
133
- method_frame = Cancel.encode(channel, consumer_tag, nowait)
134
- expect(method_frame.payload).to eq("\x00<\x00\x1E\x03foo\x01")
135
- expect(method_frame.channel).to eq(1)
136
- end
137
- end
138
-
139
- describe '.decode' do
140
- subject do
141
- CancelOk.decode("\x03foo\x01")
142
- end
143
-
144
- its(:consumer_tag) { should eq('foo') }
145
- end
146
- end
147
-
148
- RSpec.describe CancelOk do
149
- describe '.decode' do
150
- subject do
151
- CancelOk.decode("\x03foo")
152
- end
153
-
154
- its(:consumer_tag) { should eq('foo') }
155
- end
156
- end
157
-
158
- RSpec.describe Publish do
159
- describe '.encode' do
160
- it 'encodes the parameters into a list of MethodFrames' do
161
- channel = 1
162
- payload = 'Hello World!'
163
- user_headers = {:priority => 0, :content_type => 'application/octet-stream'}
164
- exchange = 'foo'
165
- routing_key = 'xyz'
166
- mandatory = false
167
- immediate = true
168
- frame_size = 512
169
- method_frames = Publish.encode(channel, payload, user_headers, exchange, routing_key, mandatory, immediate, frame_size)
170
- expect(method_frames[0].payload).to eq("\x00<\x00(\x00\x00\x03foo\x03xyz\x02")
171
- expect(method_frames[1].payload).to eq("\x00<\x00\x00\x00\x00\x00\x00\x00\x00\x00\f\x88\x00\x18application/octet-stream\x00")
172
- expect(method_frames[2].payload).to eq("Hello World!")
173
- expect(method_frames[0].channel).to eq(1)
174
- expect(method_frames[1].channel).to eq(1)
175
- expect(method_frames[2].channel).to eq(1)
176
- expect(method_frames.size).to eq(3)
177
- end
178
- end
179
- end
180
-
181
- RSpec.describe Return do
182
- describe '.decode' do
183
- subject do
184
- Return.decode("\x019\fNO_CONSUMERS\namq.fanout\x00")
185
- end
186
-
187
- its(:reply_code) { should eq(313) }
188
- its(:reply_text) { should eq('NO_CONSUMERS') }
189
- its(:exchange) { should eq('amq.fanout') }
190
- its(:routing_key) { should eq('') }
191
- end
192
- end
193
-
194
- RSpec.describe Deliver do
195
- describe '.decode' do
196
- subject do
197
- Deliver.decode("\e-1300560114000-445586772970\x00\x00\x00\x00\x00\x00\x00c\x00\namq.fanout\x00")
198
- end
199
-
200
- its(:consumer_tag) { should eq('-1300560114000-445586772970') }
201
- its(:delivery_tag) { should eq(99) }
202
- its(:redelivered) { should eq(false) }
203
- its(:exchange) { should eq('amq.fanout') }
204
- its(:routing_key) { should eq('') }
205
- end
206
- end
207
-
208
- RSpec.describe Get do
209
- describe '.encode' do
210
- it 'encodes the parameters into a MethodFrame' do
211
- channel = 1
212
- queue = 'foo'
213
- no_ack = true
214
- method_frame = Get.encode(channel, queue, no_ack)
215
- expect(method_frame.payload).to eq("\x00\x3c\x00\x46\x00\x00\x03foo\x01")
216
- expect(method_frame.channel).to eq(1)
217
- end
218
- end
219
- end
220
-
221
- RSpec.describe GetOk do
222
- describe '.decode' do
223
- subject do
224
- GetOk.decode("\x00\x00\x00\x00\x00\x00\x00\x06\x00\namq.fanout\x00\x00\x00\x00^")
225
- end
226
-
227
- its(:delivery_tag) { should eq(6) }
228
- its(:redelivered) { should eq(false) }
229
- its(:exchange) { should eq('amq.fanout') }
230
- its(:routing_key) { should eq('') }
231
- its(:message_count) { should eq(94) }
232
- end
233
- end
234
-
235
- RSpec.describe GetEmpty do
236
- describe '.decode' do
237
- subject do
238
- GetEmpty.decode("\x03foo")
239
- end
240
-
241
- its(:cluster_id) { should eq('foo') }
242
- end
243
- end
244
-
245
- RSpec.describe Ack do
246
- describe '.encode' do
247
- it 'encodes the parameters into a MethodFrame' do
248
- channel = 1
249
- delivery_tag = 6
250
- multiple = false
251
- method_frame = Ack.encode(channel, delivery_tag, multiple)
252
- expect(method_frame.payload).to eq("\x00<\x00P\x00\x00\x00\x00\x00\x00\x00\x06\x00")
253
- expect(method_frame.channel).to eq(1)
254
- end
255
- end
256
- end
257
-
258
- RSpec.describe Reject do
259
- describe '.encode' do
260
- it 'encodes the parameters into a MethodFrame' do
261
- channel = 1
262
- delivery_tag = 8
263
- requeue = true
264
- method_frame = Reject.encode(channel, delivery_tag, requeue)
265
- expect(method_frame.payload).to eq("\x00<\x00Z\x00\x00\x00\x00\x00\x00\x00\x08\x01")
266
- expect(method_frame.channel).to eq(1)
267
- end
268
- end
269
- end
270
-
271
- RSpec.describe RecoverAsync do
272
- describe '.encode' do
273
- it 'encodes the parameters into a MethodFrame' do
274
- channel = 1
275
- requeue = true
276
- method_frame = RecoverAsync.encode(channel, requeue)
277
- expect(method_frame.payload).to eq("\x00<\x00d\x01")
278
- expect(method_frame.channel).to eq(1)
279
- end
280
- end
281
- end
282
-
283
- RSpec.describe Recover do
284
- describe '.encode' do
285
- it 'encodes the parameters into a MethodFrame' do
286
- channel = 1
287
- requeue = true
288
- method_frame = Recover.encode(channel, requeue)
289
- expect(method_frame.payload).to eq("\x00<\x00n\x01")
290
- expect(method_frame.channel).to eq(1)
291
- end
292
- end
293
- end
294
-
295
- # RSpec.describe RecoverOk do
296
- # describe '.decode' do
297
- # end
298
- # end
299
-
300
- RSpec.describe Nack do
301
- describe '.decode' do
302
- subject do
303
- Nack.decode("\x00\x00\x00\x00\x00\x00\x00\x09\x03")
304
- end
305
-
306
- its(:delivery_tag) { should eq(9) }
307
- its(:multiple) { should eq(true) }
308
- its(:requeue) { should eq(true) }
309
- end
310
-
311
- describe '.encode' do
312
- it 'encodes the parameters into a MethodFrame' do
313
- channel = 1
314
- delivery_tag = 10
315
- multiple = false
316
- requeue = true
317
- method_frame = Nack.encode(channel, delivery_tag, multiple, requeue)
318
- expect(method_frame.payload).to eq("\x00<\x00x\x00\x00\x00\x00\x00\x00\x00\x0a\x02")
319
- expect(method_frame.channel).to eq(1)
320
- end
321
- end
322
- end
323
- end
324
- end
325
- end
@@ -1,9 +0,0 @@
1
- RSpec.describe AMQ::Protocol::Method, ".encode_body" do
2
- it "encodes 1-byte long payload as exactly 1 body frame" do
3
- expect(described_class.encode_body('1', 1, 65536).size).to eq(1)
4
- end
5
-
6
- it "encodes 0-byte long (blank) payload as exactly 0 body frame" do
7
- expect(described_class.encode_body('', 1, 65536).size).to eq(0)
8
- end
9
- end
@@ -1,127 +0,0 @@
1
- # encoding: binary
2
-
3
- module AMQ
4
- module Protocol
5
- class Channel
6
- RSpec.describe Open do
7
- describe '.encode' do
8
- it 'encodes the parameters into a MethodFrame' do
9
- channel = 1
10
- out_of_band = ''
11
- method_frame = Open.encode(channel, out_of_band)
12
- expect(method_frame.payload).to eq("\x00\x14\x00\n\x00")
13
- expect(method_frame.channel).to eq(1)
14
- end
15
- end
16
- end
17
-
18
- RSpec.describe OpenOk do
19
- describe '.decode' do
20
- subject do
21
- OpenOk.decode("\x00\x00\x00\x03foo")
22
- end
23
-
24
- its(:channel_id) { should eq('foo') }
25
- end
26
- end
27
-
28
- RSpec.describe Flow do
29
- describe '.decode' do
30
- subject do
31
- Flow.decode("\x01")
32
- end
33
-
34
- its(:active) { should be_truthy }
35
- end
36
-
37
- describe '.encode' do
38
- it 'encodes the parameters as a MethodFrame' do
39
- channel = 1
40
- active = true
41
- method_frame = Flow.encode(channel, active)
42
- expect(method_frame.payload).to eq("\x00\x14\x00\x14\x01")
43
- expect(method_frame.channel).to eq(1)
44
- end
45
- end
46
- end
47
-
48
- RSpec.describe FlowOk do
49
- describe '.decode' do
50
- subject do
51
- FlowOk.decode("\x00")
52
- end
53
-
54
- its(:active) { should be_falsey }
55
- end
56
-
57
- describe '.encode' do
58
- it 'encodes the parameters as a MethodFrame' do
59
- channel = 1
60
- active = true
61
- method_frame = FlowOk.encode(channel, active)
62
- expect(method_frame.payload).to eq("\x00\x14\x00\x15\x01")
63
- expect(method_frame.channel).to eq(1)
64
- end
65
- end
66
- end
67
-
68
- RSpec.describe Close do
69
- describe '.decode' do
70
- context 'with code 200' do
71
- subject do
72
- Close.decode("\x00\xc8\x07KTHXBAI\x00\x05\x00\x06")
73
- end
74
-
75
- its(:reply_code) { should eq(200) }
76
- its(:reply_text) { should eq('KTHXBAI') }
77
- its(:class_id) { should eq(5) }
78
- its(:method_id) { should eq(6) }
79
- end
80
-
81
-
82
- context 'with code 404 and reply_text length > 127 characters' do
83
- subject do
84
- raw = "\x01\x94\x80NOT_FOUND - no binding 123456789012345678901234567890123 between exchange 'amq.topic' in vhost '/' and queue 'test' in vhost '/'\x002\x002"
85
- Close.decode(raw)
86
- end
87
-
88
- its(:reply_code) { should eq(404) }
89
- its(:reply_text) { should eq(%q{NOT_FOUND - no binding 123456789012345678901234567890123 between exchange 'amq.topic' in vhost '/' and queue 'test' in vhost '/'}) }
90
- its(:class_id) { should eq(50) }
91
- its(:method_id) { should eq(50) }
92
- end
93
-
94
- context 'with an error code' do
95
- it 'returns frame and lets calling code handle the issue' do
96
- Close.decode("\x01\x38\x08NO_ROUTE\x00\x00")
97
- end
98
- end
99
- end
100
-
101
- describe '.encode' do
102
- it 'encodes the parameters into a MethodFrame' do
103
- channel = 1
104
- reply_code = 540
105
- reply_text = 'NOT_IMPLEMENTED'
106
- class_id = 0
107
- method_id = 0
108
- method_frame = Close.encode(channel, reply_code, reply_text, class_id, method_id)
109
- expect(method_frame.payload).to eq("\x00\x14\x00(\x02\x1c\x0fNOT_IMPLEMENTED\x00\x00\x00\x00")
110
- expect(method_frame.channel).to eq(1)
111
- end
112
- end
113
- end
114
-
115
- RSpec.describe CloseOk do
116
- describe '.encode' do
117
- it 'encodes the parameters into a MethodFrame' do
118
- channel = 1
119
- method_frame = CloseOk.encode(channel)
120
- expect(method_frame.payload).to eq("\x00\x14\x00\x29")
121
- expect(method_frame.channel).to eq(channel)
122
- end
123
- end
124
- end
125
- end
126
- end
127
- end
@@ -1,41 +0,0 @@
1
- # encoding: binary
2
-
3
- module AMQ
4
- module Protocol
5
- class Confirm
6
- RSpec.describe Select do
7
- describe '.decode' do
8
- subject do
9
- Select.decode("\x01")
10
- end
11
-
12
- its(:nowait) { should be_truthy }
13
- end
14
-
15
- describe '.encode' do
16
- it 'encodes the parameters into a MethodFrame' do
17
- channel = 1
18
- nowait = true
19
- method_frame = Select.encode(channel, nowait)
20
- expect(method_frame.payload).to eq("\x00U\x00\n\x01")
21
- expect(method_frame.channel).to eq(1)
22
- end
23
- end
24
- end
25
-
26
- RSpec.describe SelectOk do
27
- # describe '.decode' do
28
- # end
29
-
30
- describe '.encode' do
31
- it 'encodes the parameters into a MethodFrame' do
32
- channel = 1
33
- method_frame = SelectOk.encode(channel)
34
- expect(method_frame.payload).to eq("\000U\000\v")
35
- expect(method_frame.channel).to eq(1)
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end