use of org.apache.qpid.server.store.StorableMessageMetaData in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method getMessageInternal.
private StoredBDBMessage<?> getMessageInternal(long messageId, EnvironmentFacade environmentFacade) {
try {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
MessageMetaDataBinding valueBinding = MessageMetaDataBinding.getInstance();
LongBinding.longToEntry(messageId, key);
if (getMessageMetaDataDb().get(null, key, value, LockMode.READ_COMMITTED) == OperationStatus.SUCCESS) {
StorableMessageMetaData metaData = valueBinding.entryToObject(value);
StoredBDBMessage message = createStoredBDBMessage(messageId, metaData, true);
return message;
} else {
return null;
}
} catch (RuntimeException e) {
throw environmentFacade.handleDatabaseException("Cannot visit messages", e);
}
}
use of org.apache.qpid.server.store.StorableMessageMetaData in project qpid-broker-j by apache.
the class AbstractServerMessageTest method testReferences.
public void testReferences() {
TransactionLogResource q1 = createQueue("1");
TransactionLogResource q2 = createQueue("2");
TestMessage<StorableMessageMetaData> msg = new TestMessage<StorableMessageMetaData>(mock(StoredMessage.class), this);
assertFalse(msg.isReferenced());
assertFalse(msg.isReferenced(q1));
MessageReference<TestMessage<StorableMessageMetaData>> nonQueueRef = msg.newReference();
assertFalse(msg.isReferenced());
assertFalse(msg.isReferenced(q1));
MessageReference<TestMessage<StorableMessageMetaData>> q1ref = msg.newReference(q1);
assertTrue(msg.isReferenced());
assertTrue(msg.isReferenced(q1));
assertFalse(msg.isReferenced(q2));
q1ref.release();
assertFalse(msg.isReferenced());
assertFalse(msg.isReferenced(q1));
q1ref = msg.newReference(q1);
assertTrue(msg.isReferenced());
assertTrue(msg.isReferenced(q1));
assertFalse(msg.isReferenced(q2));
MessageReference<TestMessage<StorableMessageMetaData>> q2ref = msg.newReference(q2);
assertTrue(msg.isReferenced());
assertTrue(msg.isReferenced(q1));
assertTrue(msg.isReferenced(q2));
try {
msg.newReference(q1);
fail("Should not be able to create a second reference to the same queue");
} catch (MessageAlreadyReferencedException e) {
// pass
}
q2ref.release();
assertTrue(msg.isReferenced());
assertTrue(msg.isReferenced(q1));
assertFalse(msg.isReferenced(q2));
q1ref.release();
assertFalse(msg.isReferenced());
assertFalse(msg.isReferenced(q1));
nonQueueRef.release();
try {
msg.newReference(q1);
fail("Message should not allow new references as all references had been removed");
} catch (MessageDeletedException e) {
// pass
}
}
use of org.apache.qpid.server.store.StorableMessageMetaData in project qpid-broker-j by apache.
the class AsynchronousMessageStoreRecovererTest method createTestMessage.
private StoredMessage<?> createTestMessage(final long messageNumber) {
final StorableMessageMetaData metaData = new TestMessageMetaData(messageNumber, 0);
final StoredMessage storedMessage = mock(StoredMessage.class);
when(storedMessage.getMessageNumber()).thenReturn(messageNumber);
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 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