Skip to content

Commit ee31196

Browse files
author
Rob Harrop
committed
Make order of requeued messages unimportant in the Nack tests
1 parent 581945b commit ee31196

File tree

1 file changed

+26
-5
lines changed
  • test/src/com/rabbitmq/client/test/functional

1 file changed

+26
-5
lines changed

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import com.rabbitmq.client.GetResponse;
3636
import com.rabbitmq.client.QueueingConsumer;
3737

38+
import java.util.HashSet;
39+
import java.util.Set;
40+
3841
public class Nack extends AbstractRejectTest {
3942

4043
public void testSingleNack() throws Exception {
@@ -97,9 +100,7 @@ public void testMultiNack() throws Exception {
97100
// requeue multi
98101
channel.basicNack(tag2, true, true);
99102

100-
checkDelivery(c.nextDelivery(), m4, true);
101-
checkDelivery(c.nextDelivery(), m3, true);
102-
long tag3 = checkDelivery(c.nextDelivery(), m1, true);
103+
long tag3 = checkDeliveries(c, m1, m3, m4);
103104

104105
secondaryChannel.basicCancel(consumerTag);
105106

@@ -132,9 +133,29 @@ public void testNackAll() throws Exception {
132133
QueueingConsumer c = new QueueingConsumer(secondaryChannel);
133134
String consumerTag = secondaryChannel.basicConsume(q, true, c);
134135

135-
checkDelivery(c.nextDelivery(), m2, true);
136-
checkDelivery(c.nextDelivery(), m1, true);
136+
checkDeliveries(c, m1, m2);
137137

138138
secondaryChannel.basicCancel(consumerTag);
139139
}
140+
141+
private long checkDeliveries(QueueingConsumer c, byte[]... messages)
142+
throws InterruptedException {
143+
144+
Set<String> msgSet = new HashSet<String>();
145+
for (byte[] message : messages) {
146+
msgSet.add(new String(message));
147+
}
148+
149+
long lastTag = -1;
150+
for(int x = 0; x < messages.length; x++) {
151+
QueueingConsumer.Delivery delivery = c.nextDelivery();
152+
String m = new String(delivery.getBody());
153+
assertTrue("Unexpected message", msgSet.remove(m));
154+
checkDelivery(delivery, m.getBytes(), true);
155+
lastTag = delivery.getEnvelope().getDeliveryTag();
156+
}
157+
158+
assertTrue(msgSet.isEmpty());
159+
return lastTag;
160+
}
140161
}

0 commit comments

Comments
 (0)