Skip to content

Commit 49a70a0

Browse files
committed
Handle last_stream_member more gently in CLI
1 parent 1645542 commit 49a70a0

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

deps/rabbitmq_cli/lib/rabbitmq/cli/streams/commands/delete_replica_command.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ defmodule RabbitMQ.CLI.Streams.Commands.DeleteReplicaCommand do
2929
{:error, :quorum_queue_not_supported} ->
3030
{:error, "Cannot delete replicas from a quorum queue"}
3131

32+
{:error, :last_stream_member} ->
33+
{:error, "Cannot delete the last member of a stream"}
3234
other ->
3335
other
3436
end

deps/rabbitmq_cli/test/streams/delete_replica_command_test.exs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ defmodule RabbitMQ.CLI.Streams.Commands.DeleteReplicaCommandTest do
2020
setup context do
2121
{:ok, opts: %{
2222
node: get_rabbit_hostname(),
23-
timeout: context[:test_timeout] || 30000
23+
timeout: context[:test_timeout] || 30000,
24+
vhost: "/"
2425
}}
2526
end
2627

@@ -42,6 +43,12 @@ defmodule RabbitMQ.CLI.Streams.Commands.DeleteReplicaCommandTest do
4243
assert @command.validate(["stream-queue-a", "rabbit@new-node"], %{}) == :ok
4344
end
4445

46+
test "run: trying to delete the last member of a stream should fail and return a meaningful message", context do
47+
declare_stream("test_stream_1", "/")
48+
assert @command.run(["test_stream_1", get_rabbit_hostname()], context[:opts]) ==
49+
{:error, "Cannot delete the last member of a stream"}
50+
end
51+
4552
@tag test_timeout: 3000
4653
test "run: targeting an unreachable node throws a badrpc" do
4754
assert match?({:badrpc, _}, @command.run(["stream-queue-a", "rabbit@new-node"],

deps/rabbitmq_cli/test/test_helper.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ defmodule TestHelper do
162162
[queue_name, durable, auto_delete, args, owner, "acting-user"])
163163
end
164164

165+
def declare_stream(name, vhost) do
166+
declare_queue(name, vhost, true, false, [{"x-queue-type", :longstr, "stream"}])
167+
end
168+
165169
def delete_queue(name, vhost) do
166170
queue_name = :rabbit_misc.r(vhost, :queue, name)
167171
:rpc.call(get_rabbit_hostname(),

0 commit comments

Comments
 (0)