use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.
the class DefaultConfig method blockStore.
@Bean
public BlockStore blockStore(RskSystemProperties config) {
String database = config.databaseDir();
File blockIndexDirectory = new File(database + "/blocks/");
File dbFile = new File(blockIndexDirectory, "index");
if (!blockIndexDirectory.exists()) {
boolean mkdirsSuccess = blockIndexDirectory.mkdirs();
if (!mkdirsSuccess) {
logger.error("Unable to create blocks directory: {}", blockIndexDirectory);
}
}
DB indexDB = DBMaker.fileDB(dbFile).closeOnJvmShutdown().make();
Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = indexDB.hashMapCreate("index").keySerializer(Serializer.LONG).valueSerializer(BLOCK_INFO_SERIALIZER).counterEnable().makeOrGet();
KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
blocksDB.init();
IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
return indexedBlockStore;
}
use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.
the class DataSourcePoolTest method openUseAndCloseDataSource.
@Test
public void openUseAndCloseDataSource() {
KeyValueDataSource dataSource = DataSourcePool.levelDbByName(config, "test2");
dataSource.put(new byte[] { 0x01 }, new byte[] { 0x02 });
dataSource.close();
KeyValueDataSource dataSource2 = DataSourcePool.levelDbByName(config, "test2");
byte[] result = dataSource2.get(new byte[] { 0x01 });
Assert.assertNotNull(result);
Assert.assertEquals(1, result.length);
Assert.assertEquals(0x02, result[0]);
dataSource2.close();
}
use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.
the class DataSourcePoolTest method openAndCloseDataSource.
@Test
public void openAndCloseDataSource() {
KeyValueDataSource dataSource = DataSourcePool.levelDbByName(config, "test1");
dataSource.close();
}
use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.
the class HashMapDBTest method getUnknownKeyValue.
@Test
public void getUnknownKeyValue() {
KeyValueDataSource ds = new HashMapDB();
byte[] key = new byte[] { 0x01, 0x02 };
byte[] result = ds.get(key);
Assert.assertNull(result);
}
use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.
the class HashMapDBTest method putAndGetKeyValue.
@Test
public void putAndGetKeyValue() {
KeyValueDataSource ds = new HashMapDB();
byte[] key = new byte[] { 0x01, 0x02 };
byte[] value = new byte[] { 0x03, 0x03 };
ds.put(key, value);
byte[] result = ds.get(key);
Assert.assertNotNull(result);
Assert.assertArrayEquals(value, result);
}
Aggregations