Search in sources :

Example 1 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class SynchronousMessageStoreRecovererTest method createMockDequeueRecord.

protected Transaction.DequeueRecord createMockDequeueRecord(UUID queueId, long messageNumber) {
    Transaction.DequeueRecord dequeueRecord = mock(Transaction.DequeueRecord.class);
    MessageEnqueueRecord enqueueRecord = mock(MessageEnqueueRecord.class);
    when(enqueueRecord.getMessageNumber()).thenReturn(messageNumber);
    when(enqueueRecord.getQueueId()).thenReturn(queueId);
    when(dequeueRecord.getEnqueueRecord()).thenReturn(enqueueRecord);
    return dequeueRecord;
}
Also used : Transaction(org.apache.qpid.server.store.Transaction) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 2 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AsynchronousMessageStoreRecovererTest method testRecoveryWhenLastRecoveryMessageIsConsumedBeforeRecoveryCompleted.

@Test
public void testRecoveryWhenLastRecoveryMessageIsConsumedBeforeRecoveryCompleted() throws Exception {
    Queue<?> queue = mock(Queue.class);
    when(queue.getId()).thenReturn(UUID.randomUUID());
    when(_virtualHost.getChildren(eq(Queue.class))).thenReturn(Collections.singleton(queue));
    when(_store.getNextMessageId()).thenReturn(3L);
    when(_store.newTransaction()).thenReturn(mock(Transaction.class));
    final List<StoredMessage<?>> testMessages = new ArrayList<>();
    StoredMessage<?> storedMessage = createTestMessage(1L);
    testMessages.add(storedMessage);
    StoredMessage<?> orphanedMessage = createTestMessage(2L);
    testMessages.add(orphanedMessage);
    StoredMessage newMessage = createTestMessage(4L);
    testMessages.add(newMessage);
    final MessageEnqueueRecord messageEnqueueRecord = mock(MessageEnqueueRecord.class);
    UUID id = queue.getId();
    when(messageEnqueueRecord.getQueueId()).thenReturn(id);
    when(messageEnqueueRecord.getMessageNumber()).thenReturn(1L);
    MockStoreReader storeReader = new MockStoreReader(Collections.singletonList(messageEnqueueRecord), testMessages);
    when(_store.newMessageStoreReader()).thenReturn(storeReader);
    AsynchronousMessageStoreRecoverer recoverer = new AsynchronousMessageStoreRecoverer();
    ListenableFuture<Void> result = recoverer.recover(_virtualHost);
    assertNull(result.get());
    verify(orphanedMessage, times(1)).remove();
    verify(newMessage, times(0)).remove();
    verify(queue).recover(argThat((ArgumentMatcher<ServerMessage>) serverMessage -> serverMessage.getMessageNumber() == storedMessage.getMessageNumber()), same(messageEnqueueRecord));
}
Also used : ArrayList(java.util.ArrayList) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) Transaction(org.apache.qpid.server.store.Transaction) StoredMessage(org.apache.qpid.server.store.StoredMessage) ArgumentMatcher(org.mockito.ArgumentMatcher) UUID(java.util.UUID) Queue(org.apache.qpid.server.model.Queue) Test(org.junit.Test)

Example 3 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AsyncAutoCommitTransaction method dequeue.

@Override
public void dequeue(Collection<MessageInstance> queueEntries, Action postTransactionAction) {
    Transaction txn = null;
    try {
        for (MessageInstance entry : queueEntries) {
            MessageEnqueueRecord record = entry.getEnqueueRecord();
            if (record != null) {
                LOGGER.debug("Dequeue of message number {} from transaction log. Queue : {}", record.getMessageNumber(), record.getQueueId());
                if (txn == null) {
                    txn = _messageStore.newTransaction();
                }
                txn.dequeueMessage(record);
            }
        }
        ListenableFuture<Void> future;
        if (txn != null) {
            future = txn.commitTranAsync((Void) null);
            txn = null;
        } else {
            future = Futures.immediateFuture(null);
        }
        addFuture(future, postTransactionAction);
        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)

Example 4 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AsyncAutoCommitTransaction method enqueue.

@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, EnqueueAction postTransactionAction) {
    Transaction txn = null;
    try {
        final MessageEnqueueRecord[] records = new MessageEnqueueRecord[queues.size()];
        int i = 0;
        for (BaseQueue queue : queues) {
            if (queue.getMessageDurability().persist(message.isPersistent())) {
                LOGGER.debug("Enqueue of message number {} to transaction log. Queue : {}", message.getMessageNumber(), queue.getName());
                if (txn == null) {
                    txn = _messageStore.newTransaction();
                }
                records[i] = txn.enqueueMessage(queue, message);
            }
            i++;
        }
        ListenableFuture<Void> future;
        if (txn != null) {
            future = txn.commitTranAsync((Void) null);
            txn = null;
        } else {
            future = Futures.immediateFuture(null);
        }
        final EnqueueAction underlying = postTransactionAction;
        addEnqueueFuture(future, new Action() {

            @Override
            public void postCommit() {
                if (underlying != null) {
                    underlying.postCommit(records);
                }
            }

            @Override
            public void onRollback() {
                underlying.onRollback();
            }
        }, message.isPersistent());
        postTransactionAction = null;
    } finally {
        final EnqueueAction underlying = postTransactionAction;
        rollbackIfNecessary(new Action() {

            @Override
            public void postCommit() {
            }

            @Override
            public void onRollback() {
                if (underlying != null) {
                    underlying.onRollback();
                }
            }
        }, txn);
    }
}
Also used : Transaction(org.apache.qpid.server.store.Transaction) BaseQueue(org.apache.qpid.server.queue.BaseQueue) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 5 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class DistributedTransaction method enqueue.

@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, final EnqueueAction postTransactionAction) {
    if (_branch != null) {
        final MessageEnqueueRecord[] enqueueRecords = new MessageEnqueueRecord[queues.size()];
        int i = 0;
        for (BaseQueue queue : queues) {
            final int pos = i;
            _branch.enqueue(queue, message, new org.apache.qpid.server.util.Action<MessageEnqueueRecord>() {

                @Override
                public void performAction(final MessageEnqueueRecord record) {
                    enqueueRecords[pos] = record;
                }
            });
            i++;
        }
        addPostTransactionAction(new Action() {

            @Override
            public void postCommit() {
                postTransactionAction.postCommit(enqueueRecords);
            }

            @Override
            public void onRollback() {
                postTransactionAction.onRollback();
            }
        });
    } else {
        _autoCommitTransaction.enqueue(queues, message, postTransactionAction);
    }
}
Also used : BaseQueue(org.apache.qpid.server.queue.BaseQueue) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Aggregations

MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)24 Transaction (org.apache.qpid.server.store.Transaction)11 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 MessageInstance (org.apache.qpid.server.message.MessageInstance)6 UUID (java.util.UUID)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)5 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)4 BaseQueue (org.apache.qpid.server.queue.BaseQueue)4 MessageStore (org.apache.qpid.server.store.MessageStore)4 StoredMessage (org.apache.qpid.server.store.StoredMessage)4 Collections (java.util.Collections)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)2 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2