Skip to content

Commit 7356321

Browse files
author
Tim Watson
committed
increase test coverage
1 parent 42cace8 commit 7356321

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
package com.rabbitmq.client.test.functional;
1919

20-
import com.rabbitmq.client.*;
20+
import com.rabbitmq.client.AMQP;
21+
import com.rabbitmq.client.MessageProperties;
2122

2223
import java.io.IOException;
2324

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,6 @@ public class PerQueueTTL extends TTLHandling {
2828

2929
protected static final String TTL_ARG = "x-message-ttl";
3030

31-
public void testInvalidTypeUsedInTTL() throws Exception {
32-
try {
33-
declareQueue(TTL_INVALID_QUEUE_NAME, "foobar");
34-
fail("Should not be able to use a non-long value for x-message-ttl");
35-
} catch (IOException e) {
36-
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
37-
}
38-
}
39-
40-
public void testTTLMustBePositive() throws Exception {
41-
try {
42-
declareQueue(TTL_INVALID_QUEUE_NAME, -10);
43-
fail("Should not be able to use negative values for x-message-ttl");
44-
} catch (IOException e) {
45-
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
46-
}
47-
}
48-
4931
@Override
5032
protected AMQP.Queue.DeclareOk declareQueue(String name, Object ttlValue) throws IOException {
5133
Map<String, Object> argMap = Collections.singletonMap(TTL_ARG, ttlValue);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public void testSmallerPerQueueExpiryWins() throws IOException, InterruptedExcep
2121

2222
@Override
2323
protected AMQP.Queue.DeclareOk declareQueue(String name, Object ttlValue) throws IOException {
24+
final Object mappedTTL = (ttlValue instanceof String &&
25+
((String) ttlValue).contains("foobar")) ?
26+
ttlValue : longValue(ttlValue) * 2;
2427
this.sessionTTL = ttlValue;
25-
Map<String, Object> argMap = Collections.singletonMap(PerQueueTTL.TTL_ARG,
26-
((Object)(longValue(ttlValue) * 2)));
28+
Map<String, Object> argMap = Collections.singletonMap(PerQueueTTL.TTL_ARG, mappedTTL);
2729
return this.channel.queueDeclare(name, false, true, false, argMap);
2830
}
2931

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@ public void testMultipleTTLTypes() throws IOException {
3838
}
3939
}
4040

41+
public void testInvalidTypeUsedInTTL() throws Exception {
42+
try {
43+
declareAndBindQueue("foobar");
44+
publishAndSync(MSG[0]);
45+
fail("Should not be able to set TTL using non-numeric values");
46+
} catch (IOException e) {
47+
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
48+
}
49+
}
50+
51+
public void testTrailingCharsUsedInTTL() throws Exception {
52+
try {
53+
declareAndBindQueue("10000foobar");
54+
publishAndSync(MSG[0]);
55+
fail("Should not be able to set TTL using non-numeric values");
56+
} catch (IOException e) {
57+
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
58+
}
59+
}
60+
61+
public void testTTLMustBePositive() throws Exception {
62+
try {
63+
declareAndBindQueue(-10);
64+
publishAndSync(MSG[0]);
65+
fail("Should not be able to set TTL using negative values");
66+
} catch (IOException e) {
67+
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
68+
}
69+
}
70+
4171
public void testTTLAllowZero() throws Exception {
4272
try {
4373
declareQueue(0);

0 commit comments

Comments
 (0)