Search in sources :

Example 1 with IByteArrayKeyValueDatabase

use of org.aion.base.db.IByteArrayKeyValueDatabase in project aion by aionnetwork.

the class AccessWithExceptionTest method testGetWithNullKey.

@Test(expected = IllegalArgumentException.class)
@Parameters(method = "databaseInstanceDefinitions")
public void testGetWithNullKey(Properties dbDef) {
    // create database
    dbDef.setProperty("db_name", DatabaseTestUtils.dbName + DatabaseTestUtils.getNext());
    IByteArrayKeyValueDatabase db = DatabaseFactory.connect(dbDef);
    assertThat(db.open()).isTrue();
    // attempt get with null key
    db.get(null);
}
Also used : IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 2 with IByteArrayKeyValueDatabase

use of org.aion.base.db.IByteArrayKeyValueDatabase in project aion by aionnetwork.

the class AccessWithExceptionTest method testCommitWithClosedDatabase.

@Test(expected = RuntimeException.class)
@Parameters(method = "databaseInstanceDefinitions")
public void testCommitWithClosedDatabase(Properties dbDef) {
    // create database
    dbDef.setProperty("db_name", DatabaseTestUtils.dbName + DatabaseTestUtils.getNext());
    IByteArrayKeyValueDatabase db = DatabaseFactory.connect(dbDef);
    assertThat(db.isOpen()).isFalse();
    // TODO: differentiate between not supported and closed
    // attempt commit on closed db
    db.commit();
}
Also used : IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 3 with IByteArrayKeyValueDatabase

use of org.aion.base.db.IByteArrayKeyValueDatabase in project aion by aionnetwork.

the class ConcurrencyTest method testConcurrentAccessOnOpenDatabase.

@Test
@Parameters(method = "databaseInstanceDefinitions")
public void testConcurrentAccessOnOpenDatabase(Properties dbDef) throws InterruptedException {
    dbDef.setProperty("db_name", DatabaseTestUtils.dbName + getNext());
    // open database
    IByteArrayKeyValueDatabase db = DatabaseFactory.connect(dbDef);
    assertThat(db.open()).isTrue();
    // create distinct threads with
    List<Runnable> threads = new ArrayList<>();
    int threadSetCount = CONCURRENT_THREADS / 8;
    if (threadSetCount < 3) {
        threadSetCount = 3;
    }
    for (int i = 0; i < threadSetCount; i++) {
        // 1. thread that checks empty
        addThread4IsEmpty(threads, db);
        // 2. thread that gets keys
        addThread4Keys(threads, db);
        String keyStr = "key-" + i + ".";
        // 3. thread that gets entry
        addThread4Get(threads, db, keyStr);
        // 4. thread that puts entry
        addThread4Put(threads, db, keyStr);
        // 5. thread that deletes entry
        addThread4Delete(threads, db, keyStr);
        // 6. thread that puts entries
        addThread4PutBatch(threads, db, keyStr);
        // 7. thread that deletes entry
        addThread4DeleteBatch(threads, db, keyStr);
        // 8. thread that checks size
        addThread4Size(threads, db);
    }
    // run threads and check for exceptions
    assertConcurrent("Testing concurrent access. ", threads, TIME_OUT);
    // check that db is unlocked after updates
    assertThat(db.isLocked()).isFalse();
    // ensuring close
    db.close();
    assertThat(db.isClosed()).isTrue();
}
Also used : IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 4 with IByteArrayKeyValueDatabase

use of org.aion.base.db.IByteArrayKeyValueDatabase in project aion by aionnetwork.

the class ConcurrencyTest method testConcurrentPutBatch.

@Test
@Parameters(method = "databaseInstanceDefinitions")
public void testConcurrentPutBatch(Properties dbDef) throws InterruptedException {
    dbDef.setProperty("db_name", DatabaseTestUtils.dbName + getNext());
    IByteArrayKeyValueDatabase db = DatabaseFactory.connect(dbDef);
    assertThat(db.open()).isTrue();
    // create distinct threads with
    List<Runnable> threads = new ArrayList<>();
    for (int i = 0; i < CONCURRENT_THREADS; i++) {
        addThread4PutBatch(threads, db, "key-" + i);
    }
    // run threads
    assertConcurrent("Testing putBatch(...) ", threads, TIME_OUT);
    // check that all values were added
    assertThat(db.keys().size()).isEqualTo(3 * CONCURRENT_THREADS);
    // ensuring close
    db.close();
    assertThat(db.isClosed()).isTrue();
}
Also used : IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 5 with IByteArrayKeyValueDatabase

use of org.aion.base.db.IByteArrayKeyValueDatabase in project aion by aionnetwork.

the class ConcurrencyTest method testConcurrentUpdate.

@Test
@Parameters(method = "databaseInstanceDefinitions")
public void testConcurrentUpdate(Properties dbDef) throws InterruptedException {
    dbDef.setProperty("db_name", DatabaseTestUtils.dbName + getNext());
    // open database
    IByteArrayKeyValueDatabase db = DatabaseFactory.connect(dbDef);
    assertThat(db.open()).isTrue();
    // create distinct threads with
    List<Runnable> threads = new ArrayList<>();
    int threadSetCount = CONCURRENT_THREADS / 4;
    if (threadSetCount < 3) {
        threadSetCount = 3;
    }
    for (int i = 0; i < threadSetCount; i++) {
        String keyStr = "key-" + i + ".";
        // 1. thread that puts entry
        addThread4Put(threads, db, keyStr);
        // 2. thread that deletes entry
        addThread4Delete(threads, db, keyStr);
        // 3. thread that puts entries
        addThread4PutBatch(threads, db, keyStr);
        // 4. thread that deletes entry
        addThread4DeleteBatch(threads, db, keyStr);
    }
    // run threads and check for exceptions
    assertConcurrent("Testing concurrent updates. ", threads, TIME_OUT);
    // check that db is unlocked after updates
    assertThat(db.isLocked()).isFalse();
    // ensuring close
    db.close();
    assertThat(db.isClosed()).isTrue();
}
Also used : IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)26 Test (org.junit.Test)24 Parameters (junitparams.Parameters)18 ArrayList (java.util.ArrayList)3 ImportResult (org.aion.mcf.core.ImportResult)3 TrieImpl (org.aion.mcf.trie.TrieImpl)3 AionBlock (org.aion.zero.impl.types.AionBlock)3 HashMap (java.util.HashMap)2 Address (org.aion.base.type.Address)2 DataWord (org.aion.mcf.vm.types.DataWord)2 AionContractDetailsImpl (org.aion.zero.db.AionContractDetailsImpl)2 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)2 Properties (java.util.Properties)1 IContractDetails (org.aion.base.db.IContractDetails)1 MockDBDriver (org.aion.db.impl.mockdb.MockDBDriver)1