use of org.apache.qpid.server.message.EnqueueableMessage in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method createMockEnqueueableMessage.
protected EnqueueableMessage createMockEnqueueableMessage(long messageId, final StoredMessage<StorableMessageMetaData> storedMessage) {
EnqueueableMessage enqueueableMessage = mock(EnqueueableMessage.class);
when(enqueueableMessage.getMessageNumber()).thenReturn(messageId);
when(enqueueableMessage.getStoredMessage()).thenReturn(storedMessage);
return enqueueableMessage;
}
use of org.apache.qpid.server.message.EnqueueableMessage 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();
}
use of org.apache.qpid.server.message.EnqueueableMessage in project qpid-broker-j by apache.
the class MessageStoreSerializer_v1 method deserializeMessageInstances.
private Record deserializeMessageInstances(final MessageStore store, final Map<UUID, UUID> queueIdMap, final Map<Long, StoredMessage<?>> messageMap, final Deserializer deserializer, Record nextRecord) throws IOException {
while (nextRecord.getType() == RecordType.MESSAGE_INSTANCE) {
MessageInstanceRecord messageInstanceRecord = (MessageInstanceRecord) nextRecord;
final StoredMessage<?> storedMessage = messageMap.get(messageInstanceRecord.getMessageNumber());
final UUID queueId = queueIdMap.get(messageInstanceRecord.getQueueId());
if (storedMessage != null && queueId != null) {
final Transaction txn = store.newTransaction();
EnqueueableMessage msg = new EnqueueableMessage() {
@Override
public long getMessageNumber() {
return storedMessage.getMessageNumber();
}
@Override
public boolean isPersistent() {
return true;
}
@Override
public StoredMessage getStoredMessage() {
return storedMessage;
}
};
txn.enqueueMessage(new TransactionLogResource() {
@Override
public String getName() {
return queueId.toString();
}
@Override
public UUID getId() {
return queueId;
}
@Override
public MessageDurability getMessageDurability() {
return MessageDurability.DEFAULT;
}
}, msg);
txn.commitTranAsync(null);
}
nextRecord = deserializer.readRecord();
}
return nextRecord;
}
Aggregations