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;
}
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));
}
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);
}
}
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);
}
}
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);
}
}
Aggregations