use of org.apache.qpid.server.store.handler.MessageHandler in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method testRecoveryOfSingleMessageOnSingleQueue.
@SuppressWarnings("unchecked")
@Test
public void testRecoveryOfSingleMessageOnSingleQueue() {
final Queue<?> queue = createRegisteredMockQueue();
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(queue.getId(), messageId));
}
};
when(_virtualHost.getMessageStore()).thenReturn(store);
SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
recoverer.recover(_virtualHost);
ServerMessage<?> message = storedMessage.getMetaData().getType().createMessage(storedMessage);
verify(queue, times(1)).recover(eq(message), any(MessageEnqueueRecord.class));
}
use of org.apache.qpid.server.store.handler.MessageHandler in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method testRecoveryDeletesOrphanMessages.
@Test
public void testRecoveryDeletesOrphanMessages() {
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 {
// No messages instances
}
};
when(_virtualHost.getMessageStore()).thenReturn(store);
SynchronousMessageStoreRecoverer recoverer = new SynchronousMessageStoreRecoverer();
recoverer.recover(_virtualHost);
verify(storedMessage, times(1)).remove();
}
use of org.apache.qpid.server.store.handler.MessageHandler 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.handler.MessageHandler 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.handler.MessageHandler in project qpid-broker-j by apache.
the class MessageStoreTestCase method testAddAndRemoveMessageWithoutContent.
@Test
public void testAddAndRemoveMessageWithoutContent() throws Exception {
long messageId = 1;
int contentSize = 0;
final StoredMessage<TestMessageMetaData> message = _store.addMessage(new TestMessageMetaData(messageId, contentSize)).allContentAdded();
enqueueMessage(message, "dummyQ");
final AtomicReference<StoredMessage<?>> retrievedMessageRef = new AtomicReference<StoredMessage<?>>();
_storeReader.visitMessages(new MessageHandler() {
@Override
public boolean handle(StoredMessage<?> storedMessage) {
retrievedMessageRef.set(storedMessage);
return true;
}
});
StoredMessage<?> retrievedMessage = retrievedMessageRef.get();
assertNotNull("Message was not found", retrievedMessageRef);
assertEquals("Unexpected retrieved message", message.getMessageNumber(), retrievedMessage.getMessageNumber());
retrievedMessage.remove();
retrievedMessageRef.set(null);
_storeReader.visitMessages(new MessageHandler() {
@Override
public boolean handle(StoredMessage<?> storedMessage) {
retrievedMessageRef.set(storedMessage);
return true;
}
});
assertNull(retrievedMessageRef.get());
}
Aggregations