Search in sources :

Example 1 with ByteArrayKeyValueDatabase

use of org.aion.db.impl.ByteArrayKeyValueDatabase in project aion by aionnetwork.

the class RocksDBDriverTest method testDriverReturnNull.

// It should return null if given bad vendor
@Test
public void testDriverReturnNull() {
    Properties props = new Properties();
    props.setProperty(Props.DB_TYPE, "BAD VENDOR");
    props.setProperty(Props.DB_NAME, dbName);
    props.setProperty(Props.DB_PATH, dbPath);
    ByteArrayKeyValueDatabase db = DatabaseFactory.connect(props, log);
    assertNull(db);
}
Also used : ByteArrayKeyValueDatabase(org.aion.db.impl.ByteArrayKeyValueDatabase) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with ByteArrayKeyValueDatabase

use of org.aion.db.impl.ByteArrayKeyValueDatabase in project aion by aionnetwork.

the class H2MVMapDriverTest method testDriverReturnNull.

// It should return null if given bad vendor
@Test
public void testDriverReturnNull() {
    Properties props = new Properties();
    props.setProperty(Props.DB_TYPE, "BAD VENDOR");
    props.setProperty(Props.DB_NAME, dbName);
    props.setProperty(Props.DB_PATH, dbPath);
    ByteArrayKeyValueDatabase db = DatabaseFactory.connect(props, log);
    assertNull(db);
}
Also used : ByteArrayKeyValueDatabase(org.aion.db.impl.ByteArrayKeyValueDatabase) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with ByteArrayKeyValueDatabase

use of org.aion.db.impl.ByteArrayKeyValueDatabase in project aion by aionnetwork.

the class H2MVMapDriverTest method testDriverReturnDatabase.

// It should return an instance of the DB given the correct properties
@Test
public void testDriverReturnDatabase() {
    Properties props = new Properties();
    props.setProperty(Props.DB_TYPE, dbVendor);
    props.setProperty(Props.DB_NAME, dbName);
    props.setProperty(Props.DB_PATH, dbPath);
    ByteArrayKeyValueDatabase db = DatabaseFactory.connect(props, log);
    assertNotNull(db);
}
Also used : ByteArrayKeyValueDatabase(org.aion.db.impl.ByteArrayKeyValueDatabase) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with ByteArrayKeyValueDatabase

use of org.aion.db.impl.ByteArrayKeyValueDatabase in project aion by aionnetwork.

the class AionRepositoryImpl method getReferencedTrieNodes.

/**
 * Retrieves nodes referenced by a trie node value, where the size of the result is bounded by
 * the given limit.
 *
 * @param value a trie node value which may be referencing other nodes
 * @param limit the maximum number of key-value pairs to be retrieved by this method, which
 *     limits the search in the trie; zero and negative values for the limit will result in no
 *     search and an empty map will be returned
 * @param dbType the database where the value was stored and further keys should be searched for
 * @return an empty map when the value does not reference other trie nodes or the given limit is
 *     invalid, or a map containing all the referenced nodes reached while keeping within the
 *     limit on the result size
 */
public Map<ByteArrayWrapper, byte[]> getReferencedTrieNodes(byte[] value, int limit, DatabaseType dbType) {
    if (limit <= 0) {
        return Collections.emptyMap();
    } else {
        ByteArrayKeyValueDatabase db = selectDatabase(dbType);
        Trie trie = new TrieImpl(db);
        return trie.getReferencedTrieNodes(value, limit);
    }
}
Also used : TrieImpl(org.aion.zero.impl.trie.TrieImpl) ByteArrayKeyValueDatabase(org.aion.db.impl.ByteArrayKeyValueDatabase) SecureTrie(org.aion.zero.impl.trie.SecureTrie) Trie(org.aion.zero.impl.trie.Trie)

Example 5 with ByteArrayKeyValueDatabase

use of org.aion.db.impl.ByteArrayKeyValueDatabase in project aion by aionnetwork.

the class AionRepositoryImpl method dropDatabasesExcept.

/**
 * Calls {@link ByteArrayKeyValueDatabase#drop()} on all the current databases except for the
 * ones given in the list by name.
 *
 * @param names the names of the databases that should not be dropped
 */
public void dropDatabasesExcept(List<String> names) {
    for (ByteArrayKeyValueDatabase db : databaseGroup) {
        if (!names.contains(db.getName().get())) {
            LOG.warn("Dropping database " + db.toString() + " ...");
            db.drop();
            LOG.warn(db.toString() + " successfully dropped and reopened.");
        }
    }
}
Also used : ByteArrayKeyValueDatabase(org.aion.db.impl.ByteArrayKeyValueDatabase)

Aggregations

ByteArrayKeyValueDatabase (org.aion.db.impl.ByteArrayKeyValueDatabase)20 Test (org.junit.Test)15 Properties (java.util.Properties)6 MockDB (org.aion.db.impl.mockdb.MockDB)6 AionAddress (org.aion.types.AionAddress)5 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)5 SecureTrie (org.aion.zero.impl.trie.SecureTrie)5 HashMap (java.util.HashMap)4 RLPElement (org.aion.rlp.RLPElement)4 RLPContractDetails (org.aion.zero.impl.db.DetailsDataStore.RLPContractDetails)4 Logger (org.slf4j.Logger)3 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)2 Block (org.aion.zero.impl.types.Block)2 MiningBlock (org.aion.zero.impl.types.MiningBlock)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AionTransaction (org.aion.base.AionTransaction)1 ImportResult (org.aion.zero.impl.core.ImportResult)1 AionBlockStore (org.aion.zero.impl.db.AionBlockStore)1 BlockInfo (org.aion.zero.impl.db.AionBlockStore.BlockInfo)1