use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom5To6Test method loadConfiguredObjects.
private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects() {
final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
final ConfiguredObjectBinding binding = new ConfiguredObjectBinding();
final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
CursorOperation configuredObjectsCursor = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
UUID id = uuidBinding.entryToObject(key);
UpgradeConfiguredObjectRecord object = binding.entryToObject(value);
configuredObjectsRecords.put(id, object);
}
};
new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor);
return configuredObjectsRecords;
}
use of com.sleepycat.je.Database 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());
}
use of com.sleepycat.je.Database 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.Database 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.Database in project qpid-broker-j by apache.
the class UpgraderTest method assertContent.
private void assertContent() {
final ByteBufferBinding contentBinding = ByteBufferBinding.getInstance();
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);
QpidByteBuffer content = contentBinding.entryToObject(value);
assertNotNull("Unexpected content", content);
assertTrue("Expected content", content.hasRemaining());
}
};
new DatabaseTemplate(_environment, "MESSAGE_CONTENT", null).run(contentCursorOperation);
}
Aggregations