Search in sources :

Example 21 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class DatabaseTemplateTest method testExecuteWithTwoDatabases.

public void testExecuteWithTwoDatabases() {
    String targetDatabaseName = "targetDatabase";
    Database targetDatabase = mock(Database.class);
    Transaction txn = mock(Transaction.class);
    when(_environment.openDatabase(same(txn), same(targetDatabaseName), isA(DatabaseConfig.class))).thenReturn(targetDatabase);
    DatabaseTemplate databaseTemplate = new DatabaseTemplate(_environment, SOURCE_DATABASE, targetDatabaseName, txn);
    DatabaseRunnable databaseOperation = mock(DatabaseRunnable.class);
    databaseTemplate.run(databaseOperation);
    verify(databaseOperation).run(_sourceDatabase, targetDatabase, txn);
    verify(_sourceDatabase).close();
    verify(targetDatabase).close();
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 22 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class UpgradeFrom4to5Test method assertQueueHasOwner.

private void assertQueueHasOwner(String queueName, final String expectedOwner) {
    List<AMQShortString> durableSubNames = Collections.emptyList();
    final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
    final AtomicReference<String> actualOwner = new AtomicReference<String>();
    final AtomicBoolean foundQueue = new AtomicBoolean(false);
    CursorOperation queueNameCollector = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            QueueRecord record = binding.entryToObject(value);
            String queueName = record.getNameShortString().toString();
            if (queueName.equals(queueName)) {
                foundQueue.set(true);
                actualOwner.set(AMQShortString.toString(record.getOwner()));
            }
        }
    };
    new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);
    assertTrue("Could not find queue in database", foundQueue.get());
    assertEquals("Queue has unexpected owner", expectedOwner, actualOwner.get());
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AtomicReference(java.util.concurrent.atomic.AtomicReference) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(com.sleepycat.je.Transaction) QueueRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueRecord) Database(com.sleepycat.je.Database)

Example 23 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class UpgradeFrom4to5Test method assertQueues.

private void assertQueues(Set<String> expectedQueueNames) {
    List<AMQShortString> durableSubNames = Collections.emptyList();
    final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
    final Set<String> actualQueueNames = new HashSet<String>();
    CursorOperation queueNameCollector = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            QueueRecord record = binding.entryToObject(value);
            String queueName = record.getNameShortString().toString();
            actualQueueNames.add(queueName);
        }
    };
    new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);
    assertEquals("Unexpected queue names", expectedQueueNames, actualQueueNames);
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Transaction(com.sleepycat.je.Transaction) QueueRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueRecord) Database(com.sleepycat.je.Database) HashSet(java.util.HashSet)

Example 24 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class UpgradeFrom4to5Test method assertContent.

private void assertContent() {
    final UpgradeFrom4To5.ContentBinding contentBinding = new UpgradeFrom4To5.ContentBinding();
    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);
            ByteBuffer content = contentBinding.entryToObject(value);
            assertNotNull("Unexpected content", content);
        }
    };
    new DatabaseTemplate(_environment, MESSAGE_CONTENT_DB_NAME, null).run(contentCursorOperation);
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) ByteBuffer(java.nio.ByteBuffer)

Example 25 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class UpgradeFrom5To6Test method populateOldXidEntries.

private void populateOldXidEntries(Environment environment) {
    final DatabaseEntry value = new DatabaseEntry();
    OldRecordImpl[] enqueues = { new OldRecordImpl("TEST1", 1) };
    OldRecordImpl[] dequeues = { new OldRecordImpl("TEST2", 2) };
    OldPreparedTransaction oldPreparedTransaction = new OldPreparedTransaction(enqueues, dequeues);
    OldPreparedTransactionBinding oldPreparedTransactionBinding = new OldPreparedTransactionBinding();
    oldPreparedTransactionBinding.objectToEntry(oldPreparedTransaction, value);
    final DatabaseEntry key = getXidKey();
    new DatabaseTemplate(environment, OLD_XID_DB_NAME, null).run(new DatabaseRunnable() {

        @Override
        public void run(Database xidDatabase, Database nullDatabase, Transaction transaction) {
            xidDatabase.put(null, key, value);
        }
    });
}
Also used : OldPreparedTransactionBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransactionBinding) 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) OldRecordImpl(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldRecordImpl) DatabaseEntry(com.sleepycat.je.DatabaseEntry) OldPreparedTransaction(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)

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