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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations