Skip to content

Commit 74f47d0

Browse files
author
Alexandru Scvortov
committed
correct exceptions for waitForConfirms
The two waitForConfirms can fail with exceptions in only two cases: 1) when something happened to the underlying channel, we just throw channel exception to the caller without wrapping it, and 2) when waitForConfirmsOrDie received a nack, we throw an IOException("nacks received"). The test is for the first case. Since we don't have a way to cause a nack, we can't test for the second case.
1 parent 42ce342 commit 74f47d0

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ void basicNack(long deliveryTag, boolean multiple, boolean requeue)
703703
* non-Confirm channel, waitForConfirms returns true immediately.
704704
* @return whether all the messages were ack'd (and none were nack'd)
705705
*/
706-
boolean waitForConfirms() throws IOException, InterruptedException;
706+
boolean waitForConfirms() throws InterruptedException;
707707

708708
/** Wait until all messages published since the last call have
709709
* been either ack'd or nack'd by the broker. If any of the

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ public ConfirmListener getConfirmListener() {
166166

167167
/** {@inheritDoc} */
168168
public boolean waitForConfirms()
169-
throws IOException, InterruptedException
169+
throws InterruptedException
170170
{
171171
synchronized (unconfirmedSet) {
172172
while (true) {
173173
if (getCloseReason() != null) {
174-
throw new IOException(Utility.fixStackTrace(getCloseReason()));
174+
throw Utility.fixStackTrace(getCloseReason());
175175
}
176176
if (unconfirmedSet.isEmpty()) {
177177
boolean aux = onlyAcksReceived;
@@ -188,9 +188,8 @@ public void waitForConfirmsOrDie()
188188
throws IOException, InterruptedException
189189
{
190190
if (!waitForConfirms()) {
191-
close(AMQP.REPLY_SUCCESS, "NACKS RECEIVED", true,
192-
new RuntimeException("received nack"), false);
193-
throw new IOException(Utility.fixStackTrace(getCloseReason()));
191+
close(AMQP.REPLY_SUCCESS, "NACKS RECEIVED", true, null, false);
192+
throw new IOException("nacks received");
194193
}
195194
}
196195

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import com.rabbitmq.client.DefaultConsumer;
2424
import com.rabbitmq.client.GetResponse;
2525
import com.rabbitmq.client.MessageProperties;
26+
import com.rabbitmq.client.ShutdownSignalException;
2627
import com.rabbitmq.client.test.BrokerTestCase;
2728

29+
2830
import java.io.IOException;
2931
import java.util.Collections;
3032
import java.util.Map;
@@ -261,9 +263,9 @@ public void testWaitForConfirmsException()
261263
try {
262264
channel.waitForConfirmsOrDie();
263265
fail("waitAcks worked on a closed channel");
264-
} catch (IOException ioe) {
265-
if (ioe.getCause() == null || !(ioe.getCause() instanceof RuntimeException))
266-
fail("got the wrong exception :(");
266+
} catch (ShutdownSignalException sse) {
267+
if (!(sse.getReason() instanceof AMQP.Channel.Close))
268+
fail("didn't except for the right reason");
267269
//whoosh; everything ok
268270
} catch (InterruptedException e) {
269271
// whoosh; we should probably re-run, though

0 commit comments

Comments
 (0)