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.
- checksums.yaml +4 -4
- data/ChangeLog.md +85 -2
- data/LICENSE +1 -1
- data/README.md +2 -7
- data/lib/amq/bit_set.rb +2 -1
- data/lib/amq/endianness.rb +2 -0
- data/lib/amq/int_allocator.rb +3 -3
- data/lib/amq/pack.rb +33 -42
- data/lib/amq/protocol/channel_close.rb +24 -0
- data/lib/amq/protocol/client.rb +31 -40
- data/lib/amq/protocol/constants.rb +2 -0
- data/lib/amq/protocol/exceptions.rb +3 -1
- data/lib/amq/protocol/float_32bit.rb +2 -0
- data/lib/amq/protocol/frame.rb +16 -10
- data/lib/amq/protocol/table.rb +20 -17
- data/lib/amq/protocol/table_value_decoder.rb +49 -53
- data/lib/amq/protocol/table_value_encoder.rb +2 -1
- data/lib/amq/protocol/type_constants.rb +1 -0
- data/lib/amq/protocol/version.rb +1 -1
- data/lib/amq/protocol.rb +1 -0
- data/lib/amq/settings.rb +1 -0
- data/lib/amq/uri.rb +30 -17
- metadata +5 -45
- data/.github/ISSUE_TEMPLATE.md +0 -18
- data/.github/workflows/ci.yml +0 -31
- data/.gitignore +0 -18
- data/.gitmodules +0 -3
- data/.rspec +0 -1
- data/.travis.yml +0 -17
- data/Gemfile +0 -22
- data/Rakefile +0 -55
- data/amq-protocol.gemspec +0 -27
- data/benchmarks/int_allocator.rb +0 -34
- data/benchmarks/pure/body_framing_with_256k_payload.rb +0 -28
- data/benchmarks/pure/body_framing_with_2k_payload.rb +0 -28
- data/codegen/__init__.py +0 -0
- data/codegen/amqp_0.9.1_changes.json +0 -1
- data/codegen/codegen.py +0 -151
- data/codegen/codegen_helpers.py +0 -162
- data/codegen/protocol.rb.pytemplate +0 -320
- data/generate.rb +0 -24
- data/profiling/README.md +0 -9
- data/profiling/stackprof/body_framing_with_2k_payload.rb +0 -33
- data/spec/amq/bit_set_spec.rb +0 -227
- data/spec/amq/int_allocator_spec.rb +0 -113
- data/spec/amq/pack_spec.rb +0 -68
- data/spec/amq/protocol/basic_spec.rb +0 -325
- data/spec/amq/protocol/blank_body_encoding_spec.rb +0 -9
- data/spec/amq/protocol/channel_spec.rb +0 -127
- data/spec/amq/protocol/confirm_spec.rb +0 -41
- data/spec/amq/protocol/connection_spec.rb +0 -146
- data/spec/amq/protocol/constants_spec.rb +0 -10
- data/spec/amq/protocol/exchange_spec.rb +0 -106
- data/spec/amq/protocol/frame_spec.rb +0 -92
- data/spec/amq/protocol/method_spec.rb +0 -43
- data/spec/amq/protocol/queue_spec.rb +0 -126
- data/spec/amq/protocol/table_spec.rb +0 -259
- data/spec/amq/protocol/tx_spec.rb +0 -55
- data/spec/amq/protocol/value_decoder_spec.rb +0 -86
- data/spec/amq/protocol/value_encoder_spec.rb +0 -140
- data/spec/amq/protocol_spec.rb +0 -812
- data/spec/amq/settings_spec.rb +0 -22
- data/spec/amq/uri_parsing_spec.rb +0 -280
- data/spec/spec_helper.rb +0 -29
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
# encoding: binary
|
|
2
|
-
|
|
3
|
-
module AMQ
|
|
4
|
-
module Protocol
|
|
5
|
-
class Connection
|
|
6
|
-
RSpec.describe Start do
|
|
7
|
-
describe '.decode' do
|
|
8
|
-
subject do
|
|
9
|
-
Start.decode("\x00\t\x00\x00\x00\xFB\tcopyrightS\x00\x00\x00gCopyright (C) 2007-2010 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.\vinformationS\x00\x00\x005Licensed under the MPL. See http://www.rabbitmq.com/\bplatformS\x00\x00\x00\nErlang/OTP\aproductS\x00\x00\x00\bRabbitMQ\aversionS\x00\x00\x00\x052.2.0\x00\x00\x00\x0EPLAIN AMQPLAIN\x00\x00\x00\x05en_US")
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
its(:version_major) { should == 0 }
|
|
13
|
-
its(:version_minor) { should == 9 }
|
|
14
|
-
its(:server_properties) { should == {'copyright' => 'Copyright (C) 2007-2010 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.', 'information' => 'Licensed under the MPL. See http://www.rabbitmq.com/', 'platform' => 'Erlang/OTP', 'product' => 'RabbitMQ', 'version' => '2.2.0'} }
|
|
15
|
-
its(:mechanisms) { should == 'PLAIN AMQPLAIN' }
|
|
16
|
-
its(:locales) { should == 'en_US' }
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
RSpec.describe StartOk do
|
|
21
|
-
describe '.encode' do
|
|
22
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
23
|
-
client_properties = {:platform => 'Ruby 1.9.2', :product => 'AMQ Client', :information => 'http://github.com/ruby-amqp/amq-client', :version => '0.2.0'}
|
|
24
|
-
mechanism = 'PLAIN'
|
|
25
|
-
response = "\x00guest\x00guest"
|
|
26
|
-
locale = 'en_GB'
|
|
27
|
-
method_frame = StartOk.encode(client_properties, mechanism, response, locale)
|
|
28
|
-
# the order of the table parts isn't deterministic in Ruby 1.8
|
|
29
|
-
expect(method_frame.payload[0, 8]).to eq("\x00\n\x00\v\x00\x00\x00x")
|
|
30
|
-
expect(method_frame.payload).to include("\bplatformS\x00\x00\x00\nRuby 1.9.2")
|
|
31
|
-
expect(method_frame.payload).to include("\aproductS\x00\x00\x00\nAMQ Client")
|
|
32
|
-
expect(method_frame.payload).to include("\vinformationS\x00\x00\x00&http://github.com/ruby-amqp/amq-client")
|
|
33
|
-
expect(method_frame.payload).to include("\aversionS\x00\x00\x00\x050.2.0")
|
|
34
|
-
expect(method_frame.payload[-28, 28]).to eq("\x05PLAIN\x00\x00\x00\f\x00guest\x00guest\x05en_GB")
|
|
35
|
-
expect(method_frame.payload.length).to eq(156)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
RSpec.describe Secure do
|
|
41
|
-
describe '.decode' do
|
|
42
|
-
subject do
|
|
43
|
-
Secure.decode("\x00\x00\x00\x03foo")
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
its(:challenge) { should eq('foo') }
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
RSpec.describe SecureOk do
|
|
51
|
-
describe '.encode' do
|
|
52
|
-
it 'encodes the parameters as a MethodFrame' do
|
|
53
|
-
response = 'bar'
|
|
54
|
-
method_frame = SecureOk.encode(response)
|
|
55
|
-
expect(method_frame.payload).to eq("\x00\x0a\x00\x15\x00\x00\x00\x03bar")
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
RSpec.describe Tune do
|
|
61
|
-
describe '.decode' do
|
|
62
|
-
subject do
|
|
63
|
-
Tune.decode("\x00\x00\x00\x02\x00\x00\x00\x00")
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
its(:channel_max) { should eq(0) }
|
|
67
|
-
its(:frame_max) { should eq(131072) }
|
|
68
|
-
its(:heartbeat) { should eq(0) }
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
RSpec.describe TuneOk do
|
|
73
|
-
describe '.encode' do
|
|
74
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
75
|
-
channel_max = 0
|
|
76
|
-
frame_max = 65536
|
|
77
|
-
heartbeat = 1
|
|
78
|
-
method_frame = TuneOk.encode(channel_max, frame_max, heartbeat)
|
|
79
|
-
expect(method_frame.payload).to eq("\x00\n\x00\x1F\x00\x00\x00\x01\x00\x00\x00\x01")
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
RSpec.describe Open do
|
|
85
|
-
describe '.encode' do
|
|
86
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
87
|
-
vhost = '/test'
|
|
88
|
-
method_frame = Open.encode(vhost)
|
|
89
|
-
expect(method_frame.payload).to eq("\x00\n\x00(\x05/test\x00\x00")
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
RSpec.describe OpenOk do
|
|
95
|
-
describe '.decode' do
|
|
96
|
-
subject do
|
|
97
|
-
OpenOk.decode("\x00")
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
its(:known_hosts) { should eq('') }
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
RSpec.describe Close do
|
|
105
|
-
describe '.decode' do
|
|
106
|
-
context 'with code 200' do
|
|
107
|
-
subject do
|
|
108
|
-
Close.decode("\x00\xc8\x07KTHXBAI\x00\x05\x00\x06")
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
its(:reply_code) { should eq(200) }
|
|
112
|
-
its(:reply_text) { should eq('KTHXBAI') }
|
|
113
|
-
its(:class_id) { should eq(5) }
|
|
114
|
-
its(:method_id) { should eq(6) }
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
context 'with an error code' do
|
|
118
|
-
it 'returns method frame and lets calling code handle the issue' do
|
|
119
|
-
Close.decode("\x01\x38\x08NO_ROUTE\x00\x00")
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
describe '.encode' do
|
|
125
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
126
|
-
reply_code = 540
|
|
127
|
-
reply_text = 'NOT_IMPLEMENTED'
|
|
128
|
-
class_id = 0
|
|
129
|
-
method_id = 0
|
|
130
|
-
method_frame = Close.encode(reply_code, reply_text, class_id, method_id)
|
|
131
|
-
expect(method_frame.payload).to eq("\x00\x0a\x002\x02\x1c\x0fNOT_IMPLEMENTED\x00\x00\x00\x00")
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
RSpec.describe CloseOk do
|
|
137
|
-
describe '.encode' do
|
|
138
|
-
it 'encodes a MethodFrame' do
|
|
139
|
-
method_frame = CloseOk.encode
|
|
140
|
-
expect(method_frame.payload).to eq("\x00\n\x003")
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
RSpec.describe "(Some) AMQ::Protocol constants" do
|
|
2
|
-
it "include regular port" do
|
|
3
|
-
expect(AMQ::Protocol::DEFAULT_PORT).to eq(5672)
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
it "provides TLS/SSL port" do
|
|
7
|
-
expect(AMQ::Protocol::TLS_PORT).to eq(5671)
|
|
8
|
-
expect(AMQ::Protocol::SSL_PORT).to eq(5671)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# encoding: binary
|
|
2
|
-
|
|
3
|
-
module AMQ
|
|
4
|
-
module Protocol
|
|
5
|
-
class Exchange
|
|
6
|
-
RSpec.describe Declare do
|
|
7
|
-
describe '.encode' do
|
|
8
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
9
|
-
channel = 1
|
|
10
|
-
exchange = 'amqclient.adapters.em.exchange1'
|
|
11
|
-
type = 'fanout'
|
|
12
|
-
passive = false
|
|
13
|
-
durable = false
|
|
14
|
-
auto_delete = false
|
|
15
|
-
internal = false
|
|
16
|
-
nowait = false
|
|
17
|
-
arguments = nil
|
|
18
|
-
method_frame = Declare.encode(channel, exchange, type, passive, durable, auto_delete, internal, nowait, arguments)
|
|
19
|
-
expect(method_frame.payload).to eq("\x00(\x00\n\x00\x00\x1Famqclient.adapters.em.exchange1\x06fanout\x00\x00\x00\x00\x00")
|
|
20
|
-
expect(method_frame.channel).to eq(1)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
RSpec.describe Declare, "encoded with a symbol name" do
|
|
26
|
-
describe '.encode' do
|
|
27
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
28
|
-
channel = 1
|
|
29
|
-
exchange = :exchange2
|
|
30
|
-
type = 'fanout'
|
|
31
|
-
passive = false
|
|
32
|
-
durable = false
|
|
33
|
-
auto_delete = false
|
|
34
|
-
internal = false
|
|
35
|
-
nowait = false
|
|
36
|
-
arguments = nil
|
|
37
|
-
method_frame = Declare.encode(channel, exchange, type, passive, durable, auto_delete, internal, nowait, arguments)
|
|
38
|
-
expect(method_frame.payload).to eq("\x00(\x00\n\x00\x00\texchange2\x06fanout\x00\x00\x00\x00\x00")
|
|
39
|
-
expect(method_frame.channel).to eq(1)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
RSpec.describe Delete do
|
|
45
|
-
describe '.encode' do
|
|
46
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
47
|
-
channel = 1
|
|
48
|
-
exchange = 'amqclient.adapters.em.exchange'
|
|
49
|
-
if_unused = false
|
|
50
|
-
nowait = false
|
|
51
|
-
method_frame = Delete.encode(channel, exchange, if_unused, nowait)
|
|
52
|
-
expect(method_frame.payload).to eq("\x00(\x00\x14\x00\x00\x1Eamqclient.adapters.em.exchange\x00")
|
|
53
|
-
expect(method_frame.channel).to eq(1)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# RSpec.describe DeleteOk do
|
|
59
|
-
# describe '.decode' do
|
|
60
|
-
# end
|
|
61
|
-
# end
|
|
62
|
-
|
|
63
|
-
RSpec.describe Bind do
|
|
64
|
-
describe '.encode' do
|
|
65
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
66
|
-
channel = 1
|
|
67
|
-
destination = 'foo'
|
|
68
|
-
source = 'bar'
|
|
69
|
-
routing_key = 'xyz'
|
|
70
|
-
nowait = false
|
|
71
|
-
arguments = nil
|
|
72
|
-
method_frame = Bind.encode(channel, destination, source, routing_key, nowait, arguments)
|
|
73
|
-
expect(method_frame.payload).to eq("\x00(\x00\x1E\x00\x00\x03foo\x03bar\x03xyz\x00\x00\x00\x00\x00")
|
|
74
|
-
expect(method_frame.channel).to eq(1)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# RSpec.describe BindOk do
|
|
80
|
-
# describe '.decode' do
|
|
81
|
-
# end
|
|
82
|
-
# end
|
|
83
|
-
|
|
84
|
-
RSpec.describe Unbind do
|
|
85
|
-
describe '.encode' do
|
|
86
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
87
|
-
channel = 1
|
|
88
|
-
destination = 'foo'
|
|
89
|
-
source = 'bar'
|
|
90
|
-
routing_key = 'xyz'
|
|
91
|
-
nowait = false
|
|
92
|
-
arguments = nil
|
|
93
|
-
method_frame = Unbind.encode(channel, destination, source, routing_key, nowait, arguments)
|
|
94
|
-
expect(method_frame.payload).to eq("\x00(\x00(\x00\x00\x03foo\x03bar\x03xyz\x00\x00\x00\x00\x00")
|
|
95
|
-
expect(method_frame.channel).to eq(1)
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# RSpec.describe UnbindOk do
|
|
101
|
-
# describe '.decode' do
|
|
102
|
-
# end
|
|
103
|
-
# end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
module AMQ
|
|
2
|
-
module Protocol
|
|
3
|
-
RSpec.describe Frame do
|
|
4
|
-
describe ".encode" do
|
|
5
|
-
it "should raise FrameTypeError if type isn't one of: [:method, :header, :body, :heartbeat]" do
|
|
6
|
-
expect { Frame.encode(nil, "", 0) }.to raise_error(FrameTypeError)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "should raise FrameTypeError if type isn't valid (when type is a symbol)" do
|
|
10
|
-
expect { Frame.encode(:xyz, "test", 12) }.to raise_error(FrameTypeError)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "should raise FrameTypeError if type isn't valid (when type is a number)" do
|
|
14
|
-
expect { Frame.encode(16, "test", 12) }.to raise_error(FrameTypeError)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should raise RuntimeError if channel isn't 0 or an integer in range 1..65535" do
|
|
18
|
-
expect { Frame.encode(:method, "", -1) }.to raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
|
|
19
|
-
expect { Frame.encode(:method, "", 65536) }.to raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
|
|
20
|
-
expect { Frame.encode(:method, "", 65535) }.not_to raise_error
|
|
21
|
-
expect { Frame.encode(:method, "", 0) }.not_to raise_error
|
|
22
|
-
expect { Frame.encode(:method, "", 1) }.not_to raise_error
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "should raise RuntimeError if payload is nil" do
|
|
26
|
-
expect { Frame.encode(:method, nil, 0) }.to raise_error(RuntimeError, "Payload can't be nil")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "should encode type" do
|
|
30
|
-
expect(Frame.encode(:body, "", 0).unpack("c").first).to eql(3)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should encode channel" do
|
|
34
|
-
expect(Frame.encode(:body, "", 12).unpack("cn").last).to eql(12)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should encode size" do
|
|
38
|
-
expect(Frame.encode(:body, "test", 12).unpack("cnN").last).to eql(4)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should include payload" do
|
|
42
|
-
expect(Frame.encode(:body, "test", 12)[7..-2]).to eql("test")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "should include final octet" do
|
|
46
|
-
expect(Frame.encode(:body, "test", 12).each_byte.to_a.last).to eq("CE".hex)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "should encode unicode strings" do
|
|
50
|
-
expect { Frame.encode(:body, "à bientôt!", 12) }.to_not raise_error
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe ".new" do
|
|
55
|
-
it "should raise FrameTypeError if the type is not one of the accepted" do
|
|
56
|
-
expect { Frame.new(10) }.to raise_error(FrameTypeError)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe '#decode_header' do
|
|
61
|
-
it 'raises FrameTypeError if the decoded type is not one of the accepted' do
|
|
62
|
-
expect { Frame.decode_header("\n\x00\x01\x00\x00\x00\x05") }.to raise_error(FrameTypeError)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'raises EmptyResponseError if the header is nil' do
|
|
66
|
-
expect { Frame.decode_header(nil) }.to raise_error(EmptyResponseError)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
describe HeaderFrame do
|
|
71
|
-
subject { HeaderFrame.new("\x00<\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x98\x00\x18application/octet-stream\x02\x00", nil) }
|
|
72
|
-
|
|
73
|
-
it "should decode body_size from payload" do
|
|
74
|
-
expect(subject.body_size).to eq(10)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should decode klass_id from payload" do
|
|
78
|
-
expect(subject.klass_id).to eq(60)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should decode weight from payload" do
|
|
82
|
-
expect(subject.weight).to eq(0)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should decode properties from payload" do
|
|
86
|
-
expect(subject.properties[:delivery_mode]).to eq(2)
|
|
87
|
-
expect(subject.properties[:priority]).to eq(0)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module AMQ
|
|
2
|
-
module Protocol
|
|
3
|
-
RSpec.describe Method do
|
|
4
|
-
describe '.split_headers' do
|
|
5
|
-
it 'splits user defined headers into properties and headers' do
|
|
6
|
-
input = {:delivery_mode => 2, :content_type => 'application/octet-stream', :foo => 'bar'}
|
|
7
|
-
properties, headers = Method.split_headers(input)
|
|
8
|
-
expect(properties).to eq({:delivery_mode => 2, :content_type => 'application/octet-stream'})
|
|
9
|
-
expect(headers).to eq({:foo => 'bar'})
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe '.encode_body' do
|
|
14
|
-
context 'when the body fits in a single frame' do
|
|
15
|
-
it 'encodes a body into a BodyFrame' do
|
|
16
|
-
body_frames = Method.encode_body('Hello world', 1, 131072)
|
|
17
|
-
expect(body_frames.first.payload).to eq('Hello world')
|
|
18
|
-
expect(body_frames.first.channel).to eq(1)
|
|
19
|
-
expect(body_frames.size).to eq(1)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context 'when the body is too big to fit in a single frame' do
|
|
24
|
-
it 'encodes a body into a list of BodyFrames that each fit within the frame size' do
|
|
25
|
-
lipsum = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
|
26
|
-
frame_size = 100
|
|
27
|
-
expected_payload_size = 92
|
|
28
|
-
body_frames = Method.encode_body(lipsum, 1, frame_size)
|
|
29
|
-
expect(body_frames.map(&:payload)).to eq(lipsum.split('').each_slice(expected_payload_size).map(&:join))
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when the body fits perfectly in a single frame' do
|
|
34
|
-
it 'encodes a body into a single BodyFrame' do
|
|
35
|
-
body_frames = Method.encode_body('*' * 131064, 1, 131072)
|
|
36
|
-
expect(body_frames.first.payload).to eq('*' * 131064)
|
|
37
|
-
expect(body_frames.size).to eq(1)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
# encoding: binary
|
|
2
|
-
|
|
3
|
-
module AMQ
|
|
4
|
-
module Protocol
|
|
5
|
-
class Queue
|
|
6
|
-
RSpec.describe Declare do
|
|
7
|
-
describe '.encode' do
|
|
8
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
9
|
-
channel = 1
|
|
10
|
-
queue = 'hello.world'
|
|
11
|
-
passive = false
|
|
12
|
-
durable = true
|
|
13
|
-
exclusive = true
|
|
14
|
-
auto_delete = true
|
|
15
|
-
nowait = false
|
|
16
|
-
arguments = nil
|
|
17
|
-
method_frame = Declare.encode(channel, queue, passive, durable, exclusive, auto_delete, nowait, arguments)
|
|
18
|
-
expect(method_frame.payload).to eq("\x002\x00\n\x00\x00\vhello.world\x0E\x00\x00\x00\x00")
|
|
19
|
-
expect(method_frame.channel).to eq(1)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
RSpec.describe DeclareOk do
|
|
25
|
-
describe '.decode' do
|
|
26
|
-
subject do
|
|
27
|
-
DeclareOk.decode(" amq.gen-KduGSqQrpeUo1otnU0TWSA==\x00\x00\x00\x00\x00\x00\x00\x00")
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
its(:queue) { should eq('amq.gen-KduGSqQrpeUo1otnU0TWSA==') }
|
|
31
|
-
its(:message_count) { should eq(0) }
|
|
32
|
-
its(:consumer_count) { should eq(0) }
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
RSpec.describe Bind do
|
|
37
|
-
describe '.encode' do
|
|
38
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
39
|
-
channel = 1
|
|
40
|
-
queue = 'hello.world'
|
|
41
|
-
exchange = 'foo.bar'
|
|
42
|
-
routing_key = 'xyz'
|
|
43
|
-
nowait = false
|
|
44
|
-
arguments = nil
|
|
45
|
-
method_frame = Bind.encode(channel, queue, exchange, routing_key, nowait, arguments)
|
|
46
|
-
expect(method_frame.payload).to eq("\x002\x00\x14\x00\x00\vhello.world\afoo.bar\x03xyz\x00\x00\x00\x00\x00")
|
|
47
|
-
expect(method_frame.channel).to eq(1)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# RSpec.describe BindOk do
|
|
53
|
-
# describe '.decode' do
|
|
54
|
-
# end
|
|
55
|
-
# end
|
|
56
|
-
|
|
57
|
-
RSpec.describe Purge do
|
|
58
|
-
describe '.encode' do
|
|
59
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
60
|
-
channel = 1
|
|
61
|
-
queue = 'hello.world'
|
|
62
|
-
nowait = false
|
|
63
|
-
method_frame = Purge.encode(channel, queue, nowait)
|
|
64
|
-
expect(method_frame.payload).to eq("\x002\x00\x1E\x00\x00\vhello.world\x00")
|
|
65
|
-
expect(method_frame.channel).to eq(1)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
RSpec.describe PurgeOk do
|
|
71
|
-
describe '.decode' do
|
|
72
|
-
subject do
|
|
73
|
-
PurgeOk.decode("\x00\x00\x00\x02")
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
its(:message_count) { should eq(2) }
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
RSpec.describe Delete do
|
|
81
|
-
describe '.encode' do
|
|
82
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
83
|
-
channel = 1
|
|
84
|
-
queue = 'hello.world'
|
|
85
|
-
if_unused = false
|
|
86
|
-
if_empty = false
|
|
87
|
-
nowait = false
|
|
88
|
-
method_frame = Delete.encode(channel, queue, if_unused, if_empty, nowait)
|
|
89
|
-
expect(method_frame.payload).to eq("\x002\x00(\x00\x00\vhello.world\x00")
|
|
90
|
-
expect(method_frame.channel).to eq(1)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
RSpec.describe DeleteOk do
|
|
96
|
-
describe '.decode' do
|
|
97
|
-
subject do
|
|
98
|
-
DeleteOk.decode("\x00\x00\x00\x02")
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
its(:message_count) { should eq(2) }
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
RSpec.describe Unbind do
|
|
106
|
-
describe '.encode' do
|
|
107
|
-
it 'encodes the parameters into a MethodFrame' do
|
|
108
|
-
channel = 1
|
|
109
|
-
queue = 'hello.world'
|
|
110
|
-
exchange = 'foo.bar'
|
|
111
|
-
routing_key = 'xyz'
|
|
112
|
-
arguments = nil
|
|
113
|
-
method_frame = Unbind.encode(channel, queue, exchange, routing_key, arguments)
|
|
114
|
-
expect(method_frame.payload).to eq("\x002\x002\x00\x00\vhello.world\afoo.bar\x03xyz\x00\x00\x00\x00")
|
|
115
|
-
expect(method_frame.channel).to eq(1)
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# RSpec.describe UnbindOk do
|
|
121
|
-
# describe '.decode' do
|
|
122
|
-
# end
|
|
123
|
-
# end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|