use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AbstractQueueTestBase method testNoneOverflowPolicy.
public void testNoneOverflowPolicy() {
Map<String, Object> attributes = new HashMap<>(_arguments);
attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_MESSAGES, 2);
attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_BYTES, 100);
Queue<?> queue = getQueue();
queue.setAttributes(attributes);
ServerMessage message = createMessage(new Long(24), 50, 50);
when(message.getArrivalTime()).thenReturn(10l);
queue.enqueue(message, null, null);
message = createMessage(new Long(25), 50, 50);
when(message.getArrivalTime()).thenReturn(50l);
queue.enqueue(message, null, null);
message = createMessage(new Long(26), 50, 50);
when(message.getArrivalTime()).thenReturn(200l);
queue.enqueue(message, null, null);
assertEquals("Wrong number of messages in queue", 3, queue.getQueueDepthMessages());
assertEquals("Wrong size of messages in queue", 300, queue.getQueueDepthBytes());
assertEquals("Wrong oldest message", 10l, ((AbstractQueue) queue).getEntries().getOldestEntry().getMessage().getArrivalTime());
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AbstractQueueTestBase method testReleasedMessageIsResentToSubscriber.
/**
* Tests that a released queue entry is resent to the subscriber. Verifies also that the
* QueueContext._releasedEntry is reset to null after the entry has been reset.
*/
public void testReleasedMessageIsResentToSubscriber() throws Exception {
ServerMessage messageA = createMessage(new Long(24));
ServerMessage messageB = createMessage(new Long(25));
ServerMessage messageC = createMessage(new Long(26));
_consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
final ArrayList<QueueEntry> queueEntries = new ArrayList<QueueEntry>();
EntryListAddingAction postEnqueueAction = new EntryListAddingAction(queueEntries);
/* Enqueue three messages */
_queue.enqueue(messageA, postEnqueueAction, null);
_queue.enqueue(messageB, postEnqueueAction, null);
_queue.enqueue(messageC, postEnqueueAction, null);
while (_consumerTarget.processPending()) ;
assertEquals("Unexpected total number of messages sent to consumer", 3, _consumerTarget.getMessages().size());
assertFalse("Redelivery flag should not be set", queueEntries.get(0).isRedelivered());
assertFalse("Redelivery flag should not be set", queueEntries.get(1).isRedelivered());
assertFalse("Redelivery flag should not be set", queueEntries.get(2).isRedelivered());
/* Now release the first message only, causing it to be requeued */
queueEntries.get(0).release();
while (_consumerTarget.processPending()) ;
assertEquals("Unexpected total number of messages sent to consumer", 4, _consumerTarget.getMessages().size());
assertTrue("Redelivery flag should now be set", queueEntries.get(0).isRedelivered());
assertFalse("Redelivery flag should remain be unset", queueEntries.get(1).isRedelivered());
assertFalse("Redelivery flag should remain be unset", queueEntries.get(2).isRedelivered());
assertNull("releasedEntry should be cleared after requeue processed", _consumer.getQueueContext().getReleasedEntry());
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AbstractQueueTestBase method createMessage.
protected ServerMessage createMessage(Long id) {
AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getMessageId()).thenReturn(String.valueOf(id));
ServerMessage message = mock(ServerMessage.class);
when(message.getMessageNumber()).thenReturn(id);
when(message.getMessageHeader()).thenReturn(header);
StoredMessage storedMessage = mock(StoredMessage.class);
when(message.getStoredMessage()).thenReturn(storedMessage);
MessageReference ref = mock(MessageReference.class);
when(ref.getMessage()).thenReturn(message);
when(message.newReference()).thenReturn(ref);
when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
return message;
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AbstractQueueTestBase method testEnqueueTwoMessagesThenRegisterConsumer.
/**
* Tests enqueuing two messages.
*/
public void testEnqueueTwoMessagesThenRegisterConsumer() throws Exception {
ServerMessage messageA = createMessage(new Long(24));
ServerMessage messageB = createMessage(new Long(25));
_queue.enqueue(messageA, null, null);
_queue.enqueue(messageB, null, null);
_consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
while (_consumerTarget.processPending()) ;
assertEquals(messageB, _consumer.getQueueContext().getLastSeenEntry().getMessage());
assertNull("There should be no releasedEntry after enqueues", _consumer.getQueueContext().getReleasedEntry());
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class FlowToDiskOverflowPolicyHandlerTest method createMessage.
private ServerMessage createMessage(long size) {
ServerMessage message = mock(ServerMessage.class);
when(message.getSizeIncludingHeader()).thenReturn(size);
StoredMessage storedMessage = mock(StoredMessage.class);
when(message.getStoredMessage()).thenReturn(storedMessage);
MessageReference ref = mock(MessageReference.class);
when(ref.getMessage()).thenReturn(message);
when(message.newReference()).thenReturn(ref);
when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
return message;
}
Aggregations