use of org.apache.qpid.server.store.Transaction in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method testRecoveryOfMessageInstanceForNonExistingQueue.
@Test
public void testRecoveryOfMessageInstanceForNonExistingQueue() {
final UUID queueId = UUID.randomUUID();
final Transaction transaction = mock(Transaction.class);
final long messageId = 1;
final StoredMessage<StorableMessageMetaData> storedMessage = createMockStoredMessage(messageId);
MessageStore store = new NullMessageStore() {
@Override
public void visitMessages(MessageHandler handler) throws StoreException {
handler.handle(storedMessage);
}
@Override
public void visitMessageInstances(MessageInstanceHandler handler) throws StoreException {
handler.handle(new TestMessageEnqueueRecord(queueId, messageId));
}
@Override
public Transaction newTransaction() {
return transaction;
}
};
when(_virtualHost.getMessageStore()).thenReturn(store);
SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
recoverer.recover(_virtualHost);
verify(transaction).dequeueMessage(argThat(new MessageEnqueueRecordMatcher(queueId, messageId)));
verify(transaction, times(1)).commitTranAsync((Void) null);
}
use of org.apache.qpid.server.store.Transaction in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleDequeueWithDistributedTransaction.
@Test
public void testRecoveryOfSingleDequeueWithDistributedTransaction() {
final UUID queueId = UUID.randomUUID();
final Queue<?> queue = createRegisteredMockQueue(queueId);
final Transaction transaction = mock(Transaction.class);
final StoredMessage<StorableMessageMetaData> storedMessage = createMockStoredMessage(1);
final long messageId = storedMessage.getMessageNumber();
Transaction.DequeueRecord dequeueRecord = createMockDequeueRecord(queueId, messageId);
QueueEntry queueEntry = mock(QueueEntry.class);
when(queueEntry.acquire()).thenReturn(true);
when(queue.getMessageOnTheQueue(messageId)).thenReturn(queueEntry);
final long format = 1;
final byte[] globalId = new byte[] { 0 };
final byte[] branchId = new byte[] { 0 };
final EnqueueRecord[] enqueues = {};
final Transaction.DequeueRecord[] dequeues = { dequeueRecord };
MessageStore store = new NullMessageStore() {
@Override
public void visitMessages(MessageHandler handler) throws StoreException {
handler.handle(storedMessage);
}
@Override
public void visitMessageInstances(MessageInstanceHandler handler) throws StoreException {
// We need the message to be enqueued onto the queue so that later the distributed transaction
// can dequeue it.
handler.handle(new TestMessageEnqueueRecord(queue.getId(), messageId));
}
@Override
public void visitDistributedTransactions(DistributedTransactionHandler handler) throws StoreException {
handler.handle(new Transaction.StoredXidRecord() {
@Override
public long getFormat() {
return format;
}
@Override
public byte[] getGlobalId() {
return globalId;
}
@Override
public byte[] getBranchId() {
return branchId;
}
}, enqueues, dequeues);
}
@Override
public Transaction newTransaction() {
return transaction;
}
};
DtxRegistry dtxRegistry = new DtxRegistry(_virtualHost);
when(_virtualHost.getMessageStore()).thenReturn(store);
when(_virtualHost.getDtxRegistry()).thenReturn(dtxRegistry);
SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
recoverer.recover(_virtualHost);
DtxBranch branch = dtxRegistry.getBranch(new Xid(format, globalId, branchId));
assertNotNull("Expected dtx branch to be created", branch);
branch.commit();
verify(queueEntry, times(1)).delete();
verify(transaction).commitTran();
}
use of org.apache.qpid.server.store.Transaction in project qpid-broker-j by apache.
the class AsyncAutoCommitTransaction method dequeue.
@Override
public void dequeue(MessageEnqueueRecord record, Action postTransactionAction) {
Transaction txn = null;
try {
ListenableFuture<Void> future;
if (record != null) {
LOGGER.debug("Dequeue of message number {} from transaction log. Queue : {}", record.getMessageNumber(), record.getQueueId());
txn = _messageStore.newTransaction();
txn.dequeueMessage(record);
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.Transaction 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.Transaction 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);
}
}
Aggregations