Search in sources :

Example 1 with CompoundKeyBinding

use of org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKeyBinding 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();
}
Also used : NewPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction) OldPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction) Transaction(com.sleepycat.je.Transaction) CompoundKey(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKey) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) CompoundKeyBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKeyBinding)

Aggregations

Database (com.sleepycat.je.Database)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 Transaction (com.sleepycat.je.Transaction)1 CompoundKey (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKey)1 CompoundKeyBinding (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKeyBinding)1 NewPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction)1 OldPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)1