use of org.apache.qpid.server.store.Transaction.EnqueueRecord in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleDequeueWithDistributedTransaction.
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.EnqueueRecord in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method createMockRecord.
protected EnqueueRecord createMockRecord(Queue<?> queue, EnqueueableMessage enqueueableMessage) {
EnqueueRecord enqueueRecord = mock(EnqueueRecord.class);
when(enqueueRecord.getMessage()).thenReturn(enqueueableMessage);
when(enqueueRecord.getResource()).thenReturn(queue);
return enqueueRecord;
}
use of org.apache.qpid.server.store.Transaction.EnqueueRecord in project qpid-broker-j by apache.
the class MessageStoreTestCase method testVisitDistributedTransactions.
public void testVisitDistributedTransactions() throws Exception {
long format = 1l;
byte[] branchId = new byte[] { 2 };
byte[] globalId = new byte[] { 1 };
EnqueueRecord enqueueRecord = getTestRecord(1);
TestRecord dequeueRecord = getTestRecord(2);
EnqueueRecord[] enqueues = { enqueueRecord };
TestRecord[] dequeues = { dequeueRecord };
Transaction transaction = _store.newTransaction();
final Transaction.StoredXidRecord record = transaction.recordXid(format, globalId, branchId, enqueues, dequeues);
transaction.commitTran();
DistributedTransactionHandler handler = mock(DistributedTransactionHandler.class);
_storeReader.visitDistributedTransactions(handler);
verify(handler, times(1)).handle(eq(record), argThat(new RecordMatcher(enqueues)), argThat(new DequeueRecordMatcher(dequeues)));
}
use of org.apache.qpid.server.store.Transaction.EnqueueRecord in project qpid-broker-j by apache.
the class MessageStoreTestCase method testAddAndRemoveRecordXid.
public void testAddAndRemoveRecordXid() throws Exception {
long format = 1l;
EnqueueRecord enqueueRecord = getTestRecord(1);
TestRecord dequeueRecord = getTestRecord(2);
EnqueueRecord[] enqueues = { enqueueRecord };
TestRecord[] dequeues = { dequeueRecord };
byte[] globalId = new byte[] { 1 };
byte[] branchId = new byte[] { 2 };
Transaction transaction = _store.newTransaction();
final Transaction.StoredXidRecord record = transaction.recordXid(format, globalId, branchId, enqueues, dequeues);
transaction.commitTran();
reopenStore();
DistributedTransactionHandler handler = mock(DistributedTransactionHandler.class);
_storeReader.visitDistributedTransactions(handler);
verify(handler, times(1)).handle(eq(record), argThat(new RecordMatcher(enqueues)), argThat(new DequeueRecordMatcher(dequeues)));
transaction = _store.newTransaction();
transaction.removeXid(record);
transaction.commitTran();
reopenStore();
handler = mock(DistributedTransactionHandler.class);
_storeReader.visitDistributedTransactions(handler);
verify(handler, never()).handle(eq(record), argThat(new RecordMatcher(enqueues)), argThat(new DequeueRecordMatcher(dequeues)));
}
use of org.apache.qpid.server.store.Transaction.EnqueueRecord in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleEnqueueWithDistributedTransaction.
@SuppressWarnings("unchecked")
public void testRecoveryOfSingleEnqueueWithDistributedTransaction() {
Queue<?> queue = createRegisteredMockQueue();
final Transaction transaction = mock(Transaction.class);
final StoredMessage<StorableMessageMetaData> storedMessage = createMockStoredMessage(1);
long messageId = storedMessage.getMessageNumber();
EnqueueableMessage enqueueableMessage = createMockEnqueueableMessage(messageId, storedMessage);
EnqueueRecord enqueueRecord = createMockRecord(queue, enqueueableMessage);
final long format = 1;
final byte[] globalId = new byte[] { 0 };
final byte[] branchId = new byte[] { 0 };
final EnqueueRecord[] enqueues = { enqueueRecord };
final Transaction.DequeueRecord[] dequeues = {};
MessageStore store = new NullMessageStore() {
@Override
public void visitMessages(MessageHandler handler) throws StoreException {
handler.handle(storedMessage);
}
@Override
public void visitMessageInstances(MessageInstanceHandler handler) throws StoreException {
// No messages instances
}
@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();
ServerMessage<?> message = storedMessage.getMetaData().getType().createMessage(storedMessage);
verify(queue, times(1)).enqueue(eq(message), (Action<? super MessageInstance>) isNull(), any(MessageEnqueueRecord.class));
verify(transaction).commitTran();
}
Aggregations