Search in sources :

Example 1 with MerkleTreeKeyExistException

use of com.jd.blockchain.ledger.merkletree.MerkleTreeKeyExistException in project jdchain-core by blockchain-jd-com.

the class MerkleSortTreeTest method testIdConfliction.

/**
 * 测试插入同一个 ID 的冲突表现是否符合预期;
 */
@Test
public void testIdConfliction() {
    TreeOptions options = createTreeOptions();
    MemoryKVStorage storage = new MemoryKVStorage();
    MerkleSortTree<byte[]> mst = MerkleSortTree.createBytesTree(options, DEFAULT_MKL_KEY_PREFIX, storage);
    // 验证空的迭代器;
    SkippingIterator<MerkleValue<byte[]>> iter = mst.bytesIterator();
    assertEquals(0, iter.getTotalCount());
    assertEquals(-1, iter.getCursor());
    assertFalse(iter.hasNext());
    assertNull(iter.next());
    // 加入数据,验证顺序数据插入的生成的迭代器;
    int count = 10;
    byte[][] datas = generateRandomData(count);
    long[] ids = generateSeqenceIDs(0, count);
    addDatasAndCommit(ids, datas, mst);
    ;
    // 预期默认的 MerkleSortedTree 实现下,写入相同 id 的数据会引发移除;
    MerkleTreeKeyExistException keyExistException = null;
    try {
        mst.set(8, datas[0]);
    } catch (MerkleTreeKeyExistException e) {
        keyExistException = e;
    }
    assertNotNull(keyExistException);
}
Also used : TreeOptions(com.jd.blockchain.ledger.merkletree.TreeOptions) MerkleTreeKeyExistException(com.jd.blockchain.ledger.merkletree.MerkleTreeKeyExistException) MemoryKVStorage(com.jd.blockchain.storage.service.utils.MemoryKVStorage) MerkleValue(com.jd.blockchain.ledger.merkletree.MerkleValue) Test(org.junit.Test)

Aggregations

MerkleTreeKeyExistException (com.jd.blockchain.ledger.merkletree.MerkleTreeKeyExistException)1 MerkleValue (com.jd.blockchain.ledger.merkletree.MerkleValue)1 TreeOptions (com.jd.blockchain.ledger.merkletree.TreeOptions)1 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)1 Test (org.junit.Test)1