Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/test/java/com/rabbitmq/client/test/server/PriorityQueues.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.rabbitmq.client.test.server;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -48,6 +49,42 @@ public class PriorityQueues extends BrokerTestCase {
channel.queueDelete(q);
}

@Test public void negativeMaxPriority() throws IOException, TimeoutException, InterruptedException {
String q = "with-minus-10-priorities";
int n = -10;
try {
channel.queueDeclare(q, true, false, false, argsWithPriorities(n));
fail("Negative priority, the queue creation should have failed");
} catch (IOException ioe) {
checkShutdownSignal(AMQP.PRECONDITION_FAILED, ioe);
}
}

@Test public void excessiveMaxPriority() throws IOException, TimeoutException, InterruptedException {
String q = "with-260-priorities";
int n = 260;
try {
channel.queueDeclare(q, true, false, false, argsWithPriorities(n));
fail("Priority too high (> 255), the queue creation should have failed");
} catch (IOException ioe) {
checkShutdownSignal(AMQP.PRECONDITION_FAILED, ioe);
}
}

@Test public void maxAllowedPriority() throws IOException, TimeoutException, InterruptedException {
String q = "with-255-priorities";
int n = 255;
channel.queueDeclare(q, true, false, false, argsWithPriorities(n));
publishWithPriorities(q, n);

List<Integer> xs = prioritiesOfEnqueuedMessages(q, n);
assertEquals(Integer.valueOf(255), xs.get(0));
assertEquals(Integer.valueOf(254), xs.get(1));
assertEquals(Integer.valueOf(253), xs.get(2));

channel.queueDelete(q);
}

private List<Integer> prioritiesOfEnqueuedMessages(String q, int n) throws InterruptedException, IOException {
final List<Integer> xs = new ArrayList<Integer>();
final CountDownLatch latch = new CountDownLatch(n);
Expand Down