Skip to content

Commit 2f9a0fe

Browse files
author
Rob Harrop
committed
Tests for basic.nack
1 parent 81faae0 commit 2f9a0fe

File tree

1 file changed

+116
-0
lines changed
  • test/src/com/rabbitmq/client/test/functional

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
32+
package com.rabbitmq.client.test.functional;
33+
34+
import com.rabbitmq.client.AMQP;
35+
import com.rabbitmq.client.GetResponse;
36+
import com.rabbitmq.client.QueueingConsumer;
37+
38+
public class Nack extends AbstractRejectTest {
39+
40+
public void testSingleNack() throws Exception {
41+
String q =
42+
channel.queueDeclare("", false, true, false, null).getQueue();
43+
44+
byte[] m1 = "1".getBytes();
45+
byte[] m2 = "2".getBytes();
46+
47+
basicPublishVolatile(m1, q);
48+
basicPublishVolatile(m2, q);
49+
50+
long tag1 = checkDelivery(channel.basicGet(q, false), m1, false);
51+
long tag2 = checkDelivery(channel.basicGet(q, false), m2, false);
52+
53+
QueueingConsumer c = new QueueingConsumer(secondaryChannel);
54+
String consumerTag = secondaryChannel.basicConsume(q, false, c);
55+
56+
// requeue
57+
channel.basicNack(tag2, false, true);
58+
59+
long tag3 = checkDelivery(c.nextDelivery(), m2, true);
60+
secondaryChannel.basicCancel(consumerTag);
61+
62+
// no requeue
63+
secondaryChannel.basicNack(tag3, false, false);
64+
65+
assertNull(channel.basicGet(q, false));
66+
channel.basicAck(tag1, false);
67+
channel.basicNack(tag3, false, true);
68+
69+
expectError(AMQP.PRECONDITION_FAILED);
70+
}
71+
72+
public void testMultiNack() throws Exception {
73+
String q =
74+
channel.queueDeclare("", false, true, false, null).getQueue();
75+
76+
byte[] m1 = "1".getBytes();
77+
byte[] m2 = "2".getBytes();
78+
byte[] m3 = "3".getBytes();
79+
byte[] m4 = "4".getBytes();
80+
81+
basicPublishVolatile(m1, q);
82+
basicPublishVolatile(m2, q);
83+
basicPublishVolatile(m3, q);
84+
basicPublishVolatile(m4, q);
85+
86+
checkDelivery(channel.basicGet(q, false), m1, false);
87+
long tag1 = checkDelivery(channel.basicGet(q, false), m2, false);
88+
checkDelivery(channel.basicGet(q, false), m3, false);
89+
long tag2 = checkDelivery(channel.basicGet(q, false), m4, false);
90+
91+
// ack, leaving a gap in un-acked sequence
92+
channel.basicAck(tag1, false);
93+
94+
QueueingConsumer c = new QueueingConsumer(secondaryChannel);
95+
String consumerTag = secondaryChannel.basicConsume(q, false, c);
96+
97+
// requeue multi
98+
channel.basicNack(tag2, true, true);
99+
100+
checkDelivery(c.nextDelivery(), m4, true);
101+
checkDelivery(c.nextDelivery(), m3, true);
102+
long tag3 = checkDelivery(c.nextDelivery(), m1, true);
103+
104+
secondaryChannel.basicCancel(consumerTag);
105+
106+
// no requeue
107+
secondaryChannel.basicNack(tag3, true, false);
108+
109+
assertNull(channel.basicGet(q, false));
110+
111+
channel.basicNack(tag3, true, true);
112+
113+
expectError(AMQP.PRECONDITION_FAILED);
114+
}
115+
116+
}

0 commit comments

Comments
 (0)