use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class PriorityQueueListTest method testGetLeastSignificantOldestEntry.
public void testGetLeastSignificantOldestEntry() {
assertEquals("Unexpected last entry", _priority4message1, _list.getLeastSignificantOldestEntry());
ServerMessage<?> message = mock(ServerMessage.class);
AMQMessageHeader header = mock(AMQMessageHeader.class);
@SuppressWarnings({ "rawtypes", "unchecked" }) MessageReference<ServerMessage> ref = mock(MessageReference.class);
when(message.getMessageHeader()).thenReturn(header);
when(message.newReference()).thenReturn(ref);
when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
when(ref.getMessage()).thenReturn(message);
when(header.getPriority()).thenReturn((byte) 3);
QueueEntry newEntry = _list.add(message, null);
assertEquals("Unexpected last entry", newEntry, _list.getLeastSignificantOldestEntry());
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class PriorityQueueListTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
BrokerTestHelper.setUp();
QueueEntry[] entries = new QueueEntry[PRIORITIES.length];
Map<String, Object> queueAttributes = new HashMap<String, Object>();
queueAttributes.put(Queue.ID, UUID.randomUUID());
queueAttributes.put(Queue.NAME, getName());
queueAttributes.put(PriorityQueue.PRIORITIES, 10);
final QueueManagingVirtualHost<?> virtualHost = BrokerTestHelper.createVirtualHost("testVH");
PriorityQueueImpl queue = new PriorityQueueImpl(queueAttributes, virtualHost);
queue.open();
_list = queue.getEntries();
for (int i = 0; i < PRIORITIES.length; i++) {
ServerMessage<?> message = mock(ServerMessage.class);
AMQMessageHeader header = mock(AMQMessageHeader.class);
@SuppressWarnings({ "rawtypes", "unchecked" }) MessageReference<ServerMessage> ref = mock(MessageReference.class);
when(message.getMessageHeader()).thenReturn(header);
when(message.newReference()).thenReturn(ref);
when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
when(ref.getMessage()).thenReturn(message);
when(header.getPriority()).thenReturn(PRIORITIES[i]);
entries[i] = _list.add(message, null);
}
_priority4message1 = entries[0];
_priority4message2 = entries[3];
_priority5message1 = entries[1];
_priority5message2 = entries[2];
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class PriorityQueueTest method createMessage.
protected ServerMessage createMessage(Long id, byte i) {
ServerMessage msg = super.createMessage(id);
AMQMessageHeader hdr = msg.getMessageHeader();
when(hdr.getPriority()).thenReturn(i);
return msg;
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class QueueEntryListTestBase method testAddGenericMessage.
/**
* Test to add a generic mock message.
* @see QueueEntryListTestBase#getTestList()
* @see QueueEntryListTestBase#getExpectedListLength()
*/
public void testAddGenericMessage() throws Exception {
final QueueEntryList list = getTestList();
final ServerMessage message = createServerMessage(666l);
list.add(message, null);
final QueueEntryIterator iter = list.iterator();
int count = 0;
while (iter.advance()) {
iter.getNode();
count++;
}
assertEquals("List did not grow by one entry after a generic message added", getExpectedListLength() + 1, count);
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class QueueEntryListTestBase method createServerMessage.
private ServerMessage createServerMessage(long number) {
final ServerMessage message = mock(ServerMessage.class);
when(message.getMessageNumber()).thenReturn(number);
MessageReference ref = mock(MessageReference.class);
AMQMessageHeader hdr = mock(AMQMessageHeader.class);
when(ref.getMessage()).thenReturn(message);
when(message.newReference()).thenReturn(ref);
when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
when(message.getMessageHeader()).thenReturn(hdr);
return message;
}
Aggregations