use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class RejectPolicyHandlerTest method testNotOverfullBytes.
public void testNotOverfullBytes() throws Exception {
when(_queue.getMaximumQueueDepthBytes()).thenReturn(9L);
ServerMessage incomingMessage1 = createIncomingMessage(5);
MessageInstance messageInstance1 = mock(MessageInstance.class);
when(messageInstance1.getMessage()).thenReturn(incomingMessage1);
ServerMessage incomingMessage2 = createIncomingMessage(5);
_rejectOverflowPolicyHandler.checkReject(incomingMessage1);
_rejectOverflowPolicyHandler.postEnqueue(messageInstance1);
_rejectOverflowPolicyHandler.checkReject(incomingMessage2);
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class RejectPolicyHandlerTest method testNotOverfullMessages.
public void testNotOverfullMessages() throws Exception {
when(_queue.getMaximumQueueDepthMessages()).thenReturn(1L);
ServerMessage incomingMessage1 = createIncomingMessage(2);
MessageInstance messageInstance1 = mock(MessageInstance.class);
when(messageInstance1.getMessage()).thenReturn(incomingMessage1);
ServerMessage incomingMessage2 = createIncomingMessage(2);
_rejectOverflowPolicyHandler.checkReject(incomingMessage1);
_rejectOverflowPolicyHandler.postEnqueue(messageInstance1);
_rejectOverflowPolicyHandler.checkReject(incomingMessage2);
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class StandardQueueTest method testProcessQueueWithDequeuedEntry.
/**
* Tests whether dequeued entry is sent to subscriber
*/
public void testProcessQueueWithDequeuedEntry() throws Exception {
// total number of messages to send
int messageNumber = 4;
int dequeueMessageIndex = 1;
Map<String, Object> queueAttributes = new HashMap<>();
queueAttributes.put(Queue.NAME, "test");
// create queue with overridden method deliverAsync
StandardQueueImpl testQueue = new StandardQueueImpl(queueAttributes, getVirtualHost());
testQueue.create();
// put messages
List<StandardQueueEntry> entries = (List<StandardQueueEntry>) enqueueGivenNumberOfMessages(testQueue, messageNumber);
// dequeue message
dequeueMessage(testQueue, dequeueMessageIndex);
// latch to wait for message receipt
final CountDownLatch latch = new CountDownLatch(messageNumber - 1);
// create a consumer
TestConsumerTarget consumer = new TestConsumerTarget() {
@Override
public void notifyWork() {
while (processPending()) ;
}
/**
* Send a message and decrement latch
* @param consumer
* @param entry
* @param batch
*/
@Override
public void send(final MessageInstanceConsumer consumer, MessageInstance entry, boolean batch) {
super.send(consumer, entry, batch);
latch.countDown();
}
};
// subscribe
testQueue.addConsumer(consumer, null, entries.get(0).getMessage().getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
// wait up to 1 minute for message receipt
try {
latch.await(1, TimeUnit.MINUTES);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
List<MessageInstance> expected = Arrays.asList((MessageInstance) entries.get(0), entries.get(2), entries.get(3));
verifyReceivedMessages(expected, consumer.getMessages());
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class AutoCommitTransaction method dequeue.
@Override
public void dequeue(Collection<MessageInstance> queueEntries, Action postTransactionAction) {
Transaction txn = null;
try {
for (MessageInstance entry : queueEntries) {
MessageEnqueueRecord enqueueRecord = entry.getEnqueueRecord();
if (enqueueRecord != null) {
LOGGER.debug("Dequeue of message number {} from transaction log. Queue : {}", enqueueRecord.getMessageNumber(), enqueueRecord.getQueueId());
if (txn == null) {
txn = _messageStore.newTransaction();
}
txn.dequeueMessage(enqueueRecord);
}
}
if (txn != null) {
txn.commitTran();
txn = null;
}
postTransactionAction.postCommit();
postTransactionAction = null;
} finally {
rollbackIfNecessary(postTransactionAction, txn);
}
}
Aggregations