Source:
<code>public void testPriority() throws Exception { AmqpClient client = createAmqpClient(); AmqpConnection connection = addConnection(client.connect()); AmqpSession session = connection.createSession(); Map<Symbol, Object> properties1 = new HashMap<>(); properties1.put(Symbol.getSymbol("priority"), 50); AmqpReceiver receiver1 = session.createReceiver(getQueueName(), null, false, false, properties1); receiver1.flow(100); Map<Symbol, Object> properties2 = new HashMap<>(); properties2.put(Symbol.getSymbol("priority"), 10); AmqpReceiver receiver2 = session.createReceiver(getQueueName(), null, false, false, properties2); receiver2.flow(100); Map<Symbol, Object> properties3 = new HashMap<>(); properties3.put(Symbol.getSymbol("priority"), 5); AmqpReceiver receiver3 = session.createReceiver(getQueueName(), null, false, false, properties3); receiver3.flow(100); sendMessages(getQueueName(), 5); for (int i = 0; i < 5; i++) { AmqpMessage message1 = receiver1.receive(250, TimeUnit.MILLISECONDS); AmqpMessage message2 = receiver2.receive(250, TimeUnit.MILLISECONDS); <START> AmqpMessage message3 = receiver3.receive(250, TimeUnit.MILLISECONDS); <END> assertNotNull("did not receive message first time", message1); assertEquals("MessageID:" + i, message1.getMessageId()); message1.accept(); assertNull("message is not meant to goto lower priority receiver", message2); assertNull("message is not meant to goto lower priority receiver", message3); } receiver1.close(); sendMessages(getQueueName(), 5); for (int i = 0; i < 5; i++) { AmqpMessage message2 = receiver2.receive(250, TimeUnit.MILLISECONDS); AmqpMessage message3 = receiver3.receive(250, TimeUnit.MILLISECONDS); assertNotNull("did not receive message first time", message2); assertEquals("MessageID:" + i, message2.getMessageId()); message2.accept(); assertNull("message is not meant to goto lower priority receiver", message3); } connection.close(); }</code><technical_language>Burning 250ms loop excessive. is a receiveNoWait for initial verification arrived, and/or a small final timed wait done loop afterwards. Alternatively, pullImmediate() avoid unnecessary waiting</technical_language>

Target:
public void testPriority() throws Exception { AmqpClient client = createAmqpClient(); AmqpConnection connection = addConnection(client.connect()); AmqpSession session = connection.createSession(); Map<Symbol, Object> properties1 = new HashMap<>(); properties1.put(Symbol.getSymbol("priority"), 5); AmqpReceiver receiver1 = session.createReceiver(getQueueName(), null, false, false, properties1); receiver1.flow(100); Map<Symbol, Object> properties2 = new HashMap<>(); properties2.put(Symbol.getSymbol("priority"), 50); AmqpReceiver receiver2 = session.createReceiver(getQueueName(), null, false, false, properties2); receiver2.flow(100); Map<Symbol, Object> properties3 = new HashMap<>(); properties3.put(Symbol.getSymbol("priority"), 10); AmqpReceiver receiver3 = session.createReceiver(getQueueName(), null, false, false, properties3); receiver3.flow(100); sendMessages(getQueueName(), 5); for (int i = 0; i < 5; i++) { AmqpMessage message1 = receiver1.receiveNoWait(); AmqpMessage message2 = receiver2.receive(250, TimeUnit.MILLISECONDS); AmqpMessage message3 = receiver3.receiveNoWait(); assertNotNull("did not receive message first time", message2); assertEquals("MessageID:" + i, message2.getMessageId()); message2.accept(); assertNull("message is not meant to goto lower priority receiver", message1); assertNull("message is not meant to goto lower priority receiver", message3); } assertNoMessage(receiver1); assertNoMessage(receiver3); receiver2.close(); sendMessages(getQueueName(), 5); for (int i = 0; i < 5; i++) { AmqpMessage message1 = receiver1.receiveNoWait(); AmqpMessage message3 = receiver3.receive(250, TimeUnit.MILLISECONDS); assertNotNull("did not receive message first time", message3); assertEquals("MessageID:" + i, message3.getMessageId()); message3.accept(); assertNull("message is not meant to goto lower priority receiver", message1); } assertNoMessage(receiver1); connection.close(); }