use of org.apache.qpid.server.queue.AbstractQueue.QueueEntryFilter in project qpid-broker-j by apache.
the class AbstractQueueTestBase method testGetMessagesOnTheQueueByQueueEntryFilterWithDequeuedEntry.
/**
* Tests that dequeued message is not present in the list returned form
* {@link AbstractQueue#getMessagesOnTheQueue(QueueEntryFilter)}
*/
@Test
public void testGetMessagesOnTheQueueByQueueEntryFilterWithDequeuedEntry() {
int messageNumber = 4;
int dequeueMessageIndex = 1;
// send test messages into a test queue
enqueueGivenNumberOfMessages(_queue, messageNumber);
// dequeue message
dequeueMessage(_queue, dequeueMessageIndex);
// get messages on the queue with filter accepting all available messages
List<? extends QueueEntry> entries = ((AbstractQueue) _queue).getMessagesOnTheQueue(new QueueEntryFilter() {
@Override
public boolean accept(QueueEntry entry) {
return true;
}
@Override
public boolean filterComplete() {
return false;
}
});
// assert entries on the queue
assertEquals((long) (messageNumber - 1), (long) entries.size());
int expectedId = 0;
for (int i = 0; i < messageNumber - 1; i++) {
Long id = (entries.get(i).getMessage()).getMessageNumber();
if (i == dequeueMessageIndex) {
assertFalse("Message with id " + dequeueMessageIndex + " was dequeued and should not be returned by method getMessagesOnTheQueue!", Long.valueOf(expectedId).equals(id));
expectedId++;
}
assertEquals("Expected message with id " + expectedId + " but got message with id " + id, Long.valueOf(expectedId), id);
expectedId++;
}
}
Aggregations