Search in sources :

Example 36 with Parameters

use of junitparams.Parameters in project aion by aionnetwork.

the class TrieTest method testInsertUpdateDeleteGet.

/**
 * Tests correct retrieval using {@link TrieImpl#get(String)} after an
 * initial insert with {@link TrieImpl#update(String, String)} and after a
 * sequential update using {@link TrieImpl#update(String, String)}. Uses
 * diverse combinations of keys and values from
 * {@link #keyValue1Value2Parameters()}.
 */
@Test
@Parameters(method = "keyValue1Value2Parameters")
public void testInsertUpdateDeleteGet(String key, String value1, String value2) {
    // create a new trie object without database
    TrieImpl trie = new TrieImpl(null);
    // -------------------------------------------------------------------------------------------------------------
    // insert (key,value1) pair into the trie
    trie.update(key, value1);
    // ensure the correct value is retrieved
    assertThat(value1).isEqualTo(new String(trie.get(key)));
    // -------------------------------------------------------------------------------------------------------------
    // update to (key,value2)
    trie.update(key, value2);
    // ensure correct value retrieval after update
    assertThat(value2).isEqualTo(new String(trie.get(key)));
    // -------------------------------------------------------------------------------------------------------------
    // delete (key,value2)
    trie.update(key, "");
    // ensure correct value retrieval after update
    assertThat(value1).isNotEqualTo(new String(trie.get(key)));
    assertThat(value2).isNotEqualTo(new String(trie.get(key)));
}
Also used : TrieImpl(org.aion.mcf.trie.TrieImpl) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 37 with Parameters

use of junitparams.Parameters in project aion by aionnetwork.

the class TrieTest method testDeleteAll.

/**
 * @param pairs
 * @implNote By design the keys are distinct due to the use of HashMap.
 */
@Test
@Parameters(method = "keyValuePairsParameters")
public void testDeleteAll(HashMap<String, String> pairs) {
    boolean print = false;
    if (print) {
        System.out.println("Number of pairs = " + pairs.size());
    }
    TrieImpl trie = new TrieImpl(new MockDB("TestDeleteAll"));
    // empty at start
    assertThat(Hex.toHexString(trie.getRootHash())).isEqualTo(ROOT_HASH_EMPTY);
    String key, value;
    for (Map.Entry<String, String> entry : pairs.entrySet()) {
        key = entry.getKey();
        value = entry.getValue();
        if (print) {
            System.out.println("(" + key + "," + value + ")");
        }
        // insert (key,value)
        trie.update(key, value);
    }
    // not empty after inserts
    assertThat(Hex.toHexString(trie.getRootHash())).isNotEqualTo(ROOT_HASH_EMPTY);
    // ensure that everything is still there
    for (String deleteKey : pairs.keySet()) {
        trie.delete(deleteKey);
    }
    // empty at end
    assertThat(Hex.toHexString(trie.getRootHash())).isEqualTo(ROOT_HASH_EMPTY);
}
Also used : TrieImpl(org.aion.mcf.trie.TrieImpl) MockDB(org.aion.db.impl.mockdb.MockDB) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 38 with Parameters

use of junitparams.Parameters 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 39 with Parameters

use of junitparams.Parameters 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 40 with Parameters

use of junitparams.Parameters 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)

Aggregations

Parameters (junitparams.Parameters)311 Test (org.junit.Test)311 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 DescriptorSet (com.spotify.protoman.descriptor.DescriptorSet)43 ValidationViolation (com.spotify.protoman.validation.ValidationViolation)43 SerializableRunnableIF (org.apache.geode.test.dunit.SerializableRunnableIF)41 QueryDataSource (org.apache.druid.query.QueryDataSource)30 TableDataSource (org.apache.druid.query.TableDataSource)30 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)26 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)26 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)24 Method (java.lang.reflect.Method)19 LookupDataSource (org.apache.druid.query.LookupDataSource)19 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)18 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)17 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)13 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)12 Owner (org.candlepin.model.Owner)12 Product (org.candlepin.model.Product)12 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)11