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, final int headerSize, final int payloadSize) {
ServerMessage message = createMessage(id);
when(message.getSizeIncludingHeader()).thenReturn(new Long(headerSize + payloadSize));
return message;
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AbstractQueueTestBase method putGivenNumberOfMessages.
/**
* A helper method to put given number of messages into queue
* <p>
* Queue is not checked if messages are added into queue
*
* @param queue
* queue to put messages into
* @param messageNumber
* number of messages to put into queue
* @param queue
* @param messageNumber
*/
protected void putGivenNumberOfMessages(Queue<?> queue, int messageNumber) {
for (int i = 0; i < messageNumber; i++) {
// Create message
ServerMessage message = null;
message = createMessage((long) i);
// Put message on queue
queue.enqueue(message, null, null);
}
}
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, byte priority, final Map<String, Object> arguments, long arrivalTime) {
ServerMessage message = createMessage(id);
AMQMessageHeader hdr = message.getMessageHeader();
when(hdr.getPriority()).thenReturn(priority);
when(message.getArrivalTime()).thenReturn(arrivalTime);
when(hdr.getHeaderNames()).thenReturn(arguments.keySet());
final ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
when(hdr.containsHeader(nameCaptor.capture())).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
return arguments.containsKey(nameCaptor.getValue());
}
});
final ArgumentCaptor<Set> namesCaptor = ArgumentCaptor.forClass(Set.class);
when(hdr.containsHeaders(namesCaptor.capture())).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
return arguments.keySet().containsAll(namesCaptor.getValue());
}
});
final ArgumentCaptor<String> nameCaptor2 = ArgumentCaptor.forClass(String.class);
when(hdr.getHeader(nameCaptor2.capture())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
return arguments.get(nameCaptor2.getValue());
}
});
return message;
}
use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.
the class AbstractQueueTestBase method testReleasedOutOfComparableOrderAreRedelivered.
/**
* Tests that if a client releases entries 'out of order' (the order
* used by QueueEntryImpl.compareTo) that messages are still resent
* successfully. Specifically this test ensures the {@see AbstractQueue#requeue()}
* can correctly move the _releasedEntry to an earlier position in the QueueEntry list.
*/
public void testReleasedOutOfComparableOrderAreRedelivered() 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 third and first message only, causing it to be requeued */
queueEntries.get(2).release();
queueEntries.get(0).release();
while (_consumerTarget.processPending()) ;
assertEquals("Unexpected total number of messages sent to consumer", 5, _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());
assertTrue("Redelivery flag should now be set", 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 testMessageHeldIfNotYetValidWhenConsumerAdded.
public void testMessageHeldIfNotYetValidWhenConsumerAdded() throws Exception {
_queue.close();
Map<String, Object> attributes = new HashMap<>(_arguments);
attributes.put(Queue.NAME, _qname);
attributes.put(Queue.OWNER, _owner);
attributes.put(Queue.HOLD_ON_PUBLISH_ENABLED, Boolean.TRUE);
_queue = _virtualHost.createChild(Queue.class, attributes);
ServerMessage messageA = createMessage(new Long(24));
AMQMessageHeader messageHeader = messageA.getMessageHeader();
when(messageHeader.getNotValidBefore()).thenReturn(System.currentTimeMillis() + 20000L);
_queue.enqueue(messageA, null, null);
_consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
while (_consumerTarget.processPending()) ;
assertEquals("Message which was not yet valid was received", 0, _consumerTarget.getMessages().size());
when(messageHeader.getNotValidBefore()).thenReturn(System.currentTimeMillis() - 100L);
_queue.checkMessageStatus();
while (_consumerTarget.processPending()) ;
assertEquals("Message which was valid was not received", 1, _consumerTarget.getMessages().size());
}
Aggregations