Skip to content

Commit b31654d

Browse files
author
Tim Watson
committed
simplify PerQueueVsPerMessageTTL
1 parent d76f374 commit b31654d

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import java.io.IOException;
2323

24-
public abstract class PerMessageTTL extends TTLHandling {
24+
public class PerMessageTTL extends TTLHandling {
2525

2626
protected Object sessionTTL;
2727

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,33 @@ public class PerQueueVsPerMessageTTL extends PerMessageTTL {
1010

1111
public void testSmallerPerQueueExpiryWins() throws IOException, InterruptedException {
1212
declareAndBindQueue(10);
13+
this.sessionTTL = 1000;
1314

14-
sessionTTL = 1000;
1515
publish("message1");
1616

17-
Thread.sleep(10);
17+
Thread.sleep(20);
1818

1919
assertNull("per-queue ttl should have removed message after 10ms!", get());
2020
}
2121

22-
public void testSmallerPerMessageExpiryWins() throws IOException, InterruptedException {
23-
declareAndBindQueue(5000);
24-
25-
sessionTTL = 10;
26-
publish("message2");
27-
28-
Thread.sleep(1000);
29-
30-
assertNull("per-message ttl should have removed message after 10ms!", get());
31-
}
32-
3322
@Override
3423
protected AMQP.Queue.DeclareOk declareQueue(String name, Object ttlValue) throws IOException {
3524
this.sessionTTL = ttlValue;
36-
Map<String, Object> argMap = Collections.singletonMap(PerQueueTTL.TTL_ARG, ttlValue);
25+
Map<String, Object> argMap = Collections.singletonMap(PerQueueTTL.TTL_ARG,
26+
((Object)(longValue(ttlValue) * 2)));
3727
return this.channel.queueDeclare(name, false, true, false, argMap);
3828
}
29+
30+
private Long longValue(final Object ttl) {
31+
if (ttl instanceof Short) {
32+
return ((Short)ttl).longValue();
33+
} else if (ttl instanceof Integer) {
34+
return ((Integer)ttl).longValue();
35+
} else if (ttl instanceof Long) {
36+
return (Long) ttl;
37+
} else {
38+
throw new IllegalArgumentException("ttl not of expected type");
39+
}
40+
}
41+
3942
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ protected void expectBodyAndRemainingMessages(String body, int messagesLeft) thr
154154

155155
protected void declareAndBindQueue(Object ttlValue) throws IOException {
156156
declareQueue(ttlValue);
157+
bindQueue();
158+
}
159+
160+
protected void bindQueue() throws IOException {
157161
this.channel.queueBind(TTL_QUEUE_NAME, TTL_EXCHANGE, TTL_QUEUE_NAME);
158162
}
159163

0 commit comments

Comments
 (0)