Skip to content

Commit 3b3a332

Browse files
author
Rob Harrop
committed
update .hgignore for idea
1 parent 53bb801 commit 3b3a332

File tree

3 files changed

+80
-6
lines changed

3 files changed

+80
-6
lines changed

.hgignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ syntax: glob
99

1010
syntax: regexp
1111
^build/
12+
^out/
13+
^.idea/

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

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package com.rabbitmq.client.test.functional;
3333

3434
import com.rabbitmq.client.AMQP;
35+
import com.rabbitmq.client.GetResponse;
3536
import com.rabbitmq.client.test.BrokerTestCase;
3637

3738
import java.io.IOException;
@@ -43,14 +44,26 @@
4344
*/
4445
public class PerQueueTTL extends BrokerTestCase {
4546

47+
private static final String TTL_EXCHANGE = "ttl.exchange";
48+
4649
private static final String TTL_ARG = "x-message-ttl";
4750

4851
private static final String TTL_QUEUE_NAME = "queue.ttl";
4952

5053
private static final String TTL_INVALID_QUEUE_NAME = "invalid.queue.ttl";
5154

55+
@Override
56+
protected void createResources() throws IOException {
57+
this.channel.exchangeDeclare(TTL_EXCHANGE, "direct");
58+
}
59+
60+
@Override
61+
protected void releaseResources() throws IOException {
62+
this.channel.exchangeDelete(TTL_EXCHANGE);
63+
}
64+
5265
public void testCreateQueueWithTTL() throws IOException {
53-
AMQP.Queue.DeclareOk declareOk = declareQueue(TTL_QUEUE_NAME, 2000);
66+
AMQP.Queue.DeclareOk declareOk = declareQueue(TTL_QUEUE_NAME, 2000L);
5467
assertNotNull(declareOk);
5568
}
5669

@@ -72,9 +85,70 @@ public void testCreateQueueWithZeroTTL() throws Exception {
7285
}
7386
}
7487

88+
/*
89+
* Test messages expire when using basic get.
90+
*/
91+
public void testPublishAndGetWithExpiry() throws Exception {
92+
long ttl = 2000;
93+
declareQueue(TTL_QUEUE_NAME, ttl);
94+
this.channel.queueBind(TTL_QUEUE_NAME, TTL_EXCHANGE, TTL_QUEUE_NAME);
95+
96+
byte[] msg1 = "one".getBytes();
97+
byte[] msg2 = "two".getBytes();
98+
byte[] msg3 = "three".getBytes();
99+
100+
this.channel.basicPublish(TTL_EXCHANGE, TTL_QUEUE_NAME, null, msg1);
101+
Thread.sleep(1500);
102+
103+
this.channel.basicPublish(TTL_EXCHANGE, TTL_QUEUE_NAME, null, msg2);
104+
Thread.sleep(1000);
105+
106+
this.channel.basicPublish(TTL_EXCHANGE, TTL_QUEUE_NAME, null, msg3);
107+
108+
assertEquals("two", new String(get()));
109+
assertEquals("three", new String(get()));
110+
111+
}
112+
113+
/*
114+
* Test get expiry for messages sent under a transaction
115+
*/
116+
public void testTransactionalPublishWithGet() throws Exception {
117+
long ttl = 1000;
118+
declareQueue(TTL_QUEUE_NAME, ttl);
119+
this.channel.queueBind(TTL_QUEUE_NAME, TTL_EXCHANGE, TTL_QUEUE_NAME);
120+
121+
byte[] msg1 = "one".getBytes();
122+
byte[] msg2 = "two".getBytes();
123+
124+
this.channel.txSelect();
125+
126+
this.channel.basicPublish(TTL_EXCHANGE, TTL_QUEUE_NAME, null, msg1);
127+
Thread.sleep(1500);
128+
129+
this.channel.basicPublish(TTL_EXCHANGE, TTL_QUEUE_NAME, null, msg2);
130+
this.channel.txCommit();
131+
Thread.sleep(500);
132+
133+
assertEquals("one", new String(get()));
134+
Thread.sleep(800);
135+
136+
assertNull(get());
137+
}
138+
139+
140+
private byte[] get() throws IOException {
141+
GetResponse response = this.channel.basicGet(TTL_QUEUE_NAME, false);
142+
if(response == null) {
143+
return null;
144+
}
145+
return response.getBody();
146+
}
147+
75148
private AMQP.Queue.DeclareOk declareQueue(String name, Object ttlValue) throws IOException {
76-
AMQP.Queue.DeclareOk declareOk = this.channel.queueDeclare(name, false, false, false,
77-
Collections.<String, Object>singletonMap(TTL_ARG, ttlValue));
78-
return declareOk;
149+
Map<String, Object> argMap = Collections.singletonMap(TTL_ARG, ttlValue);
150+
return this.channel.queueDeclare(name, false, true, false, argMap);
79151
}
152+
153+
80154
}

test/src/com/rabbitmq/examples/MulticastMain.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.apache.commons.cli.ParseException;
5050

5151
import com.rabbitmq.client.AMQP;
52-
import com.rabbitmq.client.Address;
5352
import com.rabbitmq.client.Channel;
5453
import com.rabbitmq.client.Connection;
5554
import com.rabbitmq.client.ConnectionFactory;
@@ -58,7 +57,6 @@
5857
import com.rabbitmq.client.QueueingConsumer;
5958
import com.rabbitmq.client.ReturnListener;
6059
import com.rabbitmq.client.ShutdownSignalException;
61-
import com.rabbitmq.client.AMQP.Queue;
6260
import com.rabbitmq.client.QueueingConsumer.Delivery;
6361

6462

0 commit comments

Comments
 (0)