use of org.apache.qpid.server.store.StorableMessageMetaData in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method upgradeMetaData.
private void upgradeMetaData(final Environment environment, final UpgradeInteractionHandler handler, final Set<Long> messagesToDiscard, Transaction transaction) {
LOGGER.info("Message MetaData");
if (environment.getDatabaseNames().contains(OLD_METADATA_DB_NAME)) {
final MessageMetaDataBinding binding = new MessageMetaDataBinding();
CursorOperation databaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
StorableMessageMetaData metaData = binding.entryToObject(value);
// get message id
Long messageId = LongBinding.entryToLong(key);
// ONLY copy data if message is delivered to existing queue
if (messagesToDiscard.contains(messageId)) {
return;
}
DatabaseEntry newValue = new DatabaseEntry();
binding.objectToEntry(metaData, newValue);
targetDatabase.put(transaction, key, newValue);
targetDatabase.put(transaction, key, newValue);
deleteCurrent();
}
};
new DatabaseTemplate(environment, OLD_METADATA_DB_NAME, NEW_METADATA_DB_NAME, transaction).run(databaseOperation);
environment.removeDatabase(transaction, OLD_METADATA_DB_NAME);
LOGGER.info(databaseOperation.getRowCount() + " Message MetaData entries");
}
}
use of org.apache.qpid.server.store.StorableMessageMetaData 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.StorableMessageMetaData 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.StorableMessageMetaData in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecovererTest method createMockStoredMessage.
private StoredMessage<StorableMessageMetaData> createMockStoredMessage(final long messageId) {
TestMessageMetaData metaData = new TestMessageMetaData(messageId, 0);
@SuppressWarnings("unchecked") final StoredMessage<StorableMessageMetaData> storedMessage = mock(StoredMessage.class);
when(storedMessage.getMessageNumber()).thenReturn(messageId);
when(storedMessage.getMetaData()).thenReturn(metaData);
return storedMessage;
}
use of org.apache.qpid.server.store.StorableMessageMetaData 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);
}
Aggregations