|
20 | 20 | import com.rabbitmq.client.AMQP; |
21 | 21 | import com.rabbitmq.client.GetResponse; |
22 | 22 | import com.rabbitmq.client.QueueingConsumer; |
| 23 | +import com.rabbitmq.client.QueueingConsumer.Delivery; |
23 | 24 | import com.rabbitmq.client.test.BrokerTestCase; |
24 | 25 |
|
25 | 26 | import java.io.IOException; |
@@ -60,19 +61,18 @@ public void testCreateQueueTTLTypes() throws IOException { |
60 | 61 | } |
61 | 62 | } |
62 | 63 |
|
63 | | - public void testCreateQueueWithInvalidTTL() throws Exception { |
| 64 | + public void testTTLAllowZero() throws Exception { |
64 | 65 | 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); |
67 | 67 | } catch (IOException e) { |
68 | | - checkShutdownSignal(AMQP.PRECONDITION_FAILED, e); |
| 68 | + fail("Should be able to declare a queue with zero for x-message-ttl"); |
69 | 69 | } |
70 | 70 | } |
71 | 71 |
|
72 | | - public void testTTLMustBeGtZero() throws Exception { |
| 72 | + public void testCreateQueueWithInvalidTTL() throws Exception { |
73 | 73 | 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"); |
76 | 76 | } catch (IOException e) { |
77 | 77 | checkShutdownSignal(AMQP.PRECONDITION_FAILED, e); |
78 | 78 | } |
@@ -130,7 +130,6 @@ public void testPublishAndGetWithExpiry() throws Exception { |
130 | 130 |
|
131 | 131 | assertEquals(MSG[1], get()); |
132 | 132 | assertEquals(MSG[2], get()); |
133 | | - |
134 | 133 | } |
135 | 134 |
|
136 | 135 | /* |
@@ -194,6 +193,25 @@ public void testExpiryWithRequeueAfterConsume() throws Exception { |
194 | 193 | assertNull("Requeued message not expired", get()); |
195 | 194 | } |
196 | 195 |
|
| 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 | + |
197 | 215 | private String get() throws IOException { |
198 | 216 | GetResponse response = basicGet(TTL_QUEUE_NAME); |
199 | 217 | return response == null ? null : new String(response.getBody()); |
|
0 commit comments