Skip to content

Commit b6ca269

Browse files
Merge pull request #166 from ruby-amqp/march-hare-165
Correctly compute final type in MarchHare::Queue#initialize ("x-queue-type" was ignored in favor of `:type`)
2 parents 6f54822 + 9dd1360 commit b6ca269

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

lib/march_hare/queue.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,23 @@ def initialize(channel, name, options={})
5454

5555
@channel = channel
5656
@name = name
57-
@options = {:durable => false, :exclusive => false, :auto_delete => false, :passive => false, :arguments => Hash.new, :type => Types::CLASSIC}.merge(options)
57+
@options = {:durable => false, :exclusive => false, :auto_delete => false, :passive => false, :arguments => Hash.new}.merge(options)
58+
59+
args = @options[:arguments] || {}
60+
@type = @options.fetch(:type, args.fetch(XArgs::QUEUE_TYPE, Types::CLASSIC)).to_s
61+
@durable = if @type == Types::QUORUM or @type == Types::STREAM
62+
true
63+
else
64+
@options[:durable]
65+
end
5866

59-
@type = @options[:type].to_s
60-
@durable = @options[:durable]
6167
@exclusive = @options[:exclusive]
6268
@server_named = @name.empty?
6369
@auto_delete = @options[:auto_delete]
6470

6571
@arguments = if @type and !@type.empty? then
66-
(@options[:arguments] || {}).merge({XArgs::QUEUE_TYPE => @type})
72+
args = @options[:arguments] || {}
73+
{XArgs::QUEUE_TYPE => @type}.merge(args)
6774
else
6875
@options[:arguments]
6976
end

spec/higher_level_api/integration/queue_declare_spec.rb

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,54 @@
7575
end
7676

7777
context "declared as quorum" do
78-
it "is declared as durable and non-exclusive" do
79-
q = channel.quorum_queue("bunny.qq.1", arguments: {
78+
it "is declared as durable and non-exclusive via MarchHare::Channel#quorum_queue" do
79+
q = channel.quorum_queue("march_hare.qq.#{rand}", arguments: {
80+
"x-quorum-initial-group-size" => 3
81+
})
82+
expect(q).to be_durable
83+
expect(q).not_to be_exclusive
84+
q.delete
85+
end
86+
87+
it "is declared as durable and non-exclusive via MarchHare::Channel#queue with :type" do
88+
q = channel.queue("march_hare.qq.#{rand}", type: "quorum")
89+
expect(q).to be_durable
90+
expect(q).not_to be_exclusive
91+
q.delete
92+
end
93+
94+
it "is declared as durable and non-exclusive via MarchHare::Channel#queue with x-queue-type" do
95+
q = channel.queue("march_hare.qq.#{rand}", arguments: {
96+
"x-queue-type" => "quorum",
8097
"x-quorum-initial-group-size" => 3
8198
})
8299
expect(q).to be_durable
83100
expect(q).not_to be_exclusive
84101
q.delete
85102
end
103+
104+
it "is declared as a quorum queue" do
105+
q_name = "march_hare.qq.property_equivalence_check"
106+
q = channel.quorum_queue(q_name)
107+
108+
# property equivalence check should not fail for these…
109+
_ = channel.queue(q_name, type: "quorum")
110+
_ = channel.queue(q_name, arguments: {
111+
"x-queue-type" => "quorum"
112+
})
113+
114+
# …but finally fails here
115+
expect do
116+
one_off_ch = connection.create_channel
117+
one_off_ch.queue(q_name, arguments: {
118+
"x-queue-type" => "classic"
119+
})
120+
end.to raise_error(MarchHare::PreconditionFailed)
121+
122+
expect(q).to be_durable
123+
expect(q).not_to be_exclusive
124+
q.delete
125+
end
86126
end
87127

88128
context "declared as stream" do

0 commit comments

Comments
 (0)