Skip to content

Commit 0307e72

Browse files
author
Simon MacMullen
committed
Merge bug26068
2 parents 3396f9e + 2a76d63 commit 0307e72

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

src/com/rabbitmq/client/AlreadyClosedException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public AlreadyClosedException(ShutdownSignalException sse)
3030
super(sse.isHardError(),
3131
sse.isInitiatedByApplication(),
3232
sse.getReason(),
33-
sse.getReference());
33+
sse.getReference(),
34+
(sse.isHardError() ? "connection" : "channel" + " is already closed due to previous "));
3435
}
3536
}

src/com/rabbitmq/client/ShutdownSignalException.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,25 @@ public ShutdownSignalException(boolean hardError,
5757
boolean initiatedByApplication,
5858
Method reason, Object ref)
5959
{
60-
super((initiatedByApplication
61-
? ("clean " + (hardError ? "connection" : "channel") + " shutdown")
62-
: ((hardError ? "connection" : "channel") + " error"))
63-
+ "; reason: " + reason);
60+
this(hardError, initiatedByApplication, reason, ref, "");
61+
}
62+
63+
/**
64+
* Construct a ShutdownSignalException from the arguments.
65+
* @param hardError the relevant hard error
66+
* @param initiatedByApplication if the shutdown was client-initiated
67+
* @param reason AMQP method describing the exception reason
68+
* @param ref Reference to Connection or Channel that fired the signal
69+
* @param messagePrefix prefix to add to exception message
70+
*/
71+
public ShutdownSignalException(boolean hardError,
72+
boolean initiatedByApplication,
73+
Method reason, Object ref, String messagePrefix)
74+
{
75+
super(messagePrefix + (initiatedByApplication
76+
? ("clean " + (hardError ? "connection" : "channel") + " shutdown")
77+
: ((hardError ? "connection" : "channel") + " error"))
78+
+ "; reason: " + reason);
6479
this._hardError = hardError;
6580
this._initiatedByApplication = initiatedByApplication;
6681
this._reason = reason;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.rabbitmq.client.test.functional;
2+
3+
import com.rabbitmq.client.AlreadyClosedException;
4+
import com.rabbitmq.client.test.BrokerTestCase;
5+
6+
import java.io.IOException;
7+
import java.util.UUID;
8+
9+
public class ExceptionMessages extends BrokerTestCase {
10+
public void testAlreadyClosedExceptionMessageWithChannelError() throws IOException {
11+
String uuid = UUID.randomUUID().toString();
12+
try {
13+
channel.queueDeclarePassive(uuid);
14+
fail("expected queueDeclarePassive to throw");
15+
} catch (IOException e) {
16+
// ignored
17+
}
18+
19+
try {
20+
channel.queueDeclarePassive(uuid);
21+
fail("expected queueDeclarePassive to throw");
22+
} catch (AlreadyClosedException ace) {
23+
assertTrue(ace.getMessage().startsWith("channel is already closed due to channel error"));
24+
}
25+
}
26+
27+
public void testAlreadyClosedExceptionMessageWithCleanClose() throws IOException {
28+
String uuid = UUID.randomUUID().toString();
29+
30+
try {
31+
channel.close();
32+
channel.queueDeclare(uuid, false, false, false, null);
33+
} catch (AlreadyClosedException ace) {
34+
assertTrue(ace.getMessage().startsWith("channel is already closed due to clean channel shutdown"));
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)