Search in sources :

Example 21 with MessageInstance

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);
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 22 with MessageInstance

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);
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 23 with MessageInstance

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());
}
Also used : HashMap(java.util.HashMap) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) TestConsumerTarget(org.apache.qpid.server.consumer.TestConsumerTarget) MessageInstance(org.apache.qpid.server.message.MessageInstance) List(java.util.List)

Example 24 with MessageInstance

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);
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) Transaction(org.apache.qpid.server.store.Transaction) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Aggregations

MessageInstance (org.apache.qpid.server.message.MessageInstance)24 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)8 ServerMessage (org.apache.qpid.server.message.ServerMessage)8 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)5 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)3 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)3 Action (org.apache.qpid.server.util.Action)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 MessageSource (org.apache.qpid.server.message.MessageSource)2 Queue (org.apache.qpid.server.model.Queue)2 Visitor (org.apache.qpid.server.protocol.v0_8.UnacknowledgedMessageMap.Visitor)2 MockMessageInstance (org.apache.qpid.server.queue.MockMessageInstance)2 Transaction (org.apache.qpid.server.store.Transaction)2 PrivilegedAction (java.security.PrivilegedAction)1 List (java.util.List)1