use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom4to5Test method assertDeliveriesForQueue.
private Set<Long> assertDeliveriesForQueue(final String queueName, final int expectedQueueSize) {
final QueueEntryKeyBinding queueEntryKeyBinding = new QueueEntryKeyBinding();
final AtomicInteger deliveryCounter = new AtomicInteger();
final Set<Long> messagesForQueue = new HashSet<Long>();
CursorOperation deliveryDatabaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
QueueEntryKey entryKey = queueEntryKeyBinding.entryToObject(key);
String thisQueueName = entryKey.getQueueName().toString();
if (thisQueueName.equals(queueName)) {
deliveryCounter.incrementAndGet();
messagesForQueue.add(entryKey.getMessageId());
}
}
};
new DatabaseTemplate(_environment, DELIVERY_DB_NAME, null).run(deliveryDatabaseOperation);
assertEquals("Unxpected number of entries in delivery db for queue " + queueName, expectedQueueSize, deliveryCounter.get());
return messagesForQueue;
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom5To6Test method corruptDatabase.
/**
* modify the chunk offset of a message to be wrong, so we can test logic
* that preserves incomplete messages
*/
private void corruptDatabase() {
CursorOperation cursorOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
CompoundKeyBinding binding = new CompoundKeyBinding();
CompoundKey originalCompoundKey = binding.entryToObject(key);
int corruptedOffset = originalCompoundKey.getOffset() + 2;
CompoundKey corruptedCompoundKey = new CompoundKey(originalCompoundKey.getMessageId(), corruptedOffset);
DatabaseEntry newKey = new DatabaseEntry();
binding.objectToEntry(corruptedCompoundKey, newKey);
LOGGER.info("Deliberately corrupted message id " + originalCompoundKey.getMessageId() + ", changed offset from " + originalCompoundKey.getOffset() + " to " + corruptedCompoundKey.getOffset());
deleteCurrent();
sourceDatabase.put(transaction, newKey, value);
abort();
}
};
Transaction transaction = _environment.beginTransaction(null, null);
new DatabaseTemplate(_environment, OLD_CONTENT_DB_NAME, transaction).run(cursorOperation);
transaction.commit();
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom5To6Test method assertContent.
private void assertContent() {
final NewDataBinding contentBinding = new NewDataBinding();
CursorOperation contentCursorOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
long id = LongBinding.entryToLong(key);
assertTrue("Unexpected id", id > 0);
byte[] content = contentBinding.entryToObject(value);
assertNotNull("Unexpected content", content);
}
};
new DatabaseTemplate(_environment, NEW_CONTENT_DB_NAME, null).run(contentCursorOperation);
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom5To6Test method assertQueueEntries.
private void assertQueueEntries() {
final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjects = loadConfiguredObjects();
final NewQueueEntryBinding newBinding = new NewQueueEntryBinding();
CursorOperation cursorOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
NewQueueEntryKey newEntryRecord = newBinding.entryToObject(key);
assertTrue("Unexpected queue id", configuredObjects.containsKey(newEntryRecord.getQueueId()));
}
};
new DatabaseTemplate(_environment, NEW_DELIVERY_DB_NAME, null).run(cursorOperation);
}
use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.
the class UpgradeFrom5To6Test method assertXidEntries.
private void assertXidEntries(Environment environment) {
final DatabaseEntry value = new DatabaseEntry();
final DatabaseEntry key = getXidKey();
new DatabaseTemplate(environment, NEW_XID_DB_NAME, null).run(new DatabaseRunnable() {
@Override
public void run(Database xidDatabase, Database nullDatabase, Transaction transaction) {
xidDatabase.get(null, key, value, LockMode.DEFAULT);
}
});
NewPreparedTransactionBinding newBinding = new NewPreparedTransactionBinding();
NewPreparedTransaction newTransaction = newBinding.entryToObject(value);
NewRecordImpl[] newEnqueues = newTransaction.getEnqueues();
NewRecordImpl[] newDequeues = newTransaction.getDequeues();
assertEquals("Unxpected new enqueus number", 1, newEnqueues.length);
NewRecordImpl enqueue = newEnqueues[0];
assertEquals("Unxpected queue id", UUIDGenerator.generateQueueUUID("TEST1", getVirtualHost().getName()), enqueue.getId());
assertEquals("Unxpected message id", 1, enqueue.getMessageNumber());
assertEquals("Unxpected new dequeues number", 1, newDequeues.length);
NewRecordImpl dequeue = newDequeues[0];
assertEquals("Unxpected queue id", UUIDGenerator.generateQueueUUID("TEST2", getVirtualHost().getName()), dequeue.getId());
assertEquals("Unxpected message id", 2, dequeue.getMessageNumber());
}
Aggregations