Search in sources :

Example 16 with IByteArrayKeyValueDatabase

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

the class AccessWithExceptionTest method testKeysWithClosedDatabase.

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

Example 17 with IByteArrayKeyValueDatabase

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

the class AccessWithExceptionTest method testIsEmptyWithClosedDatabase.

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

Example 18 with IByteArrayKeyValueDatabase

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

the class AccessWithExceptionTest method testDeleteWithNullKey.

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

Example 19 with IByteArrayKeyValueDatabase

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

the class AccessWithExceptionTest method testSizeWithClosedDatabase.

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

Example 20 with IByteArrayKeyValueDatabase

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

the class DatabaseFactoryTest method testDriverReturnDatabase.

// It should return an instance of the DB given the correct properties
@Test
public void testDriverReturnDatabase() {
    Properties props = new Properties();
    props.setProperty("db_name", dbName + DatabaseTestUtils.getNext());
    props.setProperty("db_path", dbPath);
    // MOCKDB
    props.setProperty("db_type", DBVendor.MOCKDB.toValue());
    IByteArrayKeyValueDatabase db = DatabaseFactory.connect(props);
    // System.out.println(db.getClass().getName());
    assertNotNull(db);
    // LEVELDB
    props.setProperty("db_type", DBVendor.LEVELDB.toValue());
    props.setProperty(DatabaseFactory.PROP_MAX_FD_ALLOC, String.valueOf(LevelDBConstants.MAX_OPEN_FILES));
    props.setProperty(DatabaseFactory.PROP_BLOCK_SIZE, String.valueOf(LevelDBConstants.BLOCK_SIZE));
    props.setProperty(DatabaseFactory.PROP_WRITE_BUFFER_SIZE, String.valueOf(LevelDBConstants.WRITE_BUFFER_SIZE));
    props.setProperty(DatabaseFactory.PROP_CACHE_SIZE, String.valueOf(LevelDBConstants.CACHE_SIZE));
    db = DatabaseFactory.connect(props);
    // System.out.println(db.getClass().getName());
    assertNotNull(db);
    // H2
    props.setProperty("db_type", DBVendor.H2.toValue());
    db = DatabaseFactory.connect(props);
    // System.out.println(db.getClass().getName());
    assertNotNull(db);
    // MockDBDriver class
    props.setProperty("db_type", MockDBDriver.class.getName());
    db = DatabaseFactory.connect(props);
    // System.out.println(db.getClass().getName());
    assertNotNull(db);
}
Also used : IByteArrayKeyValueDatabase(org.aion.base.db.IByteArrayKeyValueDatabase) MockDBDriver(org.aion.db.impl.mockdb.MockDBDriver) Properties(java.util.Properties) 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