Skip to content

Commit 8f5cb90

Browse files
author
Steve Powell
committed
Add close reason Exception to IOException cause thrown by waitForConfirmsOrDie();
ConfirmBase.waitForConfirms() takes optional String testTitle to report on fail(); ConfirmBase.waitForConfirms() properly reports assertion failures thrown in waiter thread but propagates ShutdownSignalException; Confirm tests check all persistent/mandatory/immediate combinations for durable and non-durable queues; Confirm tests announce combination on failure as assertion string; Confirm tests use of bit/int flags hack encapsulated to one procedure.
1 parent a810674 commit 8f5cb90

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

src/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void waitForConfirmsOrDie()
182182
{
183183
if (!waitForConfirms()) {
184184
close(AMQP.REPLY_SUCCESS, "NACKS RECEIVED", true, null, false);
185-
throw new IOException("nacks received");
185+
throw new IOException("nacks received", getCloseReason());
186186
}
187187
}
188188

test/src/com/rabbitmq/client/test/ConfirmBase.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@
2525
import java.util.concurrent.TimeoutException;
2626
import java.util.concurrent.TimeUnit;
2727

28+
import junit.framework.AssertionFailedError;
29+
2830
public class ConfirmBase extends BrokerTestCase {
29-
protected void waitForConfirms()
30-
throws InterruptedException, TimeoutException
31+
protected void waitForConfirms() throws Exception
32+
{
33+
waitForConfirms("ConfirmBase.waitForConfirms");
34+
}
35+
36+
protected void waitForConfirms(final String testTitle) throws Exception
3137
{
3238
try {
3339
FutureTask<?> waiter = new FutureTask<Object>(new Runnable() {
@@ -36,15 +42,20 @@ public void run() {
3642
channel.waitForConfirmsOrDie();
3743
} catch (IOException e) {
3844
throw (ShutdownSignalException)e.getCause();
39-
} catch (InterruptedException e) {
40-
fail("test interrupted");
45+
} catch (InterruptedException _) {
46+
fail(testTitle + ": interrupted");
4147
}
4248
}
4349
}, null);
4450
(Executors.newSingleThreadExecutor()).execute(waiter);
4551
waiter.get(10, TimeUnit.SECONDS);
46-
} catch (ExecutionException e) {
47-
throw (ShutdownSignalException)e.getCause();
52+
} catch (ExecutionException ee) {
53+
Throwable t = ee.getCause();
54+
if (t instanceof ShutdownSignalException) throw (ShutdownSignalException) t;
55+
if (t instanceof AssertionFailedError) throw (AssertionFailedError) t;
56+
throw (Exception)t;
57+
} catch (TimeoutException _) {
58+
fail(testTitle + ": timeout");
4859
}
4960
}
5061
}

test/src/com/rabbitmq/client/test/functional/Confirm.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,26 @@ private void declareBindQueue(String queueName, boolean durable)
7676
channel.queueBind(queueName, "amq.direct", "confirm-multiple-queues");
7777
}
7878

79-
public void testPersistentMandatoryImmediateDurable() throws Exception
79+
public void testAllFlagsDurable() throws Exception
8080
{
8181
declareConsumeQueue("confirm-test", true);
82-
for (int flags=0; flags<8; ++flags) {
83-
System.out.print("Confirm durable (persistent&mandatory&immediate) = ("+flags+")");
84-
confirmTestByFlags("", "confirm-test", flags);
85-
System.out.println(" succeeded.");
86-
}
82+
confirmTestAllFlags("", "confirm-test");
8783
}
8884

89-
public void testPersistentMandatoryImmediateNondurable() throws Exception
85+
public void testAllFlagsNondurable() throws Exception
9086
{
9187
declareConsumeQueue("confirm-test-nondurable", false);
92-
for (int flags=0; flags<8; ++flags) {
93-
System.out.print("Confirm nondurable (persistent&mandatory&immediate) = ("+flags+")");
94-
confirmTestByFlags("", "confirm-test-nondurable", flags);
95-
System.out.println(" succeeded.");
96-
}
88+
confirmTestAllFlags("", "confirm-test-nondurable");
9789
}
9890

99-
private void confirmTestByFlags(String exchangeName, String queueName, int flags) throws Exception
91+
private void confirmTestAllFlags(String exchangeName, String queueName) throws Exception
10092
{
101-
boolean persistent = (flags & 4)!=0;
102-
boolean mandatory = (flags & 2)!=0;
103-
boolean immediate = (flags & 1)!=0;
104-
confirmTest(exchangeName, queueName, persistent, mandatory, immediate);
93+
for (int flags=0; flags<8; ++flags) {
94+
boolean persistent = (flags & 4)!=0;
95+
boolean mandatory = (flags & 2)!=0;
96+
boolean immediate = (flags & 1)!=0;
97+
confirmTest(exchangeName, queueName, persistent, mandatory, immediate);
98+
}
10599
}
106100

107101
public void testPersistentImmediateNoConsumer()
@@ -311,7 +305,11 @@ private void confirmTest(String exchange, String queueName,
311305
{
312306
publishN(exchange, queueName, persistent, mandatory, immediate);
313307

314-
waitForConfirms();
308+
waitForConfirms("confirmTest(exchange='" + exchange
309+
+ "', queue='" + queueName
310+
+ "', persistent=" + persistent
311+
+ ", mandatory=" + mandatory
312+
+ ", immediate=" + immediate + ")");
315313
}
316314

317315
private void publishN(String exchangeName, String queueName,

0 commit comments

Comments
 (0)