Search in sources :

Example 11 with Database

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();
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig) Test(org.junit.Test)

Example 12 with Database

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();
}
Also used : ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) Database(com.sleepycat.je.Database) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 13 with Database

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();
}
Also used : ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) Database(com.sleepycat.je.Database) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 14 with Database

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);
}
Also used : Database(com.sleepycat.je.Database) ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) EnvironmentFacade(org.apache.qpid.server.store.berkeleydb.EnvironmentFacade) DatabaseConfig(com.sleepycat.je.DatabaseConfig) Test(org.junit.Test)

Example 15 with Database

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);
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Database (com.sleepycat.je.Database)73 DatabaseEntry (com.sleepycat.je.DatabaseEntry)46 Transaction (com.sleepycat.je.Transaction)35 DatabaseConfig (com.sleepycat.je.DatabaseConfig)27 UUID (java.util.UUID)12 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)11 Environment (com.sleepycat.je.Environment)10 OperationStatus (com.sleepycat.je.OperationStatus)8 Cursor (com.sleepycat.je.Cursor)7 HashSet (java.util.HashSet)7 StoreException (org.apache.qpid.server.store.StoreException)7 HashMap (java.util.HashMap)6 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)5 File (java.io.File)5 ArrayList (java.util.ArrayList)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 Test (org.junit.Test)5 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)4