Skip to content

Commit 81faae0

Browse files
author
Rob Harrop
committed
Added requeue argument for basicNack. Reworked Reject tests to extract common functionality ready for the Nack tests
1 parent a0d6763 commit 81faae0

File tree

4 files changed

+94
-55
lines changed

4 files changed

+94
-55
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,12 @@ Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, b
544544
* @param multiple true to reject all messages up to and including
545545
* the supplied delivery tag; false to reject just the supplied
546546
* delivery tag.
547+
* @param requeue true if the rejected message(s) should be requeued rather
548+
* than discarded/dead-lettered
547549
* @throws java.io.IOException if an error is encountered
548550
*/
549-
void basicNack(long deliveryTag, boolean multiple) throws IOException;
551+
void basicNack(long deliveryTag, boolean multiple, boolean requeue)
552+
throws IOException;
550553

551554
/**
552555
* Reject a message. Supply the deliveryTag from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,10 @@ public void basicAck(long deliveryTag, boolean multiple)
720720
}
721721

722722
/** Public API - {@inheritDoc} */
723-
public void basicNack(long deliveryTag, boolean multiple)
723+
public void basicNack(long deliveryTag, boolean multiple, boolean requeue)
724724
throws IOException
725725
{
726-
transmit(new Basic.Nack(deliveryTag, multiple));
726+
transmit(new Basic.Nack(deliveryTag, multiple, requeue));
727727
}
728728

729729
/** Public API - {@inheritDoc} */
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 1.1 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License at
4+
// http://www.mozilla.org/MPL/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2010 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2010 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
31+
package com.rabbitmq.client.test.functional;
32+
33+
import com.rabbitmq.client.Channel;
34+
import com.rabbitmq.client.Envelope;
35+
import com.rabbitmq.client.GetResponse;
36+
import com.rabbitmq.client.QueueingConsumer;
37+
import com.rabbitmq.client.test.BrokerTestCase;
38+
39+
import java.io.IOException;
40+
import java.util.Arrays;
41+
42+
abstract class AbstractRejectTest extends BrokerTestCase {
43+
44+
protected Channel secondaryChannel;
45+
46+
@Override
47+
protected void setUp()
48+
throws IOException
49+
{
50+
super.setUp();
51+
secondaryChannel = connection.createChannel();
52+
53+
}
54+
55+
@Override
56+
protected void tearDown()
57+
throws IOException
58+
{
59+
if (secondaryChannel != null) {
60+
secondaryChannel.abort();
61+
secondaryChannel = null;
62+
}
63+
super.tearDown();
64+
}
65+
66+
protected long checkDelivery(QueueingConsumer.Delivery d,
67+
byte[] msg, boolean redelivered)
68+
{
69+
assertNotNull(d);
70+
return checkDelivery(d.getEnvelope(), d.getBody(), msg, redelivered);
71+
}
72+
73+
protected long checkDelivery(GetResponse r, byte[] msg, boolean redelivered)
74+
{
75+
assertNotNull(r);
76+
return checkDelivery(r.getEnvelope(), r.getBody(), msg, redelivered);
77+
}
78+
79+
protected long checkDelivery(Envelope e, byte[] m,
80+
byte[] msg, boolean redelivered)
81+
{
82+
assertNotNull(e);
83+
assertTrue(Arrays.equals(m, msg));
84+
assertEquals(e.isRedeliver(), redelivered);
85+
return e.getDeliveryTag();
86+
}
87+
}

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

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,64 +31,13 @@
3131

3232
package com.rabbitmq.client.test.functional;
3333

34-
import com.rabbitmq.client.test.BrokerTestCase;
35-
3634
import com.rabbitmq.client.AMQP;
37-
import com.rabbitmq.client.Channel;
38-
import com.rabbitmq.client.Envelope;
39-
import com.rabbitmq.client.GetResponse;
4035
import com.rabbitmq.client.QueueingConsumer;
41-
import com.rabbitmq.client.QueueingConsumer.Delivery;
4236

4337
import java.io.IOException;
44-
import java.util.Arrays;
4538

46-
public class Reject extends BrokerTestCase
39+
public class Reject extends AbstractRejectTest
4740
{
48-
49-
protected Channel secondaryChannel;
50-
51-
@Override
52-
protected void setUp()
53-
throws IOException
54-
{
55-
super.setUp();
56-
secondaryChannel = connection.createChannel();
57-
58-
}
59-
60-
@Override
61-
protected void tearDown()
62-
throws IOException
63-
{
64-
if (secondaryChannel != null) {
65-
secondaryChannel.abort();
66-
secondaryChannel = null;
67-
}
68-
super.tearDown();
69-
}
70-
71-
protected long checkDelivery(Delivery d, byte[] msg, boolean redelivered)
72-
{
73-
assertNotNull(d);
74-
return checkDelivery(d.getEnvelope(), d.getBody(), msg, redelivered);
75-
}
76-
77-
protected long checkDelivery(GetResponse r, byte[] msg, boolean redelivered)
78-
{
79-
assertNotNull(r);
80-
return checkDelivery(r.getEnvelope(), r.getBody(), msg, redelivered);
81-
}
82-
83-
protected long checkDelivery(Envelope e, byte[] m,
84-
byte[] msg, boolean redelivered)
85-
{
86-
assertNotNull(e);
87-
assertTrue(Arrays.equals(m, msg));
88-
assertEquals(e.isRedeliver(), redelivered);
89-
return e.getDeliveryTag();
90-
}
91-
9241
public void testReject()
9342
throws IOException, InterruptedException
9443
{

0 commit comments

Comments
 (0)