use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.
the class AutoCommitTransactionTest method createTestQueueEntries.
private Collection<MessageInstance> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags) {
Collection<MessageInstance> queueEntries = new ArrayList<MessageInstance>();
assertTrue("Boolean arrays must be the same length", queueDurableFlags.length == messagePersistentFlags.length);
for (int i = 0; i < queueDurableFlags.length; i++) {
final BaseQueue queue = createTestAMQQueue(queueDurableFlags[i]);
final ServerMessage message = createTestMessage(messagePersistentFlags[i]);
final boolean hasRecord = queueDurableFlags[i] && messagePersistentFlags[i];
queueEntries.add(new MockMessageInstance() {
@Override
public ServerMessage getMessage() {
return message;
}
@Override
public TransactionLogResource getOwningResource() {
return queue;
}
@Override
public MessageEnqueueRecord getEnqueueRecord() {
if (hasRecord) {
return mock(MessageEnqueueRecord.class);
} else {
return null;
}
}
});
}
return queueEntries;
}
use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.
the class JDBCMessageStoreTest method testRemoveMessagesWhenNumberOfMessagesEqualsInClauseMaxSize.
@Test
public void testRemoveMessagesWhenNumberOfMessagesEqualsInClauseMaxSize() {
final String queueName = getTestName();
final UUID transactionalLogId = UUID.randomUUID();
final TransactionLogResource resource = mockTransactionLogResource(transactionalLogId, queueName);
final int numberOfMessages = 10;
final GenericJDBCMessageStore store = (GenericJDBCMessageStore) getStore();
reOpenStoreWithInClauseMaxSize(store, numberOfMessages);
final List<MessageEnqueueRecord> records = enqueueMessages(store, resource, numberOfMessages);
assertEquals(numberOfMessages, records.size());
assertRecords(store, resource, records);
store.removeMessages(records.stream().map(MessageEnqueueRecord::getMessageNumber).collect(Collectors.toList()));
final List<StoredMessage> stored = new ArrayList<>();
store.newMessageStoreReader().visitMessages(m -> {
stored.add(m);
return true;
});
assertTrue(stored.isEmpty());
}
use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.
the class PriorityQueueImpl method reenqueueEntryWithPriority.
private long reenqueueEntryWithPriority(final QueueEntry entry, final ServerTransaction txn, final byte newPriority) {
txn.dequeue(entry.getEnqueueRecord(), new ServerTransaction.Action() {
@Override
public void postCommit() {
entry.delete();
}
@Override
public void onRollback() {
entry.release();
}
});
final ServerMessage newMessage = createMessageWithPriority(entry.getMessage(), newPriority);
txn.enqueue(this, newMessage, new ServerTransaction.EnqueueAction() {
@Override
public void postCommit(MessageEnqueueRecord... records) {
PriorityQueueImpl.this.enqueue(newMessage, null, records[0]);
}
@Override
public void onRollback() {
// noop
}
});
return newMessage.getMessageNumber();
}
use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.
the class AbstractVirtualHost method executeTransaction.
@Override
public void executeTransaction(TransactionalOperation op) {
final MessageStore store = getMessageStore();
final LocalTransaction txn = new LocalTransaction(store);
op.withinTransaction(new Transaction() {
@Override
public void dequeue(final QueueEntry messageInstance) {
final ServerTransaction.Action deleteAction = new ServerTransaction.Action() {
@Override
public void postCommit() {
messageInstance.delete();
}
@Override
public void onRollback() {
}
};
boolean acquired = messageInstance.acquireOrSteal(new Runnable() {
@Override
public void run() {
ServerTransaction txn = new AutoCommitTransaction(store);
txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction);
}
});
if (acquired) {
txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction);
}
}
@Override
public void copy(QueueEntry entry, final Queue<?> queue) {
final ServerMessage message = entry.getMessage();
txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {
@Override
public void postCommit(MessageEnqueueRecord... records) {
queue.enqueue(message, null, records[0]);
}
@Override
public void onRollback() {
}
});
}
@Override
public void move(final QueueEntry entry, final Queue<?> queue) {
final ServerMessage message = entry.getMessage();
if (entry.acquire()) {
txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {
@Override
public void postCommit(MessageEnqueueRecord... records) {
queue.enqueue(message, null, records[0]);
}
@Override
public void onRollback() {
entry.release();
}
});
txn.dequeue(entry.getEnqueueRecord(), new ServerTransaction.Action() {
@Override
public void postCommit() {
entry.delete();
}
@Override
public void onRollback() {
}
});
}
}
});
txn.commit();
}
use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.
the class AbstractQueueTestBase method deleteEntry.
private void deleteEntry(final long messageNumber, final MessageEnqueueRecord record) throws InterruptedException {
final CountDownLatch messageDeleteDetector = new CountDownLatch(1);
final ServerMessage message = createMessage(messageNumber, 2, 3);
final MessageReference reference = message.newReference();
doAnswer((Answer<Void>) invocationOnMock -> {
messageDeleteDetector.countDown();
return null;
}).when(reference).release();
_queue.enqueue(message, null, record);
_queue.visit(entry -> {
_queue.deleteEntry(entry);
return false;
});
assertTrue("Message reference is not released withing given timeout interval", messageDeleteDetector.await(2000L, TimeUnit.MILLISECONDS));
}
Aggregations