use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class QueueEntryImplTestBase method testGetNext.
/**
* Tests if entries in DEQUEUED or DELETED state are not returned by getNext method.
*/
public void testGetNext() throws Exception {
int numberOfEntries = 5;
QueueEntryImpl[] entries = new QueueEntryImpl[numberOfEntries];
Map<String, Object> queueAttributes = new HashMap<String, Object>();
queueAttributes.put(Queue.ID, UUID.randomUUID());
queueAttributes.put(Queue.NAME, getName());
final QueueManagingVirtualHost virtualHost = BrokerTestHelper.createVirtualHost("testVH");
StandardQueueImpl queue = new StandardQueueImpl(queueAttributes, virtualHost);
queue.open();
OrderedQueueEntryList queueEntryList = queue.getEntries();
// create test entries
for (int i = 0; i < numberOfEntries; i++) {
ServerMessage message = mock(ServerMessage.class);
when(message.getMessageNumber()).thenReturn((long) i);
final MessageReference reference = mock(MessageReference.class);
when(reference.getMessage()).thenReturn(message);
when(message.newReference()).thenReturn(reference);
when(message.newReference(any(TransactionLogResource.class))).thenReturn(reference);
QueueEntryImpl entry = (QueueEntryImpl) queueEntryList.add(message, null);
entries[i] = entry;
}
// test getNext for not acquired entries
for (int i = 0; i < numberOfEntries; i++) {
QueueEntryImpl queueEntry = entries[i];
QueueEntry next = queueEntry.getNextValidEntry();
if (i < numberOfEntries - 1) {
assertEquals("Unexpected entry from QueueEntryImpl#getNext()", entries[i + 1], next);
} else {
assertNull("The next entry after the last should be null", next);
}
}
// discard second
entries[1].acquire();
entries[1].delete();
// discard third
entries[2].acquire();
entries[2].delete();
QueueEntry next = entries[0].getNextValidEntry();
assertEquals("expected forth entry", entries[3], next);
next = next.getNextValidEntry();
assertEquals("expected fifth entry", entries[4], next);
next = next.getNextValidEntry();
assertNull("The next entry after the last should be null", next);
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class RejectPolicyHandlerTest method testOverfullMessages.
public void testOverfullMessages() throws Exception {
ServerMessage incomingMessage = createIncomingMessage(5);
when(_queue.getMaximumQueueDepthMessages()).thenReturn(7L);
when(_queue.getQueueDepthMessages()).thenReturn(7);
when(_queue.getQueueDepthBytes()).thenReturn(10L);
try {
_rejectOverflowPolicyHandler.checkReject(incomingMessage);
fail("Exception expected");
} catch (MessageUnacceptableException e) {
// pass
}
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class RejectPolicyHandlerTest method testIncomingMessageDeleted.
public void testIncomingMessageDeleted() throws Exception {
when(_queue.getMaximumQueueDepthMessages()).thenReturn(1L);
ServerMessage incomingMessage1 = createIncomingMessage(2);
ServerMessage incomingMessage2 = createIncomingMessage(2);
_rejectOverflowPolicyHandler.checkReject(incomingMessage1);
_rejectOverflowPolicyHandler.messageDeleted(incomingMessage1.getStoredMessage());
_rejectOverflowPolicyHandler.checkReject(incomingMessage2);
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class RejectPolicyHandlerTest method testOverfullBytes.
public void testOverfullBytes() throws Exception {
ServerMessage incomingMessage = createIncomingMessage(6);
when(_queue.getQueueDepthBytes()).thenReturn(5L);
when(_queue.getMaximumQueueDepthBytes()).thenReturn(10L);
when(_queue.getQueueDepthMessages()).thenReturn(1);
try {
_rejectOverflowPolicyHandler.checkReject(incomingMessage);
fail("Exception expected");
} catch (MessageUnacceptableException e) {
// pass
}
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class RingOverflowPolicyHandlerTest method createLastEntry.
private QueueEntry createLastEntry() {
AMQMessageHeader oldestMessageHeader = mock(AMQMessageHeader.class);
ServerMessage oldestMessage = mock(ServerMessage.class);
when(oldestMessage.getMessageHeader()).thenReturn(oldestMessageHeader);
QueueEntry oldestEntry = mock(QueueEntry.class);
when(oldestEntry.getMessage()).thenReturn(oldestMessage);
return oldestEntry;
}
Aggregations