Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/march_hare/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,23 @@ def initialize(channel, name, options={})

@channel = channel
@name = name
@options = {:durable => false, :exclusive => false, :auto_delete => false, :passive => false, :arguments => Hash.new, :type => Types::CLASSIC}.merge(options)
@options = {:durable => false, :exclusive => false, :auto_delete => false, :passive => false, :arguments => Hash.new}.merge(options)

args = @options[:arguments] || {}
@type = @options.fetch(:type, args.fetch(XArgs::QUEUE_TYPE, Types::CLASSIC)).to_s
@durable = if @type == Types::QUORUM or @type == Types::STREAM
true
else
@options[:durable]
end

@type = @options[:type].to_s
@durable = @options[:durable]
@exclusive = @options[:exclusive]
@server_named = @name.empty?
@auto_delete = @options[:auto_delete]

@arguments = if @type and !@type.empty? then
(@options[:arguments] || {}).merge({XArgs::QUEUE_TYPE => @type})
args = @options[:arguments] || {}
{XArgs::QUEUE_TYPE => @type}.merge(args)
else
@options[:arguments]
end
Expand Down
44 changes: 42 additions & 2 deletions spec/higher_level_api/integration/queue_declare_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,54 @@
end

context "declared as quorum" do
it "is declared as durable and non-exclusive" do
q = channel.quorum_queue("bunny.qq.1", arguments: {
it "is declared as durable and non-exclusive via MarchHare::Channel#quorum_queue" do
q = channel.quorum_queue("march_hare.qq.#{rand}", arguments: {
"x-quorum-initial-group-size" => 3
})
expect(q).to be_durable
expect(q).not_to be_exclusive
q.delete
end

it "is declared as durable and non-exclusive via MarchHare::Channel#queue with :type" do
q = channel.queue("march_hare.qq.#{rand}", type: "quorum")
expect(q).to be_durable
expect(q).not_to be_exclusive
q.delete
end

it "is declared as durable and non-exclusive via MarchHare::Channel#queue with x-queue-type" do
q = channel.queue("march_hare.qq.#{rand}", arguments: {
"x-queue-type" => "quorum",
"x-quorum-initial-group-size" => 3
})
expect(q).to be_durable
expect(q).not_to be_exclusive
q.delete
end

it "is declared as a quorum queue" do
q_name = "march_hare.qq.property_equivalence_check"
q = channel.quorum_queue(q_name)

# property equivalence check should not fail for these…
_ = channel.queue(q_name, type: "quorum")
_ = channel.queue(q_name, arguments: {
"x-queue-type" => "quorum"
})

# …but finally fails here
expect do
one_off_ch = connection.create_channel
one_off_ch.queue(q_name, arguments: {
"x-queue-type" => "classic"
})
end.to raise_error(MarchHare::PreconditionFailed)

expect(q).to be_durable
expect(q).not_to be_exclusive
q.delete
end
end

context "declared as stream" do
Expand Down