use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class SimpleQueueEntryImplTest method getQueueEntryImpl.
@Override
public QueueEntryImpl getQueueEntryImpl(int msgId) {
ServerMessage message = mock(ServerMessage.class);
when(message.getMessageNumber()).thenReturn((long) msgId);
final MessageReference reference = mock(MessageReference.class);
when(reference.getMessage()).thenReturn(message);
when(message.newReference()).thenReturn(reference);
when(message.newReference(any(TransactionLogResource.class))).thenReturn(reference);
return (QueueEntryImpl) queueEntryList.add(message, null);
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class SortedQueueEntryListTest method testAscendingSortKeys.
public void testAscendingSortKeys() throws Exception {
_sqel = new SelfValidatingSortedQueueEntryList(_testQueue);
// Build test list
long messageId = 0L;
for (String textKey : textkeys) {
final ServerMessage msg = generateTestMessage(messageId, textKey);
messageId++;
_sqel.add(msg, null);
}
final QueueEntryIterator iter = getTestList().iterator();
int count = 0;
while (iter.advance()) {
assertEquals("Sorted queue entry value is not as expected", textkeys[count], getSortedKeyValue(iter));
assertEquals("Message id not as expected", Long.valueOf(count), getMessageId(iter));
count++;
}
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class SortedQueueEntryListTest method generateTestMessage.
private ServerMessage generateTestMessage(final long id, final String keyValue) {
final ServerMessage message = mock(ServerMessage.class);
AMQMessageHeader hdr = mock(AMQMessageHeader.class);
when(message.getMessageHeader()).thenReturn(hdr);
when(hdr.getHeader(eq("KEY"))).thenReturn(keyValue);
when(hdr.containsHeader(eq("KEY"))).thenReturn(true);
when(hdr.getHeaderNames()).thenReturn(Collections.singleton("KEY"));
MessageReference ref = mock(MessageReference.class);
when(ref.getMessage()).thenReturn(message);
when(message.newReference()).thenReturn(ref);
when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
when(message.getMessageNumber()).thenReturn(id);
return message;
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class SortedQueueEntryListTest method testDescendingSortKeys.
public void testDescendingSortKeys() throws Exception {
_sqel = new SelfValidatingSortedQueueEntryList(_testQueue);
// Build test list
long messageId = 0L;
for (int i = textkeys.length - 1; i >= 0; i--) {
final ServerMessage msg = generateTestMessage(messageId, textkeys[i]);
messageId++;
_sqel.add(msg, null);
}
final QueueEntryIterator iter = getTestList().iterator();
int count = 0;
while (iter.advance()) {
assertEquals("Sorted queue entry value is not as expected", textkeys[count], getSortedKeyValue(iter));
assertEquals("Message id not as expected", Long.valueOf(textkeys.length - count - 1), getMessageId(iter));
count++;
}
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class SortedQueueEntryListTest method testInsertAfter.
public void testInsertAfter() throws Exception {
_sqel = new SelfValidatingSortedQueueEntryList(_testQueue);
ServerMessage msg = generateTestMessage(1, "A");
_sqel.add(msg, null);
SortedQueueEntry entry = _sqel.next(_sqel.getHead());
validateEntry(entry, "A", 1);
msg = generateTestMessage(2, "B");
_sqel.add(msg, null);
entry = _sqel.next(_sqel.getHead());
validateEntry(entry, "A", 1);
entry = _sqel.next(entry);
validateEntry(entry, "B", 2);
}
Aggregations