|
16 | 16 | package com.rabbitmq.client.test.server;
|
17 | 17 |
|
18 | 18 | import static org.junit.Assert.assertEquals;
|
| 19 | +import static org.junit.Assert.fail; |
19 | 20 |
|
20 | 21 | import java.io.IOException;
|
21 | 22 | import java.util.ArrayList;
|
@@ -48,6 +49,42 @@ public class PriorityQueues extends BrokerTestCase {
|
48 | 49 | channel.queueDelete(q);
|
49 | 50 | }
|
50 | 51 |
|
| 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 | + |
51 | 88 | private List<Integer> prioritiesOfEnqueuedMessages(String q, int n) throws InterruptedException, IOException {
|
52 | 89 | final List<Integer> xs = new ArrayList<Integer>();
|
53 | 90 | final CountDownLatch latch = new CountDownLatch(n);
|
|
0 commit comments