Search in sources :

Example 51 with Transaction

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;
}
Also used : QueueEntryKey(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueEntryKey) Transaction(com.sleepycat.je.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) QueueEntryKeyBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueEntryKeyBinding) HashSet(java.util.HashSet)

Example 52 with Transaction

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();
}
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)

Example 53 with Transaction

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);
}
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) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) NewDataBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewDataBinding)

Example 54 with Transaction

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);
}
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) UpgradeConfiguredObjectRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.UpgradeConfiguredObjectRecord) NewQueueEntryKey(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewQueueEntryKey) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID) NewQueueEntryBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewQueueEntryBinding)

Example 55 with Transaction

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());
}
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) NewPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction) Database(com.sleepycat.je.Database) NewRecordImpl(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewRecordImpl) DatabaseEntry(com.sleepycat.je.DatabaseEntry) NewPreparedTransactionBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransactionBinding)

Aggregations

Transaction (com.sleepycat.je.Transaction)74 DatabaseEntry (com.sleepycat.je.DatabaseEntry)55 Database (com.sleepycat.je.Database)35 OperationStatus (com.sleepycat.je.OperationStatus)20 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 UUID (java.util.UUID)11 Cursor (com.sleepycat.je.Cursor)10 DatabaseConfig (com.sleepycat.je.DatabaseConfig)7 DatabaseException (com.sleepycat.je.DatabaseException)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Environment (com.sleepycat.je.Environment)5 HashMap (java.util.HashMap)5 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)5 NewPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction)5 OldPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)5 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)4 StoreException (org.apache.qpid.server.store.StoreException)4 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)3 LockMode (com.sleepycat.je.LockMode)3