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