Skip to content

Commit 7e6efaf

Browse files
committed
Rename Exception and and more status
Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent 3859ddb commit 7e6efaf

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

RabbitMQ.AMQP.Client/Impl/AbstractLifeCycle.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace RabbitMQ.AMQP.Client.Impl;
44

5-
public class AmqpClosedException(string message) : Exception(message);
5+
public class AmqpNotOpenException(string message) : Exception(message);
66

77
public abstract class AbstractLifeCycle : ILifeCycle
88
{
@@ -18,9 +18,18 @@ protected virtual Task OpenAsync()
1818

1919
protected void ThrowIfClosed()
2020
{
21-
if (State == State.Closed)
21+
switch (State)
2222
{
23-
throw new AmqpClosedException(GetType().Name);
23+
case State.Closed:
24+
throw new AmqpNotOpenException("Resource is closed");
25+
case State.Closing:
26+
throw new AmqpNotOpenException("Resource is closing");
27+
case State.Reconnecting:
28+
throw new AmqpNotOpenException("Resource is Reconnecting");
29+
case State.Open:
30+
break;
31+
default:
32+
throw new ArgumentOutOfRangeException();
2433
}
2534
}
2635

Tests/ConnectionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public async Task ThrowAmqpClosedExceptionWhenItemIsClosed()
7979
await management.Queue().Name("ThrowAmqpClosedExceptionWhenItemIsClosed").Declare();
8080
var publisher = connection.PublisherBuilder().Queue("ThrowAmqpClosedExceptionWhenItemIsClosed").Build();
8181
await publisher.CloseAsync();
82-
await Assert.ThrowsAsync<AmqpClosedException>(async () =>
82+
await Assert.ThrowsAsync<AmqpNotOpenException>(async () =>
8383
await publisher.Publish(new AmqpMessage("Hello wold!"), (message, descriptor) =>
8484
{
8585
// it doest matter
@@ -88,10 +88,10 @@ await publisher.Publish(new AmqpMessage("Hello wold!"), (message, descriptor) =>
8888
await connection.CloseAsync();
8989
Assert.Empty(connection.GetPublishers());
9090

91-
Assert.Throws<AmqpClosedException>(() =>
91+
Assert.Throws<AmqpNotOpenException>(() =>
9292
connection.PublisherBuilder().Queue("ThrowAmqpClosedExceptionWhenItemIsClosed").Build());
9393

94-
await Assert.ThrowsAsync<AmqpClosedException>(async () =>
94+
await Assert.ThrowsAsync<AmqpNotOpenException>(async () =>
9595
await management.Queue().Name("ThrowAmqpClosedExceptionWhenItemIsClosed").Declare());
9696
}
9797
}

Tests/ManagementTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ await management.Request(messageId, "", "", "",
115115
public async Task RaiseManagementClosedException()
116116
{
117117
var management = new TestAmqpManagement(null);
118-
await Assert.ThrowsAsync<AmqpClosedException>(async () =>
118+
await Assert.ThrowsAsync<AmqpNotOpenException>(async () =>
119119
await management.Request(new Message(), [200]));
120120
Assert.Equal(State.Closed, management.State);
121121
}

0 commit comments

Comments
 (0)