Skip to content

Commit 2baee63

Browse files
author
Simon MacMullen
committed
Test doubled and crazy delivery tags.
1 parent 3353eda commit 2baee63

File tree

5 files changed

+75
-16
lines changed

5 files changed

+75
-16
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public static TestSuite suite() {
5454
suite.addTestSuite(AlternateExchange.class);
5555
suite.addTestSuite(QueueLifecycle.class);
5656
suite.addTestSuite(QueueExclusivity.class);
57+
suite.addTestSuite(InvalidAcks.class);
58+
suite.addTestSuite(InvalidAcksTx.class);
5759
return suite;
5860
}
5961
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.rabbitmq.client.test.functional;
2+
3+
import java.io.IOException;
4+
5+
public class InvalidAcks extends InvalidAcksBase {
6+
protected void select() throws IOException {}
7+
protected void commit() throws IOException {}
8+
}
9+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.rabbitmq.client.test.functional;
2+
3+
import com.rabbitmq.client.AMQP;
4+
import com.rabbitmq.client.GetResponse;
5+
import com.rabbitmq.client.test.BrokerTestCase;
6+
7+
import java.io.IOException;
8+
9+
/**
10+
* See bug 21846:
11+
* Basic.Ack is now required to signal a channel error immediately upon
12+
* detecting an invalid deliveryTag, even if the channel is (Tx-)transacted.
13+
*
14+
* Specifically, a client MUST not acknowledge the same message more than once.
15+
*/
16+
public abstract class InvalidAcksBase extends BrokerTestCase {
17+
protected abstract void select() throws IOException;
18+
protected abstract void commit() throws IOException;
19+
20+
public void testDoubleAck()
21+
throws IOException
22+
{
23+
select();
24+
String q = channel.queueDeclare().getQueue();
25+
basicPublishVolatile(q);
26+
commit();
27+
28+
long tag = channel.basicGet(q, false).getEnvelope().getDeliveryTag();
29+
channel.basicAck(tag, false);
30+
channel.basicAck(tag, false);
31+
32+
expectChannelError(AMQP.NOT_FOUND);
33+
}
34+
35+
private void expectChannelError(int error) {
36+
try {
37+
channel.queueDeclare();
38+
fail("Expected channel error " + error);
39+
} catch (IOException e) {
40+
checkShutdownSignal(error, e);
41+
}
42+
}
43+
44+
public void testCrazyAck()
45+
throws IOException
46+
{
47+
select();
48+
channel.basicAck(123456, false);
49+
expectChannelError(AMQP.NOT_FOUND);
50+
}
51+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.rabbitmq.client.test.functional;
2+
3+
import java.io.IOException;
4+
5+
public class InvalidAcksTx extends InvalidAcksBase {
6+
protected void select() throws IOException {
7+
channel.txSelect();
8+
}
9+
10+
protected void commit() throws IOException {
11+
channel.txCommit();
12+
}
13+
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,6 @@ public void testRollbackAcksAndReAck()
227227
closeChannel();
228228
}
229229

230-
/*
231-
it is legal to ack the same message twice
232-
*/
233-
public void testDuplicateAck()
234-
throws IOException
235-
{
236-
openChannel();
237-
basicPublish();
238-
txSelect();
239-
basicGet();
240-
basicAck();
241-
basicAck();
242-
txCommit();
243-
closeChannel();
244-
}
245-
246230
/*
247231
it is illegal to ack with an unknown delivery tag
248232
*/

0 commit comments

Comments
 (0)