use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class DatabaseTemplateTest method testExecuteWithTwoDatabases.
@Test
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.Database in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method testCommitNoSyncWithoutCoalescing.
@Test
public void testCommitNoSyncWithoutCoalescing() throws Exception {
final ReplicatedEnvironmentConfiguration node1Config = createReplicatedEnvironmentConfiguration(TEST_NODE_NAME, TEST_NODE_HOST_PORT, true, true);
when(node1Config.getFacadeParameter(eq(String.class), eq(NO_SYNC_TX_DURABILITY_PROPERTY_NAME), anyString())).thenReturn("SYNC,NO_SYNC,NONE");
final ReplicatedEnvironmentFacade node1 = createNode(node1Config, TEST_NODE_NAME, State.MASTER);
final String replicaNodeHostPort = "localhost:" + _portHelper.getNextAvailable();
final String replicaName = TEST_NODE_NAME + 1;
final ReplicatedEnvironmentConfiguration node2Config = createReplicatedEnvironmentConfiguration(replicaName, replicaNodeHostPort, false, true);
when(node2Config.getFacadeParameter(eq(String.class), eq(NO_SYNC_TX_DURABILITY_PROPERTY_NAME), anyString())).thenReturn("NO_SYNC,NO_SYNC,NONE");
final ReplicatedEnvironmentFacade node2 = createNode(node2Config, replicaName, State.REPLICA);
try (final Database db = node1.openDatabase("mydb", createDatabaseConfig())) {
putRecord(node1, db, 1, "value", true);
}
node1.close();
node2.close();
LOGGER.debug("RESTARTING " + TEST_NODE_NAME);
final ReplicatedEnvironmentFacade node1Restarted = createNode(node1Config, TEST_NODE_NAME, State.MASTER);
LOGGER.debug("RESTARTING " + replicaName);
final ReplicatedEnvironmentFacade node2Restarted = createNode(node2Config, replicaName, State.REPLICA);
try (final Database db = node1Restarted.openDatabase("mydb", null)) {
assertEquals("value", getTestKeyValue(db, 1));
}
node1Restarted.close();
node2Restarted.close();
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method testCommitNoSyncWithCoalescing.
@Test
public void testCommitNoSyncWithCoalescing() throws Exception {
final ReplicatedEnvironmentConfiguration node1Config = createReplicatedEnvironmentConfiguration(TEST_NODE_NAME, TEST_NODE_HOST_PORT, true, false);
when(node1Config.getFacadeParameter(eq(String.class), eq(NO_SYNC_TX_DURABILITY_PROPERTY_NAME), anyString())).thenReturn("NO_SYNC,NO_SYNC,NONE");
final ReplicatedEnvironmentFacade node1 = createNode(node1Config, TEST_NODE_NAME, State.MASTER);
final String replicaNodeHostPort = "localhost:" + _portHelper.getNextAvailable();
final String replicaName = TEST_NODE_NAME + 1;
final ReplicatedEnvironmentConfiguration node2Config = createReplicatedEnvironmentConfiguration(replicaName, replicaNodeHostPort, false, false);
when(node2Config.getFacadeParameter(eq(String.class), eq(NO_SYNC_TX_DURABILITY_PROPERTY_NAME), anyString())).thenReturn("NO_SYNC,NO_SYNC,NONE");
final ReplicatedEnvironmentFacade node2 = createNode(node2Config, replicaName, State.REPLICA);
try (final Database db = node1.openDatabase("mydb", createDatabaseConfig())) {
putRecord(node1, db, 1, "value", true);
}
node2.close();
node1.close();
LOGGER.debug("RESTARTING " + TEST_NODE_NAME);
final ReplicatedEnvironmentFacade node1Restarted = createNode(node1Config, TEST_NODE_NAME, State.MASTER);
LOGGER.debug("RESTARTING " + replicaName);
final ReplicatedEnvironmentFacade node2Restarted = createNode(node2Config, replicaName, State.REPLICA);
try (final Database db = node1Restarted.openDatabase("mydb", null)) {
assertEquals("value", getTestKeyValue(db, 1));
}
node1Restarted.close();
node2Restarted.close();
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method testOpenDatabaseReusesCachedHandle.
@Test
public void testOpenDatabaseReusesCachedHandle() throws Exception {
DatabaseConfig createIfAbsentDbConfig = DatabaseConfig.DEFAULT.setAllowCreate(true);
EnvironmentFacade ef = createMaster();
Database handle1 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
assertNotNull(handle1);
Database handle2 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
assertSame("Database handle should be cached", handle1, handle2);
ef.closeDatabase("myDatabase");
Database handle3 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
assertNotSame("Expecting a new handle after database closure", handle1, handle3);
}
use of com.sleepycat.je.Database 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);
}
Aggregations