Skip to content

Commit 3d8a337

Browse files
authored
Merge pull request #365 from rabbitmq/rabbitmq-server-1590
Tests for priority validation
2 parents 8be7848 + ee0ff23 commit 3d8a337

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/test/java/com/rabbitmq/client/test/server/PriorityQueues.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.rabbitmq.client.test.server;
1717

1818
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.fail;
1920

2021
import java.io.IOException;
2122
import java.util.ArrayList;
@@ -48,6 +49,42 @@ public class PriorityQueues extends BrokerTestCase {
4849
channel.queueDelete(q);
4950
}
5051

52+
@Test public void negativeMaxPriority() throws IOException, TimeoutException, InterruptedException {
53+
String q = "with-minus-10-priorities";
54+
int n = -10;
55+
try {
56+
channel.queueDeclare(q, true, false, false, argsWithPriorities(n));
57+
fail("Negative priority, the queue creation should have failed");
58+
} catch (IOException ioe) {
59+
checkShutdownSignal(AMQP.PRECONDITION_FAILED, ioe);
60+
}
61+
}
62+
63+
@Test public void excessiveMaxPriority() throws IOException, TimeoutException, InterruptedException {
64+
String q = "with-260-priorities";
65+
int n = 260;
66+
try {
67+
channel.queueDeclare(q, true, false, false, argsWithPriorities(n));
68+
fail("Priority too high (> 255), the queue creation should have failed");
69+
} catch (IOException ioe) {
70+
checkShutdownSignal(AMQP.PRECONDITION_FAILED, ioe);
71+
}
72+
}
73+
74+
@Test public void maxAllowedPriority() throws IOException, TimeoutException, InterruptedException {
75+
String q = "with-255-priorities";
76+
int n = 255;
77+
channel.queueDeclare(q, true, false, false, argsWithPriorities(n));
78+
publishWithPriorities(q, n);
79+
80+
List<Integer> xs = prioritiesOfEnqueuedMessages(q, n);
81+
assertEquals(Integer.valueOf(255), xs.get(0));
82+
assertEquals(Integer.valueOf(254), xs.get(1));
83+
assertEquals(Integer.valueOf(253), xs.get(2));
84+
85+
channel.queueDelete(q);
86+
}
87+
5188
private List<Integer> prioritiesOfEnqueuedMessages(String q, int n) throws InterruptedException, IOException {
5289
final List<Integer> xs = new ArrayList<Integer>();
5390
final CountDownLatch latch = new CountDownLatch(n);

0 commit comments

Comments
 (0)