Skip to content

Commit fe1d27d

Browse files
author
Emile Joubert
committed
Merged bug21846 into default
2 parents da07598 + 2baee63 commit fe1d27d

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
@@ -55,6 +55,8 @@ public static TestSuite suite() {
5555
suite.addTestSuite(ExchangeDeclare.class);
5656
suite.addTestSuite(QueueLifecycle.class);
5757
suite.addTestSuite(QueueExclusivity.class);
58+
suite.addTestSuite(InvalidAcks.class);
59+
suite.addTestSuite(InvalidAcksTx.class);
5860
return suite;
5961
}
6062
}
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
@@ -228,22 +228,6 @@ public void testRollbackAcksAndReAck()
228228
closeChannel();
229229
}
230230

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

0 commit comments

Comments
 (0)