Skip to content

Commit f542f55

Browse files
author
Simon MacMullen
committed
Merge bug24725
2 parents 8d84a05 + 0defd4b commit f542f55

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ protected void setUp() throws IOException {
5454
channel.queueDeclare("confirm-test-2", true, true, false, null);
5555
channel.basicConsume("confirm-test-2", true,
5656
new DefaultConsumer(channel));
57-
Map<String, Object> argMap =
58-
Collections.singletonMap(TTL_ARG, (Object)1);
59-
channel.queueDeclare("confirm-ttl", true, true, false, argMap);
6057
channel.queueBind("confirm-test", "amq.direct",
6158
"confirm-multiple-queues");
6259
channel.queueBind("confirm-test-2", "amq.direct",
@@ -140,9 +137,16 @@ public void testBasicReject()
140137
public void testQueueTTL()
141138
throws IOException, InterruptedException
142139
{
143-
publishN("", "confirm-ttl", true, false, false);
140+
for (int ttl : new int[]{ 1, 0 }) {
141+
Map<String, Object> argMap =
142+
Collections.singletonMap(TTL_ARG, (Object)ttl);
143+
channel.queueDeclare("confirm-ttl", true, true, false, argMap);
144144

145-
channel.waitForConfirmsOrDie();
145+
publishN("", "confirm-ttl", true, false, false);
146+
channel.waitForConfirmsOrDie();
147+
148+
channel.queueDelete("confirm-ttl");
149+
}
146150
}
147151

148152
public void testBasicRejectRequeue()

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,11 @@ public void testDeclareQueueWithRoutingKeyButNoDeadLetterExchange()
8484
}
8585

8686
public void testDeadLetterQueueTTLExpiredMessages() throws Exception {
87-
Map<String, Object> args = new HashMap<String, Object>();
88-
args.put("x-message-ttl", 1000);
87+
ttlTest(1000);
88+
}
8989

90-
deadLetterTest(new Runnable() {
91-
public void run() {
92-
sleep(2000);
93-
}
94-
}, args, "expired");
90+
public void testDeadLetterQueueZeroTTLExpiredMessages() throws Exception {
91+
ttlTest(0);
9592
}
9693

9794
public void testDeadLetterDeletedDLX() throws Exception {
@@ -309,6 +306,14 @@ public void process(GetResponse getResponse) {
309306
});
310307
}
311308

309+
private void ttlTest(final long ttl) throws Exception {
310+
Map<String, Object> args = new HashMap<String, Object>();
311+
args.put("x-message-ttl", ttl);
312+
deadLetterTest(new Runnable() {
313+
public void run() { sleep(ttl + 1000); }
314+
}, args, "expired");
315+
}
316+
312317
private void sleep(long millis) {
313318
try {
314319
Thread.sleep(millis);

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.rabbitmq.client.AMQP;
2121
import com.rabbitmq.client.GetResponse;
2222
import com.rabbitmq.client.QueueingConsumer;
23+
import com.rabbitmq.client.QueueingConsumer.Delivery;
2324
import com.rabbitmq.client.test.BrokerTestCase;
2425

2526
import java.io.IOException;
@@ -60,19 +61,18 @@ public void testCreateQueueTTLTypes() throws IOException {
6061
}
6162
}
6263

63-
public void testCreateQueueWithInvalidTTL() throws Exception {
64+
public void testTTLAllowZero() throws Exception {
6465
try {
65-
declareQueue(TTL_INVALID_QUEUE_NAME, "foobar");
66-
fail("Should not be able to declare a queue with a non-long value for x-message-ttl");
66+
declareQueue(0);
6767
} catch (IOException e) {
68-
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
68+
fail("Should be able to declare a queue with zero for x-message-ttl");
6969
}
7070
}
7171

72-
public void testTTLMustBeGtZero() throws Exception {
72+
public void testCreateQueueWithInvalidTTL() throws Exception {
7373
try {
74-
declareQueue(TTL_INVALID_QUEUE_NAME, 0);
75-
fail("Should not be able to declare a queue with zero for x-message-ttl");
74+
declareQueue(TTL_INVALID_QUEUE_NAME, "foobar");
75+
fail("Should not be able to declare a queue with a non-long value for x-message-ttl");
7676
} catch (IOException e) {
7777
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
7878
}
@@ -130,7 +130,6 @@ public void testPublishAndGetWithExpiry() throws Exception {
130130

131131
assertEquals(MSG[1], get());
132132
assertEquals(MSG[2], get());
133-
134133
}
135134

136135
/*
@@ -194,6 +193,25 @@ public void testExpiryWithRequeueAfterConsume() throws Exception {
194193
assertNull("Requeued message not expired", get());
195194
}
196195

196+
public void testZeroTTLDelivery() throws Exception {
197+
declareAndBindQueue(0);
198+
199+
// when there is no consumer, message should expire
200+
publish(MSG[0]);
201+
assertNull(get());
202+
203+
// when there is a consumer, message should be delivered
204+
QueueingConsumer c = new QueueingConsumer(channel);
205+
channel.basicConsume(TTL_QUEUE_NAME, c);
206+
publish(MSG[0]);
207+
Delivery d = c.nextDelivery(100);
208+
assertNotNull(d);
209+
210+
// requeued messages should expire
211+
channel.basicReject(d.getEnvelope().getDeliveryTag(), true);
212+
assertNull(c.nextDelivery(100));
213+
}
214+
197215
private String get() throws IOException {
198216
GetResponse response = basicGet(TTL_QUEUE_NAME);
199217
return response == null ? null : new String(response.getBody());

0 commit comments

Comments
 (0)